@lodestar/beacon-node 1.52.0-dev.3d90162721 → 1.52.0-dev.4996a91d93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/blocks/index.js +46 -26
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/pool/index.js +3 -1
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/utils.js +2 -1
- package/lib/api/impl/beacon/state/utils.js.map +1 -1
- package/lib/api/impl/debug/index.d.ts.map +1 -1
- package/lib/api/impl/debug/index.js +6 -2
- package/lib/api/impl/debug/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +1 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.d.ts +4 -0
- package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.js +4 -0
- package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +9 -3
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/blocks/index.d.ts.map +1 -1
- package/lib/chain/blocks/index.js +3 -17
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/chain.d.ts +6 -5
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +62 -20
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +3 -2
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -1
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- package/lib/chain/interface.d.ts +1 -1
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/opPools/opPool.js +6 -6
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/seenCache/seenAttesters.d.ts +1 -0
- package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
- package/lib/chain/seenCache/seenAttesters.js +1 -1
- package/lib/chain/seenCache/seenAttesters.js.map +1 -1
- package/lib/chain/seenCache/seenBlockAttesters.d.ts +8 -2
- package/lib/chain/seenCache/seenBlockAttesters.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockAttesters.js +43 -6
- package/lib/chain/seenCache/seenBlockAttesters.js.map +1 -1
- package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
- package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
- package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
- package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +30 -40
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.js +9 -0
- package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
- package/lib/chain/validatorMonitor.js +43 -43
- package/lib/chain/validatorMonitor.js.map +1 -1
- package/lib/network/gossip/topic.d.ts +1 -7
- package/lib/network/gossip/topic.d.ts.map +1 -1
- package/lib/network/gossip/topic.js +0 -13
- package/lib/network/gossip/topic.js.map +1 -1
- package/lib/network/network.d.ts +1 -0
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +20 -11
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +17 -4
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +4 -1
- package/lib/network/processor/gossipValidatorFn.js.map +1 -1
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +4 -2
- package/lib/network/processor/index.js.map +1 -1
- package/lib/network/reqresp/utils/collect.d.ts +4 -4
- package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
- package/lib/network/reqresp/utils/collect.js +9 -8
- package/lib/network/reqresp/utils/collect.js.map +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
- package/lib/sync/range/batch.d.ts +6 -0
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +17 -0
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +8 -1
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +43 -3
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/types.d.ts +12 -1
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js +2 -0
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +27 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +217 -21
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +14 -1
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +12 -2
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +2 -0
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/package.json +17 -17
- package/src/api/impl/beacon/blocks/index.ts +52 -28
- package/src/api/impl/beacon/pool/index.ts +9 -7
- package/src/api/impl/beacon/state/utils.ts +2 -1
- package/src/api/impl/debug/index.ts +6 -2
- package/src/api/impl/validator/index.ts +1 -2
- package/src/chain/ColumnReconstructionTracker.ts +5 -0
- package/src/chain/blocks/importExecutionPayload.ts +9 -2
- package/src/chain/blocks/index.ts +3 -31
- package/src/chain/chain.ts +95 -37
- package/src/chain/errors/executionPayloadBid.ts +3 -2
- package/src/chain/interface.ts +1 -1
- package/src/chain/opPools/opPool.ts +6 -6
- package/src/chain/seenCache/seenAttesters.ts +1 -1
- package/src/chain/seenCache/seenBlockAttesters.ts +48 -6
- package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
- package/src/chain/validation/executionPayloadBid.ts +40 -42
- package/src/chain/validation/payloadAttestationMessage.ts +10 -0
- package/src/chain/validatorMonitor.ts +43 -43
- package/src/network/gossip/topic.ts +1 -14
- package/src/network/network.ts +33 -11
- package/src/network/processor/gossipHandlers.ts +23 -11
- package/src/network/processor/gossipValidatorFn.ts +4 -0
- package/src/network/processor/index.ts +7 -2
- package/src/network/reqresp/utils/collect.ts +16 -8
- package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
- package/src/sync/range/batch.ts +20 -0
- package/src/sync/range/chain.ts +8 -0
- package/src/sync/range/range.ts +56 -3
- package/src/sync/types.ts +11 -0
- package/src/sync/unknownBlock.ts +250 -21
- package/src/sync/utils/downloadByRange.ts +29 -3
- package/src/sync/utils/downloadByRoot.ts +2 -0
package/src/sync/range/range.ts
CHANGED
|
@@ -3,13 +3,20 @@ import {StrictEventEmitter} from "strict-event-emitter-types";
|
|
|
3
3
|
import {BeaconConfig} from "@lodestar/config";
|
|
4
4
|
import {IBeaconStateViewGloas, computeStartSlotAtEpoch, isStatePostGloas} from "@lodestar/state-transition";
|
|
5
5
|
import {Epoch, Status, fulu, ssz} from "@lodestar/types";
|
|
6
|
-
import {Logger, byteArrayEquals, prettyPrintIndices, toRootHex} from "@lodestar/utils";
|
|
6
|
+
import {Logger, byteArrayEquals, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
|
|
7
7
|
import {IBlockInput} from "../../chain/blocks/blockInput/types.js";
|
|
8
8
|
import {PayloadError, PayloadErrorCode} from "../../chain/blocks/importExecutionPayload.js";
|
|
9
9
|
import {AttestationImportOpt, ImportBlockOpts} from "../../chain/blocks/index.js";
|
|
10
10
|
import {assertLinearChainSegment} from "../../chain/blocks/utils/chainSegment.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
BlockError,
|
|
13
|
+
BlockErrorCode,
|
|
14
|
+
BlockGossipError,
|
|
15
|
+
DataColumnSidecarErrorCode,
|
|
16
|
+
DataColumnSidecarValidationError,
|
|
17
|
+
} from "../../chain/errors/index.js";
|
|
12
18
|
import {IBeaconChain} from "../../chain/index.js";
|
|
19
|
+
import {verifyBlockProposerSignature} from "../../chain/validation/block.js";
|
|
13
20
|
import {Metrics} from "../../metrics/index.js";
|
|
14
21
|
import {INetwork} from "../../network/index.js";
|
|
15
22
|
import {PeerIdStr} from "../../util/peerId.js";
|
|
@@ -291,7 +298,7 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
|
|
|
291
298
|
...requests,
|
|
292
299
|
});
|
|
293
300
|
const {responses, payloadEnvelopes: downloadedPayloadEnvelopes} = result;
|
|
294
|
-
const {blocks, payloadEnvelopes} = cacheByRangeResponses({
|
|
301
|
+
const {blocks, payloadEnvelopes, signatureMismatch} = cacheByRangeResponses({
|
|
295
302
|
cache: this.chain.seenBlockInputCache,
|
|
296
303
|
seenPayloadEnvelopeInputCache: this.chain.seenPayloadEnvelopeInputCache,
|
|
297
304
|
peerIdStr: peer.peerId,
|
|
@@ -304,6 +311,52 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
|
|
|
304
311
|
seenTimestampSec: Date.now() / 1000,
|
|
305
312
|
});
|
|
306
313
|
|
|
314
|
+
if (signatureMismatch !== null) {
|
|
315
|
+
const {blockInput, columnSidecar} = signatureMismatch;
|
|
316
|
+
const block = blockInput.getBlock();
|
|
317
|
+
let isValidBlockSignature: boolean | null = true;
|
|
318
|
+
try {
|
|
319
|
+
await verifyBlockProposerSignature(this.chain, block, blockInput.blockRootHex);
|
|
320
|
+
} catch (e) {
|
|
321
|
+
isValidBlockSignature =
|
|
322
|
+
e instanceof BlockGossipError && e.type.code === BlockErrorCode.PROPOSAL_SIGNATURE_INVALID ? false : null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (isValidBlockSignature) {
|
|
326
|
+
throw new DataColumnSidecarValidationError(
|
|
327
|
+
{
|
|
328
|
+
code: DataColumnSidecarErrorCode.INCORRECT_BLOCK,
|
|
329
|
+
slot: blockInput.slot,
|
|
330
|
+
columnIndex: columnSidecar.index,
|
|
331
|
+
expected: toHex(block.signature),
|
|
332
|
+
actual: toHex(columnSidecar.signedBlockHeader.signature),
|
|
333
|
+
},
|
|
334
|
+
"DataColumnSidecar header signature doesn't match block signature"
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Later downloads reuse a cached block, evict it and the other unverified blocks of a peer
|
|
339
|
+
// proven to serve invalid signatures
|
|
340
|
+
const blockPeer = isValidBlockSignature === false ? blockInput.getBlockSource().peerIdStr : undefined;
|
|
341
|
+
const cache = this.chain.seenBlockInputCache;
|
|
342
|
+
for (const b of blocks) {
|
|
343
|
+
const isSuspect = b === blockInput || (blockPeer !== undefined && b.getBlockSource().peerIdStr === blockPeer);
|
|
344
|
+
if (
|
|
345
|
+
isSuspect &&
|
|
346
|
+
cache.get(b.blockRootHex) === b &&
|
|
347
|
+
!cache.isVerifiedProposerSignature(b.slot, b.blockRootHex, b.getBlock().signature)
|
|
348
|
+
) {
|
|
349
|
+
cache.remove(b.blockRootHex);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
throw new DownloadByRangeError({
|
|
353
|
+
code: DownloadByRangeErrorCode.INVALID_CACHED_BLOCK,
|
|
354
|
+
slot: blockInput.slot,
|
|
355
|
+
blockRoot: blockInput.blockRootHex,
|
|
356
|
+
blockPeer,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
307
360
|
const segmentBlocks = blocks.filter((b) => b.hasBlock()).sort((a, b) => a.slot - b.slot);
|
|
308
361
|
const envelopeSlots = payloadEnvelopes
|
|
309
362
|
? Array.from(payloadEnvelopes.entries())
|
package/src/sync/types.ts
CHANGED
|
@@ -107,6 +107,8 @@ export enum DroppedItemReason {
|
|
|
107
107
|
invalidSignature = "invalid_signature",
|
|
108
108
|
/** an unexpected / unhandled error code led to removal */
|
|
109
109
|
unknown = "unknown",
|
|
110
|
+
/** a block waiting on its parent was evicted because the peer that gossiped it exceeded its byte budget */
|
|
111
|
+
peerBudget = "peer_budget",
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
export enum PendingPayloadInputStatus {
|
|
@@ -123,6 +125,12 @@ export type PendingBlockInput = {
|
|
|
123
125
|
timeAddedSec: number;
|
|
124
126
|
timeSyncedSec?: number;
|
|
125
127
|
peerIdStrings: Set<string>;
|
|
128
|
+
/** Peer that gossiped a block retained for unknown parent sync */
|
|
129
|
+
retainedBy?: string;
|
|
130
|
+
retainedBytes?: number;
|
|
131
|
+
failedDownloads?: number;
|
|
132
|
+
/** A failed download is not retried before this time */
|
|
133
|
+
retryAtMs?: number;
|
|
126
134
|
};
|
|
127
135
|
|
|
128
136
|
export type PendingRootHex = {
|
|
@@ -131,6 +139,9 @@ export type PendingRootHex = {
|
|
|
131
139
|
timeAddedSec: number;
|
|
132
140
|
timeSyncedSec?: number;
|
|
133
141
|
peerIdStrings: Set<string>;
|
|
142
|
+
failedDownloads?: number;
|
|
143
|
+
/** A failed download is not retried before this time */
|
|
144
|
+
retryAtMs?: number;
|
|
134
145
|
};
|
|
135
146
|
|
|
136
147
|
export type BlockInputSyncCacheItem = PendingBlockInput | PendingRootHex;
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -10,7 +10,12 @@ import {isBlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
|
|
|
10
10
|
import {BlockInputSource, IBlockInput} from "../chain/blocks/blockInput/types.js";
|
|
11
11
|
import {PayloadError, PayloadErrorCode} from "../chain/blocks/importExecutionPayload.js";
|
|
12
12
|
import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/payloadEnvelopeInput/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
BlockError,
|
|
15
|
+
BlockErrorCode,
|
|
16
|
+
ExecutionPayloadEnvelopeError,
|
|
17
|
+
ExecutionPayloadEnvelopeErrorCode,
|
|
18
|
+
} from "../chain/errors/index.js";
|
|
14
19
|
import {ChainEvent, ChainEventData, IBeaconChain} from "../chain/index.js";
|
|
15
20
|
import {validateGloasBlockDataColumnSidecars} from "../chain/validation/dataColumnSidecar.js";
|
|
16
21
|
import {validateGossipExecutionPayloadEnvelope} from "../chain/validation/executionPayloadEnvelope.js";
|
|
@@ -54,6 +59,15 @@ import {getRateLimitedUntilMs} from "./utils/rateLimit.js";
|
|
|
54
59
|
const MAX_ATTEMPTS_PER_BLOCK = 5;
|
|
55
60
|
const MAX_KNOWN_BAD_BLOCKS = 500;
|
|
56
61
|
const MAX_PENDING_BLOCKS = 100;
|
|
62
|
+
/**
|
|
63
|
+
* A failed download is retried after this delay, doubling per failure up to one slot.
|
|
64
|
+
*/
|
|
65
|
+
const DOWNLOAD_RETRY_BASE_MS = 1_000;
|
|
66
|
+
/**
|
|
67
|
+
* Requests per peer per window, half the BeaconBlocksByRoot quota peers enforce, they disconnect a peer that exceeds it.
|
|
68
|
+
*/
|
|
69
|
+
const MAX_REQUESTS_PER_PEER = 64;
|
|
70
|
+
const REQUESTS_PER_PEER_WINDOW_MS = 10_000;
|
|
57
71
|
/**
|
|
58
72
|
* A pending payload without slot can only stay at most 2 epochs.
|
|
59
73
|
*/
|
|
@@ -127,6 +141,8 @@ export class BlockInputSync {
|
|
|
127
141
|
private subscribedToNetworkEvents = false;
|
|
128
142
|
private peerBalancer: UnknownBlockPeerBalancer;
|
|
129
143
|
private rateLimitBackoffTimeout: NodeJS.Timeout | undefined;
|
|
144
|
+
private downloadRetryTimeout: NodeJS.Timeout | undefined;
|
|
145
|
+
private downloadRetryAtMs: number | undefined;
|
|
130
146
|
/**
|
|
131
147
|
* Search unknown payload starting at PAYLOAD_DUE_BPS.
|
|
132
148
|
*/
|
|
@@ -178,6 +194,7 @@ export class BlockInputSync {
|
|
|
178
194
|
this.network.events.on(NetworkEvent.peerConnected, this.onPeerConnected);
|
|
179
195
|
this.network.events.on(NetworkEvent.peerDisconnected, this.onPeerDisconnected);
|
|
180
196
|
this.chain.clock.on(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
197
|
+
this.chain.clock.on(ClockEvent.slot, this.pruneUnresolvedBlocks);
|
|
181
198
|
|
|
182
199
|
// Seed the balancer with peers that connected before we subscribed
|
|
183
200
|
for (const peerId of this.network.getConnectedPeers()) {
|
|
@@ -198,7 +215,9 @@ export class BlockInputSync {
|
|
|
198
215
|
unsubscribeFromNetwork(): void {
|
|
199
216
|
this.logger.verbose("BlockInputSync disabled.");
|
|
200
217
|
this.clearRateLimitBackoffTimer();
|
|
218
|
+
this.clearDownloadRetryTimer();
|
|
201
219
|
this.chain.clock.off(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
220
|
+
this.chain.clock.off(ClockEvent.slot, this.pruneUnresolvedBlocks);
|
|
202
221
|
this.payloadPollAbortController?.abort();
|
|
203
222
|
this.payloadPollAbortController = undefined;
|
|
204
223
|
this.deferredPayloadRoots.clear();
|
|
@@ -346,6 +365,9 @@ export class BlockInputSync {
|
|
|
346
365
|
this.addByRootHex(missingDependency.rootHex, data.peer);
|
|
347
366
|
}
|
|
348
367
|
this.addByBlockInput(data.blockInput, data.peer);
|
|
368
|
+
if (data.source === BlockInputSource.gossip) {
|
|
369
|
+
this.limitRetainedBlocks(data.blockInput, data.peer);
|
|
370
|
+
}
|
|
349
371
|
this.triggerUnknownBlockSearch();
|
|
350
372
|
this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.UNKNOWN_PARENT});
|
|
351
373
|
this.metrics?.blockInputSync.source.inc({source: data.source});
|
|
@@ -376,7 +398,8 @@ export class BlockInputSync {
|
|
|
376
398
|
// because the payload at the finalized block is not finalized
|
|
377
399
|
const finalizedSlot = this.chain.forkChoice.getFinalizedBlock().slot;
|
|
378
400
|
const nowSec = Date.now() / 1000;
|
|
379
|
-
const
|
|
401
|
+
const slotDurationMs = this.config.getSlotDurationMs(this.config.getForkName(this.chain.clock.currentSlot));
|
|
402
|
+
const maxSecInCache = (PRUNE_UNRESOLVED_SLOT_EPOCHS * SLOTS_PER_EPOCH * slotDurationMs) / 1000;
|
|
380
403
|
|
|
381
404
|
let belowFinalizedPayloads = 0;
|
|
382
405
|
let agedOutPayloads = 0;
|
|
@@ -484,13 +507,7 @@ export class BlockInputSync {
|
|
|
484
507
|
pendingBlock.peerIdStrings.add(peerIdStr);
|
|
485
508
|
}
|
|
486
509
|
|
|
487
|
-
|
|
488
|
-
// Limit pending blocks to prevent DOS attacks that cause OOM
|
|
489
|
-
const prunedItemCount = pruneSetToMax(this.pendingBlocks, this.maxPendingBlocks);
|
|
490
|
-
if (prunedItemCount > 0) {
|
|
491
|
-
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.capacity}, prunedItemCount);
|
|
492
|
-
this.logger.verbose(`Pruned ${prunedItemCount} items from BlockInputSync.pendingBlocks`);
|
|
493
|
-
}
|
|
510
|
+
this.prunePendingBlocks();
|
|
494
511
|
return added;
|
|
495
512
|
};
|
|
496
513
|
|
|
@@ -526,15 +543,67 @@ export class BlockInputSync {
|
|
|
526
543
|
pendingBlock.peerIdStrings.add(peerIdStr);
|
|
527
544
|
}
|
|
528
545
|
|
|
529
|
-
|
|
530
|
-
// Limit pending blocks to prevent DOS attacks that cause OOM
|
|
531
|
-
const prunedItemCount = pruneSetToMax(this.pendingBlocks, this.maxPendingBlocks);
|
|
532
|
-
if (prunedItemCount > 0) {
|
|
533
|
-
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.capacity}, prunedItemCount);
|
|
534
|
-
this.logger.verbose(`Pruned ${prunedItemCount} items from BlockInputSync.pendingBlocks`);
|
|
535
|
-
}
|
|
546
|
+
this.prunePendingBlocks();
|
|
536
547
|
};
|
|
537
548
|
|
|
549
|
+
/**
|
|
550
|
+
* Limit pending blocks to prevent DOS attacks that cause OOM. Any gossip message with an unknown root adds a root-only
|
|
551
|
+
* entry before validation, so those nothing waits on are evicted before a block or a root a pending block waits on.
|
|
552
|
+
* A downloaded block is only checked against its root, so this only applies while blocks and the roots they wait on
|
|
553
|
+
* fill at most half the cap, otherwise they could pin it and evict every new root on insertion.
|
|
554
|
+
*/
|
|
555
|
+
private prunePendingBlocks(): void {
|
|
556
|
+
if (this.pendingBlocks.size <= this.maxPendingBlocks) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const awaitedRoots = new Set<RootHex>();
|
|
561
|
+
for (const pendingBlock of this.pendingBlocks.values()) {
|
|
562
|
+
if (isPendingBlockInput(pendingBlock)) {
|
|
563
|
+
awaitedRoots.add(pendingBlock.blockInput.parentRootHex);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const isKept = (rootHex: RootHex, pendingBlock: BlockInputSyncCacheItem): boolean =>
|
|
567
|
+
isPendingBlockInput(pendingBlock) || awaitedRoots.has(rootHex);
|
|
568
|
+
let keptCount = 0;
|
|
569
|
+
for (const [rootHex, pendingBlock] of this.pendingBlocks) {
|
|
570
|
+
if (isKept(rootHex, pendingBlock)) {
|
|
571
|
+
keptCount++;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
let prunedItemCount = 0;
|
|
576
|
+
if (keptCount <= this.maxPendingBlocks / 2) {
|
|
577
|
+
for (const [rootHex, pendingBlock] of this.pendingBlocks) {
|
|
578
|
+
if (this.pendingBlocks.size <= this.maxPendingBlocks) {
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
if (!isKept(rootHex, pendingBlock)) {
|
|
582
|
+
this.pendingBlocks.delete(rootHex);
|
|
583
|
+
prunedItemCount++;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
for (const [rootHex, pendingBlock] of this.pendingBlocks) {
|
|
588
|
+
if (this.pendingBlocks.size <= this.maxPendingBlocks) {
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
this.pendingBlocks.delete(rootHex);
|
|
592
|
+
prunedItemCount++;
|
|
593
|
+
// The block input cache is only trimmed on import, a block whose parent never resolves would stay there
|
|
594
|
+
if (
|
|
595
|
+
isPendingBlockInput(pendingBlock) &&
|
|
596
|
+
pendingBlock.status !== PendingBlockInputStatus.processing &&
|
|
597
|
+
this.getMissingBlockDependency(pendingBlock.blockInput).kind === "parentBlock"
|
|
598
|
+
) {
|
|
599
|
+
this.chain.seenBlockInputCache.remove(rootHex);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.capacity}, prunedItemCount);
|
|
604
|
+
this.logger.verbose(`Pruned ${prunedItemCount} items from BlockInputSync.pendingBlocks`);
|
|
605
|
+
}
|
|
606
|
+
|
|
538
607
|
private addByPayloadRootHex = (rootHex: RootHex, peerIdStr?: PeerIdStr, slot?: Slot): boolean => {
|
|
539
608
|
if (this.knownBadBlocks.has(rootHex)) {
|
|
540
609
|
this.logger.debug("Ignoring payload for known bad block root", {
|
|
@@ -665,6 +734,79 @@ export class BlockInputSync {
|
|
|
665
734
|
this.scheduleRateLimitBackoffRetry();
|
|
666
735
|
};
|
|
667
736
|
|
|
737
|
+
/**
|
|
738
|
+
* A peer can make us retain a signed block per validator key and slot until its parent resolves. Bound the bytes
|
|
739
|
+
* retained per peer, its oldest blocks still waiting on their parent are removed first.
|
|
740
|
+
*/
|
|
741
|
+
private limitRetainedBlocks(blockInput: IBlockInput, peerIdStr: PeerIdStr): void {
|
|
742
|
+
const pendingBlock = this.pendingBlocks.get(blockInput.blockRootHex);
|
|
743
|
+
if (pendingBlock === undefined || !isPendingBlockInput(pendingBlock) || pendingBlock.retainedBy !== undefined) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
pendingBlock.retainedBy = peerIdStr;
|
|
747
|
+
pendingBlock.retainedBytes = this.config
|
|
748
|
+
.getForkTypes(blockInput.slot)
|
|
749
|
+
.SignedBeaconBlock.value_serializedSize(blockInput.getBlock());
|
|
750
|
+
|
|
751
|
+
const retainedBlocks: PendingBlockInput[] = [];
|
|
752
|
+
let retainedBytes = 0;
|
|
753
|
+
for (const item of this.pendingBlocks.values()) {
|
|
754
|
+
if (isPendingBlockInput(item) && item.retainedBy === peerIdStr && this.isWaitingOnParent(item)) {
|
|
755
|
+
retainedBlocks.push(item);
|
|
756
|
+
retainedBytes += item.retainedBytes ?? 0;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
// One block of the max gossip size fits, honest blocks are far smaller
|
|
760
|
+
for (const item of retainedBlocks) {
|
|
761
|
+
if (retainedBytes <= this.config.MAX_PAYLOAD_SIZE) {
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
retainedBytes -= item.retainedBytes ?? 0;
|
|
765
|
+
this.removeUnresolvedBlock(item, DroppedItemReason.peerBudget);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Blocks are otherwise only pruned once finalization passes them, which never happens for a parent that does not resolve
|
|
771
|
+
*/
|
|
772
|
+
private pruneUnresolvedBlocks = (): void => {
|
|
773
|
+
const nowSec = Date.now() / 1000;
|
|
774
|
+
const slotDurationMs = this.config.getSlotDurationMs(this.config.getForkName(this.chain.clock.currentSlot));
|
|
775
|
+
const maxSecInCache = (PRUNE_UNRESOLVED_SLOT_EPOCHS * SLOTS_PER_EPOCH * slotDurationMs) / 1000;
|
|
776
|
+
for (const pendingBlock of this.pendingBlocks.values()) {
|
|
777
|
+
if (
|
|
778
|
+
isPendingBlockInput(pendingBlock) &&
|
|
779
|
+
nowSec - pendingBlock.timeAddedSec > maxSecInCache &&
|
|
780
|
+
this.isWaitingOnParent(pendingBlock)
|
|
781
|
+
) {
|
|
782
|
+
this.removeUnresolvedBlock(pendingBlock, DroppedItemReason.agedOut);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
private isWaitingOnParent(pendingBlock: PendingBlockInput): boolean {
|
|
788
|
+
if (pendingBlock.status === PendingBlockInputStatus.processing) {
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
const {kind} = this.getMissingBlockDependency(pendingBlock.blockInput);
|
|
792
|
+
return kind === "parentBlock" || kind === "parentPayload";
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Removes only the block itself, its descendants request it again by root and its claimed ancestors stay cached
|
|
797
|
+
*/
|
|
798
|
+
private removeUnresolvedBlock(pendingBlock: PendingBlockInput, reason: DroppedItemReason): void {
|
|
799
|
+
const rootHex = pendingBlock.blockInput.blockRootHex;
|
|
800
|
+
this.pendingBlocks.delete(rootHex);
|
|
801
|
+
this.chain.seenBlockInputCache.remove(rootHex);
|
|
802
|
+
this.metrics?.blockInputSync.removedBlocks.inc({reason});
|
|
803
|
+
this.logger.debug("Removed unresolved BlockInputSync block", {
|
|
804
|
+
slot: pendingBlock.blockInput.slot,
|
|
805
|
+
root: rootHex,
|
|
806
|
+
reason,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
668
810
|
/**
|
|
669
811
|
* Post-gloas, a locally complete block can still be blocked on its parent's execution payload lineage.
|
|
670
812
|
* Distinguish which dependency is missing so the scheduler can enqueue the right follow-up work.
|
|
@@ -813,8 +955,19 @@ export class BlockInputSync {
|
|
|
813
955
|
if (!hasConnectedPeers) {
|
|
814
956
|
this.logger.debug("No connected peers, skipping unknown block download.");
|
|
815
957
|
} else {
|
|
958
|
+
// Blocks and roots a pending block waits on are downloaded first, any gossip message with an unknown root adds
|
|
959
|
+
// another root, and they all share the per-peer request budget
|
|
960
|
+
const awaitedRoots = new Set<RootHex>();
|
|
961
|
+
for (const pendingBlock of this.pendingBlocks.values()) {
|
|
962
|
+
if (isPendingBlockInput(pendingBlock)) {
|
|
963
|
+
awaitedRoots.add(pendingBlock.blockInput.parentRootHex);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
const isAwaited = (block: BlockInputSyncCacheItem): boolean =>
|
|
967
|
+
isPendingBlockInput(block) || awaitedRoots.has(block.rootHex);
|
|
968
|
+
|
|
816
969
|
// Most of the time there is exactly 1 unknown block
|
|
817
|
-
for (const block of unknowns) {
|
|
970
|
+
for (const block of [...unknowns.filter(isAwaited), ...unknowns.filter((block) => !isAwaited(block))]) {
|
|
818
971
|
this.downloadBlock(block).catch((e) => {
|
|
819
972
|
this.logger.debug("Unexpected error - downloadBlock", {root: getBlockInputSyncCacheItemRootHex(block)}, e);
|
|
820
973
|
});
|
|
@@ -897,6 +1050,31 @@ export class BlockInputSync {
|
|
|
897
1050
|
}
|
|
898
1051
|
}
|
|
899
1052
|
|
|
1053
|
+
private scheduleDownloadRetry(retryAtMs: number): void {
|
|
1054
|
+
if (this.downloadRetryAtMs !== undefined && this.downloadRetryAtMs <= retryAtMs) {
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
this.clearDownloadRetryTimer();
|
|
1059
|
+
this.downloadRetryAtMs = retryAtMs;
|
|
1060
|
+
this.downloadRetryTimeout = setTimeout(
|
|
1061
|
+
() => {
|
|
1062
|
+
this.downloadRetryTimeout = undefined;
|
|
1063
|
+
this.downloadRetryAtMs = undefined;
|
|
1064
|
+
this.triggerUnknownBlockSearch();
|
|
1065
|
+
},
|
|
1066
|
+
Math.max(0, retryAtMs - Date.now())
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
private clearDownloadRetryTimer(): void {
|
|
1071
|
+
if (this.downloadRetryTimeout !== undefined) {
|
|
1072
|
+
clearTimeout(this.downloadRetryTimeout);
|
|
1073
|
+
this.downloadRetryTimeout = undefined;
|
|
1074
|
+
}
|
|
1075
|
+
this.downloadRetryAtMs = undefined;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
900
1078
|
/**
|
|
901
1079
|
* Start this slot's payload poll: end the previous slot's loop, move roots it never got to
|
|
902
1080
|
* into pendingPayloads, then poll from PAYLOAD_DUE to the end of the slot.
|
|
@@ -1018,6 +1196,10 @@ export class BlockInputSync {
|
|
|
1018
1196
|
if (block.status !== PendingBlockInputStatus.pending) {
|
|
1019
1197
|
return;
|
|
1020
1198
|
}
|
|
1199
|
+
if (block.retryAtMs !== undefined && block.retryAtMs > Date.now()) {
|
|
1200
|
+
this.scheduleDownloadRetry(block.retryAtMs);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1021
1203
|
|
|
1022
1204
|
const rootHex = getBlockInputSyncCacheItemRootHex(block);
|
|
1023
1205
|
const blockSlot = getBlockInputSyncCacheItemSlot(block);
|
|
@@ -1098,6 +1280,7 @@ export class BlockInputSync {
|
|
|
1098
1280
|
const pendingBlock = this.pendingBlocks.get(rootHex);
|
|
1099
1281
|
if (pendingBlock) {
|
|
1100
1282
|
pendingBlock.status = PendingBlockInputStatus.pending;
|
|
1283
|
+
pendingBlock.retryAtMs = res.err.retryAt;
|
|
1101
1284
|
}
|
|
1102
1285
|
this.logger.debug("Deferring unknown block download due to peer rate limit", logCtx, res.err);
|
|
1103
1286
|
if (!this.scheduleRateLimitBackoffRetry() || res.err.retryAt <= Date.now()) {
|
|
@@ -1111,8 +1294,19 @@ export class BlockInputSync {
|
|
|
1111
1294
|
this.metrics?.blockInputSync.downloadedBlocksError.inc();
|
|
1112
1295
|
this.logger.debug("Failed to download unknown block root, retained for retry", logCtx, res.err);
|
|
1113
1296
|
const pendingBlock = this.pendingBlocks.get(rootHex);
|
|
1114
|
-
|
|
1297
|
+
// A partial download replaces the entry with a pending one that does not carry the failure count
|
|
1298
|
+
if (
|
|
1299
|
+
pendingBlock &&
|
|
1300
|
+
(pendingBlock.status === PendingBlockInputStatus.fetching ||
|
|
1301
|
+
pendingBlock.status === PendingBlockInputStatus.pending)
|
|
1302
|
+
) {
|
|
1115
1303
|
pendingBlock.status = PendingBlockInputStatus.pending;
|
|
1304
|
+
// Not retried on every search, any gossip message with an unknown root triggers one
|
|
1305
|
+
pendingBlock.failedDownloads = (block.failedDownloads ?? 0) + 1;
|
|
1306
|
+
const slotDurationMs = this.config.getSlotDurationMs(this.config.getForkName(this.chain.clock.currentSlot));
|
|
1307
|
+
pendingBlock.retryAtMs =
|
|
1308
|
+
Date.now() + Math.min(DOWNLOAD_RETRY_BASE_MS * 2 ** (pendingBlock.failedDownloads - 1), slotDurationMs);
|
|
1309
|
+
this.scheduleDownloadRetry(pendingBlock.retryAtMs);
|
|
1116
1310
|
}
|
|
1117
1311
|
}
|
|
1118
1312
|
}
|
|
@@ -1304,7 +1498,7 @@ export class BlockInputSync {
|
|
|
1304
1498
|
const pendingPayloadByRoot: PendingPayloadRootHex = {
|
|
1305
1499
|
status: PendingPayloadInputStatus.pending,
|
|
1306
1500
|
rootHex,
|
|
1307
|
-
slot:
|
|
1501
|
+
slot: payloadInput.slot,
|
|
1308
1502
|
timeAddedSec: pendingPayload.timeAddedSec,
|
|
1309
1503
|
peerIdStrings: new Set(pendingPayload.peerIdStrings),
|
|
1310
1504
|
};
|
|
@@ -1670,6 +1864,27 @@ export class BlockInputSync {
|
|
|
1670
1864
|
} else {
|
|
1671
1865
|
excludedPeers.add(peerId);
|
|
1672
1866
|
}
|
|
1867
|
+
|
|
1868
|
+
if (e instanceof ExecutionPayloadEnvelopeError) {
|
|
1869
|
+
switch (e.type.code) {
|
|
1870
|
+
// Caused by local state, the downloaded envelope may still be valid
|
|
1871
|
+
case ExecutionPayloadEnvelopeErrorCode.BLOCK_ROOT_UNKNOWN:
|
|
1872
|
+
case ExecutionPayloadEnvelopeErrorCode.ENVELOPE_ALREADY_KNOWN:
|
|
1873
|
+
case ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING:
|
|
1874
|
+
case ExecutionPayloadEnvelopeErrorCode.UNKNOWN_BLOCK_STATE:
|
|
1875
|
+
break;
|
|
1876
|
+
// Every copy fails once the block is finalized, only a wrong slot makes the served copy invalid
|
|
1877
|
+
case ExecutionPayloadEnvelopeErrorCode.BELONG_TO_FINALIZED_BLOCK:
|
|
1878
|
+
if (envelope?.message.payload.slotNumber !== payloadInput?.slot) {
|
|
1879
|
+
envelope = payloadInput?.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
|
|
1880
|
+
}
|
|
1881
|
+
break;
|
|
1882
|
+
// The served copy is invalid, take the envelope from payloadInput or another peer on the next attempt
|
|
1883
|
+
default:
|
|
1884
|
+
envelope = payloadInput?.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
|
|
1885
|
+
break;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1673
1888
|
} finally {
|
|
1674
1889
|
this.peerBalancer.onRequestCompleted(peerId);
|
|
1675
1890
|
}
|
|
@@ -2050,11 +2265,13 @@ export class UnknownBlockPeerBalancer {
|
|
|
2050
2265
|
readonly peersMeta: Map<PeerIdStr, PeerSyncMeta>;
|
|
2051
2266
|
readonly activeRequests: Map<PeerIdStr, number>;
|
|
2052
2267
|
readonly rateLimitedUntilByPeer: Map<PeerIdStr, number>;
|
|
2268
|
+
readonly requestTimesByPeer: Map<PeerIdStr, number[]>;
|
|
2053
2269
|
|
|
2054
2270
|
constructor() {
|
|
2055
2271
|
this.peersMeta = new Map();
|
|
2056
2272
|
this.activeRequests = new Map();
|
|
2057
2273
|
this.rateLimitedUntilByPeer = new Map();
|
|
2274
|
+
this.requestTimesByPeer = new Map();
|
|
2058
2275
|
}
|
|
2059
2276
|
|
|
2060
2277
|
/** Trigger on each peer re-status */
|
|
@@ -2070,6 +2287,7 @@ export class UnknownBlockPeerBalancer {
|
|
|
2070
2287
|
this.peersMeta.delete(peerId);
|
|
2071
2288
|
this.activeRequests.delete(peerId);
|
|
2072
2289
|
this.rateLimitedUntilByPeer.delete(peerId);
|
|
2290
|
+
this.requestTimesByPeer.delete(peerId);
|
|
2073
2291
|
}
|
|
2074
2292
|
|
|
2075
2293
|
/** Reset all tracked peer state, e.g. when BlockInputSync unsubscribes from the network. */
|
|
@@ -2077,6 +2295,7 @@ export class UnknownBlockPeerBalancer {
|
|
|
2077
2295
|
this.peersMeta.clear();
|
|
2078
2296
|
this.activeRequests.clear();
|
|
2079
2297
|
this.rateLimitedUntilByPeer.clear();
|
|
2298
|
+
this.requestTimesByPeer.clear();
|
|
2080
2299
|
}
|
|
2081
2300
|
|
|
2082
2301
|
onRateLimited(peerId: PeerIdStr, rateLimitedUntilMs: number): void {
|
|
@@ -2143,7 +2362,7 @@ export class UnknownBlockPeerBalancer {
|
|
|
2143
2362
|
);
|
|
2144
2363
|
|
|
2145
2364
|
const bestPeerId = sortedEligiblePeers[0];
|
|
2146
|
-
this.onRequest(bestPeerId);
|
|
2365
|
+
this.onRequest(bestPeerId, now);
|
|
2147
2366
|
return this.peersMeta.get(bestPeerId) ?? null;
|
|
2148
2367
|
}
|
|
2149
2368
|
|
|
@@ -2151,8 +2370,18 @@ export class UnknownBlockPeerBalancer {
|
|
|
2151
2370
|
* Consumers don't need to call this method directly, it is called internally by bestPeer*() methods
|
|
2152
2371
|
* make this public for testing
|
|
2153
2372
|
*/
|
|
2154
|
-
onRequest(peerId: PeerIdStr): void {
|
|
2373
|
+
onRequest(peerId: PeerIdStr, now = Date.now()): void {
|
|
2155
2374
|
this.activeRequests.set(peerId, (this.activeRequests.get(peerId) ?? 0) + 1);
|
|
2375
|
+
|
|
2376
|
+
const requestTimes = (this.requestTimesByPeer.get(peerId) ?? []).filter(
|
|
2377
|
+
(time) => now - time < REQUESTS_PER_PEER_WINDOW_MS
|
|
2378
|
+
);
|
|
2379
|
+
requestTimes.push(now);
|
|
2380
|
+
this.requestTimesByPeer.set(peerId, requestTimes);
|
|
2381
|
+
if (requestTimes.length >= MAX_REQUESTS_PER_PEER) {
|
|
2382
|
+
const budgetUntilMs = requestTimes[0] + REQUESTS_PER_PEER_WINDOW_MS;
|
|
2383
|
+
this.onRateLimited(peerId, Math.max(this.rateLimitedUntilByPeer.get(peerId) ?? 0, budgetUntilMs));
|
|
2384
|
+
}
|
|
2156
2385
|
}
|
|
2157
2386
|
|
|
2158
2387
|
/**
|
|
@@ -121,7 +121,12 @@ export function cacheByRangeResponses({
|
|
|
121
121
|
parentPayload,
|
|
122
122
|
custodyConfig,
|
|
123
123
|
seenTimestampSec,
|
|
124
|
-
}: CacheByRangeResponsesProps): {
|
|
124
|
+
}: CacheByRangeResponsesProps): {
|
|
125
|
+
blocks: IBlockInput[];
|
|
126
|
+
payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null;
|
|
127
|
+
/** First fulu column whose header signature differs from its cached block, no later column is added */
|
|
128
|
+
signatureMismatch: {blockInput: IBlockInput; columnSidecar: fulu.DataColumnSidecar} | null;
|
|
129
|
+
} {
|
|
125
130
|
const source = BlockInputSource.byRange;
|
|
126
131
|
const updatedBatchBlocks = new Map<Slot, IBlockInput>(batchBlocks.map((block) => [block.slot, block]));
|
|
127
132
|
|
|
@@ -217,6 +222,7 @@ export function cacheByRangeResponses({
|
|
|
217
222
|
}
|
|
218
223
|
}
|
|
219
224
|
|
|
225
|
+
let signatureMismatch: {blockInput: IBlockInput; columnSidecar: fulu.DataColumnSidecar} | null = null;
|
|
220
226
|
for (const {blockRoot, columnSidecars} of responses.validatedColumnSidecars ?? []) {
|
|
221
227
|
const firstColumn = columnSidecars[0];
|
|
222
228
|
if (!firstColumn) {
|
|
@@ -264,6 +270,17 @@ export function cacheByRangeResponses({
|
|
|
264
270
|
actual: existing.type,
|
|
265
271
|
});
|
|
266
272
|
}
|
|
273
|
+
|
|
274
|
+
// Honest sidecars carry the block signature. The cached block may be unverified, the caller decides which side
|
|
275
|
+
// is invalid. A different root is reported by addColumn.
|
|
276
|
+
if (
|
|
277
|
+
existing.blockRootHex === blockRootHex &&
|
|
278
|
+
!byteArrayEquals(existing.getBlock().signature, fuluColumns[0].signedBlockHeader.signature)
|
|
279
|
+
) {
|
|
280
|
+
signatureMismatch = {blockInput: existing, columnSidecar: fuluColumns[0]};
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
|
|
267
284
|
for (const columnSidecar of fuluColumns) {
|
|
268
285
|
// will throw if root hex does not match (meaning we are following the wrong chain)
|
|
269
286
|
existing.addColumn(
|
|
@@ -279,7 +296,7 @@ export function cacheByRangeResponses({
|
|
|
279
296
|
}
|
|
280
297
|
}
|
|
281
298
|
|
|
282
|
-
return {blocks: Array.from(updatedBatchBlocks.values()), payloadEnvelopes};
|
|
299
|
+
return {blocks: Array.from(updatedBatchBlocks.values()), payloadEnvelopes, signatureMismatch};
|
|
283
300
|
}
|
|
284
301
|
|
|
285
302
|
export async function downloadByRange({
|
|
@@ -895,7 +912,7 @@ export async function validateColumnsByRangeResponse(
|
|
|
895
912
|
peerDasMetrics
|
|
896
913
|
)
|
|
897
914
|
: validateFuluBlockDataColumnSidecars(
|
|
898
|
-
null, //
|
|
915
|
+
null, // skip BLS, cacheByRangeResponses matches the header signature against the block
|
|
899
916
|
slot,
|
|
900
917
|
blockRoot,
|
|
901
918
|
blobCount,
|
|
@@ -1009,6 +1026,8 @@ export enum DownloadByRangeErrorCode {
|
|
|
1009
1026
|
|
|
1010
1027
|
/** Block segment + envelopes failed chain-segment linearity / FULL-chain checks */
|
|
1011
1028
|
INVALID_CHAIN_SEGMENT = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CHAIN_SEGMENT",
|
|
1029
|
+
/** A column header signature differs from a cached block whose proposer signature is invalid or unverifiable */
|
|
1030
|
+
INVALID_CACHED_BLOCK = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CACHED_BLOCK",
|
|
1012
1031
|
}
|
|
1013
1032
|
|
|
1014
1033
|
export type DownloadByRangeErrorType =
|
|
@@ -1105,6 +1124,13 @@ export type DownloadByRangeErrorType =
|
|
|
1105
1124
|
code: DownloadByRangeErrorCode.INVALID_CHAIN_SEGMENT;
|
|
1106
1125
|
slot: Slot;
|
|
1107
1126
|
reason: string;
|
|
1127
|
+
}
|
|
1128
|
+
| {
|
|
1129
|
+
code: DownloadByRangeErrorCode.INVALID_CACHED_BLOCK;
|
|
1130
|
+
slot: Slot;
|
|
1131
|
+
blockRoot: string;
|
|
1132
|
+
/** Set only when the block proposer signature is invalid */
|
|
1133
|
+
blockPeer?: PeerIdStr;
|
|
1108
1134
|
};
|
|
1109
1135
|
|
|
1110
1136
|
export class DownloadByRangeError extends LodestarError<DownloadByRangeErrorType> {}
|
|
@@ -165,6 +165,8 @@ export async function downloadByRoot({
|
|
|
165
165
|
timeSyncedSec,
|
|
166
166
|
timeAddedSec: cacheItem.timeAddedSec,
|
|
167
167
|
peerIdStrings: cacheItem.peerIdStrings,
|
|
168
|
+
retainedBy: isPendingBlockInput(cacheItem) ? cacheItem.retainedBy : undefined,
|
|
169
|
+
retainedBytes: isPendingBlockInput(cacheItem) ? cacheItem.retainedBytes : undefined,
|
|
168
170
|
},
|
|
169
171
|
warnings,
|
|
170
172
|
};
|