@lodestar/state-transition 1.42.0-dev.1e596a7422 → 1.42.0-dev.2219bb0cb8
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 +11 -2
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +34 -4
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +7 -3
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/package.json +7 -7
- package/src/block/processDepositRequest.ts +50 -5
- package/src/block/processExecutionPayloadEnvelope.ts +8 -3
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
import { BeaconConfig } from "@lodestar/config";
|
|
1
2
|
import { ForkSeq } from "@lodestar/params";
|
|
2
|
-
import { BLSPubkey, Bytes32, UintNum64, electra } from "@lodestar/types";
|
|
3
|
+
import { BLSPubkey, Bytes32, PubkeyHex, UintNum64, electra } from "@lodestar/types";
|
|
3
4
|
import { CachedBeaconStateElectra, CachedBeaconStateGloas } from "../types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Apply a deposit for a builder. Either increases balance for existing builder or adds new builder to registry.
|
|
6
7
|
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-apply_deposit_for_builder
|
|
7
8
|
*/
|
|
8
9
|
export declare function applyDepositForBuilder(state: CachedBeaconStateGloas, pubkey: BLSPubkey, withdrawalCredentials: Bytes32, amount: UintNum64, signature: Bytes32, slot: UintNum64): void;
|
|
9
|
-
export declare function processDepositRequest(fork: ForkSeq, state: CachedBeaconStateElectra | CachedBeaconStateGloas, depositRequest: electra.DepositRequest): void;
|
|
10
|
+
export declare function processDepositRequest(fork: ForkSeq, state: CachedBeaconStateElectra | CachedBeaconStateGloas, depositRequest: electra.DepositRequest, pendingValidatorPubkeysCache?: Set<PubkeyHex>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Build a set of pubkeys (hex-encoded) from pending deposits that have valid signatures.
|
|
13
|
+
* This is computed once and passed to each processDepositRequest call to avoid
|
|
14
|
+
* repeatedly iterating state.pendingDeposits.
|
|
15
|
+
*
|
|
16
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPendingValidatorPubkeys(config: BeaconConfig, state: CachedBeaconStateGloas): Set<PubkeyHex>;
|
|
10
19
|
//# sourceMappingURL=processDepositRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processDepositRequest.d.ts","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAqC,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAM,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"processDepositRequest.d.ts","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAmB,OAAO,EAAqC,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAEvF,OAAO,EAAC,wBAAwB,EAAE,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAK7E;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,sBAAsB,EAC7B,MAAM,EAAE,SAAS,EACjB,qBAAqB,EAAE,OAAO,EAC9B,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,SAAS,GACd,IAAI,CAaN;AAiDD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,sBAAsB,EACxD,cAAc,EAAE,OAAO,CAAC,cAAc,EACtC,4BAA4B,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,GAC5C,IAAI,CAkDN;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,GAAG,GAAG,CAAC,SAAS,CAAC,CAgB9G"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FAR_FUTURE_EPOCH, ForkSeq, UNSET_DEPOSIT_REQUESTS_START_INDEX } from "@lodestar/params";
|
|
2
2
|
import { ssz } from "@lodestar/types";
|
|
3
|
+
import { toPubkeyHex } from "@lodestar/utils";
|
|
3
4
|
import { findBuilderIndexByPubkey, isBuilderWithdrawalCredential } from "../util/gloas.js";
|
|
4
5
|
import { computeEpochAtSlot, isValidatorKnown } from "../util/index.js";
|
|
5
6
|
import { isValidDepositSignature } from "./processDeposit.js";
|
|
@@ -55,24 +56,37 @@ function addBuilderToRegistry(state, pubkey, withdrawalCredentials, amount, slot
|
|
|
55
56
|
state.builders.push(newBuilder);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
+
// TODO GLOAS: pendingValidatorPubkeys cache is currently naive and has room for improvement.
|
|
60
|
+
// Currently the cache lives in process_block, but we should put it in epochCache or elsewhere that has longer
|
|
61
|
+
// lifetime to avoid duplicated deposit signature computation
|
|
62
|
+
// See https://github.com/ChainSafe/lodestar/issues/9181
|
|
63
|
+
export function processDepositRequest(fork, state, depositRequest, pendingValidatorPubkeysCache) {
|
|
59
64
|
const { pubkey, withdrawalCredentials, amount, signature } = depositRequest;
|
|
60
65
|
// Check if this is a builder or validator deposit
|
|
61
66
|
if (fork >= ForkSeq.gloas) {
|
|
62
67
|
const stateGloas = state;
|
|
68
|
+
const pendingValidatorPubkeys = pendingValidatorPubkeysCache ?? getPendingValidatorPubkeys(state.config, stateGloas);
|
|
69
|
+
const pubkeyHex = toPubkeyHex(pubkey);
|
|
63
70
|
const builderIndex = findBuilderIndexByPubkey(stateGloas, pubkey);
|
|
64
71
|
const validatorIndex = state.epochCtx.getValidatorIndex(pubkey);
|
|
65
72
|
// Regardless of the withdrawal credentials prefix, if a builder/validator
|
|
66
73
|
// already exists with this pubkey, apply the deposit to their balance
|
|
67
74
|
const isBuilder = builderIndex !== null;
|
|
68
75
|
const isValidator = isValidatorKnown(state, validatorIndex);
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
if (isBuilder || (isBuilderPrefix && !isValidator)) {
|
|
76
|
+
const isPendingValidator = pendingValidatorPubkeys.has(pubkeyHex);
|
|
77
|
+
if (isBuilder || (isBuilderWithdrawalCredential(withdrawalCredentials) && !isValidator && !isPendingValidator)) {
|
|
72
78
|
// Apply builder deposits immediately
|
|
73
79
|
applyDepositForBuilder(stateGloas, pubkey, withdrawalCredentials, amount, signature, state.slot);
|
|
74
80
|
return;
|
|
75
81
|
}
|
|
82
|
+
// Keep the shared cache in sync: if this deposit has a valid signature, subsequent
|
|
83
|
+
// deposit requests for the same pubkey in this envelope must see it as a pending validator
|
|
84
|
+
if (pendingValidatorPubkeysCache &&
|
|
85
|
+
!isValidator &&
|
|
86
|
+
!isPendingValidator &&
|
|
87
|
+
isValidDepositSignature(state.config, pubkey, withdrawalCredentials, amount, signature)) {
|
|
88
|
+
pendingValidatorPubkeys.add(pubkeyHex);
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
// Only set deposit_requests_start_index in Electra fork, not Gloas
|
|
78
92
|
if (fork < ForkSeq.gloas && state.depositRequestsStartIndex === UNSET_DEPOSIT_REQUESTS_START_INDEX) {
|
|
@@ -88,4 +102,20 @@ export function processDepositRequest(fork, state, depositRequest) {
|
|
|
88
102
|
});
|
|
89
103
|
state.pendingDeposits.push(pendingDeposit);
|
|
90
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Build a set of pubkeys (hex-encoded) from pending deposits that have valid signatures.
|
|
107
|
+
* This is computed once and passed to each processDepositRequest call to avoid
|
|
108
|
+
* repeatedly iterating state.pendingDeposits.
|
|
109
|
+
*
|
|
110
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
|
|
111
|
+
*/
|
|
112
|
+
export function getPendingValidatorPubkeys(config, state) {
|
|
113
|
+
const result = new Set();
|
|
114
|
+
for (const pendingDeposit of state.pendingDeposits.getAllReadonly()) {
|
|
115
|
+
if (isValidDepositSignature(config, pendingDeposit.pubkey, pendingDeposit.withdrawalCredentials, pendingDeposit.amount, pendingDeposit.signature)) {
|
|
116
|
+
result.add(toPubkeyHex(pendingDeposit.pubkey));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
91
121
|
//# sourceMappingURL=processDepositRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processDepositRequest.js","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"processDepositRequest.js","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,kCAAkC,EAAC,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAoD,GAAG,EAAC,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,wBAAwB,EAAE,6BAA6B,EAAC,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAC,kBAAkB,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAA6B,EAC7B,MAAi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B,CAAC,MAAoB,EAAE,KAA6B,EAAkB;IAC9G,MAAM,MAAM,GAAG,IAAI,GAAG,EAAa,CAAC;IACpC,KAAK,MAAM,cAAc,IAAI,KAAK,CAAC,eAAe,CAAC,cAAc,EAAE,EAAE,CAAC;QACpE,IACE,uBAAuB,CACrB,MAAM,EACN,cAAc,CAAC,MAAM,EACrB,cAAc,CAAC,qBAAqB,EACpC,cAAc,CAAC,MAAM,EACrB,cAAc,CAAC,SAAS,CACzB,EACD,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processExecutionPayloadEnvelope.d.ts","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAM,MAAM,iBAAiB,CAAC;AAI3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAOnD,MAAM,MAAM,mCAAmC,GAAG;IAChD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAKF,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,sBAAsB,EAC7B,cAAc,EAAE,KAAK,CAAC,8BAA8B,EACpD,IAAI,CAAC,EAAE,mCAAmC,GACzC,sBAAsB,
|
|
1
|
+
{"version":3,"file":"processExecutionPayloadEnvelope.d.ts","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAM,MAAM,iBAAiB,CAAC;AAI3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAOnD,MAAM,MAAM,mCAAmC,GAAG;IAChD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAKF,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,sBAAsB,EAC7B,cAAc,EAAE,KAAK,CAAC,8BAA8B,EACpD,IAAI,CAAC,EAAE,mCAAmC,GACzC,sBAAsB,CA0DxB"}
|
|
@@ -6,7 +6,7 @@ import { BeaconStateView } from "../stateView/beaconStateView.js";
|
|
|
6
6
|
import { computeTimeAtSlot } from "../util/index.js";
|
|
7
7
|
import { verifySignatureSet } from "../util/signatureSets.js";
|
|
8
8
|
import { processConsolidationRequest } from "./processConsolidationRequest.js";
|
|
9
|
-
import { processDepositRequest } from "./processDepositRequest.js";
|
|
9
|
+
import { getPendingValidatorPubkeys, processDepositRequest } from "./processDepositRequest.js";
|
|
10
10
|
import { processWithdrawalRequest } from "./processWithdrawalRequest.js";
|
|
11
11
|
// Unlike other block processing functions which mutate state in-place, this function
|
|
12
12
|
// clones the state and returns the post-state, similar to stateTransition().
|
|
@@ -23,8 +23,12 @@ export function processExecutionPayloadEnvelope(state, signedEnvelope, opts) {
|
|
|
23
23
|
const postState = state.clone(opts?.dontTransferCache);
|
|
24
24
|
validateExecutionPayloadEnvelope(postState, envelope);
|
|
25
25
|
const requests = envelope.executionRequests;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (requests.deposits.length > 0) {
|
|
27
|
+
// Build cache of pending validator pubkeys once, shared across all deposit requests
|
|
28
|
+
const pendingValidatorPubkeys = getPendingValidatorPubkeys(postState.config, postState);
|
|
29
|
+
for (const deposit of requests.deposits) {
|
|
30
|
+
processDepositRequest(fork, postState, deposit, pendingValidatorPubkeys);
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
for (const withdrawal of requests.withdrawals) {
|
|
30
34
|
processWithdrawalRequest(fork, postState, withdrawal);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processExecutionPayloadEnvelope.js","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAQ,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,eAAe,EAAE,KAAK,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAC,uCAAuC,EAAC,MAAM,8CAA8C,CAAC;AACrG,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"processExecutionPayloadEnvelope.js","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAQ,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,eAAe,EAAE,KAAK,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAC,uCAAuC,EAAC,MAAM,8CAA8C,CAAC;AACrG,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,0BAA0B,EAAE,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAC7F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CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,KAAK,CACb,oEAAoE,OAAO,CAAC,SAAS,UAAU,iBAAiB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,CAChK,CAAC;IACJ,CAAC;IAED,iDAAiD;AAFhD,CAGF;AAED,SAAS,uCAAuC,CAC9C,KAA6B,EAC7B,cAAoD,EAC3C;IACT,MAAM,YAAY,GAAG,uCAAuC,CAC1D,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,QAAQ,CAAC,WAAW,EAC1B,IAAI,eAAe,CAAC,KAAK,CAAC,EAC1B,cAAc,EACd,KAAK,CAAC,iBAAiB,CAAC,aAAa,CACtC,CAAC;IACF,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAAA,CACzC"}
|
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.42.0-dev.
|
|
14
|
+
"version": "1.42.0-dev.2219bb0cb8",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
68
68
|
"@chainsafe/ssz": "^1.2.2",
|
|
69
69
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
70
|
-
"@lodestar/config": "^1.42.0-dev.
|
|
71
|
-
"@lodestar/params": "^1.42.0-dev.
|
|
72
|
-
"@lodestar/types": "^1.42.0-dev.
|
|
73
|
-
"@lodestar/utils": "^1.42.0-dev.
|
|
70
|
+
"@lodestar/config": "^1.42.0-dev.2219bb0cb8",
|
|
71
|
+
"@lodestar/params": "^1.42.0-dev.2219bb0cb8",
|
|
72
|
+
"@lodestar/types": "^1.42.0-dev.2219bb0cb8",
|
|
73
|
+
"@lodestar/utils": "^1.42.0-dev.2219bb0cb8",
|
|
74
74
|
"@vekexasia/bigint-buffer2": "^1.1.1"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@lodestar/api": "^1.42.0-dev.
|
|
77
|
+
"@lodestar/api": "^1.42.0-dev.2219bb0cb8"
|
|
78
78
|
},
|
|
79
79
|
"keywords": [
|
|
80
80
|
"ethereum",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"beacon",
|
|
83
83
|
"blockchain"
|
|
84
84
|
],
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "3761783c9d8c8c6122f34db2f2de8f3aea2582ad"
|
|
86
86
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {FAR_FUTURE_EPOCH, ForkSeq, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params";
|
|
2
|
-
import {BLSPubkey, Bytes32, UintNum64, electra, ssz} from "@lodestar/types";
|
|
3
|
+
import {BLSPubkey, Bytes32, PubkeyHex, UintNum64, electra, ssz} from "@lodestar/types";
|
|
4
|
+
import {toPubkeyHex} from "@lodestar/utils";
|
|
3
5
|
import {CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
|
|
4
6
|
import {findBuilderIndexByPubkey, isBuilderWithdrawalCredential} from "../util/gloas.js";
|
|
5
7
|
import {computeEpochAtSlot, isValidatorKnown} from "../util/index.js";
|
|
@@ -74,16 +76,24 @@ function addBuilderToRegistry(
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
// TODO GLOAS: pendingValidatorPubkeys cache is currently naive and has room for improvement.
|
|
80
|
+
// Currently the cache lives in process_block, but we should put it in epochCache or elsewhere that has longer
|
|
81
|
+
// lifetime to avoid duplicated deposit signature computation
|
|
82
|
+
// See https://github.com/ChainSafe/lodestar/issues/9181
|
|
77
83
|
export function processDepositRequest(
|
|
78
84
|
fork: ForkSeq,
|
|
79
85
|
state: CachedBeaconStateElectra | CachedBeaconStateGloas,
|
|
80
|
-
depositRequest: electra.DepositRequest
|
|
86
|
+
depositRequest: electra.DepositRequest,
|
|
87
|
+
pendingValidatorPubkeysCache?: Set<PubkeyHex>
|
|
81
88
|
): void {
|
|
82
89
|
const {pubkey, withdrawalCredentials, amount, signature} = depositRequest;
|
|
83
90
|
|
|
84
91
|
// Check if this is a builder or validator deposit
|
|
85
92
|
if (fork >= ForkSeq.gloas) {
|
|
86
93
|
const stateGloas = state as CachedBeaconStateGloas;
|
|
94
|
+
const pendingValidatorPubkeys =
|
|
95
|
+
pendingValidatorPubkeysCache ?? getPendingValidatorPubkeys(state.config, stateGloas);
|
|
96
|
+
const pubkeyHex = toPubkeyHex(pubkey);
|
|
87
97
|
const builderIndex = findBuilderIndexByPubkey(stateGloas, pubkey);
|
|
88
98
|
const validatorIndex = state.epochCtx.getValidatorIndex(pubkey);
|
|
89
99
|
|
|
@@ -91,14 +101,24 @@ export function processDepositRequest(
|
|
|
91
101
|
// already exists with this pubkey, apply the deposit to their balance
|
|
92
102
|
const isBuilder = builderIndex !== null;
|
|
93
103
|
const isValidator = isValidatorKnown(state, validatorIndex);
|
|
94
|
-
const
|
|
104
|
+
const isPendingValidator = pendingValidatorPubkeys.has(pubkeyHex);
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
if (isBuilder || (isBuilderPrefix && !isValidator)) {
|
|
106
|
+
if (isBuilder || (isBuilderWithdrawalCredential(withdrawalCredentials) && !isValidator && !isPendingValidator)) {
|
|
98
107
|
// Apply builder deposits immediately
|
|
99
108
|
applyDepositForBuilder(stateGloas, pubkey, withdrawalCredentials, amount, signature, state.slot);
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
111
|
+
|
|
112
|
+
// Keep the shared cache in sync: if this deposit has a valid signature, subsequent
|
|
113
|
+
// deposit requests for the same pubkey in this envelope must see it as a pending validator
|
|
114
|
+
if (
|
|
115
|
+
pendingValidatorPubkeysCache &&
|
|
116
|
+
!isValidator &&
|
|
117
|
+
!isPendingValidator &&
|
|
118
|
+
isValidDepositSignature(state.config, pubkey, withdrawalCredentials, amount, signature)
|
|
119
|
+
) {
|
|
120
|
+
pendingValidatorPubkeys.add(pubkeyHex);
|
|
121
|
+
}
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
// Only set deposit_requests_start_index in Electra fork, not Gloas
|
|
@@ -116,3 +136,28 @@ export function processDepositRequest(
|
|
|
116
136
|
});
|
|
117
137
|
state.pendingDeposits.push(pendingDeposit);
|
|
118
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Build a set of pubkeys (hex-encoded) from pending deposits that have valid signatures.
|
|
142
|
+
* This is computed once and passed to each processDepositRequest call to avoid
|
|
143
|
+
* repeatedly iterating state.pendingDeposits.
|
|
144
|
+
*
|
|
145
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
|
|
146
|
+
*/
|
|
147
|
+
export function getPendingValidatorPubkeys(config: BeaconConfig, state: CachedBeaconStateGloas): Set<PubkeyHex> {
|
|
148
|
+
const result = new Set<PubkeyHex>();
|
|
149
|
+
for (const pendingDeposit of state.pendingDeposits.getAllReadonly()) {
|
|
150
|
+
if (
|
|
151
|
+
isValidDepositSignature(
|
|
152
|
+
config,
|
|
153
|
+
pendingDeposit.pubkey,
|
|
154
|
+
pendingDeposit.withdrawalCredentials,
|
|
155
|
+
pendingDeposit.amount,
|
|
156
|
+
pendingDeposit.signature
|
|
157
|
+
)
|
|
158
|
+
) {
|
|
159
|
+
result.add(toPubkeyHex(pendingDeposit.pubkey));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
@@ -7,7 +7,7 @@ import {CachedBeaconStateGloas} from "../types.js";
|
|
|
7
7
|
import {computeTimeAtSlot} from "../util/index.js";
|
|
8
8
|
import {verifySignatureSet} from "../util/signatureSets.js";
|
|
9
9
|
import {processConsolidationRequest} from "./processConsolidationRequest.js";
|
|
10
|
-
import {processDepositRequest} from "./processDepositRequest.js";
|
|
10
|
+
import {getPendingValidatorPubkeys, processDepositRequest} from "./processDepositRequest.js";
|
|
11
11
|
import {processWithdrawalRequest} from "./processWithdrawalRequest.js";
|
|
12
12
|
|
|
13
13
|
export type ProcessExecutionPayloadEnvelopeOpts = {
|
|
@@ -40,8 +40,13 @@ export function processExecutionPayloadEnvelope(
|
|
|
40
40
|
|
|
41
41
|
const requests = envelope.executionRequests;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (requests.deposits.length > 0) {
|
|
44
|
+
// Build cache of pending validator pubkeys once, shared across all deposit requests
|
|
45
|
+
const pendingValidatorPubkeys = getPendingValidatorPubkeys(postState.config, postState);
|
|
46
|
+
|
|
47
|
+
for (const deposit of requests.deposits) {
|
|
48
|
+
processDepositRequest(fork, postState, deposit, pendingValidatorPubkeys);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
for (const withdrawal of requests.withdrawals) {
|