@lodestar/beacon-node 1.47.0-dev.4546ac1229 → 1.47.0-dev.57572140f8
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 +39 -11
- 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 +13 -1
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/events/index.d.ts.map +1 -1
- package/lib/api/impl/events/index.js +2 -0
- package/lib/api/impl/events/index.js.map +1 -1
- package/lib/api/impl/lodestar/index.js +1 -1
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +232 -49
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/api/impl/validator/utils.js +1 -1
- package/lib/api/impl/validator/utils.js.map +1 -1
- package/lib/api/rest/base.d.ts.map +1 -1
- package/lib/api/rest/base.js +7 -0
- package/lib/api/rest/base.js.map +1 -1
- package/lib/chain/archiveStore/archiveStore.js +1 -1
- package/lib/chain/archiveStore/archiveStore.js.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +2 -1
- package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +6 -2
- package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +14 -5
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.js +5 -0
- package/lib/chain/blocks/payloadEnvelopeInput/types.js.map +1 -1
- package/lib/chain/chain.d.ts +6 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +14 -3
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +4 -0
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/interface.d.ts +4 -1
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts +16 -0
- package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts.map +1 -0
- package/lib/chain/opPools/deferredVoluntaryExitPool.js +57 -0
- package/lib/chain/opPools/deferredVoluntaryExitPool.js.map +1 -0
- package/lib/chain/opPools/executionPayloadBidPool.d.ts +7 -2
- package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -1
- package/lib/chain/opPools/executionPayloadBidPool.js +4 -4
- package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -1
- package/lib/chain/opPools/index.d.ts +2 -1
- package/lib/chain/opPools/index.d.ts.map +1 -1
- package/lib/chain/opPools/index.js +1 -0
- package/lib/chain/opPools/index.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +23 -5
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/regen/interface.d.ts +4 -2
- package/lib/chain/regen/interface.d.ts.map +1 -1
- package/lib/chain/regen/interface.js +2 -0
- package/lib/chain/regen/interface.js.map +1 -1
- package/lib/chain/regen/queued.d.ts +2 -2
- package/lib/chain/regen/queued.d.ts.map +1 -1
- package/lib/chain/regen/queued.js +5 -5
- package/lib/chain/regen/queued.js.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +28 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +121 -13
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts +5 -1
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.js +6 -0
- package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +47 -5
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +117 -7
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/stateCache/types.d.ts +3 -3
- package/lib/chain/stateCache/types.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +2 -2
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.d.ts +9 -1
- package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +46 -1
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/execution/builder/apiClient.d.ts +64 -0
- package/lib/execution/builder/apiClient.d.ts.map +1 -0
- package/lib/execution/builder/apiClient.js +184 -0
- package/lib/execution/builder/apiClient.js.map +1 -0
- package/lib/execution/builder/validateBid.d.ts +22 -0
- package/lib/execution/builder/validateBid.d.ts.map +1 -0
- package/lib/execution/builder/validateBid.js +111 -0
- package/lib/execution/builder/validateBid.js.map +1 -0
- package/lib/metrics/metrics/lodestar.d.ts +36 -4
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +62 -2
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/processor/constants.d.ts +7 -0
- package/lib/network/processor/constants.d.ts.map +1 -0
- package/lib/network/processor/constants.js +7 -0
- package/lib/network/processor/constants.js.map +1 -0
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +6 -2
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/index.d.ts +3 -0
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +36 -15
- package/lib/network/processor/index.js.map +1 -1
- package/lib/node/deferredVoluntaryExitPublisher.d.ts +15 -0
- package/lib/node/deferredVoluntaryExitPublisher.d.ts.map +1 -0
- package/lib/node/deferredVoluntaryExitPublisher.js +38 -0
- package/lib/node/deferredVoluntaryExitPublisher.js.map +1 -0
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +7 -0
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/types.d.ts +32 -0
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js +33 -0
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +6 -2
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +143 -68
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +16 -11
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +3 -1
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/package.json +34 -34
- package/src/api/impl/beacon/blocks/index.ts +46 -14
- package/src/api/impl/beacon/pool/index.ts +15 -1
- package/src/api/impl/events/index.ts +3 -1
- package/src/api/impl/lodestar/index.ts +1 -1
- package/src/api/impl/validator/index.ts +285 -49
- package/src/api/impl/validator/utils.ts +1 -1
- package/src/api/rest/base.ts +7 -0
- package/src/chain/archiveStore/archiveStore.ts +1 -1
- package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +8 -2
- package/src/chain/blocks/payloadEnvelopeInput/types.ts +17 -4
- package/src/chain/chain.ts +16 -1
- package/src/chain/forkChoice/index.ts +4 -0
- package/src/chain/interface.ts +4 -0
- package/src/chain/opPools/deferredVoluntaryExitPool.ts +65 -0
- package/src/chain/opPools/executionPayloadBidPool.ts +13 -7
- package/src/chain/opPools/index.ts +2 -1
- package/src/chain/prepareNextSlot.ts +23 -5
- package/src/chain/produceBlock/produceBlockBody.ts +1 -1
- package/src/chain/regen/interface.ts +4 -2
- package/src/chain/regen/queued.ts +5 -5
- package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +143 -14
- package/src/chain/stateCache/fifoBlockStateCache.ts +8 -1
- package/src/chain/stateCache/persistentCheckpointsCache.ts +133 -8
- package/src/chain/stateCache/types.ts +3 -3
- package/src/chain/validation/executionPayloadBid.ts +2 -2
- package/src/chain/validation/voluntaryExit.ts +59 -2
- package/src/execution/builder/apiClient.ts +244 -0
- package/src/execution/builder/validateBid.ts +166 -0
- package/src/metrics/metrics/lodestar.ts +70 -6
- package/src/network/processor/constants.ts +6 -0
- package/src/network/processor/gossipHandlers.ts +6 -2
- package/src/network/processor/index.ts +42 -19
- package/src/node/deferredVoluntaryExitPublisher.ts +54 -0
- package/src/node/nodejs.ts +8 -0
- package/src/sync/types.ts +33 -0
- package/src/sync/unknownBlock.ts +167 -73
- package/src/sync/utils/downloadByRange.ts +21 -12
- package/src/sync/utils/downloadByRoot.ts +3 -1
package/src/chain/chain.ts
CHANGED
|
@@ -61,6 +61,7 @@ import {ProcessShutdownCallback} from "@lodestar/validator";
|
|
|
61
61
|
import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
|
|
62
62
|
import {IBeaconDb} from "../db/index.js";
|
|
63
63
|
import {BLOB_SIDECARS_IN_WRAPPER_INDEX} from "../db/repositories/blobSidecars.js";
|
|
64
|
+
import {BuilderApiClient, BuilderApiClientOpts} from "../execution/builder/apiClient.js";
|
|
64
65
|
import {BuilderStatus} from "../execution/builder/http.js";
|
|
65
66
|
import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
|
|
66
67
|
import {Metrics} from "../metrics/index.js";
|
|
@@ -79,6 +80,7 @@ import {CheckpointBalancesCache} from "./balancesCache.js";
|
|
|
79
80
|
import {BeaconProposerCache} from "./beaconProposerCache.js";
|
|
80
81
|
import {IBlockInput, isBlockInputBlobs, isBlockInputColumns} from "./blocks/blockInput/index.js";
|
|
81
82
|
import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js";
|
|
83
|
+
import {PayloadEnvelopeInputSource} from "./blocks/payloadEnvelopeInput/index.js";
|
|
82
84
|
import {PayloadEnvelopeProcessor} from "./blocks/payloadEnvelopeProcessor.js";
|
|
83
85
|
import {ImportPayloadOpts} from "./blocks/types.js";
|
|
84
86
|
import {persistBlockInput} from "./blocks/writeBlockInputToDb.js";
|
|
@@ -94,6 +96,7 @@ import {LightClientServer} from "./lightClient/index.js";
|
|
|
94
96
|
import {
|
|
95
97
|
AggregatedAttestationPool,
|
|
96
98
|
AttestationPool,
|
|
99
|
+
DeferredVoluntaryExitPool,
|
|
97
100
|
ExecutionPayloadBidPool,
|
|
98
101
|
OpPool,
|
|
99
102
|
PayloadAttestationPool,
|
|
@@ -163,6 +166,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
163
166
|
readonly executionEngine: IExecutionEngine;
|
|
164
167
|
readonly executionBuilder?: IExecutionBuilder;
|
|
165
168
|
readonly builderCircuitBreaker: BuilderCircuitBreaker;
|
|
169
|
+
readonly builderApiClient: BuilderApiClient;
|
|
166
170
|
// Expose config for convenience in modularized functions
|
|
167
171
|
readonly config: BeaconConfig;
|
|
168
172
|
readonly custodyConfig: CustodyConfig;
|
|
@@ -193,6 +197,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
193
197
|
readonly payloadAttestationPool: PayloadAttestationPool;
|
|
194
198
|
readonly proposerPreferencesPool = new ProposerPreferencesPool();
|
|
195
199
|
readonly opPool: OpPool;
|
|
200
|
+
readonly deferredVoluntaryExitPool: DeferredVoluntaryExitPool;
|
|
196
201
|
|
|
197
202
|
// Gossip seen cache
|
|
198
203
|
readonly seenAttesters = new SeenAttesters();
|
|
@@ -272,6 +277,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
272
277
|
isAnchorStateFinalized,
|
|
273
278
|
executionEngine,
|
|
274
279
|
executionBuilder,
|
|
280
|
+
builderApiClientOpts,
|
|
275
281
|
}: {
|
|
276
282
|
privateKey: PrivateKey;
|
|
277
283
|
config: BeaconConfig;
|
|
@@ -289,6 +295,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
289
295
|
isAnchorStateFinalized: boolean;
|
|
290
296
|
executionEngine: IExecutionEngine;
|
|
291
297
|
executionBuilder?: IExecutionBuilder;
|
|
298
|
+
builderApiClientOpts?: BuilderApiClientOpts;
|
|
292
299
|
}
|
|
293
300
|
) {
|
|
294
301
|
this.opts = opts;
|
|
@@ -320,6 +327,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
320
327
|
this.executionPayloadBidPool = new ExecutionPayloadBidPool();
|
|
321
328
|
this.payloadAttestationPool = new PayloadAttestationPool(config, clock, metrics);
|
|
322
329
|
this.opPool = new OpPool(config);
|
|
330
|
+
this.deferredVoluntaryExitPool = new DeferredVoluntaryExitPool(logger);
|
|
323
331
|
|
|
324
332
|
this.seenAggregatedAttestations = new SeenAggregatedAttestations(metrics);
|
|
325
333
|
this.seenContributionAndProof = new SeenContributionAndProof(metrics);
|
|
@@ -444,6 +452,8 @@ export class BeaconChain implements IBeaconChain {
|
|
|
444
452
|
{forkChoice, logger, metrics}
|
|
445
453
|
);
|
|
446
454
|
|
|
455
|
+
this.builderApiClient = new BuilderApiClient(builderApiClientOpts ?? {}, config, clock, bls, metrics, logger);
|
|
456
|
+
|
|
447
457
|
this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
|
|
448
458
|
config,
|
|
449
459
|
clock,
|
|
@@ -451,6 +461,9 @@ export class BeaconChain implements IBeaconChain {
|
|
|
451
461
|
chainEvents: emitter,
|
|
452
462
|
signal,
|
|
453
463
|
serializedCache: this.serializedCache,
|
|
464
|
+
db,
|
|
465
|
+
seenBlockInputCache: this.seenBlockInputCache,
|
|
466
|
+
custodyConfig: this.custodyConfig,
|
|
454
467
|
metrics,
|
|
455
468
|
logger,
|
|
456
469
|
});
|
|
@@ -466,7 +479,8 @@ export class BeaconChain implements IBeaconChain {
|
|
|
466
479
|
bid: anchorBid,
|
|
467
480
|
sampledColumns: this.custodyConfig.sampledColumns,
|
|
468
481
|
custodyColumns: this.custodyConfig.custodyColumns,
|
|
469
|
-
|
|
482
|
+
seenTimestampSec: Date.now() / 1000,
|
|
483
|
+
source: PayloadEnvelopeInputSource.anchorState,
|
|
470
484
|
});
|
|
471
485
|
}
|
|
472
486
|
|
|
@@ -1569,6 +1583,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1569
1583
|
// aggregatedAttestationPool tracks metrics on its own
|
|
1570
1584
|
metrics.opPool.attestationPool.size.set(this.attestationPool.getAttestationCount());
|
|
1571
1585
|
metrics.opPool.attesterSlashingPoolSize.set(this.opPool.attesterSlashingsSize);
|
|
1586
|
+
metrics.opPool.deferredVoluntaryExitPool.size.set(this.deferredVoluntaryExitPool.size());
|
|
1572
1587
|
metrics.opPool.proposerSlashingPoolSize.set(this.opPool.proposerSlashingsSize);
|
|
1573
1588
|
metrics.opPool.voluntaryExitPoolSize.set(this.opPool.voluntaryExitsSize);
|
|
1574
1589
|
metrics.opPool.syncCommitteeMessagePoolSize.set(this.syncCommitteeMessagePool.size);
|
|
@@ -134,6 +134,8 @@ export function initializeForkChoiceFromFinalizedState(
|
|
|
134
134
|
stateRoot: toRootHex(blockHeader.stateRoot),
|
|
135
135
|
blockRoot: toRootHex(checkpoint.root),
|
|
136
136
|
timeliness: true, // Optimistically assume is timely
|
|
137
|
+
ptcTimeliness: true, // Spec: block_timeliness for anchor = [True, True]
|
|
138
|
+
proposerIndex: blockHeader.proposerIndex,
|
|
137
139
|
|
|
138
140
|
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
139
141
|
justifiedRoot: toRootHex(justifiedCheckpoint.root),
|
|
@@ -230,6 +232,8 @@ export function initializeForkChoiceFromUnfinalizedState(
|
|
|
230
232
|
blockRoot: headRoot,
|
|
231
233
|
targetRoot: headRoot,
|
|
232
234
|
timeliness: true, // Optimistically assume is timely
|
|
235
|
+
ptcTimeliness: true, // Spec: block_timeliness for anchor = [True, True]
|
|
236
|
+
proposerIndex: blockHeader.proposerIndex,
|
|
233
237
|
|
|
234
238
|
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
235
239
|
justifiedRoot: toRootHex(justifiedCheckpoint.root),
|
package/src/chain/interface.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
rewards,
|
|
25
25
|
} from "@lodestar/types";
|
|
26
26
|
import {Logger} from "@lodestar/utils";
|
|
27
|
+
import {BuilderApiClient} from "../execution/builder/apiClient.js";
|
|
27
28
|
import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
|
|
28
29
|
import {Metrics} from "../metrics/metrics.js";
|
|
29
30
|
import {BufferPool} from "../util/bufferPool.js";
|
|
@@ -45,6 +46,7 @@ import {LightClientServer} from "./lightClient/index.js";
|
|
|
45
46
|
import {AggregatedAttestationPool} from "./opPools/aggregatedAttestationPool.js";
|
|
46
47
|
import {
|
|
47
48
|
AttestationPool,
|
|
49
|
+
DeferredVoluntaryExitPool,
|
|
48
50
|
ExecutionPayloadBidPool,
|
|
49
51
|
OpPool,
|
|
50
52
|
PayloadAttestationPool,
|
|
@@ -98,6 +100,7 @@ export interface IBeaconChain {
|
|
|
98
100
|
readonly executionEngine: IExecutionEngine;
|
|
99
101
|
readonly executionBuilder?: IExecutionBuilder;
|
|
100
102
|
readonly builderCircuitBreaker: BuilderCircuitBreaker;
|
|
103
|
+
readonly builderApiClient: BuilderApiClient;
|
|
101
104
|
// Expose config for convenience in modularized functions
|
|
102
105
|
readonly config: BeaconConfig;
|
|
103
106
|
readonly custodyConfig: CustodyConfig;
|
|
@@ -128,6 +131,7 @@ export interface IBeaconChain {
|
|
|
128
131
|
readonly payloadAttestationPool: PayloadAttestationPool;
|
|
129
132
|
readonly proposerPreferencesPool: ProposerPreferencesPool;
|
|
130
133
|
readonly opPool: OpPool;
|
|
134
|
+
readonly deferredVoluntaryExitPool: DeferredVoluntaryExitPool;
|
|
131
135
|
|
|
132
136
|
// Gossip seen cache
|
|
133
137
|
readonly seenAttesters: SeenAttesters;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {Logger} from "@lodestar/logger";
|
|
2
|
+
import {IBeaconStateView, VoluntaryExitValidity} from "@lodestar/state-transition";
|
|
3
|
+
import {Epoch, ValidatorIndex} from "@lodestar/types";
|
|
4
|
+
import {SignedVoluntaryExit} from "@lodestar/types/phase0";
|
|
5
|
+
import {isTransientExitValidity} from "../validation/voluntaryExit.js";
|
|
6
|
+
|
|
7
|
+
type DeferredEntry = {
|
|
8
|
+
exit: SignedVoluntaryExit;
|
|
9
|
+
validity: VoluntaryExitValidity;
|
|
10
|
+
insertedAtEpoch: Epoch;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class DeferredVoluntaryExitPool {
|
|
14
|
+
private pool = new Map<ValidatorIndex, DeferredEntry>();
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly logger: Logger,
|
|
18
|
+
private readonly maxSize = 1024,
|
|
19
|
+
private readonly maxDeferEpochs = 4096
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
insert(exit: SignedVoluntaryExit, validity: VoluntaryExitValidity, currentEpoch: Epoch): boolean {
|
|
23
|
+
if (!isTransientExitValidity(validity)) return false;
|
|
24
|
+
if (this.pool.size === this.maxSize) return false;
|
|
25
|
+
if (this.pool.has(exit.message.validatorIndex)) return false;
|
|
26
|
+
|
|
27
|
+
this.pool.set(exit.message.validatorIndex, {exit, validity, insertedAtEpoch: currentEpoch});
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
drainProcessableExits(state: IBeaconStateView): SignedVoluntaryExit[] {
|
|
33
|
+
const epoch = state.epoch;
|
|
34
|
+
const validExits: SignedVoluntaryExit[] = [];
|
|
35
|
+
for (const [validatorIndex, entry] of this.pool) {
|
|
36
|
+
try {
|
|
37
|
+
if (epoch - entry.insertedAtEpoch > this.maxDeferEpochs) {
|
|
38
|
+
this.pool.delete(validatorIndex);
|
|
39
|
+
this.logger.debug("Deferred voluntary exit expired", {validatorIndex, lastValidity: entry.validity});
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const validity = state.getVoluntaryExitValidity(entry.exit, true);
|
|
43
|
+
if (validity === VoluntaryExitValidity.valid) {
|
|
44
|
+
validExits.push(entry.exit);
|
|
45
|
+
this.pool.delete(validatorIndex);
|
|
46
|
+
} else if (!isTransientExitValidity(validity)) {
|
|
47
|
+
this.logger.debug("Deferred voluntary exit became permanently invalid", {validatorIndex, validity});
|
|
48
|
+
this.pool.delete(validatorIndex);
|
|
49
|
+
}
|
|
50
|
+
// Else if still transient - keep
|
|
51
|
+
} catch (e) {
|
|
52
|
+
this.logger.debug("Processing deferred voluntary exit failed", {validatorIndex}, e as Error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return validExits;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
has(validatorIndex: ValidatorIndex): boolean {
|
|
59
|
+
return this.pool.has(validatorIndex);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
size(): number {
|
|
63
|
+
return this.pool.size;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -11,14 +11,20 @@ const SLOTS_RETAINED = 2;
|
|
|
11
11
|
type BlockRootHex = string;
|
|
12
12
|
type BlockHashHex = string;
|
|
13
13
|
|
|
14
|
+
export type PooledExecutionPayloadBid = {
|
|
15
|
+
signedBid: gloas.SignedExecutionPayloadBid;
|
|
16
|
+
/** Time in milliseconds from the slot start when the bid was received */
|
|
17
|
+
receivedMs: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* Store the best signed execution payload bid per slot / (parent block root, parent block hash).
|
|
16
22
|
*/
|
|
17
23
|
export class ExecutionPayloadBidPool {
|
|
18
24
|
private readonly bidByParentHashByParentRootBySlot = new MapDef<
|
|
19
25
|
Slot,
|
|
20
|
-
MapDef<BlockRootHex, Map<BlockHashHex,
|
|
21
|
-
>(() => new MapDef<BlockRootHex, Map<BlockHashHex,
|
|
26
|
+
MapDef<BlockRootHex, Map<BlockHashHex, PooledExecutionPayloadBid>>
|
|
27
|
+
>(() => new MapDef<BlockRootHex, Map<BlockHashHex, PooledExecutionPayloadBid>>(() => new Map()));
|
|
22
28
|
private lowestPermissibleSlot = 0;
|
|
23
29
|
|
|
24
30
|
get size(): number {
|
|
@@ -31,7 +37,7 @@ export class ExecutionPayloadBidPool {
|
|
|
31
37
|
return count;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
add(bid: gloas.SignedExecutionPayloadBid): InsertOutcome {
|
|
40
|
+
add(bid: gloas.SignedExecutionPayloadBid, receivedMs: number): InsertOutcome {
|
|
35
41
|
const {slot, parentBlockRoot, parentBlockHash, value} = bid.message;
|
|
36
42
|
const lowestPermissibleSlot = this.lowestPermissibleSlot;
|
|
37
43
|
|
|
@@ -45,16 +51,16 @@ export class ExecutionPayloadBidPool {
|
|
|
45
51
|
const existing = bidByParentHash.get(parentHashHex);
|
|
46
52
|
|
|
47
53
|
if (existing) {
|
|
48
|
-
const existingValue = existing.message.value;
|
|
54
|
+
const existingValue = existing.signedBid.message.value;
|
|
49
55
|
const newValue = value;
|
|
50
56
|
if (newValue > existingValue) {
|
|
51
|
-
bidByParentHash.set(parentHashHex, bid);
|
|
57
|
+
bidByParentHash.set(parentHashHex, {signedBid: bid, receivedMs});
|
|
52
58
|
return InsertOutcome.NewData;
|
|
53
59
|
}
|
|
54
60
|
return newValue === existingValue ? InsertOutcome.AlreadyKnown : InsertOutcome.NotBetterThan;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
bidByParentHash.set(parentHashHex, bid);
|
|
63
|
+
bidByParentHash.set(parentHashHex, {signedBid: bid, receivedMs});
|
|
58
64
|
return InsertOutcome.NewData;
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -66,7 +72,7 @@ export class ExecutionPayloadBidPool {
|
|
|
66
72
|
slot: Slot,
|
|
67
73
|
parentBlockHash: BlockHashHex | null,
|
|
68
74
|
parentBlockRoot: BlockRootHex
|
|
69
|
-
):
|
|
75
|
+
): PooledExecutionPayloadBid | null {
|
|
70
76
|
if (parentBlockHash === null) return null;
|
|
71
77
|
const bidByParentHash = this.bidByParentHashByParentRootBySlot.get(slot)?.get(parentBlockRoot);
|
|
72
78
|
return bidByParentHash?.get(parentBlockHash) ?? null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {AggregatedAttestationPool} from "./aggregatedAttestationPool.js";
|
|
2
2
|
export {AttestationPool} from "./attestationPool.js";
|
|
3
|
-
export {
|
|
3
|
+
export {DeferredVoluntaryExitPool} from "./deferredVoluntaryExitPool.js";
|
|
4
|
+
export {ExecutionPayloadBidPool, type PooledExecutionPayloadBid} from "./executionPayloadBidPool.js";
|
|
4
5
|
export {OpPool} from "./opPool.js";
|
|
5
6
|
export {PayloadAttestationPool} from "./payloadAttestationPool.js";
|
|
6
7
|
export {ProposerPreferencesPool} from "./proposerPreferencesPool.js";
|
|
@@ -151,23 +151,38 @@ export class PrepareNextSlotScheduler {
|
|
|
151
151
|
const proposerIndex = await getProposerIndex();
|
|
152
152
|
feeRecipient = this.chain.beaconProposerCache.get(proposerIndex);
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
// Predict the proposer head of the next slot when either:
|
|
155
|
+
// - we are proposing the next slot (single-slot proposer-boost-reorg), or
|
|
156
|
+
// - this is an epoch transition: post-Fulu the next proposer may reorg a weak
|
|
157
|
+
// last-block-of-epoch and build slot 0 on the strong parent (epoch-boundary reorg),
|
|
158
|
+
// so we should dial the strong parent through the boundary instead of the weak head.
|
|
159
|
+
if (feeRecipient || isEpochTransition) {
|
|
156
160
|
const proposerHead = this.chain.predictProposerHead(clockSlot);
|
|
157
161
|
const {slot: proposerHeadSlot, blockRoot: proposerHeadRoot} = proposerHead;
|
|
158
162
|
|
|
159
|
-
// If we predict
|
|
163
|
+
// If we predict a reorg, we build the epoch transition on the proposer head (parent) instead
|
|
160
164
|
if (proposerHeadRoot !== headRoot || proposerHeadSlot !== headSlot) {
|
|
161
|
-
|
|
165
|
+
// feeRecipient set => WE propose the next slot and may reorg it out ourselves;
|
|
166
|
+
// otherwise it's a predicted reorg by another proposer (epoch-boundary reorg).
|
|
167
|
+
const logMessage = feeRecipient
|
|
168
|
+
? "Weak head detected. We may build on parent block instead"
|
|
169
|
+
: "Weak head detected. Another proposer may build on parent block instead";
|
|
170
|
+
this.logger.verbose(logMessage, {
|
|
162
171
|
proposerHeadSlot,
|
|
163
172
|
proposerHeadRoot,
|
|
164
173
|
headSlot,
|
|
165
174
|
headRoot,
|
|
175
|
+
isEpochTransition,
|
|
166
176
|
});
|
|
167
177
|
this.metrics?.weakHeadDetected.inc();
|
|
178
|
+
if (isEpochTransition) {
|
|
179
|
+
this.metrics?.precomputeNextEpochTransition.predictedReorg.inc();
|
|
180
|
+
}
|
|
168
181
|
updatedHead = proposerHead;
|
|
169
182
|
}
|
|
183
|
+
}
|
|
170
184
|
|
|
185
|
+
if (feeRecipient) {
|
|
171
186
|
if (isForkPostGloas(fork)) {
|
|
172
187
|
this.chain.builderCircuitBreaker.update(clockSlot, updatedHead);
|
|
173
188
|
} else {
|
|
@@ -182,6 +197,7 @@ export class PrepareNextSlotScheduler {
|
|
|
182
197
|
}
|
|
183
198
|
|
|
184
199
|
// post-fulu we'll always reach here because preparedState is undefined
|
|
200
|
+
// we may run epoch transition not with headBlock if it's weak
|
|
185
201
|
if (preparedState === undefined || updatedHead !== headBlock) {
|
|
186
202
|
preparedState = await this.chain.regen.getBlockSlotState(
|
|
187
203
|
updatedHead,
|
|
@@ -280,7 +296,7 @@ export class PrepareNextSlotScheduler {
|
|
|
280
296
|
// + if next slot is a skipped slot, it'd help getting target checkpoint state faster to validate attestations
|
|
281
297
|
if (isEpochTransition) {
|
|
282
298
|
this.metrics?.precomputeNextEpochTransition.count.inc({result: "success"}, 1);
|
|
283
|
-
const previousHits = this.chain.regen.updatePreComputedCheckpoint(
|
|
299
|
+
const previousHits = this.chain.regen.updatePreComputedCheckpoint(updatedHead.blockRoot, nextEpoch);
|
|
284
300
|
if (previousHits === 0) {
|
|
285
301
|
this.metrics?.precomputeNextEpochTransition.waste.inc();
|
|
286
302
|
}
|
|
@@ -289,6 +305,8 @@ export class PrepareNextSlotScheduler {
|
|
|
289
305
|
this.logger.verbose("Completed PrepareNextSlotScheduler epoch transition", {
|
|
290
306
|
nextEpoch,
|
|
291
307
|
headSlot,
|
|
308
|
+
headRoot,
|
|
309
|
+
updatedHeadRoot: updatedHead.blockRoot,
|
|
292
310
|
prepareSlot,
|
|
293
311
|
previousHits,
|
|
294
312
|
durationMs: Date.now() - start,
|
|
@@ -241,7 +241,7 @@ export async function produceBlockBody<T extends BlockType>(
|
|
|
241
241
|
const parentExecutionRequests = isExtendingPayload
|
|
242
242
|
? await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot)
|
|
243
243
|
: ssz.gloas.ExecutionRequests.defaultValue();
|
|
244
|
-
executionPayloadValue = BigInt(builderBid.message.value) * GWEI_TO_WEI;
|
|
244
|
+
executionPayloadValue = (BigInt(builderBid.message.value) + builderBid.message.executionPayment) * GWEI_TO_WEI;
|
|
245
245
|
|
|
246
246
|
const commonBlockBody = await commonBlockBodyPromise;
|
|
247
247
|
const gloasBody = Object.assign({}, commonBlockBody) as gloas.BeaconBlockBody;
|
|
@@ -21,6 +21,8 @@ export enum RegenCaller {
|
|
|
21
21
|
validateGossipAggregateAndProof = "validateGossipAggregateAndProof",
|
|
22
22
|
validateGossipAttestation = "validateGossipAttestation",
|
|
23
23
|
validateGossipVoluntaryExit = "validateGossipVoluntaryExit",
|
|
24
|
+
validateApiVoluntaryExit = "validateApiVoluntaryExit",
|
|
25
|
+
publishDeferredVoluntaryExits = "publishDeferredVoluntaryExits",
|
|
24
26
|
validateGossipExecutionPayloadBid = "validateGossipExecutionPayloadBid",
|
|
25
27
|
validateGossipPayloadAttestationMessage = "validateGossipPayloadAttestationMessage",
|
|
26
28
|
validateGossipProposerPreferences = "validateGossipProposerPreferences",
|
|
@@ -39,14 +41,14 @@ export type StateRegenerationOpts = {
|
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export interface IStateRegenerator extends IStateRegeneratorInternal {
|
|
42
|
-
dropCache(): void
|
|
44
|
+
dropCache(): Promise<void>;
|
|
43
45
|
dumpCacheSummary(): routes.lodestar.StateCacheItem[];
|
|
44
46
|
getStateSync(stateRoot: RootHex): IBeaconStateView | null;
|
|
45
47
|
getPreStateSync(block: BeaconBlock): IBeaconStateView | null;
|
|
46
48
|
getCheckpointStateOrBytes(cp: CheckpointHex): Promise<IBeaconStateView | Uint8Array | null>;
|
|
47
49
|
getCheckpointStateSync(cp: CheckpointHex): IBeaconStateView | null;
|
|
48
50
|
getClosestHeadState(head: ProtoBlock): IBeaconStateView | null;
|
|
49
|
-
|
|
51
|
+
onCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void;
|
|
50
52
|
processState(blockRootHex: RootHex, postState: IBeaconStateView): void;
|
|
51
53
|
addCheckpointState(cp: phase0.Checkpoint, item: IBeaconStateView): void;
|
|
52
54
|
updateHeadState(newHead: ProtoBlock, maybeHeadState: IBeaconStateView): void;
|
|
@@ -67,9 +67,9 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
67
67
|
return this.jobQueue.jobLen < REGEN_CAN_ACCEPT_WORK_THRESHOLD;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
dropCache(): void {
|
|
70
|
+
async dropCache(): Promise<void> {
|
|
71
71
|
this.blockStateCache.clear();
|
|
72
|
-
this.checkpointStateCache.clear();
|
|
72
|
+
await this.checkpointStateCache.clear();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
dumpCacheSummary(): routes.lodestar.StateCacheItem[] {
|
|
@@ -138,9 +138,9 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
138
138
|
return this.checkpointStateCache.getLatest(head.blockRoot, Infinity) || this.blockStateCache.get(head.stateRoot);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
this.checkpointStateCache.
|
|
143
|
-
this.blockStateCache.
|
|
141
|
+
onCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void {
|
|
142
|
+
this.checkpointStateCache.onCheckpoint(finalizedEpoch, justifiedEpoch);
|
|
143
|
+
this.blockStateCache.onCheckpoint(headStateRoot);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
processState(blockRootHex: RootHex, postState: IBeaconStateView): void {
|
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {CheckpointWithHex, IForkChoice, PayloadStatus, ProtoBlock} from "@lodestar/fork-choice";
|
|
3
|
+
import {ForkPostGloas, SLOTS_PER_EPOCH, isForkPostGloas} from "@lodestar/params";
|
|
3
4
|
import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
4
|
-
import {RootHex} from "@lodestar/types";
|
|
5
|
-
import {Logger} from "@lodestar/utils";
|
|
5
|
+
import {RootHex, SignedBeaconBlock} from "@lodestar/types";
|
|
6
|
+
import {Logger, fromHex} from "@lodestar/utils";
|
|
7
|
+
import {IBeaconDb} from "../../db/index.js";
|
|
6
8
|
import {Metrics} from "../../metrics/metrics.js";
|
|
9
|
+
import {MAX_LOOK_AHEAD_EPOCHS} from "../../sync/constants.js";
|
|
7
10
|
import {IClock} from "../../util/clock.js";
|
|
11
|
+
import {CustodyConfig} from "../../util/dataColumns.js";
|
|
8
12
|
import {SerializedCache} from "../../util/serializedCache.js";
|
|
9
13
|
import {isDaOutOfRange} from "../blocks/blockInput/index.js";
|
|
10
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
CreateFromBidProps,
|
|
16
|
+
CreateFromBlockProps,
|
|
17
|
+
PayloadEnvelopeInput,
|
|
18
|
+
PayloadEnvelopeInputPruneReason,
|
|
19
|
+
PayloadEnvelopeInputSource,
|
|
20
|
+
} from "../blocks/payloadEnvelopeInput/index.js";
|
|
11
21
|
import {ChainEvent, ChainEventEmitter} from "../emitter.js";
|
|
22
|
+
import {SeenBlockInput} from "./seenGossipBlockInput.js";
|
|
12
23
|
|
|
13
24
|
export type {PayloadEnvelopeInputState} from "../blocks/payloadEnvelopeInput/index.js";
|
|
14
25
|
export {PayloadEnvelopeInput} from "../blocks/payloadEnvelopeInput/index.js";
|
|
15
26
|
|
|
27
|
+
// Bound this cache by this max size, this is the same to SeenBlockInput
|
|
28
|
+
const MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE = (MAX_LOOK_AHEAD_EPOCHS + 1) * SLOTS_PER_EPOCH;
|
|
29
|
+
|
|
16
30
|
export type SeenPayloadEnvelopeInputModules = {
|
|
17
31
|
config: ChainForkConfig;
|
|
18
32
|
clock: IClock;
|
|
@@ -20,6 +34,9 @@ export type SeenPayloadEnvelopeInputModules = {
|
|
|
20
34
|
chainEvents: ChainEventEmitter;
|
|
21
35
|
signal: AbortSignal;
|
|
22
36
|
serializedCache: SerializedCache;
|
|
37
|
+
db: IBeaconDb;
|
|
38
|
+
seenBlockInputCache: SeenBlockInput;
|
|
39
|
+
custodyConfig: CustodyConfig;
|
|
23
40
|
metrics: Metrics | null;
|
|
24
41
|
logger?: Logger;
|
|
25
42
|
};
|
|
@@ -40,9 +57,14 @@ export class SeenPayloadEnvelopeInput {
|
|
|
40
57
|
private readonly chainEvents: ChainEventEmitter;
|
|
41
58
|
private readonly signal: AbortSignal;
|
|
42
59
|
private readonly serializedCache: SerializedCache;
|
|
60
|
+
private readonly db: IBeaconDb;
|
|
61
|
+
private readonly seenBlockInputCache: SeenBlockInput;
|
|
62
|
+
private readonly custodyConfig: CustodyConfig;
|
|
43
63
|
private readonly metrics: Metrics | null;
|
|
44
64
|
private readonly logger?: Logger;
|
|
45
65
|
private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
|
|
66
|
+
// Dedup concurrent DB reloads of the same root so callers share one reconstructed object.
|
|
67
|
+
private readonly reloading = new Map<RootHex, Promise<PayloadEnvelopeInput | undefined>>();
|
|
46
68
|
|
|
47
69
|
constructor({
|
|
48
70
|
config,
|
|
@@ -51,6 +73,9 @@ export class SeenPayloadEnvelopeInput {
|
|
|
51
73
|
chainEvents,
|
|
52
74
|
signal,
|
|
53
75
|
serializedCache,
|
|
76
|
+
db,
|
|
77
|
+
seenBlockInputCache,
|
|
78
|
+
custodyConfig,
|
|
54
79
|
metrics,
|
|
55
80
|
logger,
|
|
56
81
|
}: SeenPayloadEnvelopeInputModules) {
|
|
@@ -60,6 +85,9 @@ export class SeenPayloadEnvelopeInput {
|
|
|
60
85
|
this.chainEvents = chainEvents;
|
|
61
86
|
this.signal = signal;
|
|
62
87
|
this.serializedCache = serializedCache;
|
|
88
|
+
this.db = db;
|
|
89
|
+
this.seenBlockInputCache = seenBlockInputCache;
|
|
90
|
+
this.custodyConfig = custodyConfig;
|
|
63
91
|
this.metrics = metrics;
|
|
64
92
|
this.logger = logger;
|
|
65
93
|
|
|
@@ -86,7 +114,7 @@ export class SeenPayloadEnvelopeInput {
|
|
|
86
114
|
let deletedCount = 0;
|
|
87
115
|
for (const [, input] of this.payloadInputs) {
|
|
88
116
|
if (input.slot < finalizedSlot) {
|
|
89
|
-
this.evictPayloadInput(input);
|
|
117
|
+
this.evictPayloadInput(input, "finalized");
|
|
90
118
|
deletedCount++;
|
|
91
119
|
}
|
|
92
120
|
}
|
|
@@ -110,12 +138,13 @@ export class SeenPayloadEnvelopeInput {
|
|
|
110
138
|
const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
|
|
111
139
|
const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
|
|
112
140
|
this.payloadInputs.set(props.blockRootHex, input);
|
|
113
|
-
this.metrics?.seenCache.payloadEnvelopeInput.created.inc();
|
|
141
|
+
this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
|
|
114
142
|
this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
|
|
115
143
|
slot: input.slot,
|
|
116
144
|
root: props.blockRootHex,
|
|
117
145
|
daOutOfRange,
|
|
118
146
|
});
|
|
147
|
+
this.pruneToMaxSize();
|
|
119
148
|
return input;
|
|
120
149
|
}
|
|
121
150
|
|
|
@@ -131,12 +160,13 @@ export class SeenPayloadEnvelopeInput {
|
|
|
131
160
|
const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.slot, this.clock.currentEpoch);
|
|
132
161
|
const input = PayloadEnvelopeInput.createFromBid({...props, daOutOfRange});
|
|
133
162
|
this.payloadInputs.set(props.blockRootHex, input);
|
|
134
|
-
this.metrics?.seenCache.payloadEnvelopeInput.created.inc();
|
|
163
|
+
this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
|
|
135
164
|
this.logger?.verbose("SeenPayloadEnvelopeInput.addFromBid created new entry", {
|
|
136
165
|
slot: input.slot,
|
|
137
166
|
root: props.blockRootHex,
|
|
138
167
|
daOutOfRange,
|
|
139
168
|
});
|
|
169
|
+
this.pruneToMaxSize();
|
|
140
170
|
return input;
|
|
141
171
|
}
|
|
142
172
|
|
|
@@ -144,6 +174,80 @@ export class SeenPayloadEnvelopeInput {
|
|
|
144
174
|
return this.payloadInputs.get(blockRootHex);
|
|
145
175
|
}
|
|
146
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Like `get()`, but on a cache miss reconstruct the shell (bid + versionedHashes) from the block
|
|
179
|
+
* in `seenBlockInputCache` or the hot DB.
|
|
180
|
+
* This api is meant for BlockInputSync when a late/weird payloads for old blocks
|
|
181
|
+
*
|
|
182
|
+
* NOTE: the reconstructed entry is always EMPTY even when the block is actually FULL (its
|
|
183
|
+
* payload envelope + columns persisted in the DB). The consumer should consult fork choice if it needs to.
|
|
184
|
+
*/
|
|
185
|
+
async getOrReload(blockRootHex: RootHex): Promise<PayloadEnvelopeInput | undefined> {
|
|
186
|
+
const existing = this.payloadInputs.get(blockRootHex);
|
|
187
|
+
if (existing !== undefined) {
|
|
188
|
+
return existing;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Without this dedup, two concurrent misses each db.block.get + createFromBlock a DIFFERENT shell
|
|
192
|
+
// for the same root; processPayloadEnvelopeJob's WeakMap (keyed by object) can't dedup the import.
|
|
193
|
+
const inflight = this.reloading.get(blockRootHex);
|
|
194
|
+
if (inflight !== undefined) {
|
|
195
|
+
return inflight;
|
|
196
|
+
}
|
|
197
|
+
const promise = this.reloadFromDb(blockRootHex);
|
|
198
|
+
this.reloading.set(blockRootHex, promise);
|
|
199
|
+
try {
|
|
200
|
+
return await promise;
|
|
201
|
+
} finally {
|
|
202
|
+
this.reloading.delete(blockRootHex);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private async reloadFromDb(blockRootHex: RootHex): Promise<PayloadEnvelopeInput | undefined> {
|
|
207
|
+
// Only recover unfinalized, fork-choice-known blocks. Do not read the finalized archive. The gate
|
|
208
|
+
// also filters out un-imported blocks that may sit in seenBlockInputCache before validation.
|
|
209
|
+
if (!this.forkChoice.hasBlockHex(blockRootHex)) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// In-memory first: persistBlockInput writes db.block THEN prunes seenBlockInputCache, so a
|
|
214
|
+
// just-imported block whose async write (unfinalizedBlockWrites) has not flushed yet is still here;
|
|
215
|
+
// older blocks (already pruned from the cache) fall through to the hot db.
|
|
216
|
+
const cachedBlockInput = this.seenBlockInputCache.get(blockRootHex);
|
|
217
|
+
const block = cachedBlockInput?.hasBlock()
|
|
218
|
+
? cachedBlockInput.getBlock()
|
|
219
|
+
: await this.db.block.get(fromHex(blockRootHex));
|
|
220
|
+
if (block == null) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const forkName = this.config.getForkName(block.message.slot);
|
|
225
|
+
if (!isForkPostGloas(forkName)) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const daOutOfRange = isDaOutOfRange(this.config, forkName, block.message.slot, this.clock.currentEpoch);
|
|
230
|
+
const input = PayloadEnvelopeInput.createFromBlock({
|
|
231
|
+
blockRootHex,
|
|
232
|
+
block: block as SignedBeaconBlock<ForkPostGloas>,
|
|
233
|
+
forkName,
|
|
234
|
+
sampledColumns: this.custodyConfig.sampledColumns,
|
|
235
|
+
custodyColumns: this.custodyConfig.custodyColumns,
|
|
236
|
+
seenTimestampSec: Date.now() / 1000,
|
|
237
|
+
source: PayloadEnvelopeInputSource.reload,
|
|
238
|
+
daOutOfRange,
|
|
239
|
+
});
|
|
240
|
+
this.payloadInputs.set(blockRootHex, input);
|
|
241
|
+
this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: PayloadEnvelopeInputSource.reload});
|
|
242
|
+
this.logger?.verbose("SeenPayloadEnvelopeInput.getOrReload reconstructed entry from db", {
|
|
243
|
+
slot: input.slot,
|
|
244
|
+
root: blockRootHex,
|
|
245
|
+
});
|
|
246
|
+
// Set above (entry is at the back of the insertion order), so the cap never evicts what we just reloaded.
|
|
247
|
+
this.pruneToMaxSize();
|
|
248
|
+
return input;
|
|
249
|
+
}
|
|
250
|
+
|
|
147
251
|
hasPayload(blockRootHex: RootHex): boolean {
|
|
148
252
|
return this.payloadInputs.get(blockRootHex)?.hasPayloadEnvelope() ?? false;
|
|
149
253
|
}
|
|
@@ -155,8 +259,7 @@ export class SeenPayloadEnvelopeInput {
|
|
|
155
259
|
prune(blockRootHex: RootHex): void {
|
|
156
260
|
const input = this.payloadInputs.get(blockRootHex);
|
|
157
261
|
if (input) {
|
|
158
|
-
this.evictPayloadInput(input);
|
|
159
|
-
this.logger?.verbose("SeenPayloadEnvelopeInput.prune deleted", {slot: input.slot, root: blockRootHex});
|
|
262
|
+
this.evictPayloadInput(input, "prune");
|
|
160
263
|
}
|
|
161
264
|
}
|
|
162
265
|
|
|
@@ -170,17 +273,43 @@ export class SeenPayloadEnvelopeInput {
|
|
|
170
273
|
// ...and don't evict while columns are still being gathered: writeDataColumnsToDb awaits the
|
|
171
274
|
// same hasComputedAllData() before persisting. Such entries are pruned by a later call.
|
|
172
275
|
if (input?.hasComputedAllData()) {
|
|
173
|
-
this.evictPayloadInput(input);
|
|
174
|
-
this.logger?.verbose("SeenPayloadEnvelopeInput.pruneBelowParent deleted", {
|
|
175
|
-
slot: block.slot,
|
|
176
|
-
root: block.blockRoot,
|
|
177
|
-
});
|
|
276
|
+
this.evictPayloadInput(input, "belowParent");
|
|
178
277
|
}
|
|
179
278
|
}
|
|
180
279
|
}
|
|
181
280
|
}
|
|
182
281
|
|
|
183
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Bound this cache to have at most MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE items.
|
|
284
|
+
* Evicts by insertion order so a just-reloaded old-slot entry is not evicted right after.
|
|
285
|
+
* On unstable network, we may need to query an evicted item, UnknownBlockInput will recover
|
|
286
|
+
* it from db via getOrReload() api. Runs after every single insert, so it evicts ~1 per call.
|
|
287
|
+
*/
|
|
288
|
+
private pruneToMaxSize(): void {
|
|
289
|
+
let evicted = 0;
|
|
290
|
+
for (const input of this.payloadInputs.values()) {
|
|
291
|
+
if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
this.evictPayloadInput(input, "cap");
|
|
295
|
+
evicted++;
|
|
296
|
+
}
|
|
297
|
+
if (evicted > 0) {
|
|
298
|
+
this.logger?.debug("SeenPayloadEnvelopeInput.pruneToMaxSize evicted", {
|
|
299
|
+
evicted,
|
|
300
|
+
size: this.payloadInputs.size,
|
|
301
|
+
max: MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private evictPayloadInput(payloadInput: PayloadEnvelopeInput, reason: PayloadEnvelopeInputPruneReason): void {
|
|
307
|
+
this.metrics?.seenCache.payloadEnvelopeInput.pruned.inc({reason});
|
|
308
|
+
this.logger?.debug("SeenPayloadEnvelopeInput evicted", {
|
|
309
|
+
slot: payloadInput.slot,
|
|
310
|
+
root: payloadInput.blockRootHex,
|
|
311
|
+
reason,
|
|
312
|
+
});
|
|
184
313
|
this.serializedCache.delete(payloadInput.getSerializedCacheKeys());
|
|
185
314
|
this.payloadInputs.delete(payloadInput.blockRootHex);
|
|
186
315
|
}
|