@lodestar/state-transition 1.46.0-dev.281a8ee194 → 1.46.0-dev.3e8651f2dc
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/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/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/epochCache.d.ts +9 -0
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +13 -0
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +13 -7
- package/lib/slot/upgradeStateToGloas.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 +8 -0
- package/lib/stateView/interface.d.ts.map +1 -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/testUtils/util.d.ts +16 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +55 -2
- package/lib/testUtils/util.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/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/package.json +7 -7
- package/src/block/processDeposit.ts +75 -1
- package/src/cache/builderDepositSignatureCache.ts +81 -0
- package/src/cache/epochCache.ts +14 -0
- package/src/slot/upgradeStateToGloas.ts +17 -10
- package/src/stateView/beaconStateView.ts +13 -0
- package/src/stateView/interface.ts +8 -0
- package/src/stateView/nativeBeaconStateView.ts +9 -0
- package/src/testUtils/util.ts +73 -3
- package/src/util/index.ts +1 -0
- package/src/util/pendingDepositsLookup.ts +13 -24
- package/src/util/preVerifyBuilderDeposits.ts +153 -0
package/lib/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,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20,7 @@ export * from "./gloas.js";
|
|
|
20
20
|
export * from "./interop.js";
|
|
21
21
|
export * from "./loadState/index.js";
|
|
22
22
|
export * from "./pendingDepositsLookup.js";
|
|
23
|
+
export * from "./preVerifyBuilderDeposits.js";
|
|
23
24
|
export * from "./rootCache.js";
|
|
24
25
|
export * from "./seed.js";
|
|
25
26
|
export * from "./shuffling.js";
|
package/lib/util/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BeaconConfig } from "@lodestar/config";
|
|
2
2
|
import { PubkeyHex, electra } from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import { BuilderDepositSignatureCache } from "../cache/builderDepositSignatureCache.js";
|
|
4
4
|
/**
|
|
5
5
|
* Mutable lookup for the pending-deposit sequence used by builder-routing logic.
|
|
6
6
|
*
|
|
@@ -21,20 +21,17 @@ export declare class PendingDepositsLookup {
|
|
|
21
21
|
/** Build an empty lookup for a sequence that will be populated incrementally. */
|
|
22
22
|
static buildEmpty(): PendingDepositsLookup;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* No BLS work is done here; signature verification happens lazily in `hasPendingValidator`.
|
|
24
|
+
* Append a pending deposit to the represented sequence, keyed by its (precomputed) `pubkeyHex`.
|
|
26
25
|
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Append a pending deposit to the represented sequence.
|
|
30
|
-
* Pass `pubkeyHex` if the caller has already computed it.
|
|
31
|
-
*/
|
|
32
|
-
add(pendingDeposit: electra.PendingDeposit, pubkeyHex?: PubkeyHex): void;
|
|
26
|
+
add(pendingDeposit: electra.PendingDeposit, pubkeyHex: PubkeyHex): void;
|
|
33
27
|
/**
|
|
34
28
|
* Returns true if any pending deposit for `pubkeyHex` has a valid BLS deposit signature.
|
|
35
29
|
* Memoizes the result in `validationCache` so repeated checks for the same pubkey
|
|
36
30
|
* within a block only verify deposits that have not already been checked.
|
|
31
|
+
*
|
|
32
|
+
* Most of the time it should hit the BuilderDepositSignatureCache so we don't have to validate
|
|
33
|
+
* signatures here.
|
|
37
34
|
*/
|
|
38
|
-
hasPendingValidator(config: BeaconConfig, pubkeyHex: PubkeyHex): boolean;
|
|
35
|
+
hasPendingValidator(config: BeaconConfig, pubkeyHex: PubkeyHex, cache: BuilderDepositSignatureCache): boolean;
|
|
39
36
|
}
|
|
40
37
|
//# sourceMappingURL=pendingDepositsLookup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingDepositsLookup.d.ts","sourceRoot":"","sources":["../../src/util/pendingDepositsLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAE,OAAO,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"pendingDepositsLookup.d.ts","sourceRoot":"","sources":["../../src/util/pendingDepositsLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAE,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAC,4BAA4B,EAAC,MAAM,0CAA0C,CAAC;AAOtF;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAFlC,OAAO,eAGH;IAEJ,iFAAiF;IACjF,MAAM,CAAC,UAAU,IAAI,qBAAqB,CAEzC;IAED;;OAEG;IACH,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAOtE;IAED;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAsC5G;CACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { toPubkeyHex } from "@lodestar/utils";
|
|
2
1
|
import { isValidDepositSignature } from "../block/processDeposit.js";
|
|
3
2
|
/**
|
|
4
3
|
* Mutable lookup for the pending-deposit sequence used by builder-routing logic.
|
|
@@ -25,36 +24,26 @@ export class PendingDepositsLookup {
|
|
|
25
24
|
return new PendingDepositsLookup(new Map(), new Map());
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
* No BLS work is done here; signature verification happens lazily in `hasPendingValidator`.
|
|
30
|
-
*/
|
|
31
|
-
static build(state) {
|
|
32
|
-
const lookup = PendingDepositsLookup.buildEmpty();
|
|
33
|
-
for (const pendingDeposit of state.pendingDeposits.getAllReadonly()) {
|
|
34
|
-
lookup.add(pendingDeposit);
|
|
35
|
-
}
|
|
36
|
-
return lookup;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Append a pending deposit to the represented sequence.
|
|
40
|
-
* Pass `pubkeyHex` if the caller has already computed it.
|
|
27
|
+
* Append a pending deposit to the represented sequence, keyed by its (precomputed) `pubkeyHex`.
|
|
41
28
|
*/
|
|
42
29
|
add(pendingDeposit, pubkeyHex) {
|
|
43
|
-
const
|
|
44
|
-
const existing = this.depositsByPubkey.get(key);
|
|
30
|
+
const existing = this.depositsByPubkey.get(pubkeyHex);
|
|
45
31
|
if (existing) {
|
|
46
32
|
existing.push(pendingDeposit);
|
|
47
33
|
}
|
|
48
34
|
else {
|
|
49
|
-
this.depositsByPubkey.set(
|
|
35
|
+
this.depositsByPubkey.set(pubkeyHex, [pendingDeposit]);
|
|
50
36
|
}
|
|
51
37
|
}
|
|
52
38
|
/**
|
|
53
39
|
* Returns true if any pending deposit for `pubkeyHex` has a valid BLS deposit signature.
|
|
54
40
|
* Memoizes the result in `validationCache` so repeated checks for the same pubkey
|
|
55
41
|
* within a block only verify deposits that have not already been checked.
|
|
42
|
+
*
|
|
43
|
+
* Most of the time it should hit the BuilderDepositSignatureCache so we don't have to validate
|
|
44
|
+
* signatures here.
|
|
56
45
|
*/
|
|
57
|
-
hasPendingValidator(config, pubkeyHex) {
|
|
46
|
+
hasPendingValidator(config, pubkeyHex, cache) {
|
|
58
47
|
const validation = this.validationCache.get(pubkeyHex);
|
|
59
48
|
if (validation?.hasValidSignature === true) {
|
|
60
49
|
return true;
|
|
@@ -72,7 +61,9 @@ export class PendingDepositsLookup {
|
|
|
72
61
|
}
|
|
73
62
|
for (let i = startIndex; i < deposits.length; i++) {
|
|
74
63
|
const deposit = deposits[i];
|
|
75
|
-
|
|
64
|
+
const isValid = cache.getSignatureValidity(deposit) ??
|
|
65
|
+
isValidDepositSignature(config, deposit.pubkey, deposit.withdrawalCredentials, deposit.amount, deposit.signature);
|
|
66
|
+
if (isValid) {
|
|
76
67
|
this.validationCache.set(pubkeyHex, { hasValidSignature: true, validatedCount: i + 1 });
|
|
77
68
|
return true;
|
|
78
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingDepositsLookup.js","sourceRoot":"","sources":["../../src/util/pendingDepositsLookup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"pendingDepositsLookup.js","sourceRoot":"","sources":["../../src/util/pendingDepositsLookup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAQnE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IAEb,gBAAgB;IAChB,eAAe;IAFlC,YACmB,gBAA0D,EAC1D,eAA0D;gCAD1D,gBAAgB;+BAChB,eAAe;IAC/B,CAAC;IAEJ,iFAAiF;IACjF,MAAM,CAAC,UAAU;QACf,OAAO,IAAI,qBAAqB,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,cAAsC,EAAE,SAAoB;QAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAoB,EAAE,SAAoB,EAAE,KAAmC;QACjG,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,UAAU,EAAE,iBAAiB,KAAK,IAAI,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kFAAkF;QAClF,2DAA2D;QAC3D,MAAM,UAAU,GAAG,UAAU,EAAE,cAAc,IAAI,CAAC,CAAC;QACnD,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACnC,6DAA6D;YAC7D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,OAAO,GACX,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC;gBACnC,uBAAuB,CACrB,MAAM,EACN,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,qBAAqB,EAC7B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,SAAS,CAClB,CAAC;YACJ,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,EAAE,EAAC,iBAAiB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,EAAC,CAAC,CAAC;gBACtF,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,EAAE,EAAC,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,CAAC,MAAM,EAAC,CAAC,CAAC;QACjG,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CachedBeaconStateFulu } from "../types.js";
|
|
2
|
+
/** Verify queued deposit signatures in batches of this size. Also the time-box granularity: the
|
|
3
|
+
* deadline is checked once per batch, so overrun is bounded to a single batch. Exported for tests. */
|
|
4
|
+
export declare const BUILDER_DEPOSIT_BATCH_SIZE = 32;
|
|
5
|
+
/**
|
|
6
|
+
* Per-tick cap on builder deposits the prepareForNextSlot scanner will verify.
|
|
7
|
+
* ~2.7s for 10_000 BLS verifications on a typical server — fits within the slot budget while the
|
|
8
|
+
* pre-window (see GLOAS_PREVERIFY_WINDOW_EPOCHS) covers up to ~620k deposits over its duration.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MAX_BUILDER_DEPOSITS_PER_SLOT = 10000;
|
|
11
|
+
/**
|
|
12
|
+
* Number of epochs before GLOAS_FORK_EPOCH during which the prepareForNextSlot scanner pre-verifies
|
|
13
|
+
* builder-deposit signatures. Two: deposits arriving this late cannot collude with validator
|
|
14
|
+
* deposits — validator-vs-builder routing is decided at the fork boundary from what is already in
|
|
15
|
+
* pendingDeposits, so anything submitted inside this window is unambiguous.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GLOAS_PREVERIFY_WINDOW_EPOCHS = 2;
|
|
18
|
+
/**
|
|
19
|
+
* Summary of a single `preVerifyBuilderDepositsPreGloas` call.
|
|
20
|
+
*/
|
|
21
|
+
export type PreVerifyBuilderDepositsResult = {
|
|
22
|
+
/** Builder-prefix deposit signatures verified valid in this call (cached true). */
|
|
23
|
+
validBuilderSignaturesCount: number;
|
|
24
|
+
/** Builder-prefix deposit signatures verified invalid in this call (cached false, dropped at fork). */
|
|
25
|
+
invalidBuilderSignaturesCount: number;
|
|
26
|
+
/** Validator (builder-pubkey) deposit signatures verified valid in this call. */
|
|
27
|
+
validValidatorSignaturesCount: number;
|
|
28
|
+
/** Validator (builder-pubkey) deposit signatures verified invalid in this call (abuse signal). */
|
|
29
|
+
invalidValidatorSignaturesCount: number;
|
|
30
|
+
/** Pending deposits examined this call (all creds; < pendingDepositsCount ⇒ per-tick cap hit). */
|
|
31
|
+
scannedPendingDeposits: number;
|
|
32
|
+
/** Cumulative deposits verified & cached so far this window (cache size, pass + fail). */
|
|
33
|
+
totalCachedDeposits: number;
|
|
34
|
+
/** Distinct builder pubkeys tracked so far this window. */
|
|
35
|
+
totalBuilderPubkeys: number;
|
|
36
|
+
/** Current `state.pendingDeposits.length` — the full backlog. */
|
|
37
|
+
pendingDepositsCount: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Scanner driven by `prepareForNextSlot` over the `GLOAS_PREVERIFY_WINDOW_EPOCHS` epochs before
|
|
41
|
+
* GLOAS_FORK_EPOCH. Walks `state.pendingDeposits` (as struct values via getAllReadonlyValues) and
|
|
42
|
+
* queues, for signature verification, the deposits the fork transition will check on its hot path:
|
|
43
|
+
* - builder-prefix deposits (for onboarding); records each builder pubkey on the cache, and
|
|
44
|
+
* - validator deposits sharing a builder pubkey (the set `hasPendingValidator` walks at the fork),
|
|
45
|
+
* but only until one is found valid — `hasPendingValidator` stops at the first valid signature, so
|
|
46
|
+
* the cache marks the pubkey and the scanner skips that pubkey's remaining validator deposits.
|
|
47
|
+
*
|
|
48
|
+
* Bounded by two knobs: at most `maxBuilderDeposits` new deposits are queued per call, and the chunk
|
|
49
|
+
* verification is **time-boxed** to `maxDurationMs`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function preVerifyBuilderDepositsPreGloas(state: CachedBeaconStateFulu, maxBuilderDeposits: number, maxDurationMs: number): PreVerifyBuilderDepositsResult;
|
|
52
|
+
//# sourceMappingURL=preVerifyBuilderDeposits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preVerifyBuilderDeposits.d.ts","sourceRoot":"","sources":["../../src/util/preVerifyBuilderDeposits.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,qBAAqB,EAAC,MAAM,aAAa,CAAC;AAGlD;uGACuG;AACvG,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,mFAAmF;IACnF,2BAA2B,EAAE,MAAM,CAAC;IACpC,uGAAuG;IACvG,6BAA6B,EAAE,MAAM,CAAC;IACtC,iFAAiF;IACjF,6BAA6B,EAAE,MAAM,CAAC;IACtC,kGAAkG;IAClG,+BAA+B,EAAE,MAAM,CAAC;IACxC,kGAAkG;IAClG,sBAAsB,EAAE,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,mBAAmB,EAAE,MAAM,CAAC;IAC5B,2DAA2D;IAC3D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,qBAAqB,EAC5B,kBAAkB,EAAE,MAAM,EAC1B,aAAa,EAAE,MAAM,GACpB,8BAA8B,CAyFhC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { toPubkeyHex } from "@lodestar/utils";
|
|
2
|
+
import { verifyDepositSignatures } from "../block/processDeposit.js";
|
|
3
|
+
import { isBuilderWithdrawalCredential } from "./gloas.js";
|
|
4
|
+
/** Verify queued deposit signatures in batches of this size. Also the time-box granularity: the
|
|
5
|
+
* deadline is checked once per batch, so overrun is bounded to a single batch. Exported for tests. */
|
|
6
|
+
export const BUILDER_DEPOSIT_BATCH_SIZE = 32;
|
|
7
|
+
/**
|
|
8
|
+
* Per-tick cap on builder deposits the prepareForNextSlot scanner will verify.
|
|
9
|
+
* ~2.7s for 10_000 BLS verifications on a typical server — fits within the slot budget while the
|
|
10
|
+
* pre-window (see GLOAS_PREVERIFY_WINDOW_EPOCHS) covers up to ~620k deposits over its duration.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_BUILDER_DEPOSITS_PER_SLOT = 10_000;
|
|
13
|
+
/**
|
|
14
|
+
* Number of epochs before GLOAS_FORK_EPOCH during which the prepareForNextSlot scanner pre-verifies
|
|
15
|
+
* builder-deposit signatures. Two: deposits arriving this late cannot collude with validator
|
|
16
|
+
* deposits — validator-vs-builder routing is decided at the fork boundary from what is already in
|
|
17
|
+
* pendingDeposits, so anything submitted inside this window is unambiguous.
|
|
18
|
+
*/
|
|
19
|
+
export const GLOAS_PREVERIFY_WINDOW_EPOCHS = 2;
|
|
20
|
+
/**
|
|
21
|
+
* Scanner driven by `prepareForNextSlot` over the `GLOAS_PREVERIFY_WINDOW_EPOCHS` epochs before
|
|
22
|
+
* GLOAS_FORK_EPOCH. Walks `state.pendingDeposits` (as struct values via getAllReadonlyValues) and
|
|
23
|
+
* queues, for signature verification, the deposits the fork transition will check on its hot path:
|
|
24
|
+
* - builder-prefix deposits (for onboarding); records each builder pubkey on the cache, and
|
|
25
|
+
* - validator deposits sharing a builder pubkey (the set `hasPendingValidator` walks at the fork),
|
|
26
|
+
* but only until one is found valid — `hasPendingValidator` stops at the first valid signature, so
|
|
27
|
+
* the cache marks the pubkey and the scanner skips that pubkey's remaining validator deposits.
|
|
28
|
+
*
|
|
29
|
+
* Bounded by two knobs: at most `maxBuilderDeposits` new deposits are queued per call, and the chunk
|
|
30
|
+
* verification is **time-boxed** to `maxDurationMs`.
|
|
31
|
+
*/
|
|
32
|
+
export function preVerifyBuilderDepositsPreGloas(state, maxBuilderDeposits, maxDurationMs) {
|
|
33
|
+
const cache = state.epochCtx.builderDepositSignatureCache;
|
|
34
|
+
// Collect uncached deposits to verify as struct values. Full rescan each tick: iteration is
|
|
35
|
+
// O(pendingDeposits) but runs in prepareNextSlot spare time, and isVerified() is an O(1) skip for
|
|
36
|
+
// already-cached deposits. For a ContainerNodeStructType, getAllReadonlyValues() returns each
|
|
37
|
+
// node.value by reference — the stable cache key.
|
|
38
|
+
const queue = [];
|
|
39
|
+
let scannedPendingDeposits = 0;
|
|
40
|
+
for (const deposit of state.pendingDeposits.getAllReadonlyValues()) {
|
|
41
|
+
if (queue.length >= maxBuilderDeposits)
|
|
42
|
+
break; // per-tick cap; next tick resumes via isVerified()
|
|
43
|
+
scannedPendingDeposits++;
|
|
44
|
+
if (cache.isVerified(deposit))
|
|
45
|
+
continue; // already verified in an earlier tick
|
|
46
|
+
if (isBuilderWithdrawalCredential(deposit.withdrawalCredentials)) {
|
|
47
|
+
// Record the builder pubkey so validator deposits sharing it get pre-verified — this or a
|
|
48
|
+
// later tick, since those validator deposits precede the builder deposit in the queue. A cached
|
|
49
|
+
// builder deposit already added its pubkey, so it's safe to skip via the `continue` above.
|
|
50
|
+
cache.addBuilderPubkey(toPubkeyHex(deposit.pubkey));
|
|
51
|
+
queue.push(deposit);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Validator deposit — pre-verify only if it shares a builder pubkey (the set hasPendingValidator
|
|
55
|
+
// walks at the fork) AND we haven't already cached a valid validator deposit for that pubkey.
|
|
56
|
+
// this is the same logic to hasPendingValidator.
|
|
57
|
+
const pubkeyHex = toPubkeyHex(deposit.pubkey);
|
|
58
|
+
if (cache.isBuilderPubkey(pubkeyHex) && !cache.hasValidValidatorDeposit(pubkeyHex)) {
|
|
59
|
+
queue.push(deposit);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const pendingDepositsCount = state.pendingDeposits.length;
|
|
64
|
+
if (queue.length === 0) {
|
|
65
|
+
return {
|
|
66
|
+
validBuilderSignaturesCount: 0,
|
|
67
|
+
invalidBuilderSignaturesCount: 0,
|
|
68
|
+
validValidatorSignaturesCount: 0,
|
|
69
|
+
invalidValidatorSignaturesCount: 0,
|
|
70
|
+
scannedPendingDeposits,
|
|
71
|
+
totalCachedDeposits: cache.cachedDepositCount,
|
|
72
|
+
totalBuilderPubkeys: cache.builderPubkeyCount,
|
|
73
|
+
pendingDepositsCount,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Verify in chunks; chunking caps the fallback blast radius so one bad signature only forces 32
|
|
77
|
+
// individual re-verifications. Key each result by the deposit value object. Counts are tracked
|
|
78
|
+
// incrementally (not queue.length - verified) so they stay correct when we time-box out early.
|
|
79
|
+
const deadline = Date.now() + maxDurationMs;
|
|
80
|
+
let validBuilderSignaturesCount = 0;
|
|
81
|
+
let invalidBuilderSignaturesCount = 0;
|
|
82
|
+
let validValidatorSignaturesCount = 0;
|
|
83
|
+
let invalidValidatorSignaturesCount = 0;
|
|
84
|
+
for (let chunkStart = 0; chunkStart < queue.length; chunkStart += BUILDER_DEPOSIT_BATCH_SIZE) {
|
|
85
|
+
const end = Math.min(chunkStart + BUILDER_DEPOSIT_BATCH_SIZE, queue.length);
|
|
86
|
+
const chunk = queue.slice(chunkStart, end);
|
|
87
|
+
const chunkResults = verifyDepositSignatures(state.epochCtx.config, chunk);
|
|
88
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
89
|
+
cache.setSignatureValidity(chunk[j], chunkResults[j]);
|
|
90
|
+
const isBuilder = isBuilderWithdrawalCredential(chunk[j].withdrawalCredentials);
|
|
91
|
+
if (chunkResults[j]) {
|
|
92
|
+
if (isBuilder) {
|
|
93
|
+
validBuilderSignaturesCount++;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
validValidatorSignaturesCount++;
|
|
97
|
+
// A valid validator deposit satisfies hasPendingValidator() for this pubkey; stop
|
|
98
|
+
// pre-verifying its remaining validator deposits on later ticks.
|
|
99
|
+
cache.setValidValidatorDeposit(toPubkeyHex(chunk[j].pubkey));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (isBuilder) {
|
|
103
|
+
invalidBuilderSignaturesCount++;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
invalidValidatorSignaturesCount++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Time-box: keep everything verified so far (already cached) and stop
|
|
110
|
+
if (Date.now() >= deadline)
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
validBuilderSignaturesCount,
|
|
115
|
+
invalidBuilderSignaturesCount,
|
|
116
|
+
validValidatorSignaturesCount,
|
|
117
|
+
invalidValidatorSignaturesCount,
|
|
118
|
+
scannedPendingDeposits,
|
|
119
|
+
totalCachedDeposits: cache.cachedDepositCount,
|
|
120
|
+
totalBuilderPubkeys: cache.builderPubkeyCount,
|
|
121
|
+
pendingDepositsCount,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=preVerifyBuilderDeposits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preVerifyBuilderDeposits.js","sourceRoot":"","sources":["../../src/util/preVerifyBuilderDeposits.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAC,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAC,6BAA6B,EAAC,MAAM,YAAY,CAAC;AAEzD;uGACuG;AACvG,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAwB/C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gCAAgC,CAC9C,KAA4B,EAC5B,kBAA0B,EAC1B,aAAqB;IAErB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAE1D,4FAA4F;IAC5F,kGAAkG;IAClG,8FAA8F;IAC9F,kDAAkD;IAClD,MAAM,KAAK,GAA6B,EAAE,CAAC;IAC3C,IAAI,sBAAsB,GAAG,CAAC,CAAC;IAC/B,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,eAAe,CAAC,oBAAoB,EAAE,EAAE,CAAC;QACnE,IAAI,KAAK,CAAC,MAAM,IAAI,kBAAkB;YAAE,MAAM,CAAC,mDAAmD;QAClG,sBAAsB,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,SAAS,CAAC,sCAAsC;QA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AC7B,6BAA6B;QAC7B,+BAA+B;QAC/B,sBAAsB;QACtB,mBAAmB,EAAE,KAAK,CAAC,kBAAkB;QAC7C,mBAAmB,EAAE,KAAK,CAAC,kBAAkB;QAC7C,oBAAoB;KACrB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.46.0-dev.
|
|
14
|
+
"version": "1.46.0-dev.3e8651f2dc",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -71,14 +71,14 @@
|
|
|
71
71
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
72
72
|
"@chainsafe/ssz": "^1.6.2",
|
|
73
73
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
74
|
-
"@lodestar/config": "^1.46.0-dev.
|
|
75
|
-
"@lodestar/params": "^1.46.0-dev.
|
|
76
|
-
"@lodestar/types": "^1.46.0-dev.
|
|
77
|
-
"@lodestar/utils": "^1.46.0-dev.
|
|
74
|
+
"@lodestar/config": "^1.46.0-dev.3e8651f2dc",
|
|
75
|
+
"@lodestar/params": "^1.46.0-dev.3e8651f2dc",
|
|
76
|
+
"@lodestar/types": "^1.46.0-dev.3e8651f2dc",
|
|
77
|
+
"@lodestar/utils": "^1.46.0-dev.3e8651f2dc",
|
|
78
78
|
"@vekexasia/bigint-buffer2": "^1.1.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@lodestar/api": "^1.46.0-dev.
|
|
81
|
+
"@lodestar/api": "^1.46.0-dev.3e8651f2dc"
|
|
82
82
|
},
|
|
83
83
|
"keywords": [
|
|
84
84
|
"ethereum",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"beacon",
|
|
87
87
|
"blockchain"
|
|
88
88
|
],
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "efa50dd77363efe05773fa47bcc1e62a06bbbe50"
|
|
90
90
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {PublicKey, Signature, verify} from "@chainsafe/blst";
|
|
1
|
+
import {PublicKey, Signature, verify, verifyMultipleAggregateSignatures} from "@chainsafe/blst";
|
|
2
2
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
3
|
import {
|
|
4
4
|
DEPOSIT_CONTRACT_TREE_DEPTH,
|
|
@@ -138,6 +138,10 @@ export function addValidatorToRegistry(
|
|
|
138
138
|
state.balances.push(amount);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Verify a single deposit signature (proof of possession). See {@link verifyDepositSignatures} for
|
|
143
|
+
* the batch equivalent — the two MUST stay consistent (same domain, signing root, and checks).
|
|
144
|
+
*/
|
|
141
145
|
export function isValidDepositSignature(
|
|
142
146
|
config: BeaconConfig,
|
|
143
147
|
pubkey: Uint8Array,
|
|
@@ -164,3 +168,73 @@ export function isValidDepositSignature(
|
|
|
164
168
|
return false; // Catch all BLS errors: failed key validation, failed signature validation, invalid signature
|
|
165
169
|
}
|
|
166
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Batch equivalent of {@link isValidDepositSignature} — verify many deposit signatures at once.
|
|
174
|
+
* MUST stay consistent with `isValidDepositSignature`: same fork-agnostic deposit domain, same
|
|
175
|
+
* `DepositMessage` signing root, same group + infinity checks. Tries a single aggregate verify and,
|
|
176
|
+
* on failure, falls back to verifying each deposit individually so the valid deposits in a batch
|
|
177
|
+
* containing an invalid one are still identified. Returns a boolean per input deposit; `slot` is not
|
|
178
|
+
* part of the signature check.
|
|
179
|
+
*
|
|
180
|
+
* Used by the pre-Gloas builder-deposit pre-verify scanner (see `preVerifyBuilderDeposits.ts`).
|
|
181
|
+
*/
|
|
182
|
+
export function verifyDepositSignatures(config: BeaconConfig, deposits: electra.PendingDeposit[]): boolean[] {
|
|
183
|
+
const results = new Array<boolean>(deposits.length).fill(false);
|
|
184
|
+
// fork-agnostic domain since deposits are valid across forks, matching isValidDepositSignature
|
|
185
|
+
const domain = computeDomain(DOMAIN_DEPOSIT, config.GENESIS_FORK_VERSION, ZERO_HASH);
|
|
186
|
+
|
|
187
|
+
const signatureSets: {pk: PublicKey; msg: Uint8Array; sig: Signature}[] = [];
|
|
188
|
+
const signatureSetDepositIndices: number[] = [];
|
|
189
|
+
for (let i = 0; i < deposits.length; i++) {
|
|
190
|
+
const {pubkey, withdrawalCredentials, amount, signature} = deposits[i];
|
|
191
|
+
let pk: PublicKey;
|
|
192
|
+
let sig: Signature;
|
|
193
|
+
try {
|
|
194
|
+
// Parse without group/infinity checks; deferred to the verify call below so it can be
|
|
195
|
+
// batched across all sets.
|
|
196
|
+
pk = PublicKey.fromBytes(pubkey);
|
|
197
|
+
sig = Signature.fromBytes(signature);
|
|
198
|
+
} catch (_) {
|
|
199
|
+
// Malformed pubkey or signature bytes - invalid deposit, results[i] stays false
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const msg = computeSigningRoot(ssz.phase0.DepositMessage, {pubkey, withdrawalCredentials, amount}, domain);
|
|
203
|
+
signatureSets.push({pk, msg, sig});
|
|
204
|
+
signatureSetDepositIndices.push(i);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (signatureSets.length === 0) {
|
|
208
|
+
return results;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Deposit pubkeys and signatures are untrusted, so group + infinity checks are required.
|
|
212
|
+
// The trailing (true, true) args delegate those checks to blst, amortized across the batch.
|
|
213
|
+
let batchValid: boolean;
|
|
214
|
+
try {
|
|
215
|
+
batchValid =
|
|
216
|
+
signatureSets.length >= 2
|
|
217
|
+
? verifyMultipleAggregateSignatures(signatureSets, true, true)
|
|
218
|
+
: verify(signatureSets[0].msg, signatureSets[0].pk, signatureSets[0].sig, true, true);
|
|
219
|
+
} catch (_) {
|
|
220
|
+
batchValid = false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (batchValid) {
|
|
224
|
+
for (const depositIndex of signatureSetDepositIndices) {
|
|
225
|
+
results[depositIndex] = true;
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
for (let s = 0; s < signatureSets.length; s++) {
|
|
229
|
+
try {
|
|
230
|
+
if (verify(signatureSets[s].msg, signatureSets[s].pk, signatureSets[s].sig, true, true)) {
|
|
231
|
+
results[signatureSetDepositIndices[s]] = true;
|
|
232
|
+
}
|
|
233
|
+
} catch (_) {
|
|
234
|
+
// invalid point / malformed → invalid signature, results[i] stays false
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return results;
|
|
240
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {PubkeyHex, electra} from "@lodestar/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Caches deposit signature-verification results — passes (`true`) and failures (`false`) — so the
|
|
5
|
+
* Fulu → Gloas fork transition can skip the bulk verification cost AND skip re-verifying deposits
|
|
6
|
+
* already proven invalid. Covers both builder-prefix deposits (onboarding) and validator deposits
|
|
7
|
+
* that share a pubkey with a builder deposit (the ones `hasPendingValidator` checks at the fork).
|
|
8
|
+
*
|
|
9
|
+
* Keyed by the deposit's struct **value object** — `electra.PendingDeposit` is a
|
|
10
|
+
* `ContainerNodeStructType`, so its `node.value` is a stable object reused across
|
|
11
|
+
* prepareNextSlot-derived states and carried by reference through the gloas pendingDeposits
|
|
12
|
+
* migration. No merkle-root computation, no slot bucketing.
|
|
13
|
+
*
|
|
14
|
+
* Also tracks builder pubkeys seen so the scanner knows which validator deposits to pre-verify (only
|
|
15
|
+
* those sharing a pubkey with a builder deposit ever reach `hasPendingValidator`). The mapped boolean
|
|
16
|
+
* records whether a *valid* validator deposit for that pubkey has been found: once true, the scanner
|
|
17
|
+
* stops pre-verifying further validator deposits for it — `hasPendingValidator` short-circuits on the
|
|
18
|
+
* first valid signature at the fork, so the rest would never be read.
|
|
19
|
+
*
|
|
20
|
+
* Lifecycle owned by `prepareNextSlot`: filled during the pre-fork window, then `clear()`ed once the
|
|
21
|
+
* Gloas fork is finalized. `onboardBuildersFromPendingDeposits()` only reads it. A plain `Map` (not a
|
|
22
|
+
* `WeakMap`) is used so the drop is deterministic and the contents are inspectable for logging.
|
|
23
|
+
*
|
|
24
|
+
* Single instance across the application (created in `EpochCache.createFromState`, shared
|
|
25
|
+
* by-reference through `clone()`).
|
|
26
|
+
*/
|
|
27
|
+
export class BuilderDepositSignatureCache {
|
|
28
|
+
private validityByDeposit = new Map<electra.PendingDeposit, boolean>();
|
|
29
|
+
/** builder pubkey → whether a valid validator deposit sharing it has already been pre-verified. */
|
|
30
|
+
private builderPubkeys = new Map<PubkeyHex, boolean>();
|
|
31
|
+
|
|
32
|
+
setSignatureValidity(deposit: electra.PendingDeposit, isValid: boolean): void {
|
|
33
|
+
this.validityByDeposit.set(deposit, isValid);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getSignatureValidity(deposit: electra.PendingDeposit): boolean | null {
|
|
37
|
+
return this.validityByDeposit.get(deposit) ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isVerified(deposit: electra.PendingDeposit): boolean {
|
|
41
|
+
return this.validityByDeposit.has(deposit);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Record a builder deposit's pubkey so the scanner pre-verifies validator deposits for it.
|
|
45
|
+
* Idempotent; never downgrades a pubkey already marked as having a valid validator deposit. */
|
|
46
|
+
addBuilderPubkey(pubkeyHex: PubkeyHex): void {
|
|
47
|
+
if (!this.builderPubkeys.has(pubkeyHex)) {
|
|
48
|
+
this.builderPubkeys.set(pubkeyHex, false);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
isBuilderPubkey(pubkeyHex: PubkeyHex): boolean {
|
|
53
|
+
return this.builderPubkeys.has(pubkeyHex);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True once a valid validator deposit sharing this builder pubkey has been pre-verified — the
|
|
57
|
+
* scanner then skips this pubkey's remaining validator deposits (as `hasPendingValidator` would). */
|
|
58
|
+
hasValidValidatorDeposit(pubkeyHex: PubkeyHex): boolean {
|
|
59
|
+
return this.builderPubkeys.get(pubkeyHex) === true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Mark that a valid validator deposit sharing this builder pubkey was found. */
|
|
63
|
+
setValidValidatorDeposit(pubkeyHex: PubkeyHex): void {
|
|
64
|
+
this.builderPubkeys.set(pubkeyHex, true);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Cumulative deposits verified & cached this window (pass + fail). */
|
|
68
|
+
get cachedDepositCount(): number {
|
|
69
|
+
return this.validityByDeposit.size;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Distinct builder pubkeys tracked this window. */
|
|
73
|
+
get builderPubkeyCount(): number {
|
|
74
|
+
return this.builderPubkeys.size;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
clear(): void {
|
|
78
|
+
this.validityByDeposit.clear();
|
|
79
|
+
this.builderPubkeys.clear();
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/cache/epochCache.ts
CHANGED
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
} from "../util/shuffling.js";
|
|
54
54
|
import {computeBaseRewardPerIncrement, computeSyncParticipantReward} from "../util/syncCommittee.js";
|
|
55
55
|
import {sumTargetUnslashedBalanceIncrements} from "../util/targetUnslashedBalance.js";
|
|
56
|
+
import {BuilderDepositSignatureCache} from "./builderDepositSignatureCache.js";
|
|
56
57
|
import {EffectiveBalanceIncrements, getEffectiveBalanceIncrementsWithLen} from "./effectiveBalanceIncrements.js";
|
|
57
58
|
import {EpochTransitionCache} from "./epochTransitionCache.js";
|
|
58
59
|
import {PubkeyCache, createPubkeyCache, syncPubkeys} from "./pubkeyCache.js";
|
|
@@ -112,6 +113,13 @@ export class EpochCache {
|
|
|
112
113
|
* Couples both index→pubkey and pubkey→index lookups, keeping them in sync atomically.
|
|
113
114
|
*/
|
|
114
115
|
pubkeyCache: PubkeyCache;
|
|
116
|
+
/**
|
|
117
|
+
* Shared across all clones of the same chain head. Holds builder deposit signature validity
|
|
118
|
+
* pre-verified by the prepareForNextSlot scheduler in the `GLOAS_PREVERIFY_WINDOW_EPOCHS` epochs
|
|
119
|
+
* leading up to GLOAS_FORK_EPOCH, so `onboardBuildersFromPendingDeposits()` at the fork transition
|
|
120
|
+
* can skip the bulk verification cost. There should only exist one for the entire application.
|
|
121
|
+
*/
|
|
122
|
+
builderDepositSignatureCache: BuilderDepositSignatureCache;
|
|
115
123
|
/**
|
|
116
124
|
* Indexes of the block proposers for the current epoch.
|
|
117
125
|
* For pre-fulu, this is computed and cached from the current shuffling.
|
|
@@ -245,6 +253,7 @@ export class EpochCache {
|
|
|
245
253
|
constructor(data: {
|
|
246
254
|
config: BeaconConfig;
|
|
247
255
|
pubkeyCache: PubkeyCache;
|
|
256
|
+
builderDepositSignatureCache: BuilderDepositSignatureCache;
|
|
248
257
|
proposers: number[];
|
|
249
258
|
proposersPrevEpoch: number[] | null;
|
|
250
259
|
proposersNextEpoch: ProposersDeferred;
|
|
@@ -277,6 +286,7 @@ export class EpochCache {
|
|
|
277
286
|
}) {
|
|
278
287
|
this.config = data.config;
|
|
279
288
|
this.pubkeyCache = data.pubkeyCache;
|
|
289
|
+
this.builderDepositSignatureCache = data.builderDepositSignatureCache;
|
|
280
290
|
this.proposers = data.proposers;
|
|
281
291
|
this.proposersPrevEpoch = data.proposersPrevEpoch;
|
|
282
292
|
this.proposersNextEpoch = data.proposersNextEpoch;
|
|
@@ -514,6 +524,8 @@ export class EpochCache {
|
|
|
514
524
|
return new EpochCache({
|
|
515
525
|
config,
|
|
516
526
|
pubkeyCache,
|
|
527
|
+
// Created once per application (shared by-reference through clone()).
|
|
528
|
+
builderDepositSignatureCache: new BuilderDepositSignatureCache(),
|
|
517
529
|
proposers,
|
|
518
530
|
// On first epoch, set to null to prevent unnecessary work since this is only used for metrics
|
|
519
531
|
proposersPrevEpoch: null,
|
|
@@ -558,6 +570,8 @@ export class EpochCache {
|
|
|
558
570
|
config: this.config,
|
|
559
571
|
// Common append-only structures shared with all states, no need to clone
|
|
560
572
|
pubkeyCache: this.pubkeyCache,
|
|
573
|
+
// Singleton per application, shared by-reference across clones
|
|
574
|
+
builderDepositSignatureCache: this.builderDepositSignatureCache,
|
|
561
575
|
// Immutable data
|
|
562
576
|
proposers: this.proposers,
|
|
563
577
|
proposersPrevEpoch: this.proposersPrevEpoch,
|