@lodestar/state-transition 1.43.0 → 1.44.0-dev.552cdce8d0
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/processDepositRequest.d.ts +3 -11
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +27 -35
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +4 -3
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/lightClient/spec/index.d.ts +22 -0
- package/lib/lightClient/spec/index.d.ts.map +1 -0
- package/lib/lightClient/spec/index.js +58 -0
- package/lib/lightClient/spec/index.js.map +1 -0
- package/lib/lightClient/spec/isBetterUpdate.d.ts +23 -0
- package/lib/lightClient/spec/isBetterUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/isBetterUpdate.js +66 -0
- package/lib/lightClient/spec/isBetterUpdate.js.map +1 -0
- package/lib/lightClient/spec/processLightClientUpdate.d.ts +12 -0
- package/lib/lightClient/spec/processLightClientUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/processLightClientUpdate.js +80 -0
- package/lib/lightClient/spec/processLightClientUpdate.js.map +1 -0
- package/lib/lightClient/spec/store.d.ts +45 -0
- package/lib/lightClient/spec/store.d.ts.map +1 -0
- package/lib/lightClient/spec/store.js +56 -0
- package/lib/lightClient/spec/store.js.map +1 -0
- package/lib/lightClient/spec/utils.d.ts +47 -0
- package/lib/lightClient/spec/utils.d.ts.map +1 -0
- package/lib/lightClient/spec/utils.js +197 -0
- package/lib/lightClient/spec/utils.js.map +1 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.d.ts +4 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.d.ts.map +1 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.js +22 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.js.map +1 -0
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts +5 -0
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/validateLightClientUpdate.js +88 -0
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -0
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +33 -28
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +8 -3
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +15 -4
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +1 -1
- package/lib/stateView/interface.d.ts.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/pendingDepositsLookup.d.ts +40 -0
- package/lib/util/pendingDepositsLookup.d.ts.map +1 -0
- package/lib/util/pendingDepositsLookup.js +84 -0
- package/lib/util/pendingDepositsLookup.js.map +1 -0
- package/lib/util/shuffling.d.ts +6 -5
- package/lib/util/shuffling.d.ts.map +1 -1
- package/lib/util/shuffling.js +13 -15
- package/lib/util/shuffling.js.map +1 -1
- package/package.json +12 -7
- package/src/block/processDepositRequest.ts +29 -47
- package/src/block/processParentExecutionPayload.ts +4 -3
- package/src/lightClient/spec/index.ts +101 -0
- package/src/lightClient/spec/isBetterUpdate.ts +94 -0
- package/src/lightClient/spec/processLightClientUpdate.ts +119 -0
- package/src/lightClient/spec/store.ts +106 -0
- package/src/lightClient/spec/utils.ts +317 -0
- package/src/lightClient/spec/validateLightClientBootstrap.ts +39 -0
- package/src/lightClient/spec/validateLightClientUpdate.ts +145 -0
- package/src/slot/upgradeStateToGloas.ts +41 -44
- package/src/stateView/beaconStateView.ts +15 -4
- package/src/stateView/interface.ts +1 -1
- package/src/util/index.ts +1 -0
- package/src/util/pendingDepositsLookup.ts +105 -0
- package/src/util/shuffling.ts +17 -15
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import {PubkeyHex, electra} from "@lodestar/types";
|
|
3
|
+
import {toPubkeyHex} from "@lodestar/utils";
|
|
4
|
+
import {isValidDepositSignature} from "../block/processDeposit.js";
|
|
5
|
+
import {CachedBeaconStateGloas} from "../types.js";
|
|
6
|
+
|
|
7
|
+
type PendingDepositsValidation = {
|
|
8
|
+
hasValidSignature: boolean;
|
|
9
|
+
validatedCount: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Mutable lookup for the pending-deposit sequence used by builder-routing logic.
|
|
14
|
+
*
|
|
15
|
+
* This is to implement the spec's `is_pending_validator(pending_deposits, pubkey)` lazily:
|
|
16
|
+
* deposits are grouped by pubkey without verifying signatures, and BLS verification is
|
|
17
|
+
* deferred until a builder deposit needs to know whether the same pubkey already has a
|
|
18
|
+
* valid pending validator deposit.
|
|
19
|
+
*
|
|
20
|
+
* Call `add()` whenever a deposit is appended to the represented sequence. A cached `true`
|
|
21
|
+
* result short-circuits all subsequent checks for that pubkey; a cached `false` records
|
|
22
|
+
* how many deposits were already verified, so appending a new deposit only verifies the
|
|
23
|
+
* newly-appended tail rather than re-running BLS on previously-invalid entries.
|
|
24
|
+
*/
|
|
25
|
+
export class PendingDepositsLookup {
|
|
26
|
+
private constructor(
|
|
27
|
+
private readonly depositsByPubkey: Map<PubkeyHex, electra.PendingDeposit[]>,
|
|
28
|
+
private readonly validationCache: Map<PubkeyHex, PendingDepositsValidation>
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/** Build an empty lookup for a sequence that will be populated incrementally. */
|
|
32
|
+
static buildEmpty(): PendingDepositsLookup {
|
|
33
|
+
return new PendingDepositsLookup(new Map(), new Map());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Build a pubkey -> pending-deposits lookup from `state.pendingDeposits`.
|
|
38
|
+
* No BLS work is done here; signature verification happens lazily in `hasPendingValidator`.
|
|
39
|
+
*/
|
|
40
|
+
static build(state: CachedBeaconStateGloas): PendingDepositsLookup {
|
|
41
|
+
const lookup = PendingDepositsLookup.buildEmpty();
|
|
42
|
+
for (const pendingDeposit of state.pendingDeposits.getAllReadonly()) {
|
|
43
|
+
lookup.add(pendingDeposit);
|
|
44
|
+
}
|
|
45
|
+
return lookup;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Append a pending deposit to the represented sequence.
|
|
50
|
+
* Pass `pubkeyHex` if the caller has already computed it.
|
|
51
|
+
*/
|
|
52
|
+
add(pendingDeposit: electra.PendingDeposit, pubkeyHex?: PubkeyHex): void {
|
|
53
|
+
const key = pubkeyHex ?? toPubkeyHex(pendingDeposit.pubkey);
|
|
54
|
+
const existing = this.depositsByPubkey.get(key);
|
|
55
|
+
if (existing) {
|
|
56
|
+
existing.push(pendingDeposit);
|
|
57
|
+
} else {
|
|
58
|
+
this.depositsByPubkey.set(key, [pendingDeposit]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns true if any pending deposit for `pubkeyHex` has a valid BLS deposit signature.
|
|
64
|
+
* Memoizes the result in `validationCache` so repeated checks for the same pubkey
|
|
65
|
+
* within a block only verify deposits that have not already been checked.
|
|
66
|
+
*/
|
|
67
|
+
hasPendingValidator(config: BeaconConfig, pubkeyHex: PubkeyHex): boolean {
|
|
68
|
+
const validation = this.validationCache.get(pubkeyHex);
|
|
69
|
+
if (validation?.hasValidSignature === true) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const deposits = this.depositsByPubkey.get(pubkeyHex);
|
|
74
|
+
if (deposits === undefined) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// hasValidSignature is false or undefined; resume from the last validatedCount so
|
|
79
|
+
// previously-checked invalid deposits are not re-verified.
|
|
80
|
+
const startIndex = validation?.validatedCount ?? 0;
|
|
81
|
+
if (startIndex === deposits.length) {
|
|
82
|
+
// Nothing new to check; the cached false result still holds.
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (let i = startIndex; i < deposits.length; i++) {
|
|
87
|
+
const deposit = deposits[i];
|
|
88
|
+
if (
|
|
89
|
+
isValidDepositSignature(
|
|
90
|
+
config,
|
|
91
|
+
deposit.pubkey,
|
|
92
|
+
deposit.withdrawalCredentials,
|
|
93
|
+
deposit.amount,
|
|
94
|
+
deposit.signature
|
|
95
|
+
)
|
|
96
|
+
) {
|
|
97
|
+
this.validationCache.set(pubkeyHex, {hasValidSignature: true, validatedCount: i + 1});
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.validationCache.set(pubkeyHex, {hasValidSignature: false, validatedCount: deposits.length});
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/util/shuffling.ts
CHANGED
|
@@ -17,29 +17,31 @@ import {computeStartSlotAtEpoch} from "./epoch.js";
|
|
|
17
17
|
import {EpochShuffling} from "./epochShuffling.js";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Block root that decided the proposer shuffling for `proposalEpoch` (keys that shuffling).
|
|
21
|
+
* Computed for the requested epoch, not `state.epoch`, so it is correct when `state` is one
|
|
22
|
+
* epoch off the requested epoch (e.g. serving next-epoch duties from the current state).
|
|
22
23
|
*
|
|
23
|
-
* Returns `null`
|
|
24
|
-
*
|
|
24
|
+
* Returns `null` when the genesis block decides its own shuffling (caller falls back to the
|
|
25
|
+
* genesis block root).
|
|
25
26
|
*/
|
|
26
|
-
export function proposerShufflingDecisionRoot(
|
|
27
|
-
|
|
27
|
+
export function proposerShufflingDecisionRoot(
|
|
28
|
+
fork: ForkName,
|
|
29
|
+
state: IBeaconStateView,
|
|
30
|
+
proposalEpoch: Epoch
|
|
31
|
+
): Root | null {
|
|
32
|
+
const decisionSlot = proposerShufflingDecisionSlot(fork, proposalEpoch);
|
|
28
33
|
if (state.slot === decisionSlot) {
|
|
29
34
|
return null;
|
|
30
35
|
}
|
|
31
36
|
return state.getBlockRootAtSlot(decisionSlot);
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const epoch = isForkPostFulu(fork) ? state.epoch - 1 : state.epoch;
|
|
41
|
-
const startSlot = computeStartSlotAtEpoch(epoch);
|
|
42
|
-
return Math.max(startSlot - 1, 0);
|
|
39
|
+
/** Slot whose block root keys the proposer shuffling for `proposalEpoch`. */
|
|
40
|
+
function proposerShufflingDecisionSlot(fork: ForkName, proposalEpoch: Epoch): Slot {
|
|
41
|
+
// Post-Fulu the shuffling is decided one epoch earlier (deterministic proposer lookahead,
|
|
42
|
+
// MIN_SEED_LOOKAHEAD = 1); pre-Fulu it is the last block before `proposalEpoch`.
|
|
43
|
+
const decisionEpoch = isForkPostFulu(fork) ? proposalEpoch - 1 : proposalEpoch;
|
|
44
|
+
return Math.max(computeStartSlotAtEpoch(decisionEpoch) - 1, 0);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/**
|