@lodestar/state-transition 1.46.0-dev.22517ea3d8 → 1.46.0-dev.3d8f7cf440
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/block/externalData.js +2 -4
- package/lib/block/externalData.js.map +1 -1
- package/lib/block/index.js.map +1 -1
- package/lib/block/initiateValidatorExit.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestations.js.map +1 -1
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.js.map +1 -1
- package/lib/block/processBlobKzgCommitments.js.map +1 -1
- package/lib/block/processBlockHeader.js.map +1 -1
- package/lib/block/processBlsToExecutionChange.js.map +1 -1
- package/lib/block/processBuilderDepositRequest.js.map +1 -1
- package/lib/block/processBuilderExitRequest.js.map +1 -1
- package/lib/block/processConsolidationRequest.js.map +1 -1
- package/lib/block/processDeposit.d.ts +15 -0
- package/lib/block/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js +73 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processEth1Data.js.map +1 -1
- package/lib/block/processExecutionPayload.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts +2 -2
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +8 -3
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/block/processPayloadAttestation.js.map +1 -1
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.js +1 -2
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/block/slashValidator.js.map +1 -1
- package/lib/block/types.js +1 -2
- package/lib/block/types.js.map +1 -1
- package/lib/cache/builderDepositSignatureCache.d.ts +48 -0
- package/lib/cache/builderDepositSignatureCache.d.ts.map +1 -0
- package/lib/cache/builderDepositSignatureCache.js +70 -0
- package/lib/cache/builderDepositSignatureCache.js.map +1 -0
- package/lib/cache/effectiveBalanceIncrements.js.map +1 -1
- package/lib/cache/epochCache.d.ts +9 -0
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +14 -2
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.js.map +1 -1
- package/lib/cache/pubkeyCache.js.map +1 -1
- package/lib/cache/rewardCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts +2 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +3 -2
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.js.map +1 -1
- package/lib/cache/types.d.ts +1 -0
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/epoch/computeUnrealizedCheckpoints.js.map +1 -1
- package/lib/epoch/getAttestationDeltas.js.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/index.js +1 -2
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
- package/lib/epoch/processEffectiveBalanceUpdates.js.map +1 -1
- package/lib/epoch/processEth1DataReset.js.map +1 -1
- package/lib/epoch/processHistoricalRootsUpdate.js.map +1 -1
- package/lib/epoch/processHistoricalSummariesUpdate.js.map +1 -1
- package/lib/epoch/processInactivityUpdates.js.map +1 -1
- package/lib/epoch/processJustificationAndFinalization.js.map +1 -1
- package/lib/epoch/processParticipationFlagUpdates.js.map +1 -1
- package/lib/epoch/processParticipationRecordUpdates.js.map +1 -1
- package/lib/epoch/processPendingAttestations.js.map +1 -1
- package/lib/epoch/processPendingConsolidations.js.map +1 -1
- package/lib/epoch/processPendingDeposits.js.map +1 -1
- package/lib/epoch/processProposerLookahead.js.map +1 -1
- package/lib/epoch/processPtcWindow.js.map +1 -1
- package/lib/epoch/processRandaoMixesReset.js.map +1 -1
- package/lib/epoch/processRegistryUpdates.js.map +1 -1
- package/lib/epoch/processRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/processSlashings.js.map +1 -1
- package/lib/epoch/processSlashingsReset.js.map +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/lightClient/proofs.js.map +1 -1
- package/lib/lightClient/spec/index.js.map +1 -1
- package/lib/lightClient/spec/isBetterUpdate.js.map +1 -1
- package/lib/lightClient/spec/processLightClientUpdate.js.map +1 -1
- package/lib/lightClient/spec/store.js.map +1 -1
- package/lib/lightClient/spec/utils.d.ts +0 -2
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +8 -2
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientBootstrap.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +3 -2
- package/lib/metrics.js.map +1 -1
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/blockRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.d.ts +2 -2
- package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -1
- package/lib/signatureSets/executionPayloadBid.js +7 -5
- package/lib/signatureSets/executionPayloadBid.js.map +1 -1
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerPreferences.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/slot/index.d.ts +1 -0
- package/lib/slot/index.d.ts.map +1 -1
- package/lib/slot/index.js +1 -0
- package/lib/slot/index.js.map +1 -1
- package/lib/slot/upgradeStateToAltair.js.map +1 -1
- package/lib/slot/upgradeStateToBellatrix.js.map +1 -1
- package/lib/slot/upgradeStateToCapella.js.map +1 -1
- package/lib/slot/upgradeStateToDeneb.js.map +1 -1
- package/lib/slot/upgradeStateToElectra.js.map +1 -1
- package/lib/slot/upgradeStateToFulu.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +13 -7
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts +7 -0
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -0
- package/lib/slot/upgradeStateToHeze.js +83 -0
- package/lib/slot/upgradeStateToHeze.js.map +1 -0
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +6 -5
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +3 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +7 -0
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +16 -3
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js +4 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +3 -0
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +6 -0
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/testUtils/infura.js.map +1 -1
- package/lib/testUtils/interop.js.map +1 -1
- package/lib/testUtils/params.d.ts.map +1 -1
- package/lib/testUtils/state.js +1 -1
- package/lib/testUtils/state.js.map +1 -1
- package/lib/testUtils/testFileCache.js.map +1 -1
- package/lib/testUtils/util.d.ts +17 -2
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +57 -4
- package/lib/testUtils/util.js.map +1 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/util/aggregator.js.map +1 -1
- package/lib/util/altair.js.map +1 -1
- package/lib/util/array.js.map +1 -1
- package/lib/util/attestation.js.map +1 -1
- package/lib/util/attesterStatus.js.map +1 -1
- package/lib/util/balance.js.map +1 -1
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/blockRoot.js.map +1 -1
- package/lib/util/capella.js.map +1 -1
- package/lib/util/clock.d.ts +6 -0
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +1 -2
- package/lib/util/clock.js.map +1 -1
- package/lib/util/computeAnchorCheckpoint.js.map +1 -1
- package/lib/util/deposit.d.ts.map +1 -1
- package/lib/util/deposit.js +10 -8
- package/lib/util/deposit.js.map +1 -1
- package/lib/util/domain.js.map +1 -1
- package/lib/util/electra.js.map +1 -1
- package/lib/util/epoch.js.map +1 -1
- package/lib/util/epochShuffling.js.map +1 -1
- package/lib/util/execution.js.map +1 -1
- package/lib/util/finality.js.map +1 -1
- package/lib/util/fulu.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +7 -2
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/loadState/findModifiedInactivityScores.js.map +1 -1
- package/lib/util/loadState/findModifiedValidators.js.map +1 -1
- package/lib/util/loadState/loadState.d.ts.map +1 -1
- package/lib/util/loadState/loadState.js +36 -5
- package/lib/util/loadState/loadState.js.map +1 -1
- package/lib/util/loadState/loadValidator.js.map +1 -1
- package/lib/util/pendingDepositsLookup.d.ts +7 -10
- package/lib/util/pendingDepositsLookup.d.ts.map +1 -1
- package/lib/util/pendingDepositsLookup.js +10 -19
- package/lib/util/pendingDepositsLookup.js.map +1 -1
- package/lib/util/preVerifyBuilderDeposits.d.ts +52 -0
- package/lib/util/preVerifyBuilderDeposits.d.ts.map +1 -0
- package/lib/util/preVerifyBuilderDeposits.js +124 -0
- package/lib/util/preVerifyBuilderDeposits.js.map +1 -0
- package/lib/util/rootCache.js.map +1 -1
- package/lib/util/seed.js.map +1 -1
- package/lib/util/shuffling.js +1 -2
- package/lib/util/shuffling.js.map +1 -1
- package/lib/util/signatureSets.js +1 -2
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/signingRoot.js.map +1 -1
- package/lib/util/slot.js.map +1 -1
- package/lib/util/ssz.d.ts +5 -0
- package/lib/util/ssz.d.ts.map +1 -1
- package/lib/util/ssz.js +8 -1
- package/lib/util/ssz.js.map +1 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/lib/util/syncCommittee.js.map +1 -1
- package/lib/util/targetUnslashedBalance.js.map +1 -1
- package/lib/util/validator.d.ts +5 -0
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +9 -0
- package/lib/util/validator.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts +1 -0
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +20 -8
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +9 -9
- package/src/block/processDeposit.ts +75 -1
- package/src/block/processExecutionPayloadBid.ts +18 -8
- package/src/cache/builderDepositSignatureCache.ts +81 -0
- package/src/cache/epochCache.ts +14 -0
- package/src/cache/stateCache.ts +5 -2
- package/src/cache/types.ts +1 -0
- package/src/index.ts +4 -0
- package/src/lightClient/spec/utils.ts +9 -2
- package/src/metrics.ts +3 -2
- package/src/signatureSets/executionPayloadBid.ts +7 -9
- package/src/slot/index.ts +1 -0
- package/src/slot/upgradeStateToGloas.ts +17 -10
- package/src/slot/upgradeStateToHeze.ts +91 -0
- package/src/stateTransition.ts +5 -0
- package/src/stateView/beaconStateView.ts +13 -0
- package/src/stateView/interface.ts +21 -2
- package/src/stateView/nativeBeaconStateView.ts +9 -0
- package/src/testUtils/state.ts +1 -1
- package/src/testUtils/util.ts +75 -5
- package/src/types.ts +2 -0
- package/src/util/deposit.ts +11 -9
- package/src/util/genesis.ts +8 -2
- package/src/util/index.ts +1 -0
- package/src/util/loadState/loadState.ts +50 -11
- package/src/util/pendingDepositsLookup.ts +13 -24
- package/src/util/preVerifyBuilderDeposits.ts +153 -0
- package/src/util/ssz.ts +9 -1
- package/src/util/validator.ts +17 -0
- package/src/util/weakSubjectivity.ts +61 -22
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {electra} from "@lodestar/types";
|
|
2
|
+
import {toPubkeyHex} from "@lodestar/utils";
|
|
3
|
+
import {verifyDepositSignatures} from "../block/processDeposit.js";
|
|
4
|
+
import {CachedBeaconStateFulu} from "../types.js";
|
|
5
|
+
import {isBuilderWithdrawalCredential} from "./gloas.js";
|
|
6
|
+
|
|
7
|
+
/** Verify queued deposit signatures in batches of this size. Also the time-box granularity: the
|
|
8
|
+
* deadline is checked once per batch, so overrun is bounded to a single batch. Exported for tests. */
|
|
9
|
+
export const BUILDER_DEPOSIT_BATCH_SIZE = 32;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Per-tick cap on builder deposits the prepareForNextSlot scanner will verify.
|
|
13
|
+
* ~2.7s for 10_000 BLS verifications on a typical server — fits within the slot budget while the
|
|
14
|
+
* pre-window (see GLOAS_PREVERIFY_WINDOW_EPOCHS) covers up to ~620k deposits over its duration.
|
|
15
|
+
*/
|
|
16
|
+
export const MAX_BUILDER_DEPOSITS_PER_SLOT = 10_000;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Number of epochs before GLOAS_FORK_EPOCH during which the prepareForNextSlot scanner pre-verifies
|
|
20
|
+
* builder-deposit signatures. Two: deposits arriving this late cannot collude with validator
|
|
21
|
+
* deposits — validator-vs-builder routing is decided at the fork boundary from what is already in
|
|
22
|
+
* pendingDeposits, so anything submitted inside this window is unambiguous.
|
|
23
|
+
*/
|
|
24
|
+
export const GLOAS_PREVERIFY_WINDOW_EPOCHS = 2;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Summary of a single `preVerifyBuilderDepositsPreGloas` call.
|
|
28
|
+
*/
|
|
29
|
+
export type PreVerifyBuilderDepositsResult = {
|
|
30
|
+
/** Builder-prefix deposit signatures verified valid in this call (cached true). */
|
|
31
|
+
validBuilderSignaturesCount: number;
|
|
32
|
+
/** Builder-prefix deposit signatures verified invalid in this call (cached false, dropped at fork). */
|
|
33
|
+
invalidBuilderSignaturesCount: number;
|
|
34
|
+
/** Validator (builder-pubkey) deposit signatures verified valid in this call. */
|
|
35
|
+
validValidatorSignaturesCount: number;
|
|
36
|
+
/** Validator (builder-pubkey) deposit signatures verified invalid in this call (abuse signal). */
|
|
37
|
+
invalidValidatorSignaturesCount: number;
|
|
38
|
+
/** Pending deposits examined this call (all creds; < pendingDepositsCount ⇒ per-tick cap hit). */
|
|
39
|
+
scannedPendingDeposits: number;
|
|
40
|
+
/** Cumulative deposits verified & cached so far this window (cache size, pass + fail). */
|
|
41
|
+
totalCachedDeposits: number;
|
|
42
|
+
/** Distinct builder pubkeys tracked so far this window. */
|
|
43
|
+
totalBuilderPubkeys: number;
|
|
44
|
+
/** Current `state.pendingDeposits.length` — the full backlog. */
|
|
45
|
+
pendingDepositsCount: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Scanner driven by `prepareForNextSlot` over the `GLOAS_PREVERIFY_WINDOW_EPOCHS` epochs before
|
|
50
|
+
* GLOAS_FORK_EPOCH. Walks `state.pendingDeposits` (as struct values via getAllReadonlyValues) and
|
|
51
|
+
* queues, for signature verification, the deposits the fork transition will check on its hot path:
|
|
52
|
+
* - builder-prefix deposits (for onboarding); records each builder pubkey on the cache, and
|
|
53
|
+
* - validator deposits sharing a builder pubkey (the set `hasPendingValidator` walks at the fork),
|
|
54
|
+
* but only until one is found valid — `hasPendingValidator` stops at the first valid signature, so
|
|
55
|
+
* the cache marks the pubkey and the scanner skips that pubkey's remaining validator deposits.
|
|
56
|
+
*
|
|
57
|
+
* Bounded by two knobs: at most `maxBuilderDeposits` new deposits are queued per call, and the chunk
|
|
58
|
+
* verification is **time-boxed** to `maxDurationMs`.
|
|
59
|
+
*/
|
|
60
|
+
export function preVerifyBuilderDepositsPreGloas(
|
|
61
|
+
state: CachedBeaconStateFulu,
|
|
62
|
+
maxBuilderDeposits: number,
|
|
63
|
+
maxDurationMs: number
|
|
64
|
+
): PreVerifyBuilderDepositsResult {
|
|
65
|
+
const cache = state.epochCtx.builderDepositSignatureCache;
|
|
66
|
+
|
|
67
|
+
// Collect uncached deposits to verify as struct values. Full rescan each tick: iteration is
|
|
68
|
+
// O(pendingDeposits) but runs in prepareNextSlot spare time, and isVerified() is an O(1) skip for
|
|
69
|
+
// already-cached deposits. For a ContainerNodeStructType, getAllReadonlyValues() returns each
|
|
70
|
+
// node.value by reference — the stable cache key.
|
|
71
|
+
const queue: electra.PendingDeposit[] = [];
|
|
72
|
+
let scannedPendingDeposits = 0;
|
|
73
|
+
for (const deposit of state.pendingDeposits.getAllReadonlyValues()) {
|
|
74
|
+
if (queue.length >= maxBuilderDeposits) break; // per-tick cap; next tick resumes via isVerified()
|
|
75
|
+
scannedPendingDeposits++;
|
|
76
|
+
if (cache.isVerified(deposit)) continue; // already verified in an earlier tick
|
|
77
|
+
|
|
78
|
+
if (isBuilderWithdrawalCredential(deposit.withdrawalCredentials)) {
|
|
79
|
+
// Record the builder pubkey so validator deposits sharing it get pre-verified — this or a
|
|
80
|
+
// later tick, since those validator deposits precede the builder deposit in the queue. A cached
|
|
81
|
+
// builder deposit already added its pubkey, so it's safe to skip via the `continue` above.
|
|
82
|
+
cache.addBuilderPubkey(toPubkeyHex(deposit.pubkey));
|
|
83
|
+
queue.push(deposit);
|
|
84
|
+
} else {
|
|
85
|
+
// Validator deposit — pre-verify only if it shares a builder pubkey (the set hasPendingValidator
|
|
86
|
+
// walks at the fork) AND we haven't already cached a valid validator deposit for that pubkey.
|
|
87
|
+
// this is the same logic to hasPendingValidator.
|
|
88
|
+
const pubkeyHex = toPubkeyHex(deposit.pubkey);
|
|
89
|
+
if (cache.isBuilderPubkey(pubkeyHex) && !cache.hasValidValidatorDeposit(pubkeyHex)) {
|
|
90
|
+
queue.push(deposit);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const pendingDepositsCount = state.pendingDeposits.length;
|
|
96
|
+
if (queue.length === 0) {
|
|
97
|
+
return {
|
|
98
|
+
validBuilderSignaturesCount: 0,
|
|
99
|
+
invalidBuilderSignaturesCount: 0,
|
|
100
|
+
validValidatorSignaturesCount: 0,
|
|
101
|
+
invalidValidatorSignaturesCount: 0,
|
|
102
|
+
scannedPendingDeposits,
|
|
103
|
+
totalCachedDeposits: cache.cachedDepositCount,
|
|
104
|
+
totalBuilderPubkeys: cache.builderPubkeyCount,
|
|
105
|
+
pendingDepositsCount,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Verify in chunks; chunking caps the fallback blast radius so one bad signature only forces 32
|
|
110
|
+
// individual re-verifications. Key each result by the deposit value object. Counts are tracked
|
|
111
|
+
// incrementally (not queue.length - verified) so they stay correct when we time-box out early.
|
|
112
|
+
const deadline = Date.now() + maxDurationMs;
|
|
113
|
+
let validBuilderSignaturesCount = 0;
|
|
114
|
+
let invalidBuilderSignaturesCount = 0;
|
|
115
|
+
let validValidatorSignaturesCount = 0;
|
|
116
|
+
let invalidValidatorSignaturesCount = 0;
|
|
117
|
+
for (let chunkStart = 0; chunkStart < queue.length; chunkStart += BUILDER_DEPOSIT_BATCH_SIZE) {
|
|
118
|
+
const end = Math.min(chunkStart + BUILDER_DEPOSIT_BATCH_SIZE, queue.length);
|
|
119
|
+
const chunk = queue.slice(chunkStart, end);
|
|
120
|
+
const chunkResults = verifyDepositSignatures(state.epochCtx.config, chunk);
|
|
121
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
122
|
+
cache.setSignatureValidity(chunk[j], chunkResults[j]);
|
|
123
|
+
const isBuilder = isBuilderWithdrawalCredential(chunk[j].withdrawalCredentials);
|
|
124
|
+
if (chunkResults[j]) {
|
|
125
|
+
if (isBuilder) {
|
|
126
|
+
validBuilderSignaturesCount++;
|
|
127
|
+
} else {
|
|
128
|
+
validValidatorSignaturesCount++;
|
|
129
|
+
// A valid validator deposit satisfies hasPendingValidator() for this pubkey; stop
|
|
130
|
+
// pre-verifying its remaining validator deposits on later ticks.
|
|
131
|
+
cache.setValidValidatorDeposit(toPubkeyHex(chunk[j].pubkey));
|
|
132
|
+
}
|
|
133
|
+
} else if (isBuilder) {
|
|
134
|
+
invalidBuilderSignaturesCount++;
|
|
135
|
+
} else {
|
|
136
|
+
invalidValidatorSignaturesCount++;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Time-box: keep everything verified so far (already cached) and stop
|
|
140
|
+
if (Date.now() >= deadline) break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
validBuilderSignaturesCount,
|
|
145
|
+
invalidBuilderSignaturesCount,
|
|
146
|
+
validValidatorSignaturesCount,
|
|
147
|
+
invalidValidatorSignaturesCount,
|
|
148
|
+
scannedPendingDeposits,
|
|
149
|
+
totalCachedDeposits: cache.cachedDepositCount,
|
|
150
|
+
totalBuilderPubkeys: cache.builderPubkeyCount,
|
|
151
|
+
pendingDepositsCount,
|
|
152
|
+
};
|
|
153
|
+
}
|
package/src/util/ssz.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BranchNode, LeafNode, Node, zeroNode} from "@chainsafe/persistent-merkle-tree";
|
|
2
2
|
import {progressiveSubtreeFillToContents} from "@chainsafe/ssz";
|
|
3
3
|
|
|
4
|
-
// TODO: move these utils to @chainsafe/ssz
|
|
4
|
+
// TODO: move these utils to @chainsafe/ssz, see https://github.com/ChainSafe/ssz/issues/542
|
|
5
5
|
|
|
6
6
|
/** Root node (chunks + length mix-in) of a zero-filled ProgressiveListBasicType of `length` items */
|
|
7
7
|
export function zeroProgressiveListBasicRootNode(itemsPerChunk: number, length: number): Node {
|
|
@@ -15,6 +15,14 @@ export function zeroProgressiveListBasicRootNode(itemsPerChunk: number, length:
|
|
|
15
15
|
return new BranchNode(zeroProgressiveNode(numSubtrees), LeafNode.fromUint32(length));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Check if an array-type ViewDU (ListBasic, ListComposite or their progressive equivalents) has its
|
|
20
|
+
* internal nodes cache populated. The flag is a private attribute maintained by all of these classes.
|
|
21
|
+
*/
|
|
22
|
+
export function isViewDUNodesPopulated(view: unknown): boolean {
|
|
23
|
+
return (view as {nodesPopulated?: boolean}).nodesPopulated === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
/**
|
|
19
27
|
* Root node of a progressive list from its chunk/element nodes + length mix-in.
|
|
20
28
|
* `nodes` are packed 32-byte chunk leaves for basic lists, or element root nodes for composite lists.
|
package/src/util/validator.ts
CHANGED
|
@@ -128,6 +128,23 @@ export function getConsolidationChurnLimit(fork: ForkSeq, epochCtx: EpochCache):
|
|
|
128
128
|
return getBalanceChurnLimitFromCache(epochCtx) - getActivationExitChurnLimit(epochCtx);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// NOTE: duplicates the quotient/min choices in get{Exit,Activation,Consolidation}ChurnLimit.
|
|
132
|
+
export function getGloasChurnLimits(
|
|
133
|
+
config: ChainForkConfig,
|
|
134
|
+
totalActiveBalanceIncrements: number
|
|
135
|
+
): {exit: number; activation: number; consolidation: number} {
|
|
136
|
+
const exit = getBalanceChurnLimit(
|
|
137
|
+
totalActiveBalanceIncrements,
|
|
138
|
+
config.CHURN_LIMIT_QUOTIENT_GLOAS,
|
|
139
|
+
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
exit,
|
|
143
|
+
activation: Math.min(config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT_GLOAS, exit),
|
|
144
|
+
consolidation: getBalanceChurnLimit(totalActiveBalanceIncrements, config.CONSOLIDATION_CHURN_LIMIT_QUOTIENT, 0),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
131
148
|
export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): number {
|
|
132
149
|
// Compounding withdrawal credential only available since Electra
|
|
133
150
|
if (hasCompoundingWithdrawalCredential(withdrawalCredentials)) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {BeaconConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
|
+
ForkSeq,
|
|
4
5
|
MAX_DEPOSITS,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE,
|
|
6
7
|
SLOTS_PER_EPOCH,
|
|
7
8
|
isForkPostElectra,
|
|
9
|
+
isForkPostGloas,
|
|
8
10
|
} from "@lodestar/params";
|
|
9
11
|
import {Epoch, Root, ssz} from "@lodestar/types";
|
|
10
12
|
import {Checkpoint} from "@lodestar/types/phase0";
|
|
@@ -14,10 +16,14 @@ import {BeaconStateAllForks, CachedBeaconStateAllForks} from "../types.js";
|
|
|
14
16
|
import {computeCheckpointEpochAtStateSlot, computeEpochAtSlot, getCurrentEpoch} from "./epoch.js";
|
|
15
17
|
import {getCurrentSlot} from "./slot.js";
|
|
16
18
|
import {
|
|
19
|
+
getActivationChurnLimit,
|
|
17
20
|
getActiveValidatorIndices,
|
|
18
21
|
getBalanceChurnLimit,
|
|
19
22
|
getBalanceChurnLimitFromCache,
|
|
20
23
|
getChurnLimit,
|
|
24
|
+
getConsolidationChurnLimit,
|
|
25
|
+
getExitChurnLimit,
|
|
26
|
+
getGloasChurnLimits,
|
|
21
27
|
} from "./validator.js";
|
|
22
28
|
|
|
23
29
|
export const ETH_TO_GWEI = 10 ** 9;
|
|
@@ -49,18 +55,26 @@ export function computeWeakSubjectivityPeriodCachedState(
|
|
|
49
55
|
const activeValidatorCount = state.epochCtx.currentShuffling.activeIndices.length;
|
|
50
56
|
const fork = config.getForkName(state.slot);
|
|
51
57
|
|
|
52
|
-
return
|
|
53
|
-
?
|
|
58
|
+
return isForkPostGloas(fork)
|
|
59
|
+
? computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
54
60
|
state.epochCtx.totalActiveBalanceIncrements,
|
|
55
|
-
|
|
61
|
+
getExitChurnLimit(state.epochCtx),
|
|
62
|
+
getActivationChurnLimit(state.epochCtx),
|
|
63
|
+
getConsolidationChurnLimit(ForkSeq.gloas, state.epochCtx),
|
|
56
64
|
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
57
65
|
)
|
|
58
|
-
:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
: isForkPostElectra(fork)
|
|
67
|
+
? computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
68
|
+
state.epochCtx.totalActiveBalanceIncrements,
|
|
69
|
+
getBalanceChurnLimitFromCache(state.epochCtx),
|
|
70
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
71
|
+
)
|
|
72
|
+
: computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
73
|
+
activeValidatorCount,
|
|
74
|
+
state.epochCtx.totalActiveBalanceIncrements,
|
|
75
|
+
getChurnLimit(config, activeValidatorCount),
|
|
76
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
77
|
+
);
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
/**
|
|
@@ -80,22 +94,32 @@ export function computeWeakSubjectivityPeriod(config: ChainForkConfig, state: Be
|
|
|
80
94
|
totalActiveBalanceIncrements = 1;
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
const churnLimitsGloas = getGloasChurnLimits(config, totalActiveBalanceIncrements);
|
|
98
|
+
|
|
99
|
+
return isForkPostGloas(fork)
|
|
100
|
+
? computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
85
101
|
totalActiveBalanceIncrements,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
90
|
-
),
|
|
102
|
+
churnLimitsGloas.exit,
|
|
103
|
+
churnLimitsGloas.activation,
|
|
104
|
+
churnLimitsGloas.consolidation,
|
|
91
105
|
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
92
106
|
)
|
|
93
|
-
:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
: isForkPostElectra(fork)
|
|
108
|
+
? computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
109
|
+
totalActiveBalanceIncrements,
|
|
110
|
+
getBalanceChurnLimit(
|
|
111
|
+
totalActiveBalanceIncrements,
|
|
112
|
+
config.CHURN_LIMIT_QUOTIENT,
|
|
113
|
+
config.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA
|
|
114
|
+
),
|
|
115
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
116
|
+
)
|
|
117
|
+
: computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
118
|
+
activeIndices.length,
|
|
119
|
+
totalActiveBalanceIncrements,
|
|
120
|
+
getChurnLimit(config, activeIndices.length),
|
|
121
|
+
config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
122
|
+
);
|
|
99
123
|
}
|
|
100
124
|
|
|
101
125
|
export function computeWeakSubjectivityPeriodFromConstituentsPhase0(
|
|
@@ -142,6 +166,21 @@ export function computeWeakSubjectivityPeriodFromConstituentsElectra(
|
|
|
142
166
|
return minWithdrawabilityDelay + epochsForValidatorSetChurn;
|
|
143
167
|
}
|
|
144
168
|
|
|
169
|
+
export function computeWeakSubjectivityPeriodFromConstituentsGloas(
|
|
170
|
+
totalBalanceByIncrement: number,
|
|
171
|
+
exitChurnLimit: number,
|
|
172
|
+
activationChurnLimit: number,
|
|
173
|
+
consolidationChurnLimit: number,
|
|
174
|
+
minWithdrawabilityDelay: number
|
|
175
|
+
): number {
|
|
176
|
+
// Keep t as increment for now. Multiply final result by EFFECTIVE_BALANCE_INCREMENT
|
|
177
|
+
const t = totalBalanceByIncrement;
|
|
178
|
+
const delta = Math.floor((2 * exitChurnLimit) / 3) + Math.floor(activationChurnLimit / 3) + consolidationChurnLimit;
|
|
179
|
+
const epochsForValidatorSetChurn = Math.floor(((SAFETY_DECAY * t) / (2 * delta * 100)) * EFFECTIVE_BALANCE_INCREMENT);
|
|
180
|
+
|
|
181
|
+
return minWithdrawabilityDelay + epochsForValidatorSetChurn;
|
|
182
|
+
}
|
|
183
|
+
|
|
145
184
|
export function getLatestBlockRoot(state: BeaconStateAllForks): Root {
|
|
146
185
|
const header = ssz.phase0.BeaconBlockHeader.clone(state.latestBlockHeader);
|
|
147
186
|
if (ssz.Root.equals(header.stateRoot, ZERO_HASH)) {
|