@lodestar/beacon-node 1.49.0-dev.3f33d73d55 → 1.49.0-dev.418afc191b
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 +13 -4
- 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 +4 -2
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/index.js +28 -0
- package/lib/api/impl/beacon/state/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +3 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/archiveStore.d.ts +1 -2
- package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
- package/lib/chain/archiveStore/archiveStore.js +23 -7
- package/lib/chain/archiveStore/archiveStore.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/metrics.js +5 -6
- package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.d.ts +11 -2
- package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +46 -28
- package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts +2 -2
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +1 -0
- package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +13 -0
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/chain.d.ts +10 -0
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +85 -16
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/envelopeReconstructionError.d.ts +23 -0
- package/lib/chain/errors/envelopeReconstructionError.d.ts.map +1 -0
- package/lib/chain/errors/envelopeReconstructionError.js +13 -0
- package/lib/chain/errors/envelopeReconstructionError.js.map +1 -0
- package/lib/chain/errors/index.d.ts +1 -0
- package/lib/chain/errors/index.d.ts.map +1 -1
- package/lib/chain/errors/index.js +1 -0
- package/lib/chain/errors/index.js.map +1 -1
- package/lib/chain/errors/payloadAttestation.d.ts +4 -0
- package/lib/chain/errors/payloadAttestation.d.ts.map +1 -1
- package/lib/chain/errors/payloadAttestation.js +1 -0
- package/lib/chain/errors/payloadAttestation.js.map +1 -1
- package/lib/chain/interface.d.ts +6 -1
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/options.d.ts +2 -4
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +1 -1
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
- package/lib/chain/produceBlock/computeNewStateRoot.js +4 -2
- package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.js +8 -1
- package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
- package/lib/db/beacon.d.ts +1 -2
- package/lib/db/beacon.d.ts.map +1 -1
- package/lib/db/beacon.js +1 -3
- package/lib/db/beacon.js.map +1 -1
- package/lib/db/buckets.d.ts +0 -1
- package/lib/db/buckets.d.ts.map +1 -1
- package/lib/db/buckets.js +1 -1
- package/lib/db/buckets.js.map +1 -1
- package/lib/db/interface.d.ts +1 -2
- package/lib/db/interface.d.ts.map +1 -1
- package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
- package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
- package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts +21 -9
- package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts.map +1 -1
- package/lib/db/repositories/executionPayloadEnvelopeArchive.js +32 -12
- package/lib/db/repositories/executionPayloadEnvelopeArchive.js.map +1 -1
- package/lib/db/repositories/index.d.ts +1 -2
- package/lib/db/repositories/index.d.ts.map +1 -1
- package/lib/db/repositories/index.js +1 -2
- package/lib/db/repositories/index.js.map +1 -1
- package/lib/execution/engine/disabled.d.ts +1 -0
- package/lib/execution/engine/disabled.d.ts.map +1 -1
- package/lib/execution/engine/disabled.js +3 -0
- package/lib/execution/engine/disabled.js.map +1 -1
- package/lib/execution/engine/http.d.ts +2 -1
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +7 -1
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +3 -1
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.js +6 -1
- package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
- package/lib/execution/engine/mock.d.ts +1 -0
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +14 -2
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/transportMetrics.d.ts +13 -0
- package/lib/execution/engine/transportMetrics.d.ts.map +1 -0
- package/lib/execution/engine/transportMetrics.js +2 -0
- package/lib/execution/engine/transportMetrics.js.map +1 -0
- package/lib/execution/engine/types.d.ts +11 -0
- package/lib/execution/engine/types.d.ts.map +1 -1
- package/lib/execution/engine/types.js +10 -0
- package/lib/execution/engine/types.js.map +1 -1
- package/lib/metrics/metrics/beacon.d.ts +9 -0
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js +16 -0
- package/lib/metrics/metrics/beacon.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +27 -11
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +58 -23
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/metrics/metrics.d.ts +3 -1
- package/lib/metrics/metrics.d.ts.map +1 -1
- package/lib/metrics/metrics.js +2 -2
- package/lib/metrics/metrics.js.map +1 -1
- package/lib/network/processor/index.d.ts +1 -1
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +42 -21
- package/lib/network/processor/index.js.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +47 -34
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +23 -4
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/index.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/index.js +20 -4
- package/lib/network/reqresp/handlers/index.js.map +1 -1
- package/lib/node/nodejs.d.ts +2 -7
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +2 -22
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/interface.d.ts +1 -2
- package/lib/sync/interface.d.ts.map +1 -1
- package/lib/sync/options.d.ts +0 -6
- package/lib/sync/options.d.ts.map +1 -1
- package/lib/sync/options.js +0 -2
- package/lib/sync/options.js.map +1 -1
- package/lib/sync/types.d.ts +18 -3
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js +19 -3
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +19 -0
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +184 -15
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/util/execution.d.ts +42 -0
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +123 -2
- package/lib/util/execution.js.map +1 -1
- package/lib/util/headerEnvelope.d.ts +17 -0
- package/lib/util/headerEnvelope.d.ts.map +1 -0
- package/lib/util/headerEnvelope.js +43 -0
- package/lib/util/headerEnvelope.js.map +1 -0
- package/lib/util/shuffle.d.ts +0 -4
- package/lib/util/shuffle.d.ts.map +1 -1
- package/lib/util/shuffle.js +0 -8
- package/lib/util/shuffle.js.map +1 -1
- package/package.json +16 -16
- package/src/api/impl/beacon/blocks/index.ts +16 -3
- package/src/api/impl/beacon/pool/index.ts +6 -2
- package/src/api/impl/beacon/state/index.ts +36 -0
- package/src/api/impl/validator/index.ts +3 -1
- package/src/chain/archiveStore/archiveStore.ts +24 -8
- package/src/chain/archiveStore/historicalState/metrics.ts +5 -7
- package/src/chain/archiveStore/utils/archiveBlocks.ts +54 -32
- package/src/chain/archiveStore/utils/pruneHistory.ts +4 -2
- package/src/chain/blocks/importExecutionPayload.ts +14 -0
- package/src/chain/chain.ts +96 -20
- package/src/chain/errors/envelopeReconstructionError.ts +22 -0
- package/src/chain/errors/index.ts +1 -0
- package/src/chain/errors/payloadAttestation.ts +2 -0
- package/src/chain/interface.ts +6 -1
- package/src/chain/options.ts +3 -5
- package/src/chain/produceBlock/computeNewStateRoot.ts +9 -2
- package/src/chain/validation/payloadAttestationMessage.ts +9 -0
- package/src/db/beacon.ts +0 -5
- package/src/db/buckets.ts +2 -2
- package/src/db/interface.ts +0 -3
- package/src/db/repositories/executionPayloadEnvelopeArchive.ts +43 -13
- package/src/db/repositories/index.ts +6 -2
- package/src/execution/engine/disabled.ts +4 -0
- package/src/execution/engine/http.ts +12 -0
- package/src/execution/engine/interface.ts +4 -1
- package/src/execution/engine/jsonRpcHttpClient.ts +9 -2
- package/src/execution/engine/mock.ts +22 -2
- package/src/execution/engine/transportMetrics.ts +9 -0
- package/src/execution/engine/types.ts +25 -0
- package/src/metrics/metrics/beacon.ts +16 -0
- package/src/metrics/metrics/lodestar.ts +68 -26
- package/src/metrics/metrics.ts +7 -2
- package/src/network/processor/index.ts +51 -22
- package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +57 -39
- package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +27 -5
- package/src/network/reqresp/handlers/index.ts +49 -5
- package/src/node/nodejs.ts +0 -27
- package/src/sync/interface.ts +1 -2
- package/src/sync/options.ts +0 -8
- package/src/sync/types.ts +19 -3
- package/src/sync/unknownBlock.ts +192 -14
- package/src/util/execution.ts +175 -2
- package/src/util/headerEnvelope.ts +76 -0
- package/src/util/shuffle.ts +0 -9
- package/lib/chain/archiveStore/utils/updateBackfillRange.d.ts +0 -20
- package/lib/chain/archiveStore/utils/updateBackfillRange.d.ts.map +0 -1
- package/lib/chain/archiveStore/utils/updateBackfillRange.js +0 -40
- package/lib/chain/archiveStore/utils/updateBackfillRange.js.map +0 -1
- package/lib/db/repositories/backfilledRanges.d.ts +0 -18
- package/lib/db/repositories/backfilledRanges.d.ts.map +0 -1
- package/lib/db/repositories/backfilledRanges.js +0 -26
- package/lib/db/repositories/backfilledRanges.js.map +0 -1
- package/lib/sync/backfill/backfill.d.ts +0 -169
- package/lib/sync/backfill/backfill.d.ts.map +0 -1
- package/lib/sync/backfill/backfill.js +0 -686
- package/lib/sync/backfill/backfill.js.map +0 -1
- package/lib/sync/backfill/errors.d.ts +0 -30
- package/lib/sync/backfill/errors.d.ts.map +0 -1
- package/lib/sync/backfill/errors.js +0 -15
- package/lib/sync/backfill/errors.js.map +0 -1
- package/lib/sync/backfill/index.d.ts +0 -2
- package/lib/sync/backfill/index.d.ts.map +0 -1
- package/lib/sync/backfill/index.js +0 -2
- package/lib/sync/backfill/index.js.map +0 -1
- package/lib/sync/backfill/verify.d.ts +0 -18
- package/lib/sync/backfill/verify.d.ts.map +0 -1
- package/lib/sync/backfill/verify.js +0 -36
- package/lib/sync/backfill/verify.js.map +0 -1
- package/src/chain/archiveStore/utils/updateBackfillRange.ts +0 -50
- package/src/db/repositories/backfilledRanges.ts +0 -29
- package/src/sync/backfill/backfill.ts +0 -916
- package/src/sync/backfill/errors.ts +0 -23
- package/src/sync/backfill/index.ts +0 -1
- package/src/sync/backfill/verify.ts +0 -58
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {ForkSeq, SLOTS_PER_EPOCH, isForkPostGloas} from "@lodestar/params";
|
|
|
5
5
|
import {RequestError, RequestErrorCode} from "@lodestar/reqresp";
|
|
6
6
|
import {computeTimeAtSlot} from "@lodestar/state-transition";
|
|
7
7
|
import {RootHex, Slot, gloas} from "@lodestar/types";
|
|
8
|
-
import {Logger, fromHex, prettyPrintIndices, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
|
|
8
|
+
import {Logger, fromHex, isErrorAborted, prettyPrintIndices, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
|
|
9
9
|
import {isBlockInputBlobs, 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";
|
|
@@ -18,6 +18,7 @@ import {Metrics} from "../metrics/index.js";
|
|
|
18
18
|
import {INetwork, NetworkEvent, NetworkEventData, prettyPrintPeerIdStr} from "../network/index.js";
|
|
19
19
|
import {PeerSyncMeta} from "../network/peers/peersData.js";
|
|
20
20
|
import {MAX_PEERS_PER_ROOT} from "../network/processor/constants.js";
|
|
21
|
+
import {ClockEvent} from "../util/clock.js";
|
|
21
22
|
import {PeerIdStr} from "../util/peerId.js";
|
|
22
23
|
import {shuffle} from "../util/shuffle.js";
|
|
23
24
|
import {sortBy} from "../util/sortBy.js";
|
|
@@ -26,6 +27,7 @@ import {MAX_CONCURRENT_REQUESTS} from "./constants.js";
|
|
|
26
27
|
import {SyncOptions} from "./options.js";
|
|
27
28
|
import {
|
|
28
29
|
BlockInputSyncCacheItem,
|
|
30
|
+
DeferredPayloadResult,
|
|
29
31
|
DownloadResult,
|
|
30
32
|
DroppedItemReason,
|
|
31
33
|
FetchResult,
|
|
@@ -57,6 +59,11 @@ const MAX_PENDING_BLOCKS = 100;
|
|
|
57
59
|
*/
|
|
58
60
|
const PRUNE_UNRESOLVED_SLOT_EPOCHS = 2;
|
|
59
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Poll pending payloads of the current slot this often, between PAYLOAD_DUE and the end of the slot.
|
|
64
|
+
*/
|
|
65
|
+
export const PAYLOAD_POLL_INTERVAL_MS = 1_000;
|
|
66
|
+
|
|
60
67
|
type AdvancePendingBlockResult =
|
|
61
68
|
| "ready"
|
|
62
69
|
| "queued_block"
|
|
@@ -116,6 +123,11 @@ export class BlockInputSync {
|
|
|
116
123
|
private subscribedToNetworkEvents = false;
|
|
117
124
|
private peerBalancer: UnknownBlockPeerBalancer;
|
|
118
125
|
private rateLimitBackoffTimeout: NodeJS.Timeout | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Search unknown payload starting at PAYLOAD_DUE_BPS.
|
|
128
|
+
*/
|
|
129
|
+
private readonly deferredPayloadRoots = new Map<RootHex, {slot: Slot; source: BlockInputSource; peer?: PeerIdStr}>();
|
|
130
|
+
private payloadPollAbortController: AbortController | undefined;
|
|
119
131
|
|
|
120
132
|
constructor(
|
|
121
133
|
private readonly config: ChainForkConfig,
|
|
@@ -161,6 +173,7 @@ export class BlockInputSync {
|
|
|
161
173
|
this.chain.emitter.on(routes.events.EventType.executionPayload, this.onPayloadImported);
|
|
162
174
|
this.network.events.on(NetworkEvent.peerConnected, this.onPeerConnected);
|
|
163
175
|
this.network.events.on(NetworkEvent.peerDisconnected, this.onPeerDisconnected);
|
|
176
|
+
this.chain.clock.on(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
164
177
|
|
|
165
178
|
// Seed the balancer with peers that connected before we subscribed
|
|
166
179
|
for (const peerId of this.network.getConnectedPeers()) {
|
|
@@ -172,12 +185,19 @@ export class BlockInputSync {
|
|
|
172
185
|
}
|
|
173
186
|
|
|
174
187
|
this.subscribedToNetworkEvents = true;
|
|
188
|
+
// we subscribe mid-slot, and a root can be deferred at any point in the slot, so start this
|
|
189
|
+
// slot's loop now instead of waiting for the next ClockEvent.slot
|
|
190
|
+
this.startPayloadPollAtSlot(this.chain.clock.currentSlot);
|
|
175
191
|
}
|
|
176
192
|
}
|
|
177
193
|
|
|
178
194
|
unsubscribeFromNetwork(): void {
|
|
179
195
|
this.logger.verbose("BlockInputSync disabled.");
|
|
180
196
|
this.clearRateLimitBackoffTimer();
|
|
197
|
+
this.chain.clock.off(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
198
|
+
this.payloadPollAbortController?.abort();
|
|
199
|
+
this.payloadPollAbortController = undefined;
|
|
200
|
+
this.deferredPayloadRoots.clear();
|
|
181
201
|
this.chain.emitter.off(ChainEvent.unknownBlockRoot, this.onUnknownBlockRoot);
|
|
182
202
|
this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRoot, this.onUnknownEnvelopeBlockRoot);
|
|
183
203
|
this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRootSlot, this.onUnknownEnvelopeBlockRootSlot);
|
|
@@ -207,8 +227,11 @@ export class BlockInputSync {
|
|
|
207
227
|
private onUnknownBlockRoot = (data: ChainEventData[ChainEvent.unknownBlockRoot]): void => {
|
|
208
228
|
try {
|
|
209
229
|
const isNewRoot = this.addByRootHex(data.rootHex, data.peer);
|
|
210
|
-
|
|
230
|
+
// A retained entry (an earlier download failed, #10018) is not new but still needs a retry pass.
|
|
231
|
+
if (this.pendingBlocks.get(data.rootHex)?.status === PendingBlockInputStatus.pending) {
|
|
211
232
|
this.triggerUnknownBlockSearch();
|
|
233
|
+
}
|
|
234
|
+
if (isNewRoot) {
|
|
212
235
|
this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.UNKNOWN_BLOCK_ROOT});
|
|
213
236
|
this.metrics?.blockInputSync.source.inc({source: data.source});
|
|
214
237
|
}
|
|
@@ -246,6 +269,20 @@ export class BlockInputSync {
|
|
|
246
269
|
|
|
247
270
|
private onUnknownEnvelopeBlockRootSlot = (data: ChainEventData[ChainEvent.unknownEnvelopeBlockRootSlot]): void => {
|
|
248
271
|
try {
|
|
272
|
+
if (data.slot === this.chain.clock.currentSlot) {
|
|
273
|
+
// we receive the optimistic search, the poll loop searches it at PAYLOAD_DUE or on its next
|
|
274
|
+
// tick. If that loop already returned - every root it watched was imported - this root waits
|
|
275
|
+
// for the next slot, where startPayloadPollAtSlot moves it to pendingPayloads. That is not the normal
|
|
276
|
+
// scenario, and in a forking condition it only delays the search of the extra root
|
|
277
|
+
const deferred = this.deferredPayloadRoots.get(data.rootHex);
|
|
278
|
+
if (deferred === undefined) {
|
|
279
|
+
this.deferredPayloadRoots.set(data.rootHex, {slot: data.slot, source: data.source, peer: data.peer});
|
|
280
|
+
} else if (deferred.peer === undefined) {
|
|
281
|
+
deferred.peer = data.peer;
|
|
282
|
+
}
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
249
286
|
const isNewRoot = this.addByPayloadRootHex(data.rootHex, data.peer, data.slot);
|
|
250
287
|
if (isNewRoot) {
|
|
251
288
|
this.triggerUnknownBlockSearch();
|
|
@@ -359,12 +396,21 @@ export class BlockInputSync {
|
|
|
359
396
|
}
|
|
360
397
|
}
|
|
361
398
|
|
|
362
|
-
let
|
|
399
|
+
let belowFinalizedBlocks = 0;
|
|
400
|
+
let agedOutBlocks = 0;
|
|
363
401
|
for (const [rootHex, block] of this.pendingBlocks) {
|
|
364
402
|
const slot = getBlockInputSyncCacheItemSlot(block);
|
|
365
|
-
if (typeof slot
|
|
403
|
+
if (typeof slot !== "number") {
|
|
404
|
+
// we may not be able to download a root, hence there is no slot for it
|
|
405
|
+
if (nowSec - block.timeAddedSec > maxSecInCache) {
|
|
406
|
+
this.pendingBlocks.delete(rootHex);
|
|
407
|
+
agedOutBlocks++;
|
|
408
|
+
}
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (slot < finalizedSlot) {
|
|
366
412
|
this.pendingBlocks.delete(rootHex);
|
|
367
|
-
|
|
413
|
+
belowFinalizedBlocks++;
|
|
368
414
|
}
|
|
369
415
|
}
|
|
370
416
|
|
|
@@ -377,16 +423,20 @@ export class BlockInputSync {
|
|
|
377
423
|
if (agedOutPayloads > 0) {
|
|
378
424
|
this.metrics?.blockInputSync.removedPayloads.inc({reason: DroppedItemReason.agedOut}, agedOutPayloads);
|
|
379
425
|
}
|
|
380
|
-
if (
|
|
381
|
-
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.belowFinalized},
|
|
426
|
+
if (belowFinalizedBlocks > 0) {
|
|
427
|
+
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.belowFinalized}, belowFinalizedBlocks);
|
|
428
|
+
}
|
|
429
|
+
if (agedOutBlocks > 0) {
|
|
430
|
+
this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.agedOut}, agedOutBlocks);
|
|
382
431
|
}
|
|
383
432
|
|
|
384
|
-
this.logger.debug("BlockInputSync.pruneFinalized dropped
|
|
433
|
+
this.logger.debug("BlockInputSync.pruneFinalized dropped stale pending items", {
|
|
385
434
|
finalizedSlot,
|
|
386
435
|
finalizedRoot: checkpoint.rootHex,
|
|
387
436
|
belowFinalizedPayloads,
|
|
388
437
|
agedOutPayloads,
|
|
389
|
-
|
|
438
|
+
belowFinalizedBlocks,
|
|
439
|
+
agedOutBlocks,
|
|
390
440
|
unresolvedSlotPayloads,
|
|
391
441
|
});
|
|
392
442
|
};
|
|
@@ -800,6 +850,122 @@ export class BlockInputSync {
|
|
|
800
850
|
}
|
|
801
851
|
}
|
|
802
852
|
|
|
853
|
+
/**
|
|
854
|
+
* Start this slot's payload poll: end the previous slot's loop, move roots it never got to
|
|
855
|
+
* into pendingPayloads, then poll from PAYLOAD_DUE to the end of the slot.
|
|
856
|
+
*/
|
|
857
|
+
private startPayloadPollAtSlot = (slot: Slot): void => {
|
|
858
|
+
if (!isForkPostGloas(this.config.getForkName(slot))) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
// end the previous slot's loop, wherever it is: its sleep is bound to this same controller
|
|
862
|
+
this.payloadPollAbortController?.abort();
|
|
863
|
+
this.payloadPollAbortController = new AbortController();
|
|
864
|
+
// entries from an earlier slot is not polled
|
|
865
|
+
for (const [rootHex, {slot: deferredSlot, source, peer}] of this.deferredPayloadRoots) {
|
|
866
|
+
if (deferredSlot < slot) {
|
|
867
|
+
if (!this.chain.forkChoice.hasPayloadHexUnsafe(rootHex)) {
|
|
868
|
+
this.addDeferredPayloadRoot(rootHex, deferredSlot, source, peer);
|
|
869
|
+
}
|
|
870
|
+
this.deferredPayloadRoots.delete(rootHex);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
this.pollPayloadsAtSlot(slot, this.payloadPollAbortController.signal).catch((e) => {
|
|
874
|
+
if (!isErrorAborted(e)) {
|
|
875
|
+
this.logger.debug("Error polling payloads", {slot}, e as Error);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Poll unknown payloads of the current slot.
|
|
882
|
+
*/
|
|
883
|
+
private async pollPayloadsAtSlot(slot: Slot, signal: AbortSignal): Promise<void> {
|
|
884
|
+
// fixed tick count so the loop cannot outlive its slot: for mainnet, it's 6 ticks
|
|
885
|
+
const tickCount = Math.floor(
|
|
886
|
+
(this.config.SLOT_DURATION_MS - this.config.getPayloadDueMs()) / PAYLOAD_POLL_INTERVAL_MS
|
|
887
|
+
);
|
|
888
|
+
// a root still missing on several ticks is searched on each of them, recorded once
|
|
889
|
+
const searchedRoots = new Set<RootHex>();
|
|
890
|
+
let polls = 0;
|
|
891
|
+
|
|
892
|
+
try {
|
|
893
|
+
await sleep(Math.max(0, this.config.getPayloadDueMs() - this.chain.clock.msFromSlot(slot)), signal);
|
|
894
|
+
|
|
895
|
+
for (polls = 0; polls < tickCount; polls++) {
|
|
896
|
+
let importedCount = 0;
|
|
897
|
+
for (const [rootHex, {slot: deferredSlot, source, peer}] of this.deferredPayloadRoots) {
|
|
898
|
+
if (this.chain.forkChoice.hasPayloadHexUnsafe(rootHex)) {
|
|
899
|
+
importedCount++;
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
// copy to the regular pendingPayloads so that we can search
|
|
903
|
+
this.addDeferredPayloadRoot(rootHex, deferredSlot, source, peer);
|
|
904
|
+
searchedRoots.add(rootHex);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// an empty deferredPayloadRoots means there is no optimistic search comes before PAYLOAD_DUE
|
|
908
|
+
// we have to poll until the payload of current slot is imported or slot end
|
|
909
|
+
if (this.deferredPayloadRoots.size > 0 && importedCount === this.deferredPayloadRoots.size) {
|
|
910
|
+
if (searchedRoots.size > 0) {
|
|
911
|
+
// the backup search was needed
|
|
912
|
+
this.metrics?.blockInputSync.deferredPayloadResult.inc({
|
|
913
|
+
result: DeferredPayloadResult.ImportedAfterSearch,
|
|
914
|
+
});
|
|
915
|
+
this.metrics?.blockInputSync.deferredPayloadPolls.observe(polls);
|
|
916
|
+
this.logger.verbose("Payload imported after unknown sync search", {
|
|
917
|
+
slot,
|
|
918
|
+
roots: Array.from(searchedRoots).join(","),
|
|
919
|
+
polls,
|
|
920
|
+
});
|
|
921
|
+
} else {
|
|
922
|
+
// this happens most of the time on devnet
|
|
923
|
+
// gossip delivered everything before PAYLOAD_DUE
|
|
924
|
+
this.metrics?.blockInputSync.deferredPayloadResult.inc({
|
|
925
|
+
result: DeferredPayloadResult.ImportedBeforeSearch,
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
this.triggerUnknownBlockSearch();
|
|
932
|
+
if (polls < tickCount - 1) {
|
|
933
|
+
// no sleep after the last tick: the loop would otherwise end right at the slot boundary,
|
|
934
|
+
// where startPayloadPollAtSlot aborts it
|
|
935
|
+
await sleep(PAYLOAD_POLL_INTERVAL_MS, signal);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// reaching here means the early return never fired
|
|
940
|
+
if (this.deferredPayloadRoots.size > 0) {
|
|
941
|
+
this.metrics?.blockInputSync.deferredPayloadResult.inc({result: DeferredPayloadResult.Unresolved});
|
|
942
|
+
this.logger.debug("Deferred payloads still missing at end of slot", {
|
|
943
|
+
slot,
|
|
944
|
+
roots: Array.from(this.deferredPayloadRoots.keys()).join(","),
|
|
945
|
+
});
|
|
946
|
+
} else {
|
|
947
|
+
// no optimistic search and no payload import ended the loop, eg a skipped slot
|
|
948
|
+
this.metrics?.blockInputSync.deferredPayloadResult.inc({result: DeferredPayloadResult.ResolvedNoRoot});
|
|
949
|
+
this.logger.debug("No deferred payloads at slot", {
|
|
950
|
+
slot,
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
} catch (e) {
|
|
954
|
+
if (!isErrorAborted(e)) {
|
|
955
|
+
throw e;
|
|
956
|
+
}
|
|
957
|
+
this.logger.verbose("Payload poll aborted", {slot, polls, msIntoSlot: this.chain.clock.msFromSlot(slot)});
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
private addDeferredPayloadRoot(rootHex: RootHex, slot: Slot, source: BlockInputSource, peer?: PeerIdStr): void {
|
|
962
|
+
const isNewRoot = this.addByPayloadRootHex(rootHex, peer, slot);
|
|
963
|
+
if (isNewRoot) {
|
|
964
|
+
this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.DEFERRED_PAYLOAD_BLOCK_ROOT});
|
|
965
|
+
this.metrics?.blockInputSync.payloadSource.inc({source});
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
803
969
|
private async downloadBlock(block: BlockInputSyncCacheItem): Promise<void> {
|
|
804
970
|
if (block.status !== PendingBlockInputStatus.pending) {
|
|
805
971
|
return;
|
|
@@ -823,7 +989,12 @@ export class BlockInputSync {
|
|
|
823
989
|
if (!res.err) {
|
|
824
990
|
this.metrics?.blockInputSync.downloadedBlocksSuccess.inc();
|
|
825
991
|
const pending = res.result;
|
|
826
|
-
this
|
|
992
|
+
// pruning may have deleted this entry while we were awaiting the network, do not resurrect it via the set below
|
|
993
|
+
if (!this.pendingBlocks.has(rootHex)) {
|
|
994
|
+
this.logger.verbose("Dropping downloaded block, entry pruned during fetch", logCtx);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
this.pendingBlocks.set(rootHex, pending);
|
|
827
998
|
const blockSlot = pending.blockInput.slot;
|
|
828
999
|
const finalizedSlot = this.chain.forkChoice.getFinalizedBlock().slot;
|
|
829
1000
|
const delaySec = Date.now() / 1000 - computeTimeAtSlot(this.config, blockSlot, this.chain.genesisTime);
|
|
@@ -885,8 +1056,11 @@ export class BlockInputSync {
|
|
|
885
1056
|
}
|
|
886
1057
|
|
|
887
1058
|
this.metrics?.blockInputSync.downloadedBlocksError.inc();
|
|
888
|
-
this.logger.debug("
|
|
889
|
-
this.
|
|
1059
|
+
this.logger.debug("Failed to download unknown block root, retained for retry", logCtx, res.err);
|
|
1060
|
+
const pendingBlock = this.pendingBlocks.get(rootHex);
|
|
1061
|
+
if (pendingBlock && pendingBlock.status === PendingBlockInputStatus.fetching) {
|
|
1062
|
+
pendingBlock.status = PendingBlockInputStatus.pending;
|
|
1063
|
+
}
|
|
890
1064
|
}
|
|
891
1065
|
}
|
|
892
1066
|
|
|
@@ -1153,7 +1327,7 @@ export class BlockInputSync {
|
|
|
1153
1327
|
}
|
|
1154
1328
|
|
|
1155
1329
|
this.metrics?.blockInputSync.downloadedPayloadsResult.inc({result: DownloadResult.Failed});
|
|
1156
|
-
this.logger.debug("
|
|
1330
|
+
this.logger.debug("Failed to download unknown payload root, retained for retry", logCtx, res.err);
|
|
1157
1331
|
if (!isPendingPayloadEnvelope(payload)) {
|
|
1158
1332
|
payload.status = PendingPayloadInputStatus.pending;
|
|
1159
1333
|
}
|
|
@@ -1613,7 +1787,11 @@ export class BlockInputSync {
|
|
|
1613
1787
|
this.peerBalancer.onRequestCompleted(peerId);
|
|
1614
1788
|
}
|
|
1615
1789
|
|
|
1616
|
-
|
|
1790
|
+
const cacheItemRootHex = getBlockInputSyncCacheItemRootHex(cacheItem);
|
|
1791
|
+
// pruning may have dropped it mid-fetch
|
|
1792
|
+
if (this.pendingBlocks.has(cacheItemRootHex)) {
|
|
1793
|
+
this.pendingBlocks.set(cacheItemRootHex, cacheItem);
|
|
1794
|
+
}
|
|
1617
1795
|
|
|
1618
1796
|
if (cacheItem.status === PendingBlockInputStatus.downloaded) {
|
|
1619
1797
|
// download was successful, no need to go with another peer, return
|
package/src/util/execution.ts
CHANGED
|
@@ -2,12 +2,18 @@ import {routes} from "@lodestar/api";
|
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
3
|
import {ForkPostFulu, ForkPreFulu} from "@lodestar/params";
|
|
4
4
|
import {signedBlockToSignedHeader} from "@lodestar/state-transition";
|
|
5
|
-
import {DataColumnSidecar, SignedBeaconBlock, deneb, isGloasDataColumnSidecar} from "@lodestar/types";
|
|
6
|
-
import {fromHex, toHex} from "@lodestar/utils";
|
|
5
|
+
import {DataColumnSidecar, SignedBeaconBlock, Slot, deneb, gloas, isGloasDataColumnSidecar, ssz} from "@lodestar/types";
|
|
6
|
+
import {Logger, fromHex, toHex, toRootHex} from "@lodestar/utils";
|
|
7
7
|
import {isBlockInputBlobs, isBlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
|
|
8
8
|
import {BlockInputSource, IBlockInput} from "../chain/blocks/blockInput/types.js";
|
|
9
9
|
import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/payloadEnvelopeInput/index.js";
|
|
10
10
|
import {ChainEvent, ChainEventEmitter} from "../chain/emitter.js";
|
|
11
|
+
import {
|
|
12
|
+
EnvelopeReconstructionError,
|
|
13
|
+
EnvelopeReconstructionErrorCode,
|
|
14
|
+
} from "../chain/errors/envelopeReconstructionError.js";
|
|
15
|
+
import {IBeaconDb} from "../db/index.js";
|
|
16
|
+
import {ArchivedEnvelope, decodeArchivedEnvelope} from "../db/repositories/index.js";
|
|
11
17
|
import {IExecutionEngine} from "../execution/index.js";
|
|
12
18
|
import {Metrics} from "../metrics/index.js";
|
|
13
19
|
import {computePreFuluKzgCommitmentsInclusionProof} from "./blobs.js";
|
|
@@ -17,6 +23,7 @@ import {
|
|
|
17
23
|
getDataColumnSidecarsFromColumnSidecar,
|
|
18
24
|
getGloasDataColumnSidecars,
|
|
19
25
|
} from "./dataColumns.js";
|
|
26
|
+
import {signedHeaderEnvelopeToFull} from "./headerEnvelope.js";
|
|
20
27
|
|
|
21
28
|
export enum DataColumnEngineResult {
|
|
22
29
|
PreFulu = "pre_fulu",
|
|
@@ -251,3 +258,169 @@ export async function getDataColumnSidecarsFromExecution(
|
|
|
251
258
|
);
|
|
252
259
|
return DataColumnEngineResult.SuccessResolved;
|
|
253
260
|
}
|
|
261
|
+
|
|
262
|
+
/** engine_getPayloadBodiesByHashV2: ELs MUST support at least 32 hashes per request. */
|
|
263
|
+
const MAX_BODIES_REQUEST = 32;
|
|
264
|
+
|
|
265
|
+
type SlotEnvelopeBytes = {slot: Slot; envelopeBytes: Uint8Array};
|
|
266
|
+
|
|
267
|
+
type RangeEntry = ArchivedEnvelope & {slot: Slot};
|
|
268
|
+
|
|
269
|
+
/** What a body root mismatch means on a given serving path */
|
|
270
|
+
export type ReconstructMismatchPolicy = "throw" | "omit";
|
|
271
|
+
|
|
272
|
+
export type RebuildMiss =
|
|
273
|
+
/** EL does not have the block, or has pruned its block access list */
|
|
274
|
+
| {slot: Slot; reason: "unavailable"}
|
|
275
|
+
/** An EL body does not hash to its stored root (local inconsistency) */
|
|
276
|
+
| {slot: Slot; reason: "mismatch"; error: EnvelopeReconstructionError};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Stream finalized envelopes over [startSlot, endSlot) as serialized bytes, rebuilding header
|
|
280
|
+
* entries from EL bodies 32 per round-trip.
|
|
281
|
+
*
|
|
282
|
+
* Ends at the first entry that cannot be served by throwing RANGE_UNSERVABLE with that slot: the
|
|
283
|
+
* by-range spec inherits BeaconBlocksByRange v2 semantics (consecutive, MAY be short), and a hole
|
|
284
|
+
* looks like a lying peer to one that already holds the blocks. Entries are attempted regardless of
|
|
285
|
+
* age; the EL's block access list retention is the floor, not MIN_EPOCHS_FOR_BLOCK_REQUESTS.
|
|
286
|
+
*
|
|
287
|
+
* Throws ENGINE_UNAVAILABLE if the EL call fails. Either may surface after envelopes were yielded.
|
|
288
|
+
*/
|
|
289
|
+
export async function* reconstructExecutionPayloadEnvelopesByRange(
|
|
290
|
+
db: IBeaconDb,
|
|
291
|
+
executionEngine: IExecutionEngine,
|
|
292
|
+
logger: Logger,
|
|
293
|
+
metrics: Metrics | null,
|
|
294
|
+
startSlot: Slot,
|
|
295
|
+
endSlot: Slot
|
|
296
|
+
): AsyncIterable<SlotEnvelopeBytes> {
|
|
297
|
+
const archive = db.executionPayloadEnvelopeArchive;
|
|
298
|
+
let batch: RangeEntry[] = [];
|
|
299
|
+
|
|
300
|
+
for await (const {key, value: bytes} of archive.binaryEntriesStream({gte: startSlot, lt: endSlot})) {
|
|
301
|
+
batch.push({slot: archive.decodeKey(key), ...decodeArchivedEnvelope(bytes)});
|
|
302
|
+
if (batch.length === MAX_BODIES_REQUEST) {
|
|
303
|
+
yield* reconstructBatch(executionEngine, logger, metrics, batch);
|
|
304
|
+
batch = [];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (batch.length > 0) {
|
|
308
|
+
yield* reconstructBatch(executionEngine, logger, metrics, batch);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Rebuild a range batch, yielding what precedes the first unservable entry before throwing
|
|
314
|
+
* RANGE_UNSERVABLE for it
|
|
315
|
+
*/
|
|
316
|
+
async function* reconstructBatch(
|
|
317
|
+
executionEngine: IExecutionEngine,
|
|
318
|
+
logger: Logger,
|
|
319
|
+
metrics: Metrics | null,
|
|
320
|
+
batch: RangeEntry[]
|
|
321
|
+
): AsyncIterable<SlotEnvelopeBytes> {
|
|
322
|
+
const headerEnvelopes: gloas.SignedExecutionPayloadHeaderEnvelope[] = [];
|
|
323
|
+
for (const entry of batch) {
|
|
324
|
+
if (entry.headerEnvelope !== undefined) headerEnvelopes.push(entry.headerEnvelope);
|
|
325
|
+
}
|
|
326
|
+
const rebuilt = await reconstructEnvelopesBatch(executionEngine, metrics, headerEnvelopes);
|
|
327
|
+
|
|
328
|
+
let rebuiltIdx = 0;
|
|
329
|
+
for (const entry of batch) {
|
|
330
|
+
if (entry.envelopeBytes !== undefined) {
|
|
331
|
+
yield {slot: entry.slot, envelopeBytes: entry.envelopeBytes};
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const result = rebuilt[rebuiltIdx++];
|
|
335
|
+
if (isRebuildMiss(result)) {
|
|
336
|
+
// Peer-triggered, so debug: a persistent local mismatch would otherwise log on every request
|
|
337
|
+
if (result.reason === "mismatch") {
|
|
338
|
+
logger.debug("Archived envelope failed body root check against EL bodies", {slot: entry.slot}, result.error);
|
|
339
|
+
} else {
|
|
340
|
+
logger.debug("EL cannot serve bodies for archived envelope, ending range", {slot: entry.slot});
|
|
341
|
+
}
|
|
342
|
+
throw new EnvelopeReconstructionError(
|
|
343
|
+
{code: EnvelopeReconstructionErrorCode.RANGE_UNSERVABLE, slot: entry.slot},
|
|
344
|
+
`archived envelope range unservable from slot=${entry.slot}`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
yield {slot: entry.slot, envelopeBytes: ssz.gloas.SignedExecutionPayloadEnvelope.serialize(result)};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Rebuild header envelopes from EL bodies, 32 per round-trip. Aligned with the input, with a
|
|
353
|
+
* {@link RebuildMiss} where the envelope could not be rebuilt; the caller decides what a miss means
|
|
354
|
+
* on its path. Throws ENGINE_UNAVAILABLE only.
|
|
355
|
+
*/
|
|
356
|
+
export async function reconstructExecutionPayloadEnvelopes(
|
|
357
|
+
executionEngine: IExecutionEngine,
|
|
358
|
+
metrics: Metrics | null,
|
|
359
|
+
headerEnvelopes: gloas.SignedExecutionPayloadHeaderEnvelope[]
|
|
360
|
+
): Promise<(gloas.SignedExecutionPayloadEnvelope | RebuildMiss)[]> {
|
|
361
|
+
const out: (gloas.SignedExecutionPayloadEnvelope | RebuildMiss)[] = [];
|
|
362
|
+
for (let i = 0; i < headerEnvelopes.length; i += MAX_BODIES_REQUEST) {
|
|
363
|
+
out.push(
|
|
364
|
+
...(await reconstructEnvelopesBatch(executionEngine, metrics, headerEnvelopes.slice(i, i + MAX_BODIES_REQUEST)))
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function isRebuildMiss(result: gloas.SignedExecutionPayloadEnvelope | RebuildMiss): result is RebuildMiss {
|
|
371
|
+
return "reason" in result;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* One EL round-trip. Aligned with the input; never throws per envelope, only ENGINE_UNAVAILABLE.
|
|
376
|
+
* Every serving path (by-range, by-root, REST) comes through here, so the outcome metrics are
|
|
377
|
+
* incremented once, in this function.
|
|
378
|
+
*/
|
|
379
|
+
async function reconstructEnvelopesBatch(
|
|
380
|
+
executionEngine: IExecutionEngine,
|
|
381
|
+
metrics: Metrics | null,
|
|
382
|
+
headerEnvelopes: gloas.SignedExecutionPayloadHeaderEnvelope[]
|
|
383
|
+
): Promise<(gloas.SignedExecutionPayloadEnvelope | RebuildMiss)[]> {
|
|
384
|
+
if (headerEnvelopes.length === 0) return [];
|
|
385
|
+
const hashes = headerEnvelopes.map((headerEnvelope) => toRootHex(headerEnvelope.message.payloadHeader.blockHash));
|
|
386
|
+
|
|
387
|
+
let bodies: Awaited<ReturnType<IExecutionEngine["getPayloadBodiesByHashV2"]>>;
|
|
388
|
+
try {
|
|
389
|
+
bodies = await executionEngine.getPayloadBodiesByHashV2(hashes);
|
|
390
|
+
} catch (e) {
|
|
391
|
+
metrics?.payloadEnvelopeReconstruction.engineErrors.inc();
|
|
392
|
+
throw new EnvelopeReconstructionError(
|
|
393
|
+
{code: EnvelopeReconstructionErrorCode.ENGINE_UNAVAILABLE},
|
|
394
|
+
`engine_getPayloadBodiesByHashV2 failed: ${(e as Error).message}`
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return headerEnvelopes.map((headerEnvelope, i) => {
|
|
399
|
+
const slot = headerEnvelope.message.payloadHeader.slotNumber;
|
|
400
|
+
const body = bodies[i];
|
|
401
|
+
// A zero-length block access list cannot be valid, RLP encodes an empty list as 0xc0
|
|
402
|
+
if (body == null || body.withdrawals == null || body.blockAccessList == null || body.blockAccessList.length === 0) {
|
|
403
|
+
metrics?.payloadEnvelopeReconstruction.envelopes.inc({result: "unavailable"});
|
|
404
|
+
return {slot, reason: "unavailable"};
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
const envelope = signedHeaderEnvelopeToFull(headerEnvelope, {
|
|
408
|
+
transactions: body.transactions,
|
|
409
|
+
withdrawals: body.withdrawals,
|
|
410
|
+
blockAccessList: body.blockAccessList,
|
|
411
|
+
});
|
|
412
|
+
metrics?.payloadEnvelopeReconstruction.envelopes.inc({result: "ok"});
|
|
413
|
+
return envelope;
|
|
414
|
+
} catch (e) {
|
|
415
|
+
if (
|
|
416
|
+
e instanceof EnvelopeReconstructionError &&
|
|
417
|
+
e.type.code === EnvelopeReconstructionErrorCode.BODY_ROOT_MISMATCH
|
|
418
|
+
) {
|
|
419
|
+
metrics?.payloadEnvelopeReconstruction.envelopes.inc({result: "mismatch"});
|
|
420
|
+
metrics?.payloadEnvelopeReconstruction.mismatchByField.inc({field: e.type.field});
|
|
421
|
+
return {slot, reason: "mismatch", error: e};
|
|
422
|
+
}
|
|
423
|
+
throw e;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {
|
|
3
|
+
BlockAccessList,
|
|
4
|
+
ExecutionPayloadEnvelope,
|
|
5
|
+
ExecutionPayloadHeaderEnvelope,
|
|
6
|
+
SignedExecutionPayloadEnvelope,
|
|
7
|
+
SignedExecutionPayloadHeaderEnvelope,
|
|
8
|
+
Transactions,
|
|
9
|
+
Withdrawals,
|
|
10
|
+
} from "@lodestar/types/gloas";
|
|
11
|
+
import {toRootHex} from "@lodestar/utils";
|
|
12
|
+
import {
|
|
13
|
+
EnvelopeReconstructionError,
|
|
14
|
+
EnvelopeReconstructionErrorCode,
|
|
15
|
+
} from "../chain/errors/envelopeReconstructionError.js";
|
|
16
|
+
|
|
17
|
+
/** The parts of an execution payload the EL serves back via engine_getPayloadBodiesByHashV2 */
|
|
18
|
+
export type ExecutionPayloadBodies = {
|
|
19
|
+
transactions: Transactions;
|
|
20
|
+
withdrawals: Withdrawals;
|
|
21
|
+
blockAccessList: BlockAccessList;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ExecutionPayloadBodyField = keyof ExecutionPayloadBodies;
|
|
25
|
+
|
|
26
|
+
const {transactions, withdrawals, blockAccessList} = ssz.gloas.ExecutionPayload.fields;
|
|
27
|
+
|
|
28
|
+
/** Replace the three body lists by their roots; hashes to the same root as the full envelope */
|
|
29
|
+
export function toHeaderEnvelope(envelope: ExecutionPayloadEnvelope): ExecutionPayloadHeaderEnvelope {
|
|
30
|
+
const {payload, ...envelopeFields} = envelope;
|
|
31
|
+
const {transactions: txs, withdrawals: wds, blockAccessList: bal, ...scalars} = payload;
|
|
32
|
+
return {
|
|
33
|
+
...envelopeFields,
|
|
34
|
+
payloadHeader: {
|
|
35
|
+
...scalars,
|
|
36
|
+
transactionsRoot: transactions.hashTreeRoot(txs),
|
|
37
|
+
withdrawalsRoot: withdrawals.hashTreeRoot(wds),
|
|
38
|
+
blockAccessListRoot: blockAccessList.hashTreeRoot(bal),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function toSignedHeaderEnvelope(envelope: SignedExecutionPayloadEnvelope): SignedExecutionPayloadHeaderEnvelope {
|
|
44
|
+
return {message: toHeaderEnvelope(envelope.message), signature: envelope.signature};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Rebuild the full signed envelope from header envelope + EL bodies, each body verified against its stored
|
|
49
|
+
* root. Throws {@link EnvelopeReconstructionError} BODY_ROOT_MISMATCH naming the first body that differs.
|
|
50
|
+
*/
|
|
51
|
+
export function signedHeaderEnvelopeToFull(
|
|
52
|
+
headerEnvelope: SignedExecutionPayloadHeaderEnvelope,
|
|
53
|
+
bodies: ExecutionPayloadBodies
|
|
54
|
+
): SignedExecutionPayloadEnvelope {
|
|
55
|
+
const {payloadHeader, ...envelopeFields} = headerEnvelope.message;
|
|
56
|
+
const {transactionsRoot, withdrawalsRoot, blockAccessListRoot, ...scalars} = payloadHeader;
|
|
57
|
+
const slot = scalars.slotNumber;
|
|
58
|
+
|
|
59
|
+
assertBodyRoot("transactions", slot, transactionsRoot, transactions.hashTreeRoot(bodies.transactions));
|
|
60
|
+
assertBodyRoot("withdrawals", slot, withdrawalsRoot, withdrawals.hashTreeRoot(bodies.withdrawals));
|
|
61
|
+
assertBodyRoot("blockAccessList", slot, blockAccessListRoot, blockAccessList.hashTreeRoot(bodies.blockAccessList));
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
message: {...envelopeFields, payload: {...scalars, ...bodies}},
|
|
65
|
+
signature: headerEnvelope.signature,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function assertBodyRoot(field: ExecutionPayloadBodyField, slot: number, stored: Uint8Array, rebuilt: Uint8Array): void {
|
|
70
|
+
if (!ssz.Root.equals(stored, rebuilt)) {
|
|
71
|
+
throw new EnvelopeReconstructionError(
|
|
72
|
+
{code: EnvelopeReconstructionErrorCode.BODY_ROOT_MISMATCH, slot, field},
|
|
73
|
+
`reconstructed ${field} root mismatch slot=${slot} stored=${toRootHex(stored)} rebuilt=${toRootHex(rebuilt)}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/util/shuffle.ts
CHANGED
|
@@ -10,12 +10,3 @@ export function shuffle<T>(arr: T[]): T[] {
|
|
|
10
10
|
}
|
|
11
11
|
return _arr;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Return one random item from array
|
|
16
|
-
*/
|
|
17
|
-
export function shuffleOne<T>(arr: T[]): T | undefined {
|
|
18
|
-
if (arr.length === 0) return undefined;
|
|
19
|
-
|
|
20
|
-
return arr[Math.floor(Math.random() * arr.length)];
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CheckpointWithHex } from "@lodestar/fork-choice";
|
|
2
|
-
import { Logger } from "@lodestar/logger";
|
|
3
|
-
import { IBeaconDb } from "../../../db/interface.js";
|
|
4
|
-
import { IBeaconChain } from "../../interface.js";
|
|
5
|
-
/**
|
|
6
|
-
* Backfill sync relies on verified connected ranges (which are represented as key,value
|
|
7
|
-
* with a verified jump from a key back to value). Since the node could have progressed
|
|
8
|
-
* ahead from, we need to save the forward progress of this node as another backfill
|
|
9
|
-
* range entry, that backfill sync will use to jump back if this node is restarted
|
|
10
|
-
* for any reason.
|
|
11
|
-
* The current backfill has its own backfill entry from anchor slot to last backfilled
|
|
12
|
-
* slot. And this would create the entry from the current finalized slot to the anchor
|
|
13
|
-
* slot.
|
|
14
|
-
*/
|
|
15
|
-
export declare function updateBackfillRange({ chain, db, logger }: {
|
|
16
|
-
chain: IBeaconChain;
|
|
17
|
-
db: IBeaconDb;
|
|
18
|
-
logger: Logger;
|
|
19
|
-
}, finalized: CheckpointWithHex): Promise<void>;
|
|
20
|
-
//# sourceMappingURL=updateBackfillRange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateBackfillRange.d.ts","sourceRoot":"","sources":["../../../../src/chain/archiveStore/utils/updateBackfillRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,EAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAC,EAAE;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,EACzE,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|