@lodestar/beacon-node 1.49.0-dev.ae6cc426f1 → 1.49.0-dev.c535e94f25
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.js +2 -2
- 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/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +9 -7
- 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 +0 -5
- 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/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +14 -3
- 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/blocks/index.js +2 -2
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
- package/lib/chain/emitter.d.ts +10 -0
- package/lib/chain/emitter.d.ts.map +1 -1
- package/lib/chain/emitter.js +4 -0
- package/lib/chain/emitter.js.map +1 -1
- package/lib/chain/errors/attesterSlashingError.d.ts +4 -1
- package/lib/chain/errors/attesterSlashingError.d.ts.map +1 -1
- package/lib/chain/errors/attesterSlashingError.js +1 -0
- package/lib/chain/errors/attesterSlashingError.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/errors/proposerSlashingError.d.ts +4 -1
- package/lib/chain/errors/proposerSlashingError.d.ts.map +1 -1
- package/lib/chain/errors/proposerSlashingError.js +1 -0
- package/lib/chain/errors/proposerSlashingError.js.map +1 -1
- package/lib/chain/options.d.ts +0 -4
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +0 -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/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +6 -6
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +2 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +3 -2
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +1 -2
- package/lib/chain/validation/attesterSlashing.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/chain/validation/proposerSlashing.js +1 -2
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validatorMonitor.d.ts.map +1 -1
- package/lib/chain/validatorMonitor.js +2 -2
- package/lib/chain/validatorMonitor.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/blockArchive.d.ts +5 -0
- package/lib/db/repositories/blockArchive.d.ts.map +1 -1
- package/lib/db/repositories/blockArchive.js +36 -1
- package/lib/db/repositories/blockArchive.js.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/index.d.ts +0 -1
- package/lib/db/repositories/index.d.ts.map +1 -1
- package/lib/db/repositories/index.js +0 -1
- package/lib/db/repositories/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +12 -11
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +25 -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/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +15 -0
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/gossip/topic.d.ts +1 -1
- package/lib/network/gossip/topic.d.ts.map +1 -1
- package/lib/network/gossip/topic.js +1 -1
- package/lib/network/gossip/topic.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +16 -5
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/gossipValidatorFn.d.ts +2 -0
- package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +88 -7
- package/lib/network/processor/gossipValidatorFn.js.map +1 -1
- package/lib/network/processor/index.d.ts +6 -2
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +62 -24
- package/lib/network/processor/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 +21 -2
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js +22 -2
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +20 -0
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +199 -15
- package/lib/sync/unknownBlock.js.map +1 -1
- 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 +2 -2
- package/src/api/impl/beacon/pool/index.ts +6 -2
- package/src/api/impl/validator/index.ts +9 -7
- package/src/chain/archiveStore/archiveStore.ts +0 -6
- package/src/chain/archiveStore/historicalState/metrics.ts +5 -7
- package/src/chain/archiveStore/utils/pruneHistory.ts +14 -4
- package/src/chain/blocks/importExecutionPayload.ts +14 -0
- package/src/chain/blocks/index.ts +2 -2
- package/src/chain/blocks/payloadEnvelopeInput/types.ts +1 -1
- package/src/chain/emitter.ts +7 -2
- package/src/chain/errors/attesterSlashingError.ts +3 -1
- package/src/chain/errors/payloadAttestation.ts +2 -0
- package/src/chain/errors/proposerSlashingError.ts +3 -1
- package/src/chain/options.ts +0 -5
- package/src/chain/produceBlock/computeNewStateRoot.ts +9 -2
- package/src/chain/produceBlock/produceBlockBody.ts +17 -6
- package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +3 -2
- package/src/chain/validation/attesterSlashing.ts +1 -2
- package/src/chain/validation/payloadAttestationMessage.ts +9 -0
- package/src/chain/validation/proposerSlashing.ts +1 -2
- package/src/chain/validatorMonitor.ts +12 -2
- package/src/db/beacon.ts +0 -5
- package/src/db/buckets.ts +1 -1
- package/src/db/interface.ts +0 -3
- package/src/db/repositories/blockArchive.ts +38 -1
- package/src/db/repositories/index.ts +0 -1
- package/src/metrics/metrics/lodestar.ts +34 -26
- package/src/metrics/metrics.ts +7 -2
- package/src/network/gossip/gossipsub.ts +18 -1
- package/src/network/gossip/topic.ts +2 -2
- package/src/network/processor/gossipHandlers.ts +18 -5
- package/src/network/processor/gossipValidatorFn.ts +111 -7
- package/src/network/processor/index.ts +81 -24
- 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 +24 -5
- package/src/sync/unknownBlock.ts +207 -14
- 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,
|
|
@@ -152,6 +164,7 @@ export class BlockInputSync {
|
|
|
152
164
|
this.logger.verbose("BlockInputSync enabled.");
|
|
153
165
|
this.chain.emitter.on(ChainEvent.unknownBlockRoot, this.onUnknownBlockRoot);
|
|
154
166
|
this.chain.emitter.on(ChainEvent.unknownEnvelopeBlockRoot, this.onUnknownEnvelopeBlockRoot);
|
|
167
|
+
this.chain.emitter.on(ChainEvent.unknownEnvelopeBlockRootSlot, this.onUnknownEnvelopeBlockRootSlot);
|
|
155
168
|
this.chain.emitter.on(ChainEvent.incompleteBlockInput, this.onIncompleteBlockInput);
|
|
156
169
|
this.chain.emitter.on(ChainEvent.incompletePayloadEnvelope, this.onIncompletePayloadEnvelope);
|
|
157
170
|
this.chain.emitter.on(ChainEvent.blockUnknownParent, this.onUnknownParent);
|
|
@@ -160,6 +173,7 @@ export class BlockInputSync {
|
|
|
160
173
|
this.chain.emitter.on(routes.events.EventType.executionPayload, this.onPayloadImported);
|
|
161
174
|
this.network.events.on(NetworkEvent.peerConnected, this.onPeerConnected);
|
|
162
175
|
this.network.events.on(NetworkEvent.peerDisconnected, this.onPeerDisconnected);
|
|
176
|
+
this.chain.clock.on(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
163
177
|
|
|
164
178
|
// Seed the balancer with peers that connected before we subscribed
|
|
165
179
|
for (const peerId of this.network.getConnectedPeers()) {
|
|
@@ -171,14 +185,22 @@ export class BlockInputSync {
|
|
|
171
185
|
}
|
|
172
186
|
|
|
173
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);
|
|
174
191
|
}
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
unsubscribeFromNetwork(): void {
|
|
178
195
|
this.logger.verbose("BlockInputSync disabled.");
|
|
179
196
|
this.clearRateLimitBackoffTimer();
|
|
197
|
+
this.chain.clock.off(ClockEvent.slot, this.startPayloadPollAtSlot);
|
|
198
|
+
this.payloadPollAbortController?.abort();
|
|
199
|
+
this.payloadPollAbortController = undefined;
|
|
200
|
+
this.deferredPayloadRoots.clear();
|
|
180
201
|
this.chain.emitter.off(ChainEvent.unknownBlockRoot, this.onUnknownBlockRoot);
|
|
181
202
|
this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRoot, this.onUnknownEnvelopeBlockRoot);
|
|
203
|
+
this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRootSlot, this.onUnknownEnvelopeBlockRootSlot);
|
|
182
204
|
this.chain.emitter.off(ChainEvent.incompleteBlockInput, this.onIncompleteBlockInput);
|
|
183
205
|
this.chain.emitter.off(ChainEvent.incompletePayloadEnvelope, this.onIncompletePayloadEnvelope);
|
|
184
206
|
this.chain.emitter.off(ChainEvent.blockUnknownParent, this.onUnknownParent);
|
|
@@ -205,8 +227,11 @@ export class BlockInputSync {
|
|
|
205
227
|
private onUnknownBlockRoot = (data: ChainEventData[ChainEvent.unknownBlockRoot]): void => {
|
|
206
228
|
try {
|
|
207
229
|
const isNewRoot = this.addByRootHex(data.rootHex, data.peer);
|
|
208
|
-
|
|
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) {
|
|
209
232
|
this.triggerUnknownBlockSearch();
|
|
233
|
+
}
|
|
234
|
+
if (isNewRoot) {
|
|
210
235
|
this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.UNKNOWN_BLOCK_ROOT});
|
|
211
236
|
this.metrics?.blockInputSync.source.inc({source: data.source});
|
|
212
237
|
}
|
|
@@ -242,6 +267,33 @@ export class BlockInputSync {
|
|
|
242
267
|
}
|
|
243
268
|
};
|
|
244
269
|
|
|
270
|
+
private onUnknownEnvelopeBlockRootSlot = (data: ChainEventData[ChainEvent.unknownEnvelopeBlockRootSlot]): void => {
|
|
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
|
+
|
|
286
|
+
const isNewRoot = this.addByPayloadRootHex(data.rootHex, data.peer, data.slot);
|
|
287
|
+
if (isNewRoot) {
|
|
288
|
+
this.triggerUnknownBlockSearch();
|
|
289
|
+
this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.UNKNOWN_PAYLOAD_BLOCK_ROOT_SLOT});
|
|
290
|
+
this.metrics?.blockInputSync.payloadSource.inc({source: data.source});
|
|
291
|
+
}
|
|
292
|
+
} catch (e) {
|
|
293
|
+
this.logger.debug("Error handling unknownEnvelopeBlockRootSlot event", {}, e as Error);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
245
297
|
private onIncompletePayloadEnvelope = (data: ChainEventData[ChainEvent.incompletePayloadEnvelope]): void => {
|
|
246
298
|
try {
|
|
247
299
|
this.addByPayloadInput(data.payloadInput, data.peer);
|
|
@@ -344,12 +396,21 @@ export class BlockInputSync {
|
|
|
344
396
|
}
|
|
345
397
|
}
|
|
346
398
|
|
|
347
|
-
let
|
|
399
|
+
let belowFinalizedBlocks = 0;
|
|
400
|
+
let agedOutBlocks = 0;
|
|
348
401
|
for (const [rootHex, block] of this.pendingBlocks) {
|
|
349
402
|
const slot = getBlockInputSyncCacheItemSlot(block);
|
|
350
|
-
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) {
|
|
351
412
|
this.pendingBlocks.delete(rootHex);
|
|
352
|
-
|
|
413
|
+
belowFinalizedBlocks++;
|
|
353
414
|
}
|
|
354
415
|
}
|
|
355
416
|
|
|
@@ -362,16 +423,20 @@ export class BlockInputSync {
|
|
|
362
423
|
if (agedOutPayloads > 0) {
|
|
363
424
|
this.metrics?.blockInputSync.removedPayloads.inc({reason: DroppedItemReason.agedOut}, agedOutPayloads);
|
|
364
425
|
}
|
|
365
|
-
if (
|
|
366
|
-
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);
|
|
367
431
|
}
|
|
368
432
|
|
|
369
|
-
this.logger.debug("BlockInputSync.pruneFinalized dropped
|
|
433
|
+
this.logger.debug("BlockInputSync.pruneFinalized dropped stale pending items", {
|
|
370
434
|
finalizedSlot,
|
|
371
435
|
finalizedRoot: checkpoint.rootHex,
|
|
372
436
|
belowFinalizedPayloads,
|
|
373
437
|
agedOutPayloads,
|
|
374
|
-
|
|
438
|
+
belowFinalizedBlocks,
|
|
439
|
+
agedOutBlocks,
|
|
375
440
|
unresolvedSlotPayloads,
|
|
376
441
|
});
|
|
377
442
|
};
|
|
@@ -785,6 +850,122 @@ export class BlockInputSync {
|
|
|
785
850
|
}
|
|
786
851
|
}
|
|
787
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
|
+
|
|
788
969
|
private async downloadBlock(block: BlockInputSyncCacheItem): Promise<void> {
|
|
789
970
|
if (block.status !== PendingBlockInputStatus.pending) {
|
|
790
971
|
return;
|
|
@@ -808,7 +989,12 @@ export class BlockInputSync {
|
|
|
808
989
|
if (!res.err) {
|
|
809
990
|
this.metrics?.blockInputSync.downloadedBlocksSuccess.inc();
|
|
810
991
|
const pending = res.result;
|
|
811
|
-
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);
|
|
812
998
|
const blockSlot = pending.blockInput.slot;
|
|
813
999
|
const finalizedSlot = this.chain.forkChoice.getFinalizedBlock().slot;
|
|
814
1000
|
const delaySec = Date.now() / 1000 - computeTimeAtSlot(this.config, blockSlot, this.chain.genesisTime);
|
|
@@ -870,8 +1056,11 @@ export class BlockInputSync {
|
|
|
870
1056
|
}
|
|
871
1057
|
|
|
872
1058
|
this.metrics?.blockInputSync.downloadedBlocksError.inc();
|
|
873
|
-
this.logger.debug("
|
|
874
|
-
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
|
+
}
|
|
875
1064
|
}
|
|
876
1065
|
}
|
|
877
1066
|
|
|
@@ -1138,7 +1327,7 @@ export class BlockInputSync {
|
|
|
1138
1327
|
}
|
|
1139
1328
|
|
|
1140
1329
|
this.metrics?.blockInputSync.downloadedPayloadsResult.inc({result: DownloadResult.Failed});
|
|
1141
|
-
this.logger.debug("
|
|
1330
|
+
this.logger.debug("Failed to download unknown payload root, retained for retry", logCtx, res.err);
|
|
1142
1331
|
if (!isPendingPayloadEnvelope(payload)) {
|
|
1143
1332
|
payload.status = PendingPayloadInputStatus.pending;
|
|
1144
1333
|
}
|
|
@@ -1598,7 +1787,11 @@ export class BlockInputSync {
|
|
|
1598
1787
|
this.peerBalancer.onRequestCompleted(peerId);
|
|
1599
1788
|
}
|
|
1600
1789
|
|
|
1601
|
-
|
|
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
|
+
}
|
|
1602
1795
|
|
|
1603
1796
|
if (cacheItem.status === PendingBlockInputStatus.downloaded) {
|
|
1604
1797
|
// download was successful, no need to go with another peer, return
|
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"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Backfill sync relies on verified connected ranges (which are represented as key,value
|
|
3
|
-
* with a verified jump from a key back to value). Since the node could have progressed
|
|
4
|
-
* ahead from, we need to save the forward progress of this node as another backfill
|
|
5
|
-
* range entry, that backfill sync will use to jump back if this node is restarted
|
|
6
|
-
* for any reason.
|
|
7
|
-
* The current backfill has its own backfill entry from anchor slot to last backfilled
|
|
8
|
-
* slot. And this would create the entry from the current finalized slot to the anchor
|
|
9
|
-
* slot.
|
|
10
|
-
*/
|
|
11
|
-
export async function updateBackfillRange({ chain, db, logger }, finalized) {
|
|
12
|
-
try {
|
|
13
|
-
// Mark the sequence in backfill db from finalized block's slot till anchor slot as
|
|
14
|
-
// filled.
|
|
15
|
-
const finalizedBlockFC = chain.forkChoice.getBlockHexDefaultStatus(finalized.rootHex);
|
|
16
|
-
if (finalizedBlockFC && finalizedBlockFC.slot > chain.anchorStateLatestBlockSlot) {
|
|
17
|
-
await db.backfilledRanges.put(finalizedBlockFC.slot, chain.anchorStateLatestBlockSlot);
|
|
18
|
-
// Clear previously marked sequence till anchorStateLatestBlockSlot, without
|
|
19
|
-
// touching backfill sync process sequence which are at
|
|
20
|
-
// <=anchorStateLatestBlockSlot i.e. clear >anchorStateLatestBlockSlot
|
|
21
|
-
// and < currentSlot
|
|
22
|
-
const filteredSeqs = await db.backfilledRanges.entries({
|
|
23
|
-
gt: chain.anchorStateLatestBlockSlot,
|
|
24
|
-
lt: finalizedBlockFC.slot,
|
|
25
|
-
});
|
|
26
|
-
logger.debug("updated backfilledRanges", {
|
|
27
|
-
key: finalizedBlockFC.slot,
|
|
28
|
-
value: chain.anchorStateLatestBlockSlot,
|
|
29
|
-
});
|
|
30
|
-
if (filteredSeqs.length > 0) {
|
|
31
|
-
await db.backfilledRanges.batchDelete(filteredSeqs.map((entry) => entry.key));
|
|
32
|
-
logger.debug(`Forward Sync - cleaned up backfilledRanges between ${finalizedBlockFC.slot},${chain.anchorStateLatestBlockSlot}`, { seqs: JSON.stringify(filteredSeqs) });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
logger.error("Error updating backfilledRanges on finalization", { epoch: finalized.epoch }, e);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=updateBackfillRange.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateBackfillRange.js","sourceRoot":"","sources":["../../../../src/chain/archiveStore/utils/updateBackfillRange.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAuD,EACzE,SAA4B;IAE5B,IAAI,CAAC;QACH,mFAAmF;QACnF,UAAU;QACV,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAAC,wBAAwB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACtF,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,IAAI,GAAG,KAAK,CAAC,0BAA0B,EAAE,CAAC;YACjF,MAAM,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAEvF,4EAA4E;YAC5E,uDAAuD;YACvD,sEAAsE;YACtE,oBAAoB;YACpB,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;gBACrD,EAAE,EAAE,KAAK,CAAC,0BAA0B;gBACpC,EAAE,EAAE,gBAAgB,CAAC,IAAI;aAC1B,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;gBACvC,GAAG,EAAE,gBAAgB,CAAC,IAAI;gBAC1B,KAAK,EAAE,KAAK,CAAC,0BAA0B;aACxC,CAAC,CAAC;YACH,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC9E,MAAM,CAAC,KAAK,CACV,sDAAsD,gBAAgB,CAAC,IAAI,IAAI,KAAK,CAAC,0BAA0B,EAAE,EACjH,EAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAC,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,iDAAiD,EAAE,EAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAC,EAAE,CAAU,CAAC,CAAC;IACxG,CAAC;AACH,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ChainForkConfig } from "@lodestar/config";
|
|
2
|
-
import { DatabaseController, Repository } from "@lodestar/db";
|
|
3
|
-
import { Slot } from "@lodestar/types";
|
|
4
|
-
/**
|
|
5
|
-
* Slot to slot ranges that ensure that block range is fully backfilled
|
|
6
|
-
*
|
|
7
|
-
* If node starts backfilling at slots 1000, and backfills to 800, there will be an entry
|
|
8
|
-
* 1000 -> 800
|
|
9
|
-
*
|
|
10
|
-
* When the node is backfilling if it starts at 1200 and backfills to 1000, it will find this sequence and,
|
|
11
|
-
* jump directly to 800 and delete the key 1000.
|
|
12
|
-
*/
|
|
13
|
-
export declare class BackfilledRanges extends Repository<Slot, Slot> {
|
|
14
|
-
constructor(config: ChainForkConfig, db: DatabaseController<Uint8Array, Uint8Array>);
|
|
15
|
-
decodeKey(data: Buffer): number;
|
|
16
|
-
getId(_value: Slot): number;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=backfilledRanges.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backfilledRanges.d.ts","sourceRoot":"","sources":["../../../src/db/repositories/backfilledRanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,IAAI,EAAM,MAAM,iBAAiB,CAAC;AAI1C;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC;IAC1D,YAAY,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,EAGlF;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9B;IAED,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,CAE1B;CACF"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Repository } from "@lodestar/db";
|
|
2
|
-
import { ssz } from "@lodestar/types";
|
|
3
|
-
import { bytesToInt } from "@lodestar/utils";
|
|
4
|
-
import { Bucket, getBucketNameByValue } from "../buckets.js";
|
|
5
|
-
/**
|
|
6
|
-
* Slot to slot ranges that ensure that block range is fully backfilled
|
|
7
|
-
*
|
|
8
|
-
* If node starts backfilling at slots 1000, and backfills to 800, there will be an entry
|
|
9
|
-
* 1000 -> 800
|
|
10
|
-
*
|
|
11
|
-
* When the node is backfilling if it starts at 1200 and backfills to 1000, it will find this sequence and,
|
|
12
|
-
* jump directly to 800 and delete the key 1000.
|
|
13
|
-
*/
|
|
14
|
-
export class BackfilledRanges extends Repository {
|
|
15
|
-
constructor(config, db) {
|
|
16
|
-
const bucket = Bucket.backfilled_ranges;
|
|
17
|
-
super(config, db, bucket, ssz.Slot, getBucketNameByValue(bucket));
|
|
18
|
-
}
|
|
19
|
-
decodeKey(data) {
|
|
20
|
-
return bytesToInt(super.decodeKey(data), "be");
|
|
21
|
-
}
|
|
22
|
-
getId(_value) {
|
|
23
|
-
throw new Error("Cannot get the db key from slot");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=backfilledRanges.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backfilledRanges.js","sourceRoot":"","sources":["../../../src/db/repositories/backfilledRanges.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,UAAU,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAO,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAiB,SAAQ,UAAsB;IAC1D,YAAY,MAAuB,EAAE,EAA8C;QACjF,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACxC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,MAAY;QAChB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { StrictEventEmitter } from "strict-event-emitter-types";
|
|
3
|
-
import { BeaconConfig } from "@lodestar/config";
|
|
4
|
-
import { IBeaconStateView } from "@lodestar/state-transition";
|
|
5
|
-
import { Root, SignedBeaconBlock, Slot, phase0 } from "@lodestar/types";
|
|
6
|
-
import { Logger } from "@lodestar/utils";
|
|
7
|
-
import { IBeaconChain } from "../../chain/index.js";
|
|
8
|
-
import { IBeaconDb } from "../../db/index.js";
|
|
9
|
-
import { Metrics } from "../../metrics/metrics.js";
|
|
10
|
-
import { INetwork } from "../../network/index.js";
|
|
11
|
-
import { BackfillBlock, BackfillBlockHeader } from "./verify.js";
|
|
12
|
-
export type BackfillSyncModules = {
|
|
13
|
-
chain: IBeaconChain;
|
|
14
|
-
db: IBeaconDb;
|
|
15
|
-
network: INetwork;
|
|
16
|
-
config: BeaconConfig;
|
|
17
|
-
logger: Logger;
|
|
18
|
-
metrics: Metrics | null;
|
|
19
|
-
anchorState: IBeaconStateView;
|
|
20
|
-
wsCheckpoint?: phase0.Checkpoint;
|
|
21
|
-
signal: AbortSignal;
|
|
22
|
-
};
|
|
23
|
-
type BackfillModules = BackfillSyncModules & {
|
|
24
|
-
syncAnchor: BackFillSyncAnchor;
|
|
25
|
-
backfillStartFromSlot: Slot;
|
|
26
|
-
prevFinalizedCheckpointBlock: BackfillBlockHeader;
|
|
27
|
-
wsCheckpointHeader: BackfillBlockHeader | null;
|
|
28
|
-
backfillRangeWrittenSlot: Slot | null;
|
|
29
|
-
};
|
|
30
|
-
export type BackfillSyncOpts = {
|
|
31
|
-
backfillBatchSize: number;
|
|
32
|
-
};
|
|
33
|
-
export declare enum BackfillSyncEvent {
|
|
34
|
-
completed = "BackfillSync-completed"
|
|
35
|
-
}
|
|
36
|
-
export declare enum BackfillSyncMethod {
|
|
37
|
-
database = "database",
|
|
38
|
-
backfilled_ranges = "backfilled_ranges",
|
|
39
|
-
rangesync = "rangesync",
|
|
40
|
-
blockbyroot = "blockbyroot"
|
|
41
|
-
}
|
|
42
|
-
export declare enum BackfillSyncStatus {
|
|
43
|
-
pending = "pending",
|
|
44
|
-
syncing = "syncing",
|
|
45
|
-
completed = "completed",
|
|
46
|
-
aborted = "aborted"
|
|
47
|
-
}
|
|
48
|
-
type BackfillSyncEvents = {
|
|
49
|
-
[BackfillSyncEvent.completed]: (
|
|
50
|
-
/** Oldest slot synced */
|
|
51
|
-
oldestSlotSynced: Slot) => void;
|
|
52
|
-
};
|
|
53
|
-
type BackfillSyncEmitter = StrictEventEmitter<EventEmitter, BackfillSyncEvents>;
|
|
54
|
-
/**
|
|
55
|
-
* At any given point, we should have
|
|
56
|
-
* 1. anchorBlock (with its root anchorBlockRoot at anchorSlot) for next round of sync
|
|
57
|
-
* which is the same as the lastBackSyncedBlock
|
|
58
|
-
* 2. We know the anchorBlockRoot but don't have its anchorBlock and anchorSlot yet, and its
|
|
59
|
-
* parent of lastBackSyncedBlock we synced in a previous successfull round
|
|
60
|
-
* 3. We just started with only anchorBlockRoot, but we know (and will validate) its anchorSlot
|
|
61
|
-
*/
|
|
62
|
-
type BackFillSyncAnchor = {
|
|
63
|
-
anchorBlock: SignedBeaconBlock;
|
|
64
|
-
anchorBlockRoot: Root;
|
|
65
|
-
anchorSlot: Slot;
|
|
66
|
-
lastBackSyncedBlock: BackfillBlock;
|
|
67
|
-
} | {
|
|
68
|
-
anchorBlock: null;
|
|
69
|
-
anchorBlockRoot: Root;
|
|
70
|
-
anchorSlot: null;
|
|
71
|
-
lastBackSyncedBlock: BackfillBlock;
|
|
72
|
-
} | {
|
|
73
|
-
anchorBlock: null;
|
|
74
|
-
anchorBlockRoot: Root;
|
|
75
|
-
anchorSlot: Slot;
|
|
76
|
-
lastBackSyncedBlock: null;
|
|
77
|
-
};
|
|
78
|
-
declare const BackfillSync_base: new () => BackfillSyncEmitter;
|
|
79
|
-
export declare class BackfillSync extends BackfillSync_base {
|
|
80
|
-
/** Lowest slot that we have backfilled to */
|
|
81
|
-
syncAnchor: BackFillSyncAnchor;
|
|
82
|
-
private readonly chain;
|
|
83
|
-
private readonly network;
|
|
84
|
-
private readonly db;
|
|
85
|
-
private readonly config;
|
|
86
|
-
private readonly logger;
|
|
87
|
-
private readonly metrics;
|
|
88
|
-
/**
|
|
89
|
-
* Process in blocks of at max batchSize
|
|
90
|
-
*/
|
|
91
|
-
private opts;
|
|
92
|
-
/**
|
|
93
|
-
* If wsCheckpoint provided was in past then the (db) state from which beacon node started,
|
|
94
|
-
* needs to be validated as per spec.
|
|
95
|
-
*
|
|
96
|
-
* 1. This could lie in between of the previous backfilled range, in which case it would be
|
|
97
|
-
* sufficient to check if its DB, once the linkage to that range has been verified.
|
|
98
|
-
* 2. Else if it lies outside the backfilled range, the linkage to this checkpoint in
|
|
99
|
-
* backfill needs to be verified.
|
|
100
|
-
*/
|
|
101
|
-
private wsCheckpointHeader;
|
|
102
|
-
private wsValidated;
|
|
103
|
-
/**
|
|
104
|
-
* From https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/weak-subjectivity.md
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* If
|
|
108
|
-
* 1. The wsCheckpoint provided was ahead of the db's finalized checkpoint or
|
|
109
|
-
* 2. There were gaps in the backfill - keys to backfillRanges are always (by construction)
|
|
110
|
-
* a) Finalized Checkpoint or b) previous wsCheckpoint
|
|
111
|
-
*
|
|
112
|
-
* the linkage to the previous finalized/wss checkpoint(s) needs to be verfied. If there is
|
|
113
|
-
* no such checkpoint remaining, the linkage to genesis needs to be validated
|
|
114
|
-
*
|
|
115
|
-
* Initialize with the blockArchive's last block, and on verification update to the next
|
|
116
|
-
* preceding backfillRange key's checkpoint.
|
|
117
|
-
*/
|
|
118
|
-
private prevFinalizedCheckpointBlock;
|
|
119
|
-
/** Starting point that this specific backfill sync "session" started from */
|
|
120
|
-
private backfillStartFromSlot;
|
|
121
|
-
private backfillRangeWrittenSlot;
|
|
122
|
-
private processor;
|
|
123
|
-
private peers;
|
|
124
|
-
private status;
|
|
125
|
-
private signal;
|
|
126
|
-
constructor(opts: BackfillSyncOpts, modules: BackfillModules);
|
|
127
|
-
/**
|
|
128
|
-
* Use the root of the anchorState of the beacon node as the starting point of the
|
|
129
|
-
* backfill sync with its expected slot to be anchorState.slot, which will be
|
|
130
|
-
* validated once the block is resolved in the backfill sync.
|
|
131
|
-
*
|
|
132
|
-
* NOTE: init here is quite light involving couple of
|
|
133
|
-
*
|
|
134
|
-
* 1. db keys lookup in stateArchive/backfilledRanges
|
|
135
|
-
* 2. computing root(s) for anchorBlockRoot and prevFinalizedCheckpointBlock
|
|
136
|
-
*
|
|
137
|
-
* The way we initialize beacon node, wsCheckpoint's slot is always <= anchorSlot
|
|
138
|
-
* If:
|
|
139
|
-
* the root belonging to wsCheckpoint is in the DB, we need to verify linkage to it
|
|
140
|
-
* i.e. it becomes our first prevFinalizedCheckpointBlock
|
|
141
|
-
* Else
|
|
142
|
-
* we initialize prevFinalizedCheckpointBlock from the last stored db finalized state
|
|
143
|
-
* for verification and when we go below its epoch we just check if a correct block
|
|
144
|
-
* corresponding to wsCheckpoint root was stored.
|
|
145
|
-
*
|
|
146
|
-
* and then we continue going back and verifying the next unconnected previous finalized
|
|
147
|
-
* or wsCheckpoints identifiable as the keys of backfill sync.
|
|
148
|
-
*/
|
|
149
|
-
static init<T extends BackfillSync = BackfillSync>(opts: BackfillSyncOpts, modules: BackfillSyncModules): Promise<T>;
|
|
150
|
-
/** Throw / return all AsyncGenerators */
|
|
151
|
-
close(): void;
|
|
152
|
-
/**
|
|
153
|
-
* @returns Returns oldestSlotSynced
|
|
154
|
-
*/
|
|
155
|
-
private sync;
|
|
156
|
-
private addPeer;
|
|
157
|
-
private removePeer;
|
|
158
|
-
/**
|
|
159
|
-
* Ensure that any weak subjectivity checkpoint provided in past with respect
|
|
160
|
-
* the initialization point is the same block tree as the DB once backfill
|
|
161
|
-
*/
|
|
162
|
-
private checkIfCheckpointSyncedAndValidate;
|
|
163
|
-
private checkUpdateFromBackfillSequences;
|
|
164
|
-
private fastBackfillDb;
|
|
165
|
-
private syncBlockByRoot;
|
|
166
|
-
private syncRange;
|
|
167
|
-
}
|
|
168
|
-
export {};
|
|
169
|
-
//# sourceMappingURL=backfill.d.ts.map
|