@lodestar/beacon-node 1.52.0-dev.f2144dd2ac → 1.52.0-dev.f343d455cc
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 +22 -8
- 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 +15 -8
- 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/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
- package/lib/chain/archiveStore/utils/pruneHistory.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 +71 -25
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/attestationError.d.ts +15 -1
- package/lib/chain/errors/attestationError.d.ts.map +1 -1
- package/lib/chain/errors/attestationError.js +8 -0
- package/lib/chain/errors/attestationError.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +6 -1
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -0
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.d.ts +55 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js +8 -0
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/interface.d.ts +1 -1
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/lightClient/index.d.ts +13 -6
- package/lib/chain/lightClient/index.d.ts.map +1 -1
- package/lib/chain/lightClient/index.js +95 -115
- package/lib/chain/lightClient/index.js.map +1 -1
- package/lib/chain/opPools/opPool.js +6 -6
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts +45 -0
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +265 -69
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +23 -15
- package/lib/chain/produceBlock/produceBlockBody.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/validation/aggregateAndProof.d.ts.map +1 -1
- package/lib/chain/validation/aggregateAndProof.js +24 -7
- package/lib/chain/validation/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +32 -16
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +9 -1
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +18 -31
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +100 -9
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.js +9 -0
- package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +39 -6
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/chain/validatorMonitor.js +43 -43
- package/lib/chain/validatorMonitor.js.map +1 -1
- package/lib/execution/engine/blockHash.d.ts +12 -0
- package/lib/execution/engine/blockHash.d.ts.map +1 -0
- package/lib/execution/engine/blockHash.js +17 -0
- package/lib/execution/engine/blockHash.js.map +1 -0
- package/lib/execution/engine/http.d.ts +2 -2
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +13 -7
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +16 -3
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/interface.js +11 -0
- package/lib/execution/engine/interface.js.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
- package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
- package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
- package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.js +4 -4
- package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +6 -6
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/payloadIdCache.d.ts +6 -1
- package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
- package/lib/execution/engine/payloadIdCache.js +7 -2
- package/lib/execution/engine/payloadIdCache.js.map +1 -1
- package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/restHttpClient.js +9 -5
- package/lib/execution/engine/restHttpClient.js.map +1 -1
- package/lib/execution/engine/restTransport.d.ts +2 -2
- package/lib/execution/engine/restTransport.d.ts.map +1 -1
- package/lib/execution/engine/restTransport.js +4 -4
- package/lib/execution/engine/restTransport.js.map +1 -1
- package/lib/execution/engine/signal.d.ts +6 -0
- package/lib/execution/engine/signal.d.ts.map +1 -0
- package/lib/execution/engine/signal.js +24 -0
- package/lib/execution/engine/signal.js.map +1 -0
- package/lib/execution/engine/transport.d.ts +2 -2
- package/lib/execution/engine/transport.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/beacon.d.ts +5 -0
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js +5 -0
- package/lib/metrics/metrics/beacon.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +1 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +5 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/events.d.ts +6 -2
- package/lib/network/core/events.d.ts.map +1 -1
- package/lib/network/core/events.js +9 -0
- package/lib/network/core/events.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +3 -2
- package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts +1 -0
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +5 -2
- package/lib/network/gossip/gossipsub.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.map +1 -1
- package/lib/network/network.js +6 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +22 -2
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
- package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.js +11 -2
- package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +19 -6
- package/lib/network/processor/gossipHandlers.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/handlers/dataColumnSidecarsByRange.js +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/sync/range/batch.d.ts +10 -0
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +29 -0
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/chain.d.ts +17 -2
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +60 -20
- 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 +44 -3
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/range/utils/batches.d.ts +20 -4
- package/lib/sync/range/utils/batches.d.ts.map +1 -1
- package/lib/sync/range/utils/batches.js +31 -13
- package/lib/sync/range/utils/batches.js.map +1 -1
- package/lib/sync/range/utils/peerBalancer.d.ts +1 -1
- package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -1
- package/lib/sync/range/utils/peerBalancer.js +5 -2
- package/lib/sync/range/utils/peerBalancer.js.map +1 -1
- package/lib/sync/types.d.ts +14 -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 +28 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +340 -27
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +22 -1
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +55 -25
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts +24 -2
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +48 -5
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/lib/util/asyncIterableToEvents.d.ts +20 -3
- package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
- package/lib/util/asyncIterableToEvents.js +76 -20
- package/lib/util/asyncIterableToEvents.js.map +1 -1
- package/lib/util/dataColumns.d.ts +1 -1
- package/lib/util/dataColumns.d.ts.map +1 -1
- package/lib/util/dataColumns.js +4 -1
- package/lib/util/dataColumns.js.map +1 -1
- package/lib/util/eventLoop.d.ts +3 -3
- package/lib/util/eventLoop.d.ts.map +1 -1
- package/lib/util/eventLoop.js +3 -3
- package/lib/util/eventLoop.js.map +1 -1
- package/package.json +27 -27
- package/src/api/impl/beacon/blocks/index.ts +24 -8
- 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 +17 -9
- package/src/chain/ColumnReconstructionTracker.ts +5 -0
- package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
- package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
- package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
- package/src/chain/blocks/importExecutionPayload.ts +9 -2
- package/src/chain/blocks/index.ts +3 -31
- package/src/chain/chain.ts +104 -42
- package/src/chain/errors/attestationError.ts +11 -1
- package/src/chain/errors/executionPayloadBid.ts +6 -0
- package/src/chain/errors/executionPayloadEnvelope.ts +58 -0
- package/src/chain/interface.ts +1 -1
- package/src/chain/lightClient/index.ts +108 -142
- package/src/chain/opPools/opPool.ts +6 -6
- package/src/chain/prepareNextSlot.ts +347 -89
- package/src/chain/produceBlock/produceBlockBody.ts +25 -16
- package/src/chain/seenCache/seenAttesters.ts +1 -1
- package/src/chain/seenCache/seenBlockAttesters.ts +48 -6
- package/src/chain/validation/aggregateAndProof.ts +24 -9
- package/src/chain/validation/attestation.ts +31 -20
- package/src/chain/validation/block.ts +9 -1
- package/src/chain/validation/executionPayloadBid.ts +21 -33
- package/src/chain/validation/executionPayloadEnvelope.ts +115 -8
- package/src/chain/validation/payloadAttestationMessage.ts +10 -0
- package/src/chain/validation/voluntaryExit.ts +44 -6
- package/src/chain/validatorMonitor.ts +43 -43
- package/src/execution/engine/blockHash.ts +27 -0
- package/src/execution/engine/http.ts +18 -10
- package/src/execution/engine/interface.ts +18 -3
- package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
- package/src/execution/engine/jsonRpcTransport.ts +8 -4
- package/src/execution/engine/mock.ts +13 -8
- package/src/execution/engine/payloadIdCache.ts +12 -4
- package/src/execution/engine/restHttpClient.ts +17 -11
- package/src/execution/engine/restTransport.ts +5 -4
- package/src/execution/engine/signal.ts +28 -0
- package/src/execution/engine/transport.ts +3 -2
- package/src/index.ts +6 -1
- package/src/metrics/metrics/beacon.ts +9 -0
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/core/events.ts +12 -0
- package/src/network/core/networkCoreWorkerHandler.ts +6 -2
- package/src/network/gossip/gossipsub.ts +6 -2
- package/src/network/gossip/topic.ts +1 -14
- package/src/network/network.ts +6 -2
- package/src/network/peers/peerManager.ts +26 -2
- package/src/network/peers/utils/prioritizePeers.ts +14 -1
- package/src/network/processor/gossipHandlers.ts +25 -13
- package/src/network/processor/index.ts +7 -2
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +1 -1
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
- package/src/sync/range/batch.ts +33 -0
- package/src/sync/range/chain.ts +72 -17
- package/src/sync/range/range.ts +57 -3
- package/src/sync/range/utils/batches.ts +38 -13
- package/src/sync/range/utils/peerBalancer.ts +4 -1
- package/src/sync/types.ts +13 -0
- package/src/sync/unknownBlock.ts +389 -29
- package/src/sync/utils/downloadByRange.ts +89 -29
- package/src/sync/utils/downloadByRoot.ts +75 -7
- package/src/util/asyncIterableToEvents.ts +100 -21
- package/src/util/dataColumns.ts +4 -1
- package/src/util/eventLoop.ts +3 -3
|
@@ -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({
|
|
@@ -468,6 +485,25 @@ export async function validateResponses({
|
|
|
468
485
|
}
|
|
469
486
|
|
|
470
487
|
if (!columnsRequest) {
|
|
488
|
+
// Same as the 0-block check below, for a post-Gloas batch outside the DA window where no columns are requested
|
|
489
|
+
const payloadEnvelopeCount = payloadEnvelopes?.length ?? 0;
|
|
490
|
+
if (
|
|
491
|
+
payloadEnvelopeCount > 0 &&
|
|
492
|
+
parentPayload === undefined &&
|
|
493
|
+
!validatedResponses.validatedBlocks?.length &&
|
|
494
|
+
!batchBlocks?.length
|
|
495
|
+
) {
|
|
496
|
+
throw new DownloadByRangeError(
|
|
497
|
+
{
|
|
498
|
+
code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS,
|
|
499
|
+
...requestsLogMeta({blocksRequest}),
|
|
500
|
+
columnSidecarCount: 0,
|
|
501
|
+
payloadEnvelopeCount,
|
|
502
|
+
},
|
|
503
|
+
"Envelopes returned without blocks in BeaconBlocksByRange response"
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
471
507
|
// Only envelope and/or parent-by-root validation needed
|
|
472
508
|
if (parentPayload !== undefined) {
|
|
473
509
|
const parentValidated = await validateParentPayloadColumns(parentPayload, columnSidecars ?? [], peerDasMetrics);
|
|
@@ -490,14 +526,27 @@ export async function validateResponses({
|
|
|
490
526
|
validatedResponses.validatedBlocks?.length ? validatedResponses.validatedBlocks : undefined
|
|
491
527
|
);
|
|
492
528
|
|
|
529
|
+
// Epoch with 0 blocks: columns and envelopes only exist for a block, so data here means the peer withheld blocks or
|
|
530
|
+
// served junk. The parent payload is not requested either, Batch only does once it has blocks
|
|
493
531
|
if (!blocksForDataValidation.length) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
532
|
+
const columnSidecarCount = columnSidecars?.length ?? 0;
|
|
533
|
+
const payloadEnvelopeCount = payloadEnvelopes?.length ?? 0;
|
|
534
|
+
if (columnSidecarCount > 0 || payloadEnvelopeCount > 0) {
|
|
535
|
+
throw new DownloadByRangeError(
|
|
536
|
+
{
|
|
537
|
+
code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS,
|
|
538
|
+
...requestsLogMeta({blocksRequest}),
|
|
539
|
+
columnSidecarCount,
|
|
540
|
+
payloadEnvelopeCount,
|
|
541
|
+
},
|
|
542
|
+
"Columns or envelopes returned without blocks in BeaconBlocksByRange response"
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return {
|
|
547
|
+
result: {responses: validatedResponses, payloadEnvelopes: needsEnvelopeValidation ? new Map() : null},
|
|
548
|
+
warnings,
|
|
549
|
+
};
|
|
501
550
|
}
|
|
502
551
|
|
|
503
552
|
if (!columnSidecars) {
|
|
@@ -589,26 +638,19 @@ export function validateBlockByRangeResponse(
|
|
|
589
638
|
): WarnResult<ValidatedBlock[], DownloadByRangeError> {
|
|
590
639
|
const {startSlot, count} = blocksRequest;
|
|
591
640
|
|
|
592
|
-
//
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
// if what the correct behavior should be
|
|
641
|
+
// A 0-block response is accepted as correct, epochs with 0 blocks happen on devnets with poor liveness.
|
|
642
|
+
// If it was wrong, the next batch fails with an unknown parent and SyncChain handles it,
|
|
643
|
+
// see classifyProcessingFault()
|
|
596
644
|
if (!blocks.length) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
// new DownloadByRangeError({
|
|
607
|
-
// code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
608
|
-
// ...requestsLogMeta({blocksRequest}),
|
|
609
|
-
// }),
|
|
610
|
-
// ],
|
|
611
|
-
// };
|
|
645
|
+
return {
|
|
646
|
+
result: [],
|
|
647
|
+
warnings: [
|
|
648
|
+
new DownloadByRangeError({
|
|
649
|
+
code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
650
|
+
...requestsLogMeta({blocksRequest}),
|
|
651
|
+
}),
|
|
652
|
+
],
|
|
653
|
+
};
|
|
612
654
|
}
|
|
613
655
|
|
|
614
656
|
if (blocks.length > count) {
|
|
@@ -895,7 +937,7 @@ export async function validateColumnsByRangeResponse(
|
|
|
895
937
|
peerDasMetrics
|
|
896
938
|
)
|
|
897
939
|
: validateFuluBlockDataColumnSidecars(
|
|
898
|
-
null, //
|
|
940
|
+
null, // skip BLS, cacheByRangeResponses matches the header signature against the block
|
|
899
941
|
slot,
|
|
900
942
|
blockRoot,
|
|
901
943
|
blobCount,
|
|
@@ -978,6 +1020,8 @@ function requestsLogMeta({blocksRequest, columnsRequest}: DownloadByRangeRequest
|
|
|
978
1020
|
export enum DownloadByRangeErrorCode {
|
|
979
1021
|
MISSING_BLOCKS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOCK_RESPONSE",
|
|
980
1022
|
MISSING_COLUMNS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS_RESPONSE",
|
|
1023
|
+
/** Columns or envelopes were returned for a range with no blocks */
|
|
1024
|
+
DATA_WITHOUT_BLOCKS = "DOWNLOAD_BY_RANGE_ERROR_DATA_WITHOUT_BLOCKS",
|
|
981
1025
|
|
|
982
1026
|
/** Error at the reqresp layer */
|
|
983
1027
|
REQ_RESP_ERROR = "DOWNLOAD_BY_RANGE_ERROR_REQ_RESP_ERROR",
|
|
@@ -1009,6 +1053,8 @@ export enum DownloadByRangeErrorCode {
|
|
|
1009
1053
|
|
|
1010
1054
|
/** Block segment + envelopes failed chain-segment linearity / FULL-chain checks */
|
|
1011
1055
|
INVALID_CHAIN_SEGMENT = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CHAIN_SEGMENT",
|
|
1056
|
+
/** A column header signature differs from a cached block whose proposer signature is invalid or unverifiable */
|
|
1057
|
+
INVALID_CACHED_BLOCK = "DOWNLOAD_BY_RANGE_ERROR_INVALID_CACHED_BLOCK",
|
|
1012
1058
|
}
|
|
1013
1059
|
|
|
1014
1060
|
export type DownloadByRangeErrorType =
|
|
@@ -1019,6 +1065,13 @@ export type DownloadByRangeErrorType =
|
|
|
1019
1065
|
columnStartSlot?: number;
|
|
1020
1066
|
columnCount?: number;
|
|
1021
1067
|
}
|
|
1068
|
+
| {
|
|
1069
|
+
code: DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS;
|
|
1070
|
+
blockStartSlot?: number;
|
|
1071
|
+
blockCount?: number;
|
|
1072
|
+
columnSidecarCount: number;
|
|
1073
|
+
payloadEnvelopeCount: number;
|
|
1074
|
+
}
|
|
1022
1075
|
| {
|
|
1023
1076
|
code: DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS;
|
|
1024
1077
|
slot: number;
|
|
@@ -1105,6 +1158,13 @@ export type DownloadByRangeErrorType =
|
|
|
1105
1158
|
code: DownloadByRangeErrorCode.INVALID_CHAIN_SEGMENT;
|
|
1106
1159
|
slot: Slot;
|
|
1107
1160
|
reason: string;
|
|
1161
|
+
}
|
|
1162
|
+
| {
|
|
1163
|
+
code: DownloadByRangeErrorCode.INVALID_CACHED_BLOCK;
|
|
1164
|
+
slot: Slot;
|
|
1165
|
+
blockRoot: string;
|
|
1166
|
+
/** Set only when the block proposer signature is invalid */
|
|
1167
|
+
blockPeer?: PeerIdStr;
|
|
1108
1168
|
};
|
|
1109
1169
|
|
|
1110
1170
|
export class DownloadByRangeError extends LodestarError<DownloadByRangeErrorType> {}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {routes} from "@lodestar/api";
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
3
|
import {ForkPostFulu, ForkPostGloas, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
|
|
4
|
-
import {
|
|
4
|
+
import {getBlockProposerSignatureSet} from "@lodestar/state-transition";
|
|
5
|
+
import {ColumnIndex, SignedBeaconBlock, Slot, ValidatorIndex, fulu} from "@lodestar/types";
|
|
5
6
|
import {LodestarError, byteArrayEquals, fromHex, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
|
|
6
7
|
import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
|
|
7
8
|
import {BlockInputSource, IBlockInput} from "../../chain/blocks/blockInput/types.js";
|
|
@@ -30,10 +31,12 @@ export type FetchByRootCoreProps = {
|
|
|
30
31
|
peerMeta: PeerSyncMeta;
|
|
31
32
|
};
|
|
32
33
|
export type FetchByRootProps = FetchByRootCoreProps & {
|
|
34
|
+
chain: IBeaconChain;
|
|
33
35
|
cacheItem: BlockInputSyncCacheItem;
|
|
34
36
|
blockRoot: Uint8Array;
|
|
35
37
|
};
|
|
36
38
|
export type FetchByRootAndValidateBlockProps = Omit<FetchByRootCoreProps, "peerMeta"> & {
|
|
39
|
+
chain: IBeaconChain;
|
|
37
40
|
peerIdStr: PeerIdStr;
|
|
38
41
|
blockRoot: Uint8Array;
|
|
39
42
|
};
|
|
@@ -112,9 +115,8 @@ export async function downloadByRoot({
|
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (isBlockInputColumns(blockInput) && !hasAllDataPreDownload) {
|
|
118
|
+
// Like range sync, download every sampled column, half of them only counts as available for reconstruction
|
|
119
|
+
if (isBlockInputColumns(blockInput) && !blockInput.hasComputedAllData()) {
|
|
118
120
|
// columnSidecars could be undefined if gossip resulted in full block+columns so we don't download any
|
|
119
121
|
if (!columnSidecars) {
|
|
120
122
|
throw new DownloadByRootError({
|
|
@@ -151,7 +153,10 @@ export async function downloadByRoot({
|
|
|
151
153
|
|
|
152
154
|
let status: PendingBlockInputStatus;
|
|
153
155
|
let timeSyncedSec: number | undefined;
|
|
154
|
-
if (
|
|
156
|
+
if (
|
|
157
|
+
blockInput.hasBlock() &&
|
|
158
|
+
(isBlockInputColumns(blockInput) ? blockInput.hasComputedAllData() : blockInput.hasAllData())
|
|
159
|
+
) {
|
|
155
160
|
status = PendingBlockInputStatus.downloaded;
|
|
156
161
|
timeSyncedSec = Date.now() / 1000;
|
|
157
162
|
} else {
|
|
@@ -165,6 +170,8 @@ export async function downloadByRoot({
|
|
|
165
170
|
timeSyncedSec,
|
|
166
171
|
timeAddedSec: cacheItem.timeAddedSec,
|
|
167
172
|
peerIdStrings: cacheItem.peerIdStrings,
|
|
173
|
+
retainedBy: isPendingBlockInput(cacheItem) ? cacheItem.retainedBy : undefined,
|
|
174
|
+
retainedBytes: isPendingBlockInput(cacheItem) ? cacheItem.retainedBytes : undefined,
|
|
168
175
|
},
|
|
169
176
|
warnings,
|
|
170
177
|
};
|
|
@@ -188,6 +195,7 @@ export async function fetchByRoot({
|
|
|
188
195
|
} else {
|
|
189
196
|
block = await fetchAndValidateBlock({
|
|
190
197
|
config,
|
|
198
|
+
chain,
|
|
191
199
|
network,
|
|
192
200
|
peerIdStr,
|
|
193
201
|
blockRoot,
|
|
@@ -195,7 +203,7 @@ export async function fetchByRoot({
|
|
|
195
203
|
}
|
|
196
204
|
|
|
197
205
|
const forkName = config.getForkName(block.message.slot);
|
|
198
|
-
if (
|
|
206
|
+
if (isBlockInputColumns(cacheItem.blockInput) && !cacheItem.blockInput.hasComputedAllData()) {
|
|
199
207
|
columnSidecarResult = await fetchAndValidateColumns({
|
|
200
208
|
config,
|
|
201
209
|
chain,
|
|
@@ -210,6 +218,7 @@ export async function fetchByRoot({
|
|
|
210
218
|
} else {
|
|
211
219
|
block = await fetchAndValidateBlock({
|
|
212
220
|
config,
|
|
221
|
+
chain,
|
|
213
222
|
network,
|
|
214
223
|
peerIdStr,
|
|
215
224
|
blockRoot,
|
|
@@ -243,10 +252,11 @@ export async function fetchByRoot({
|
|
|
243
252
|
|
|
244
253
|
export async function fetchAndValidateBlock({
|
|
245
254
|
config,
|
|
255
|
+
chain,
|
|
246
256
|
network,
|
|
247
257
|
peerIdStr,
|
|
248
258
|
blockRoot,
|
|
249
|
-
}:
|
|
259
|
+
}: FetchByRootAndValidateBlockProps): Promise<SignedBeaconBlock> {
|
|
250
260
|
const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
|
|
251
261
|
const block = response.at(0);
|
|
252
262
|
if (!block) {
|
|
@@ -268,6 +278,41 @@ export async function fetchAndValidateBlock({
|
|
|
268
278
|
"block does not match requested root"
|
|
269
279
|
);
|
|
270
280
|
}
|
|
281
|
+
|
|
282
|
+
const blockRootHex = toRootHex(blockRoot);
|
|
283
|
+
const {slot, proposerIndex} = block.message;
|
|
284
|
+
// Before the signature check, honest peers serve the genesis block unsigned
|
|
285
|
+
const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
|
|
286
|
+
if (slot < finalizedSlot) {
|
|
287
|
+
throw new DownloadByRootError({
|
|
288
|
+
code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT,
|
|
289
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
290
|
+
slot,
|
|
291
|
+
finalizedSlot,
|
|
292
|
+
blockRoot: blockRootHex,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (proposerIndex >= chain.pubkeyCache.size) {
|
|
296
|
+
throw new DownloadByRootError({
|
|
297
|
+
code: DownloadByRootErrorCode.UNKNOWN_PROPOSER,
|
|
298
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
299
|
+
slot,
|
|
300
|
+
blockRoot: blockRootHex,
|
|
301
|
+
proposerIndex,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
// Not marked as verified, the block has not passed proposer or ancestry checks yet
|
|
305
|
+
if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, blockRootHex, block.signature)) {
|
|
306
|
+
const signatureSet = getBlockProposerSignatureSet(chain.config, block);
|
|
307
|
+
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: false}))) {
|
|
308
|
+
throw new DownloadByRootError({
|
|
309
|
+
code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
310
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
311
|
+
slot,
|
|
312
|
+
blockRoot: blockRootHex,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
271
316
|
return block;
|
|
272
317
|
}
|
|
273
318
|
|
|
@@ -374,6 +419,9 @@ export enum DownloadByRootErrorCode {
|
|
|
374
419
|
INVALID_KZG_PROOF = "DOWNLOAD_BY_ROOT_ERROR_INVALID_KZG_PROOF",
|
|
375
420
|
MISSING_BLOCK_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_BLOCK_RESPONSE",
|
|
376
421
|
MISSING_COLUMN_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_COLUMN_RESPONSE",
|
|
422
|
+
BELOW_FINALIZED_SLOT = "DOWNLOAD_BY_ROOT_ERROR_BELOW_FINALIZED_SLOT",
|
|
423
|
+
UNKNOWN_PROPOSER = "DOWNLOAD_BY_ROOT_ERROR_UNKNOWN_PROPOSER",
|
|
424
|
+
PROPOSAL_SIGNATURE_INVALID = "DOWNLOAD_BY_ROOT_ERROR_PROPOSAL_SIGNATURE_INVALID",
|
|
377
425
|
Z = "DOWNLOAD_BY_ROOT_ERROR_Z",
|
|
378
426
|
}
|
|
379
427
|
export type DownloadByRootErrorType =
|
|
@@ -423,6 +471,26 @@ export type DownloadByRootErrorType =
|
|
|
423
471
|
code: DownloadByRootErrorCode.MISSING_COLUMN_RESPONSE;
|
|
424
472
|
peer: string;
|
|
425
473
|
blockRoot: string;
|
|
474
|
+
}
|
|
475
|
+
| {
|
|
476
|
+
code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT;
|
|
477
|
+
peer: string;
|
|
478
|
+
slot: Slot;
|
|
479
|
+
finalizedSlot: Slot;
|
|
480
|
+
blockRoot: string;
|
|
481
|
+
}
|
|
482
|
+
| {
|
|
483
|
+
code: DownloadByRootErrorCode.UNKNOWN_PROPOSER;
|
|
484
|
+
peer: string;
|
|
485
|
+
slot: Slot;
|
|
486
|
+
blockRoot: string;
|
|
487
|
+
proposerIndex: ValidatorIndex;
|
|
488
|
+
}
|
|
489
|
+
| {
|
|
490
|
+
code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID;
|
|
491
|
+
peer: string;
|
|
492
|
+
slot: Slot;
|
|
493
|
+
blockRoot: string;
|
|
426
494
|
};
|
|
427
495
|
|
|
428
496
|
export class DownloadByRootError extends LodestarError<DownloadByRootErrorType> {}
|
|
@@ -10,6 +10,11 @@ export type RequestCancelEvent = {
|
|
|
10
10
|
id: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
export type ResponsePullEvent = {
|
|
14
|
+
id: number;
|
|
15
|
+
count: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
13
18
|
export enum IteratorEventType {
|
|
14
19
|
next = "iterator.next",
|
|
15
20
|
done = "iterator.done",
|
|
@@ -25,11 +30,22 @@ export type AsyncIterableEventBus<Args, Item> = {
|
|
|
25
30
|
emitRequest(data: RequestEvent<Args>): void;
|
|
26
31
|
emitRequestCancel(data: RequestCancelEvent): void;
|
|
27
32
|
emitResponse(data: IteratorEvent<Item>): void;
|
|
33
|
+
emitResponsePull(data: ResponsePullEvent): void;
|
|
28
34
|
onRequest(handler: (data: RequestEvent<Args>) => void): void;
|
|
29
35
|
onRequestCancel(handler: (data: RequestCancelEvent) => void): void;
|
|
30
36
|
onResponse(handler: (data: IteratorEvent<Item>) => void): void;
|
|
37
|
+
onResponsePull(handler: (data: ResponsePullEvent) => void): void;
|
|
31
38
|
};
|
|
32
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Credit window: the consumer grants this many items up front and refunds one per item it pulls, so the
|
|
42
|
+
* producer runs at most `window` (plus one in-flight) items ahead regardless of read speed. Bounds
|
|
43
|
+
* consumer-side buffering on the serving bridge. The requester bridge passes Infinity to stay eager: we
|
|
44
|
+
* buffer our own responses into an array anyway, and pacing the worker there only risks the libp2p read
|
|
45
|
+
* buffer overflowing. Must be >= 1.
|
|
46
|
+
*/
|
|
47
|
+
export const RESP_BRIDGE_WINDOW = 2;
|
|
48
|
+
|
|
33
49
|
type PendingItem<T> = {
|
|
34
50
|
items: LinkedList<T>;
|
|
35
51
|
done: boolean;
|
|
@@ -44,8 +60,15 @@ export class AsyncIterableBridgeCaller<Args, Item> {
|
|
|
44
60
|
private readonly pending = new Map<number, PendingItem<Item>>();
|
|
45
61
|
|
|
46
62
|
constructor(
|
|
47
|
-
private readonly events: Pick<
|
|
63
|
+
private readonly events: Pick<
|
|
64
|
+
AsyncIterableEventBus<Args, Item>,
|
|
65
|
+
"onResponse" | "emitRequest" | "emitRequestCancel" | "emitResponsePull"
|
|
66
|
+
>,
|
|
67
|
+
private readonly window = RESP_BRIDGE_WINDOW
|
|
48
68
|
) {
|
|
69
|
+
if (window < 1) {
|
|
70
|
+
throw new Error(`AsyncIterableBridgeCaller window must be >= 1, got ${window}`);
|
|
71
|
+
}
|
|
49
72
|
events.onResponse(this.onResponse.bind(this));
|
|
50
73
|
}
|
|
51
74
|
|
|
@@ -71,12 +94,18 @@ export class AsyncIterableBridgeCaller<Args, Item> {
|
|
|
71
94
|
callArgs,
|
|
72
95
|
id,
|
|
73
96
|
});
|
|
97
|
+
// Grant the initial window; next() refunds one credit per consumed item. An Infinity window
|
|
98
|
+
// grants unbounded credit up front so the producer never waits (requester bridge, see above).
|
|
99
|
+
self.events.emitResponsePull({id, count: self.window});
|
|
74
100
|
|
|
75
101
|
return {
|
|
76
102
|
async next() {
|
|
77
103
|
while (true) {
|
|
78
104
|
const item = req.items.shift();
|
|
79
105
|
if (item !== null) {
|
|
106
|
+
if (self.window !== Infinity) {
|
|
107
|
+
self.events.emitResponsePull({id, count: 1});
|
|
108
|
+
}
|
|
80
109
|
return {value: item, done: false};
|
|
81
110
|
}
|
|
82
111
|
|
|
@@ -142,29 +171,52 @@ export class AsyncIterableBridgeCaller<Args, Item> {
|
|
|
142
171
|
}
|
|
143
172
|
}
|
|
144
173
|
|
|
174
|
+
type HandlerState<Item> = {
|
|
175
|
+
iterator: AsyncIterator<Item>;
|
|
176
|
+
credit: number;
|
|
177
|
+
cancelled: boolean;
|
|
178
|
+
onCredit: null | (() => void);
|
|
179
|
+
};
|
|
180
|
+
|
|
145
181
|
export class AsyncIterableBridgeHandler<Args, Item> {
|
|
146
|
-
private readonly
|
|
182
|
+
private readonly states = new Map<number, HandlerState<Item>>();
|
|
147
183
|
|
|
148
184
|
constructor(
|
|
149
|
-
private readonly events: Pick<
|
|
185
|
+
private readonly events: Pick<
|
|
186
|
+
AsyncIterableEventBus<Args, Item>,
|
|
187
|
+
"onRequest" | "onRequestCancel" | "emitResponse" | "onResponsePull"
|
|
188
|
+
>,
|
|
150
189
|
private readonly handler: (args: Args) => AsyncIterable<Item>
|
|
151
190
|
) {
|
|
152
191
|
events.onRequest(this.onRequest.bind(this));
|
|
153
192
|
events.onRequestCancel(this.onRequestCancel.bind(this));
|
|
193
|
+
events.onResponsePull(this.onResponsePull.bind(this));
|
|
154
194
|
}
|
|
155
195
|
|
|
156
196
|
get iteratingCount(): number {
|
|
157
|
-
return this.
|
|
197
|
+
return this.states.size;
|
|
158
198
|
}
|
|
159
199
|
|
|
160
200
|
private async onRequest(data: RequestEvent<Args>): Promise<void> {
|
|
201
|
+
let state: HandlerState<Item> | undefined;
|
|
161
202
|
try {
|
|
162
|
-
|
|
163
|
-
|
|
203
|
+
state = {
|
|
204
|
+
iterator: this.handler(data.callArgs)[Symbol.asyncIterator](),
|
|
205
|
+
credit: 0,
|
|
206
|
+
cancelled: false,
|
|
207
|
+
onCredit: null,
|
|
208
|
+
};
|
|
209
|
+
this.states.set(data.id, state);
|
|
164
210
|
|
|
165
211
|
while (true) {
|
|
166
|
-
|
|
167
|
-
if (
|
|
212
|
+
await this.waitForCredit(state);
|
|
213
|
+
if (state.cancelled) {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
state.credit--;
|
|
217
|
+
|
|
218
|
+
const result = await state.iterator.next();
|
|
219
|
+
if (result.done || state.cancelled) {
|
|
168
220
|
break;
|
|
169
221
|
}
|
|
170
222
|
|
|
@@ -175,29 +227,56 @@ export class AsyncIterableBridgeHandler<Args, Item> {
|
|
|
175
227
|
});
|
|
176
228
|
}
|
|
177
229
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
230
|
+
if (!state.cancelled) {
|
|
231
|
+
this.events.emitResponse({
|
|
232
|
+
type: IteratorEventType.done,
|
|
233
|
+
id: data.id,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
182
236
|
} catch (e) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
237
|
+
if (!state?.cancelled) {
|
|
238
|
+
this.events.emitResponse({
|
|
239
|
+
type: IteratorEventType.error,
|
|
240
|
+
id: data.id,
|
|
241
|
+
error: toThreadBoundaryError(e as Error),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
188
244
|
} finally {
|
|
189
|
-
this.
|
|
245
|
+
this.states.delete(data.id);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private waitForCredit(state: HandlerState<Item>): Promise<void> {
|
|
250
|
+
if (state.credit > 0 || state.cancelled) {
|
|
251
|
+
return Promise.resolve();
|
|
252
|
+
}
|
|
253
|
+
return new Promise<void>((resolve) => {
|
|
254
|
+
state.onCredit = resolve;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private onResponsePull(data: ResponsePullEvent): void {
|
|
259
|
+
const state = this.states.get(data.id);
|
|
260
|
+
if (!state) {
|
|
261
|
+
return;
|
|
190
262
|
}
|
|
263
|
+
state.credit += data.count;
|
|
264
|
+
state.onCredit?.();
|
|
265
|
+
state.onCredit = null;
|
|
191
266
|
}
|
|
192
267
|
|
|
193
268
|
private onRequestCancel(data: RequestCancelEvent): void {
|
|
194
|
-
const
|
|
195
|
-
if (!
|
|
269
|
+
const state = this.states.get(data.id);
|
|
270
|
+
if (!state) {
|
|
196
271
|
return;
|
|
197
272
|
}
|
|
273
|
+
// Unblock the loop if it is parked on credit so it can observe the cancel and stop
|
|
274
|
+
state.cancelled = true;
|
|
275
|
+
state.onCredit?.();
|
|
276
|
+
state.onCredit = null;
|
|
198
277
|
|
|
199
278
|
// An async generator queues return() behind the next() that is in flight, so at most one more
|
|
200
279
|
// item is produced before its finally blocks run. Any error surfaces through that next() call.
|
|
201
|
-
void iterator.return().catch(() => {});
|
|
280
|
+
void state.iterator.return?.().catch(() => {});
|
|
202
281
|
}
|
|
203
282
|
}
|
package/src/util/dataColumns.ts
CHANGED
|
@@ -288,7 +288,7 @@ export function getBlobKzgCommitments(
|
|
|
288
288
|
* each blob in the block, assemble the sidecars which can be distributed to peers.
|
|
289
289
|
*
|
|
290
290
|
* SPEC FUNCTION
|
|
291
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
291
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/fulu/validator.md#get_data_column_sidecars
|
|
292
292
|
*/
|
|
293
293
|
export function getFuluDataColumnSidecars(
|
|
294
294
|
signedBlockHeader: SignedBeaconBlockHeader,
|
|
@@ -299,6 +299,9 @@ export function getFuluDataColumnSidecars(
|
|
|
299
299
|
if (cellsAndKzgProofs.length !== kzgCommitments.length) {
|
|
300
300
|
throw Error("Invalid cellsAndKzgProofs length for getDataColumnSidecars");
|
|
301
301
|
}
|
|
302
|
+
if (kzgCommitments.length === 0) {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
302
305
|
|
|
303
306
|
const sidecars: fulu.DataColumnSidecar[] = [];
|
|
304
307
|
for (let columnIndex = 0; columnIndex < NUMBER_OF_COLUMNS; columnIndex++) {
|
package/src/util/eventLoop.ts
CHANGED
|
@@ -22,9 +22,9 @@ export function callInNextEventLoop(callback: () => void): void {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Schedules a callback for the `check` phase
|
|
26
|
-
* and there is no 1ms timer delay.
|
|
25
|
+
* Schedules a callback for the `check` phase, after the `poll` phase handles ready I/O.
|
|
26
|
+
* Pending promise continuations run first, and there is no 1ms timer delay.
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function callAfterIO(callback: () => void): void {
|
|
29
29
|
setImmediate(callback);
|
|
30
30
|
}
|