@lodestar/beacon-node 1.39.0 → 1.40.0-dev.1c71f4299a
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 +8 -18
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/beacon/state/utils.d.ts +2 -7
- package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/utils.js +0 -12
- package/lib/api/impl/beacon/state/utils.js.map +1 -1
- package/lib/api/impl/config/constants.d.ts +3 -0
- package/lib/api/impl/config/constants.d.ts.map +1 -1
- package/lib/api/impl/config/constants.js +5 -1
- package/lib/api/impl/config/constants.js.map +1 -1
- package/lib/api/impl/debug/index.d.ts +1 -1
- package/lib/api/impl/debug/index.d.ts.map +1 -1
- package/lib/api/impl/debug/index.js +3 -6
- package/lib/api/impl/debug/index.js.map +1 -1
- package/lib/api/impl/lodestar/index.d.ts.map +1 -1
- package/lib/api/impl/lodestar/index.js +6 -1
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/proof/index.d.ts.map +1 -1
- package/lib/api/impl/proof/index.js +1 -2
- package/lib/api/impl/proof/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +1 -3
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -3
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +23 -14
- package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
- package/lib/chain/blocks/blockInput/blockInput.d.ts +2 -0
- package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
- package/lib/chain/blocks/blockInput/blockInput.js +6 -0
- package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +14 -9
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/index.d.ts.map +1 -1
- package/lib/chain/blocks/index.js +0 -14
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/blocks/types.d.ts +0 -2
- package/lib/chain/blocks/types.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +8 -8
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +1 -0
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.d.ts +1 -4
- package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.js +20 -28
- package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
- package/lib/chain/chain.d.ts +16 -3
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +165 -7
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/initState.d.ts +1 -1
- package/lib/chain/initState.d.ts.map +1 -1
- package/lib/chain/initState.js +5 -3
- package/lib/chain/initState.js.map +1 -1
- package/lib/chain/interface.d.ts +16 -3
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/lightClient/proofs.d.ts.map +1 -1
- package/lib/chain/lightClient/proofs.js +0 -2
- package/lib/chain/lightClient/proofs.js.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts +5 -9
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js +12 -141
- package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
- package/lib/chain/opPools/opPool.js +5 -8
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +4 -7
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.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 +1 -5
- package/lib/chain/regen/interface.d.ts.map +1 -1
- package/lib/chain/regen/queued.d.ts +4 -7
- package/lib/chain/regen/queued.d.ts.map +1 -1
- package/lib/chain/regen/queued.js +15 -25
- package/lib/chain/regen/queued.js.map +1 -1
- package/lib/chain/regen/regen.d.ts +1 -1
- package/lib/chain/regen/regen.d.ts.map +1 -1
- package/lib/chain/regen/regen.js +13 -17
- package/lib/chain/regen/regen.js.map +1 -1
- package/lib/chain/shufflingCache.d.ts +16 -11
- package/lib/chain/shufflingCache.d.ts.map +1 -1
- package/lib/chain/shufflingCache.js +47 -41
- package/lib/chain/shufflingCache.js.map +1 -1
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts +1 -2
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -1
- package/lib/chain/stateCache/blockStateCacheImpl.js +2 -2
- package/lib/chain/stateCache/blockStateCacheImpl.js.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts +1 -2
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.js +4 -4
- package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +4 -5
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js +9 -10
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +5 -6
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +17 -17
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/stateCache/types.d.ts +5 -6
- package/lib/chain/stateCache/types.d.ts.map +1 -1
- package/lib/chain/stateCache/types.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +2 -2
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +1 -1
- package/lib/chain/validation/attesterSlashing.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +2 -0
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
- package/lib/chain/validation/blsToExecutionChange.js +9 -2
- package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +2 -1
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validatorMonitor.d.ts +2 -0
- package/lib/chain/validatorMonitor.d.ts.map +1 -1
- package/lib/chain/validatorMonitor.js +42 -3
- package/lib/chain/validatorMonitor.js.map +1 -1
- package/lib/db/repositories/checkpointState.d.ts +2 -6
- package/lib/db/repositories/checkpointState.d.ts.map +1 -1
- package/lib/db/repositories/checkpointState.js +3 -15
- package/lib/db/repositories/checkpointState.js.map +1 -1
- package/lib/db/repositories/stateArchive.d.ts +9 -9
- package/lib/db/repositories/stateArchive.d.ts.map +1 -1
- package/lib/db/repositories/stateArchive.js +6 -21
- package/lib/db/repositories/stateArchive.js.map +1 -1
- package/lib/execution/engine/mock.d.ts +9 -6
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +34 -7
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +8 -6
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +27 -17
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +0 -3
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js +2 -4
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts +1 -2
- package/lib/network/reqresp/handlers/beaconBlocksByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRoot.js +5 -26
- package/lib/network/reqresp/handlers/beaconBlocksByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts +1 -2
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +5 -7
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -2
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -5
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/index.js +2 -2
- package/lib/network/reqresp/handlers/index.js.map +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +17 -2
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +0 -1
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +0 -3
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +0 -3
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/util/sszBytes.js +1 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/beacon/blocks/index.ts +8 -18
- package/src/api/impl/beacon/state/utils.ts +2 -22
- package/src/api/impl/config/constants.ts +8 -0
- package/src/api/impl/debug/index.ts +2 -6
- package/src/api/impl/lodestar/index.ts +7 -1
- package/src/api/impl/proof/index.ts +1 -2
- package/src/api/impl/validator/index.ts +1 -3
- package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -3
- package/src/chain/archiveStore/utils/archiveBlocks.ts +25 -14
- package/src/chain/blocks/blockInput/blockInput.ts +8 -0
- package/src/chain/blocks/importBlock.ts +15 -9
- package/src/chain/blocks/index.ts +0 -19
- package/src/chain/blocks/types.ts +0 -2
- package/src/chain/blocks/verifyBlock.ts +9 -11
- package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
- package/src/chain/blocks/writeBlockInputToDb.ts +24 -30
- package/src/chain/chain.ts +191 -10
- package/src/chain/initState.ts +5 -3
- package/src/chain/interface.ts +18 -2
- package/src/chain/lightClient/proofs.ts +0 -2
- package/src/chain/opPools/aggregatedAttestationPool.ts +19 -191
- package/src/chain/opPools/opPool.ts +5 -7
- package/src/chain/prepareNextSlot.ts +2 -6
- package/src/chain/produceBlock/produceBlockBody.ts +6 -1
- package/src/chain/regen/interface.ts +1 -5
- package/src/chain/regen/queued.ts +15 -34
- package/src/chain/regen/regen.ts +12 -18
- package/src/chain/shufflingCache.ts +67 -50
- package/src/chain/stateCache/blockStateCacheImpl.ts +2 -3
- package/src/chain/stateCache/fifoBlockStateCache.ts +4 -5
- package/src/chain/stateCache/inMemoryCheckpointsCache.ts +9 -15
- package/src/chain/stateCache/persistentCheckpointsCache.ts +17 -25
- package/src/chain/stateCache/types.ts +5 -10
- package/src/chain/validation/attestation.ts +3 -3
- package/src/chain/validation/attesterSlashing.ts +8 -1
- package/src/chain/validation/block.ts +3 -0
- package/src/chain/validation/blsToExecutionChange.ts +9 -7
- package/src/chain/validation/proposerSlashing.ts +2 -1
- package/src/chain/validatorMonitor.ts +52 -3
- package/src/db/repositories/checkpointState.ts +3 -19
- package/src/db/repositories/stateArchive.ts +13 -27
- package/src/execution/engine/mock.ts +40 -13
- package/src/index.ts +1 -1
- package/src/metrics/metrics/lodestar.ts +28 -17
- package/src/network/processor/gossipHandlers.ts +0 -3
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +2 -4
- package/src/network/reqresp/handlers/beaconBlocksByRoot.ts +5 -32
- package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -9
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +5 -2
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -5
- package/src/network/reqresp/handlers/index.ts +2 -2
- package/src/network/reqresp/utils/dataColumnResponseValidation.ts +1 -1
- package/src/node/nodejs.ts +18 -3
- package/src/sync/range/chain.ts +0 -1
- package/src/sync/range/range.ts +0 -3
- package/src/sync/unknownBlock.ts +0 -3
- package/src/util/sszBytes.ts +1 -1
|
@@ -5,7 +5,6 @@ import {IForkChoice} from "@lodestar/fork-choice";
|
|
|
5
5
|
import {
|
|
6
6
|
ForkName,
|
|
7
7
|
ForkSeq,
|
|
8
|
-
MAX_ATTESTATIONS,
|
|
9
8
|
MAX_ATTESTATIONS_ELECTRA,
|
|
10
9
|
MAX_COMMITTEES_PER_SLOT,
|
|
11
10
|
MIN_ATTESTATION_INCLUSION_DELAY,
|
|
@@ -23,7 +22,6 @@ import {
|
|
|
23
22
|
CachedBeaconStateAllForks,
|
|
24
23
|
CachedBeaconStateAltair,
|
|
25
24
|
CachedBeaconStateGloas,
|
|
26
|
-
CachedBeaconStatePhase0,
|
|
27
25
|
EffectiveBalanceIncrements,
|
|
28
26
|
RootCache,
|
|
29
27
|
computeEpochAtSlot,
|
|
@@ -32,21 +30,12 @@ import {
|
|
|
32
30
|
getAttestationParticipationStatus,
|
|
33
31
|
getBlockRootAtSlot,
|
|
34
32
|
} from "@lodestar/state-transition";
|
|
35
|
-
import {
|
|
36
|
-
Attestation,
|
|
37
|
-
Epoch,
|
|
38
|
-
RootHex,
|
|
39
|
-
Slot,
|
|
40
|
-
ValidatorIndex,
|
|
41
|
-
electra,
|
|
42
|
-
isElectraAttestation,
|
|
43
|
-
phase0,
|
|
44
|
-
ssz,
|
|
45
|
-
} from "@lodestar/types";
|
|
33
|
+
import {Attestation, Epoch, RootHex, Slot, electra, isElectraAttestation, phase0, ssz} from "@lodestar/types";
|
|
46
34
|
import {MapDef, assert, toRootHex} from "@lodestar/utils";
|
|
47
35
|
import {Metrics} from "../../metrics/metrics.js";
|
|
48
36
|
import {IntersectResult, intersectUint8Arrays} from "../../util/bitArray.js";
|
|
49
37
|
import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
|
|
38
|
+
import {ShufflingCache} from "../shufflingCache.js";
|
|
50
39
|
import {InsertOutcome} from "./types.js";
|
|
51
40
|
import {pruneBySlot, signatureFromBytesNoCheck} from "./utils.js";
|
|
52
41
|
|
|
@@ -54,8 +43,6 @@ type DataRootHex = string;
|
|
|
54
43
|
|
|
55
44
|
type CommitteeIndex = number;
|
|
56
45
|
|
|
57
|
-
// for pre-electra
|
|
58
|
-
type AttestationWithScore = {attestation: Attestation; score: number};
|
|
59
46
|
/**
|
|
60
47
|
* for electra, this is to consolidate aggregated attestations of the same attestation data into a single attestation to be included in block
|
|
61
48
|
* note that this is local definition in this file and it's NOT validator consolidation
|
|
@@ -110,15 +97,6 @@ const MAX_RETAINED_ATTESTATIONS_PER_GROUP = 4;
|
|
|
110
97
|
*/
|
|
111
98
|
const MAX_RETAINED_ATTESTATIONS_PER_GROUP_ELECTRA = 8;
|
|
112
99
|
|
|
113
|
-
/**
|
|
114
|
-
* Pre-electra, each slot has 64 committees, and each block has 128 attestations max so in average
|
|
115
|
-
* we get 2 attestation per groups.
|
|
116
|
-
* Starting from Jan 2024, we have a performance issue getting attestations for a block. Based on the
|
|
117
|
-
* fact that lot of groups will have only 1 full participation attestation, increase this number
|
|
118
|
-
* a bit higher than average. This also help decrease number of slots to search for attestations.
|
|
119
|
-
*/
|
|
120
|
-
const MAX_ATTESTATIONS_PER_GROUP = 3;
|
|
121
|
-
|
|
122
100
|
/**
|
|
123
101
|
* For electra, there is on chain aggregation of attestations across committees, so we can just pick up to 8
|
|
124
102
|
* attestations per group, sort by scores to get first 8.
|
|
@@ -230,123 +208,18 @@ export class AggregatedAttestationPool {
|
|
|
230
208
|
this.lowestPermissibleSlot = Math.max(clockSlot - slotsToRetain, 0);
|
|
231
209
|
}
|
|
232
210
|
|
|
233
|
-
getAttestationsForBlock(
|
|
234
|
-
const forkSeq = ForkSeq[fork];
|
|
235
|
-
return forkSeq >= ForkSeq.electra
|
|
236
|
-
? this.getAttestationsForBlockElectra(fork, forkChoice, state)
|
|
237
|
-
: this.getAttestationsForBlockPreElectra(fork, forkChoice, state);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Get attestations to be included in a block pre-electra. Returns up to $MAX_ATTESTATIONS items
|
|
242
|
-
*/
|
|
243
|
-
getAttestationsForBlockPreElectra(
|
|
211
|
+
getAttestationsForBlock(
|
|
244
212
|
fork: ForkName,
|
|
245
213
|
forkChoice: IForkChoice,
|
|
214
|
+
shufflingCache: ShufflingCache,
|
|
246
215
|
state: CachedBeaconStateAllForks
|
|
247
|
-
):
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const notSeenValidatorsFn = getNotSeenValidatorsFn(this.config, state);
|
|
253
|
-
const validateAttestationDataFn = getValidateAttestationDataFn(forkChoice, state);
|
|
254
|
-
|
|
255
|
-
const attestationsByScore: AttestationWithScore[] = [];
|
|
256
|
-
|
|
257
|
-
const slots = Array.from(this.attestationGroupByIndexByDataHexBySlot.keys()).sort((a, b) => b - a);
|
|
258
|
-
let minScore = Number.MAX_SAFE_INTEGER;
|
|
259
|
-
let slotCount = 0;
|
|
260
|
-
slot: for (const slot of slots) {
|
|
261
|
-
slotCount++;
|
|
262
|
-
const attestationGroupByIndexByDataHash = this.attestationGroupByIndexByDataHexBySlot.get(slot);
|
|
263
|
-
// should not happen
|
|
264
|
-
if (!attestationGroupByIndexByDataHash) {
|
|
265
|
-
throw Error(`No aggregated attestation pool for slot=${slot}`);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const epoch = computeEpochAtSlot(slot);
|
|
269
|
-
// validateAttestation condition: Attestation target epoch not in previous or current epoch
|
|
270
|
-
if (!(epoch === stateEpoch || epoch === statePrevEpoch)) {
|
|
271
|
-
continue; // Invalid attestations
|
|
272
|
-
}
|
|
273
|
-
// validateAttestation condition: Attestation slot not within inclusion window
|
|
274
|
-
if (
|
|
275
|
-
!(
|
|
276
|
-
slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot &&
|
|
277
|
-
// Post deneb, attestations are valid for current and previous epoch
|
|
278
|
-
(ForkSeq[fork] >= ForkSeq.deneb || stateSlot <= slot + SLOTS_PER_EPOCH)
|
|
279
|
-
)
|
|
280
|
-
) {
|
|
281
|
-
continue; // Invalid attestations
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const inclusionDistance = stateSlot - slot;
|
|
285
|
-
for (const attestationGroupByIndex of attestationGroupByIndexByDataHash.values()) {
|
|
286
|
-
for (const [committeeIndex, attestationGroup] of attestationGroupByIndex.entries()) {
|
|
287
|
-
const notSeenCommitteeMembers = notSeenValidatorsFn(epoch, slot, committeeIndex);
|
|
288
|
-
if (notSeenCommitteeMembers === null || notSeenCommitteeMembers.size === 0) {
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
slotCount > 2 &&
|
|
294
|
-
attestationsByScore.length >= MAX_ATTESTATIONS &&
|
|
295
|
-
notSeenCommitteeMembers.size / inclusionDistance < minScore
|
|
296
|
-
) {
|
|
297
|
-
// after 2 slots, there are a good chance that we have 2 * MAX_ATTESTATIONS attestations and break the for loop early
|
|
298
|
-
// if not, we may have to scan all slots in the pool
|
|
299
|
-
// if we have enough attestations and the max possible score is lower than scores of `attestationsByScore`, we should skip
|
|
300
|
-
// otherwise it takes time to check attestation, add it and remove it later after the sort by score
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (validateAttestationDataFn(attestationGroup.data) !== null) {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// TODO: Is it necessary to validateAttestation for:
|
|
309
|
-
// - Attestation committee index not within current committee count
|
|
310
|
-
// - Attestation aggregation bits length does not match committee length
|
|
311
|
-
//
|
|
312
|
-
// These properties should not change after being validate in gossip
|
|
313
|
-
// IF they have to be validated, do it only with one attestation per group since same data
|
|
314
|
-
// The committeeCountPerSlot can be precomputed once per slot
|
|
315
|
-
const getAttestationsResult = attestationGroup.getAttestationsForBlock(
|
|
316
|
-
fork,
|
|
317
|
-
state.epochCtx.effectiveBalanceIncrements,
|
|
318
|
-
notSeenCommitteeMembers,
|
|
319
|
-
MAX_ATTESTATIONS_PER_GROUP
|
|
320
|
-
);
|
|
321
|
-
for (const {attestation, newSeenEffectiveBalance} of getAttestationsResult.result) {
|
|
322
|
-
const score = newSeenEffectiveBalance / inclusionDistance;
|
|
323
|
-
if (score < minScore) {
|
|
324
|
-
minScore = score;
|
|
325
|
-
}
|
|
326
|
-
attestationsByScore.push({
|
|
327
|
-
attestation,
|
|
328
|
-
score,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Stop accumulating attestations there are enough that may have good scoring
|
|
333
|
-
if (attestationsByScore.length >= MAX_ATTESTATIONS * 2) {
|
|
334
|
-
break slot;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
216
|
+
): Attestation[] {
|
|
217
|
+
const forkSeq = ForkSeq[fork];
|
|
218
|
+
if (forkSeq < ForkSeq.electra) {
|
|
219
|
+
throw new Error("Does not support producing blocks for pre-electra forks anymore");
|
|
338
220
|
}
|
|
339
221
|
|
|
340
|
-
|
|
341
|
-
const attestationsForBlock: phase0.Attestation[] = [];
|
|
342
|
-
for (const [i, attestationWithScore] of sortedAttestationsByScore.entries()) {
|
|
343
|
-
if (i >= MAX_ATTESTATIONS) {
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
// attestations could be modified in this op pool, so we need to clone for block
|
|
347
|
-
attestationsForBlock.push(ssz.phase0.Attestation.clone(attestationWithScore.attestation));
|
|
348
|
-
}
|
|
349
|
-
return attestationsForBlock;
|
|
222
|
+
return this.getAttestationsForBlockElectra(fork, forkChoice, shufflingCache, state);
|
|
350
223
|
}
|
|
351
224
|
|
|
352
225
|
/**
|
|
@@ -355,6 +228,7 @@ export class AggregatedAttestationPool {
|
|
|
355
228
|
getAttestationsForBlockElectra(
|
|
356
229
|
fork: ForkName,
|
|
357
230
|
forkChoice: IForkChoice,
|
|
231
|
+
shufflingCache: ShufflingCache,
|
|
358
232
|
state: CachedBeaconStateAllForks
|
|
359
233
|
): electra.Attestation[] {
|
|
360
234
|
const stateSlot = state.slot;
|
|
@@ -362,7 +236,7 @@ export class AggregatedAttestationPool {
|
|
|
362
236
|
const statePrevEpoch = stateEpoch - 1;
|
|
363
237
|
const rootCache = new RootCache(state);
|
|
364
238
|
|
|
365
|
-
const notSeenValidatorsFn = getNotSeenValidatorsFn(this.config, state);
|
|
239
|
+
const notSeenValidatorsFn = getNotSeenValidatorsFn(this.config, shufflingCache, state);
|
|
366
240
|
const validateAttestationDataFn = getValidateAttestationDataFn(forkChoice, state);
|
|
367
241
|
|
|
368
242
|
const slots = Array.from(this.attestationGroupByIndexByDataHexBySlot.keys()).sort((a, b) => b - a);
|
|
@@ -864,41 +738,14 @@ export function aggregateConsolidation({byCommittee, attData}: AttestationsConso
|
|
|
864
738
|
* Pre-compute participation from a CachedBeaconStateAllForks, for use to check if an attestation's committee
|
|
865
739
|
* has already attested or not.
|
|
866
740
|
*/
|
|
867
|
-
export function getNotSeenValidatorsFn(
|
|
741
|
+
export function getNotSeenValidatorsFn(
|
|
742
|
+
config: BeaconConfig,
|
|
743
|
+
shufflingCache: ShufflingCache,
|
|
744
|
+
state: CachedBeaconStateAllForks
|
|
745
|
+
): GetNotSeenValidatorsFn {
|
|
868
746
|
const stateSlot = state.slot;
|
|
869
747
|
if (config.getForkName(stateSlot) === ForkName.phase0) {
|
|
870
|
-
|
|
871
|
-
// As we are close to altair, this is not really important, it's mainly for e2e.
|
|
872
|
-
// The performance is not great due to the different BeaconState data structure to altair.
|
|
873
|
-
// check for phase0 block already
|
|
874
|
-
const phase0State = state as CachedBeaconStatePhase0;
|
|
875
|
-
const stateEpoch = computeEpochAtSlot(stateSlot);
|
|
876
|
-
|
|
877
|
-
const previousEpochParticipants = extractParticipationPhase0(
|
|
878
|
-
phase0State.previousEpochAttestations.getAllReadonly(),
|
|
879
|
-
state
|
|
880
|
-
);
|
|
881
|
-
const currentEpochParticipants = extractParticipationPhase0(
|
|
882
|
-
phase0State.currentEpochAttestations.getAllReadonly(),
|
|
883
|
-
state
|
|
884
|
-
);
|
|
885
|
-
|
|
886
|
-
return (epoch: Epoch, slot: Slot, committeeIndex: number) => {
|
|
887
|
-
const participants =
|
|
888
|
-
epoch === stateEpoch ? currentEpochParticipants : epoch === stateEpoch - 1 ? previousEpochParticipants : null;
|
|
889
|
-
if (participants === null) {
|
|
890
|
-
return null;
|
|
891
|
-
}
|
|
892
|
-
const committee = state.epochCtx.getBeaconCommittee(slot, committeeIndex);
|
|
893
|
-
|
|
894
|
-
const notSeenCommitteeMembers = new Set<number>();
|
|
895
|
-
for (const [i, validatorIndex] of committee.entries()) {
|
|
896
|
-
if (!participants.has(validatorIndex)) {
|
|
897
|
-
notSeenCommitteeMembers.add(i);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return notSeenCommitteeMembers.size === 0 ? null : notSeenCommitteeMembers;
|
|
901
|
-
};
|
|
748
|
+
throw new Error("getNotSeenValidatorsFn is not supported phase0 state");
|
|
902
749
|
}
|
|
903
750
|
|
|
904
751
|
// altair and future forks
|
|
@@ -927,7 +774,8 @@ export function getNotSeenValidatorsFn(config: BeaconConfig, state: CachedBeacon
|
|
|
927
774
|
return notSeenCommitteeMembers.size === 0 ? null : notSeenCommitteeMembers;
|
|
928
775
|
}
|
|
929
776
|
|
|
930
|
-
const
|
|
777
|
+
const decisionRoot = state.epochCtx.getShufflingDecisionRoot(computeEpochAtSlot(slot));
|
|
778
|
+
const committee = shufflingCache.getBeaconCommittee(epoch, decisionRoot, slot, committeeIndex);
|
|
931
779
|
notSeenCommitteeMembers = new Set<number>();
|
|
932
780
|
for (const [i, validatorIndex] of committee.entries()) {
|
|
933
781
|
// no need to check flagIsTimelySource as if validator is not seen, it's participation status is 0
|
|
@@ -942,26 +790,6 @@ export function getNotSeenValidatorsFn(config: BeaconConfig, state: CachedBeacon
|
|
|
942
790
|
};
|
|
943
791
|
}
|
|
944
792
|
|
|
945
|
-
export function extractParticipationPhase0(
|
|
946
|
-
attestations: phase0.PendingAttestation[],
|
|
947
|
-
state: CachedBeaconStateAllForks
|
|
948
|
-
): Set<ValidatorIndex> {
|
|
949
|
-
const {epochCtx} = state;
|
|
950
|
-
const allParticipants = new Set<ValidatorIndex>();
|
|
951
|
-
for (const att of attestations) {
|
|
952
|
-
const aggregationBits = att.aggregationBits;
|
|
953
|
-
const attData = att.data;
|
|
954
|
-
const attSlot = attData.slot;
|
|
955
|
-
const committeeIndex = attData.index;
|
|
956
|
-
const committee = epochCtx.getBeaconCommittee(attSlot, committeeIndex);
|
|
957
|
-
const participants = aggregationBits.intersectValues(committee);
|
|
958
|
-
for (const participant of participants) {
|
|
959
|
-
allParticipants.add(participant);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
return allParticipants;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
793
|
/**
|
|
966
794
|
* This returns a function to validate if an attestation data is compatible to a state.
|
|
967
795
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
-
import {Id, Repository} from "@lodestar/db";
|
|
2
|
+
import {DbBatch, Id, Repository} from "@lodestar/db";
|
|
3
3
|
import {
|
|
4
4
|
BLS_WITHDRAWAL_PREFIX,
|
|
5
5
|
ForkName,
|
|
@@ -440,23 +440,21 @@ async function persistDiff<K extends Id, V>(
|
|
|
440
440
|
serializeKey: (key: K) => number | string
|
|
441
441
|
): Promise<void> {
|
|
442
442
|
const persistedKeys = await dbRepo.keys();
|
|
443
|
-
const
|
|
444
|
-
const keysToDelete: K[] = [];
|
|
443
|
+
const batch: DbBatch<K, V> = [];
|
|
445
444
|
|
|
446
445
|
const persistedKeysSerialized = new Set(persistedKeys.map(serializeKey));
|
|
447
446
|
for (const item of items) {
|
|
448
447
|
if (!persistedKeysSerialized.has(serializeKey(item.key))) {
|
|
449
|
-
|
|
448
|
+
batch.push({type: "put", key: item.key, value: item.value});
|
|
450
449
|
}
|
|
451
450
|
}
|
|
452
451
|
|
|
453
452
|
const targetKeysSerialized = new Set(items.map((item) => serializeKey(item.key)));
|
|
454
453
|
for (const persistedKey of persistedKeys) {
|
|
455
454
|
if (!targetKeysSerialized.has(serializeKey(persistedKey))) {
|
|
456
|
-
|
|
455
|
+
batch.push({type: "del", key: persistedKey});
|
|
457
456
|
}
|
|
458
457
|
}
|
|
459
458
|
|
|
460
|
-
if (
|
|
461
|
-
if (keysToDelete.length > 0) await dbRepo.batchDelete(keysToDelete);
|
|
459
|
+
if (batch.length > 0) await dbRepo.batch(batch);
|
|
462
460
|
}
|
|
@@ -117,12 +117,7 @@ export class PrepareNextSlotScheduler {
|
|
|
117
117
|
// the slot 0 of next epoch will likely use this Previous Root Checkpoint state for state transition so we transfer cache here
|
|
118
118
|
// the resulting state with cache will be cached in Checkpoint State Cache which is used for the upcoming block processing
|
|
119
119
|
// for other slots dontTransferCached=true because we don't run state transition on this state
|
|
120
|
-
|
|
121
|
-
// Shuffling calculation will be done asynchronously when passing asyncShufflingCalculation=true. Shuffling will be queued in
|
|
122
|
-
// beforeProcessEpoch and should theoretically be ready immediately after the synchronous epoch transition finished and the
|
|
123
|
-
// event loop is free. In long periods of non-finality too many forks will cause the shufflingCache to throw an error for
|
|
124
|
-
// too many queued shufflings so only run async during normal epoch transition. See issue ChainSafe/lodestar#7244
|
|
125
|
-
{dontTransferCache: !isEpochTransition, asyncShufflingCalculation: true},
|
|
120
|
+
{dontTransferCache: !isEpochTransition},
|
|
126
121
|
RegenCaller.precomputeEpoch
|
|
127
122
|
);
|
|
128
123
|
|
|
@@ -148,6 +143,7 @@ export class PrepareNextSlotScheduler {
|
|
|
148
143
|
updatedPrepareState = (await this.chain.regen.getBlockSlotState(
|
|
149
144
|
proposerHeadRoot,
|
|
150
145
|
prepareSlot,
|
|
146
|
+
// only transfer cache if epoch transition because that's the state we will use to stateTransition() the 1st block of epoch
|
|
151
147
|
{dontTransferCache: !isEpochTransition},
|
|
152
148
|
RegenCaller.predictProposerHead
|
|
153
149
|
)) as CachedBeaconStateExecutions;
|
|
@@ -661,7 +661,12 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
661
661
|
this.opPool.getSlashingsAndExits(currentState, blockType, this.metrics);
|
|
662
662
|
|
|
663
663
|
const endAttestations = stepsMetrics?.startTimer();
|
|
664
|
-
const attestations = this.aggregatedAttestationPool.getAttestationsForBlock(
|
|
664
|
+
const attestations = this.aggregatedAttestationPool.getAttestationsForBlock(
|
|
665
|
+
fork,
|
|
666
|
+
this.forkChoice,
|
|
667
|
+
this.shufflingCache,
|
|
668
|
+
currentState
|
|
669
|
+
);
|
|
665
670
|
endAttestations?.({
|
|
666
671
|
step: BlockProductionStep.attestations,
|
|
667
672
|
});
|
|
@@ -31,10 +31,6 @@ export enum RegenFnName {
|
|
|
31
31
|
|
|
32
32
|
export type StateRegenerationOpts = {
|
|
33
33
|
dontTransferCache: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Do not queue shuffling calculation async. Forces sync JIT calculation in afterProcessEpoch if not passed as `true`
|
|
36
|
-
*/
|
|
37
|
-
asyncShufflingCalculation?: boolean;
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
export interface IStateRegenerator extends IStateRegeneratorInternal {
|
|
@@ -90,5 +86,5 @@ export interface IStateRegeneratorInternal {
|
|
|
90
86
|
/**
|
|
91
87
|
* Return the exact state with `stateRoot`
|
|
92
88
|
*/
|
|
93
|
-
getState(stateRoot: RootHex, rCaller: RegenCaller
|
|
89
|
+
getState(stateRoot: RootHex, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks>;
|
|
94
90
|
}
|
|
@@ -79,21 +79,15 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Get a state from block state cache.
|
|
82
|
-
* This is not for block processing so don't transfer cache
|
|
83
82
|
*/
|
|
84
83
|
getStateSync(stateRoot: RootHex): CachedBeaconStateAllForks | null {
|
|
85
|
-
return this.blockStateCache.get(stateRoot
|
|
84
|
+
return this.blockStateCache.get(stateRoot);
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
/**
|
|
89
88
|
* Get state for block processing.
|
|
90
|
-
* By default, do not transfer cache except for the block at clock slot
|
|
91
|
-
* which is usually the gossip block.
|
|
92
89
|
*/
|
|
93
|
-
getPreStateSync(
|
|
94
|
-
block: BeaconBlock,
|
|
95
|
-
opts: StateRegenerationOpts = {dontTransferCache: true}
|
|
96
|
-
): CachedBeaconStateAllForks | null {
|
|
90
|
+
getPreStateSync(block: BeaconBlock): CachedBeaconStateAllForks | null {
|
|
97
91
|
const parentRoot = toRootHex(block.parentRoot);
|
|
98
92
|
const parentBlock = this.forkChoice.getBlockHex(parentRoot);
|
|
99
93
|
if (!parentBlock) {
|
|
@@ -108,7 +102,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
108
102
|
|
|
109
103
|
// Check the checkpoint cache (if the pre-state is a checkpoint state)
|
|
110
104
|
if (parentEpoch < blockEpoch) {
|
|
111
|
-
const checkpointState = this.checkpointStateCache.getLatest(parentRoot, blockEpoch
|
|
105
|
+
const checkpointState = this.checkpointStateCache.getLatest(parentRoot, blockEpoch);
|
|
112
106
|
if (checkpointState && computeEpochAtSlot(checkpointState.slot) === blockEpoch) {
|
|
113
107
|
return checkpointState;
|
|
114
108
|
}
|
|
@@ -118,7 +112,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
118
112
|
// Otherwise the state transition may not be cached and wasted. Queue for regen since the
|
|
119
113
|
// work required will still be significant.
|
|
120
114
|
if (parentEpoch === blockEpoch) {
|
|
121
|
-
const state = this.blockStateCache.get(parentBlock.stateRoot
|
|
115
|
+
const state = this.blockStateCache.get(parentBlock.stateRoot);
|
|
122
116
|
if (state) {
|
|
123
117
|
return state;
|
|
124
118
|
}
|
|
@@ -132,21 +126,17 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
132
126
|
}
|
|
133
127
|
|
|
134
128
|
/**
|
|
135
|
-
* Get checkpoint state from cache
|
|
129
|
+
* Get checkpoint state from cache
|
|
136
130
|
*/
|
|
137
131
|
getCheckpointStateSync(cp: CheckpointHex): CachedBeaconStateAllForks | null {
|
|
138
|
-
return this.checkpointStateCache.get(cp
|
|
132
|
+
return this.checkpointStateCache.get(cp);
|
|
139
133
|
}
|
|
140
134
|
|
|
141
135
|
/**
|
|
142
|
-
* Get state closest to head
|
|
136
|
+
* Get state closest to head
|
|
143
137
|
*/
|
|
144
138
|
getClosestHeadState(head: ProtoBlock): CachedBeaconStateAllForks | null {
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
this.checkpointStateCache.getLatest(head.blockRoot, Infinity, opts) ||
|
|
148
|
-
this.blockStateCache.get(head.stateRoot, opts)
|
|
149
|
-
);
|
|
139
|
+
return this.checkpointStateCache.getLatest(head.blockRoot, Infinity) || this.blockStateCache.get(head.stateRoot);
|
|
150
140
|
}
|
|
151
141
|
|
|
152
142
|
pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void {
|
|
@@ -181,10 +171,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
181
171
|
maybeHeadStateRoot,
|
|
182
172
|
};
|
|
183
173
|
const headState =
|
|
184
|
-
newHeadStateRoot === maybeHeadStateRoot
|
|
185
|
-
? maybeHeadState
|
|
186
|
-
: // maybeHeadState was already in block state cache so we don't transfer the cache
|
|
187
|
-
this.blockStateCache.get(newHeadStateRoot, {dontTransferCache: true});
|
|
174
|
+
newHeadStateRoot === maybeHeadStateRoot ? maybeHeadState : this.blockStateCache.get(newHeadStateRoot);
|
|
188
175
|
|
|
189
176
|
if (headState) {
|
|
190
177
|
this.blockStateCache.setHeadState(headState);
|
|
@@ -199,9 +186,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
199
186
|
|
|
200
187
|
// for the new FIFOBlockStateCache, it's important to reload state to regen head state here if needed
|
|
201
188
|
const allowDiskReload = true;
|
|
202
|
-
|
|
203
|
-
const cloneOpts = {dontTransferCache: false};
|
|
204
|
-
this.regen.getState(newHeadStateRoot, RegenCaller.processBlock, cloneOpts, allowDiskReload).then(
|
|
189
|
+
this.regen.getState(newHeadStateRoot, RegenCaller.processBlock, allowDiskReload).then(
|
|
205
190
|
(headStateRegen) => this.blockStateCache.setHeadState(headStateRegen),
|
|
206
191
|
(e) => this.logger.error("Error on head state regen", logCtx, e)
|
|
207
192
|
);
|
|
@@ -224,7 +209,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
224
209
|
this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getPreState});
|
|
225
210
|
|
|
226
211
|
// First attempt to fetch the state from caches before queueing
|
|
227
|
-
const cachedState = this.getPreStateSync(block
|
|
212
|
+
const cachedState = this.getPreStateSync(block);
|
|
228
213
|
|
|
229
214
|
if (cachedState !== null) {
|
|
230
215
|
return cachedState;
|
|
@@ -243,7 +228,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
243
228
|
this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getCheckpointState});
|
|
244
229
|
|
|
245
230
|
// First attempt to fetch the state from cache before queueing
|
|
246
|
-
const checkpointState = this.checkpointStateCache.get(toCheckpointHex(cp)
|
|
231
|
+
const checkpointState = this.checkpointStateCache.get(toCheckpointHex(cp));
|
|
247
232
|
if (checkpointState) {
|
|
248
233
|
return checkpointState;
|
|
249
234
|
}
|
|
@@ -271,22 +256,18 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
271
256
|
return this.jobQueue.push({key: "getBlockSlotState", args: [blockRoot, slot, opts, rCaller]});
|
|
272
257
|
}
|
|
273
258
|
|
|
274
|
-
async getState(
|
|
275
|
-
stateRoot: RootHex,
|
|
276
|
-
rCaller: RegenCaller,
|
|
277
|
-
opts: StateRegenerationOpts = {dontTransferCache: true}
|
|
278
|
-
): Promise<CachedBeaconStateAllForks> {
|
|
259
|
+
async getState(stateRoot: RootHex, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
|
|
279
260
|
this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getState});
|
|
280
261
|
|
|
281
262
|
// First attempt to fetch the state from cache before queueing
|
|
282
|
-
const state = this.blockStateCache.get(stateRoot
|
|
263
|
+
const state = this.blockStateCache.get(stateRoot);
|
|
283
264
|
if (state) {
|
|
284
265
|
return state;
|
|
285
266
|
}
|
|
286
267
|
|
|
287
268
|
// The state is not immediately available in the cache, enqueue the job
|
|
288
269
|
this.metrics?.regenFnQueuedTotal.inc({caller: rCaller, entrypoint: RegenFnName.getState});
|
|
289
|
-
return this.jobQueue.push({key: "getState", args: [stateRoot, rCaller
|
|
270
|
+
return this.jobQueue.push({key: "getState", args: [stateRoot, rCaller]});
|
|
290
271
|
}
|
|
291
272
|
|
|
292
273
|
private jobQueueProcessor = async (regenRequest: RegenRequest): Promise<CachedBeaconStateAllForks> => {
|
package/src/chain/regen/regen.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// Otherwise, get the state normally.
|
|
81
|
-
return this.getState(parentBlock.stateRoot, regenCaller,
|
|
81
|
+
return this.getState(parentBlock.stateRoot, regenCaller, allowDiskReload);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -124,8 +124,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
124
124
|
const {checkpointStateCache} = this.modules;
|
|
125
125
|
const epoch = computeEpochAtSlot(slot);
|
|
126
126
|
const latestCheckpointStateCtx = allowDiskReload
|
|
127
|
-
? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch
|
|
128
|
-
: checkpointStateCache.getLatest(blockRoot, epoch
|
|
127
|
+
? await checkpointStateCache.getOrReloadLatest(blockRoot, epoch)
|
|
128
|
+
: checkpointStateCache.getLatest(blockRoot, epoch);
|
|
129
129
|
|
|
130
130
|
// If a checkpoint state exists with the given checkpoint root, it either is in requested epoch
|
|
131
131
|
// or needs to have empty slots processed until the requested epoch
|
|
@@ -136,7 +136,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
136
136
|
// Otherwise, use the fork choice to get the stateRoot from block at the checkpoint root
|
|
137
137
|
// regenerate that state,
|
|
138
138
|
// then process empty slots until the requested epoch
|
|
139
|
-
const blockStateCtx = await this.getState(block.stateRoot, regenCaller,
|
|
139
|
+
const blockStateCtx = await this.getState(block.stateRoot, regenCaller, allowDiskReload);
|
|
140
140
|
return processSlotsByCheckpoint(this.modules, blockStateCtx, slot, regenCaller, opts);
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -148,23 +148,15 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
148
148
|
async getState(
|
|
149
149
|
stateRoot: RootHex,
|
|
150
150
|
caller: RegenCaller,
|
|
151
|
-
opts?: StateRegenerationOpts,
|
|
152
151
|
// internal option, don't want to expose to external caller
|
|
153
152
|
allowDiskReload = false
|
|
154
153
|
): Promise<CachedBeaconStateAllForks> {
|
|
155
154
|
// Trivial case, state at stateRoot is already cached
|
|
156
|
-
const cachedStateCtx = this.modules.blockStateCache.get(stateRoot
|
|
155
|
+
const cachedStateCtx = this.modules.blockStateCache.get(stateRoot);
|
|
157
156
|
if (cachedStateCtx) {
|
|
158
157
|
return cachedStateCtx;
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
// in block gossip validation (getPreState() call), dontTransferCache is specified as true because we only want to transfer cache in verifyBlocksStateTransitionOnly()
|
|
162
|
-
// but here we want to process blocks as fast as possible so force to transfer cache in this case
|
|
163
|
-
if (opts && allowDiskReload) {
|
|
164
|
-
// if there is no `opts` specified, it already means "false"
|
|
165
|
-
opts.dontTransferCache = false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
160
|
// Otherwise we have to use the fork choice to traverse backwards, block by block,
|
|
169
161
|
// searching the state caches
|
|
170
162
|
// then replay blocks forward to the desired stateRoot
|
|
@@ -179,7 +171,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
179
171
|
const getSeedStateTimer = this.modules.metrics?.regenGetState.getSeedState.startTimer({caller});
|
|
180
172
|
// iterateAncestorBlocks only returns ancestor blocks, not the block itself
|
|
181
173
|
for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot)) {
|
|
182
|
-
state = this.modules.blockStateCache.get(b.stateRoot
|
|
174
|
+
state = this.modules.blockStateCache.get(b.stateRoot);
|
|
183
175
|
if (state) {
|
|
184
176
|
break;
|
|
185
177
|
}
|
|
@@ -187,8 +179,8 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
187
179
|
if (!lastBlockToReplay) continue;
|
|
188
180
|
const epoch = computeEpochAtSlot(lastBlockToReplay.slot - 1);
|
|
189
181
|
state = allowDiskReload
|
|
190
|
-
? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch
|
|
191
|
-
: checkpointStateCache.getLatest(b.blockRoot, epoch
|
|
182
|
+
? await checkpointStateCache.getOrReloadLatest(b.blockRoot, epoch)
|
|
183
|
+
: checkpointStateCache.getLatest(b.blockRoot, epoch);
|
|
192
184
|
if (state) {
|
|
193
185
|
break;
|
|
194
186
|
}
|
|
@@ -255,6 +247,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
255
247
|
try {
|
|
256
248
|
// Only advances state trusting block's signture and hashes.
|
|
257
249
|
// We are only running the state transition to get a specific state's data.
|
|
250
|
+
// stateTransition() does the clone() inside, transfer cache to make the regen faster
|
|
258
251
|
state = stateTransition(
|
|
259
252
|
state,
|
|
260
253
|
block,
|
|
@@ -265,6 +258,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
265
258
|
verifyStateRoot: false,
|
|
266
259
|
verifyProposer: false,
|
|
267
260
|
verifySignatures: false,
|
|
261
|
+
dontTransferCache: false,
|
|
268
262
|
},
|
|
269
263
|
this.modules
|
|
270
264
|
);
|
|
@@ -390,8 +384,8 @@ export async function processSlotsToNearestCheckpoint(
|
|
|
390
384
|
const checkpointState = postState;
|
|
391
385
|
const cp = getCheckpointFromState(checkpointState);
|
|
392
386
|
checkpointStateCache.add(cp, checkpointState);
|
|
393
|
-
// consumers should not mutate
|
|
394
|
-
emitter?.emit(ChainEvent.checkpoint, cp, checkpointState
|
|
387
|
+
// consumers should not mutate state ever
|
|
388
|
+
emitter?.emit(ChainEvent.checkpoint, cp, checkpointState);
|
|
395
389
|
|
|
396
390
|
if (count >= 1) {
|
|
397
391
|
// in normal condition, we only process 1 epoch so never reach this
|