@lodestar/state-transition 1.39.0-dev.86298a43e6 → 1.39.0-dev.95389042f8

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.
@@ -3,9 +3,9 @@ import { capella } from "@lodestar/types";
3
3
  import { CachedBeaconStateCapella, CachedBeaconStateElectra, CachedBeaconStateGloas } from "../types.js";
4
4
  export declare function processWithdrawals(fork: ForkSeq, state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas, payload?: capella.FullOrBlindedExecutionPayload): void;
5
5
  export declare function getExpectedWithdrawals(fork: ForkSeq, state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas): {
6
- withdrawals: capella.Withdrawal[];
7
- sampledValidators: number;
8
- processedPartialWithdrawalsCount: number;
6
+ expectedWithdrawals: capella.Withdrawal[];
9
7
  processedBuilderWithdrawalsCount: number;
8
+ processedPartialWithdrawalsCount: number;
9
+ processedValidatorSweepCount: number;
10
10
  };
11
11
  //# sourceMappingURL=processWithdrawals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"processWithdrawals.d.ts","sourceRoot":"","sources":["../../src/block/processWithdrawals.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,EAMR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiB,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAC,wBAAwB,EAAE,wBAAwB,EAAE,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAUvG,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,sBAAsB,EACnF,OAAO,CAAC,EAAE,OAAO,CAAC,6BAA6B,GAC9C,IAAI,CA0FN;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,sBAAsB,GAClF;IACD,WAAW,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gCAAgC,EAAE,MAAM,CAAC;IACzC,gCAAgC,EAAE,MAAM,CAAC;CAC1C,CA2KA"}
1
+ {"version":3,"file":"processWithdrawals.d.ts","sourceRoot":"","sources":["../../src/block/processWithdrawals.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,EAMR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiB,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAC,wBAAwB,EAAE,wBAAwB,EAAE,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAUvG,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,sBAAsB,EACnF,OAAO,CAAC,EAAE,OAAO,CAAC,6BAA6B,GAC9C,IAAI,CAuFN;AAkND,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,sBAAsB,GAClF;IACD,mBAAmB,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;IAC1C,gCAAgC,EAAE,MAAM,CAAC;IACzC,gCAAgC,EAAE,MAAM,CAAC;IACzC,4BAA4B,EAAE,MAAM,CAAC;CACtC,CA6DA"}
@@ -1,7 +1,7 @@
1
1
  import { byteArrayEquals } from "@chainsafe/ssz";
2
2
  import { FAR_FUTURE_EPOCH, ForkSeq, MAX_EFFECTIVE_BALANCE, MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP, MAX_WITHDRAWALS_PER_PAYLOAD, MIN_ACTIVATION_BALANCE, } from "@lodestar/params";
3
3
  import { ssz } from "@lodestar/types";
4
- import { MapDef, toRootHex } from "@lodestar/utils";
4
+ import { toRootHex } from "@lodestar/utils";
5
5
  import { isBuilderPaymentWithdrawable, isParentBlockFull } from "../util/gloas.js";
6
6
  import { decreaseBalance, getMaxEffectiveBalance, hasEth1WithdrawalCredential, hasExecutionWithdrawalCredential, isCapellaPayloadHeader, } from "../util/index.js";
7
7
  export function processWithdrawals(fork, state, payload) {
@@ -9,9 +9,10 @@ export function processWithdrawals(fork, state, payload) {
9
9
  if (fork >= ForkSeq.gloas && !isParentBlockFull(state)) {
10
10
  return;
11
11
  }
12
- // processedPartialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
13
12
  // processedBuilderWithdrawalsCount is withdrawals coming from builder payment since gloas (EIP-7732)
14
- const { withdrawals: expectedWithdrawals, processedPartialWithdrawalsCount, processedBuilderWithdrawalsCount, } = getExpectedWithdrawals(fork, state);
13
+ // processedPartialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
14
+ // processedValidatorSweepCount is withdrawals coming from validator sweep
15
+ const { expectedWithdrawals, processedBuilderWithdrawalsCount, processedPartialWithdrawalsCount } = getExpectedWithdrawals(fork, state);
15
16
  const numWithdrawals = expectedWithdrawals.length;
16
17
  // After gloas, withdrawals are verified later in processExecutionPayloadEnvelope
17
18
  if (fork < ForkSeq.gloas) {
@@ -37,11 +38,9 @@ export function processWithdrawals(fork, state, payload) {
37
38
  }
38
39
  }
39
40
  }
40
- for (let i = 0; i < numWithdrawals; i++) {
41
- const withdrawal = expectedWithdrawals[i];
42
- decreaseBalance(state, withdrawal.validatorIndex, Number(withdrawal.amount));
43
- }
41
+ applyWithdrawals(state, expectedWithdrawals);
44
42
  if (fork >= ForkSeq.electra) {
43
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/electra/beacon-chain.md#new-update_pending_partial_withdrawals
45
44
  const stateElectra = state;
46
45
  stateElectra.pendingPartialWithdrawals = stateElectra.pendingPartialWithdrawals.sliceFrom(processedPartialWithdrawalsCount);
47
46
  }
@@ -61,10 +60,12 @@ export function processWithdrawals(fork, state, payload) {
61
60
  ]);
62
61
  }
63
62
  // Update the nextWithdrawalIndex
63
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-update_next_withdrawal_index
64
64
  const latestWithdrawal = expectedWithdrawals.at(-1);
65
65
  if (latestWithdrawal) {
66
66
  state.nextWithdrawalIndex = latestWithdrawal.index + 1;
67
67
  }
68
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-update_next_withdrawal_validator_index
68
69
  // Update the nextWithdrawalValidatorIndex
69
70
  if (latestWithdrawal && expectedWithdrawals.length === MAX_WITHDRAWALS_PER_PAYLOAD) {
70
71
  // All slots filled, nextWithdrawalValidatorIndex should be validatorIndex having next turn
@@ -77,110 +78,119 @@ export function processWithdrawals(fork, state, payload) {
77
78
  (state.nextWithdrawalValidatorIndex + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP) % state.validators.length;
78
79
  }
79
80
  }
80
- export function getExpectedWithdrawals(fork, state) {
81
- if (fork < ForkSeq.capella) {
82
- throw new Error(`getExpectedWithdrawals not supported at forkSeq=${fork} < ForkSeq.capella`);
83
- }
81
+ function getBuilderWithdrawals(state, withdrawalIndex, balanceAfterWithdrawals) {
82
+ const builderWithdrawals = [];
84
83
  const epoch = state.epochCtx.epoch;
85
- let withdrawalIndex = state.nextWithdrawalIndex;
86
- const { validators, balances, nextWithdrawalValidatorIndex } = state;
87
- const withdrawals = [];
88
- const withdrawnBalances = new MapDef(() => 0);
89
- const isPostElectra = fork >= ForkSeq.electra;
90
- const isPostGloas = fork >= ForkSeq.gloas;
91
- // partialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
92
- let processedPartialWithdrawalsCount = 0;
93
- // builderWithdrawalsCount is withdrawals coming from builder payments since Gloas (EIP-7732)
94
- let processedBuilderWithdrawalsCount = 0;
95
- if (isPostGloas) {
96
- const stateGloas = state;
97
- const allBuilderPendingWithdrawals = stateGloas.builderPendingWithdrawals.length <= MAX_WITHDRAWALS_PER_PAYLOAD
98
- ? stateGloas.builderPendingWithdrawals.getAllReadonly()
99
- : null;
100
- for (let i = 0; i < stateGloas.builderPendingWithdrawals.length; i++) {
101
- const withdrawal = allBuilderPendingWithdrawals
102
- ? allBuilderPendingWithdrawals[i]
103
- : stateGloas.builderPendingWithdrawals.getReadonly(i);
104
- if (withdrawal.withdrawableEpoch > epoch || withdrawals.length + 1 === MAX_WITHDRAWALS_PER_PAYLOAD) {
105
- break;
84
+ const allBuilderPendingWithdrawals = state.builderPendingWithdrawals.length <= MAX_WITHDRAWALS_PER_PAYLOAD
85
+ ? state.builderPendingWithdrawals.getAllReadonly()
86
+ : null;
87
+ let processedCount = 0;
88
+ for (let i = 0; i < state.builderPendingWithdrawals.length; i++) {
89
+ const withdrawal = allBuilderPendingWithdrawals
90
+ ? allBuilderPendingWithdrawals[i]
91
+ : state.builderPendingWithdrawals.getReadonly(i);
92
+ if (withdrawal.withdrawableEpoch > epoch || builderWithdrawals.length === MAX_WITHDRAWALS_PER_PAYLOAD) {
93
+ break;
94
+ }
95
+ if (isBuilderPaymentWithdrawable(state, withdrawal)) {
96
+ const builderIndex = withdrawal.builderIndex;
97
+ const builder = state.validators.get(withdrawal.builderIndex);
98
+ let balance = balanceAfterWithdrawals.get(builderIndex);
99
+ if (balance === undefined) {
100
+ balance = state.balances.get(builderIndex);
101
+ balanceAfterWithdrawals.set(builderIndex, balance);
106
102
  }
107
- if (isBuilderPaymentWithdrawable(stateGloas, withdrawal)) {
108
- const totalWithdrawn = withdrawnBalances.getOrDefault(withdrawal.builderIndex);
109
- const balance = state.balances.get(withdrawal.builderIndex) - totalWithdrawn;
110
- const builder = state.validators.get(withdrawal.builderIndex);
111
- let withdrawableBalance = 0;
112
- if (builder.slashed) {
113
- withdrawableBalance = balance < withdrawal.amount ? balance : withdrawal.amount;
114
- }
115
- else if (balance > MIN_ACTIVATION_BALANCE) {
116
- withdrawableBalance =
117
- balance - MIN_ACTIVATION_BALANCE < withdrawal.amount ? balance - MIN_ACTIVATION_BALANCE : withdrawal.amount;
118
- }
119
- if (withdrawableBalance > 0) {
120
- withdrawals.push({
121
- index: withdrawalIndex,
122
- validatorIndex: withdrawal.builderIndex,
123
- address: withdrawal.feeRecipient,
124
- amount: BigInt(withdrawableBalance),
125
- });
126
- withdrawalIndex++;
127
- withdrawnBalances.set(withdrawal.builderIndex, totalWithdrawn + withdrawableBalance);
128
- }
103
+ let withdrawableBalance = 0;
104
+ if (builder.slashed) {
105
+ withdrawableBalance = balance < withdrawal.amount ? balance : withdrawal.amount;
129
106
  }
130
- processedBuilderWithdrawalsCount++;
131
- }
132
- }
133
- if (isPostElectra) {
134
- // In pre-gloas, partialWithdrawalBound == MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP
135
- const partialWithdrawalBound = Math.min(withdrawals.length + MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP, MAX_WITHDRAWALS_PER_PAYLOAD - 1);
136
- const stateElectra = state;
137
- // MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP = 8, PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728 so we should only call getAllReadonly() if it makes sense
138
- // pendingPartialWithdrawals comes from EIP-7002 smart contract where it takes fee so it's more likely than not validator is in correct condition to withdraw
139
- // also we may break early if withdrawableEpoch > epoch
140
- const allPendingPartialWithdrawals = stateElectra.pendingPartialWithdrawals.length <= partialWithdrawalBound
141
- ? stateElectra.pendingPartialWithdrawals.getAllReadonly()
142
- : null;
143
- // EIP-7002: Execution layer triggerable withdrawals
144
- for (let i = 0; i < stateElectra.pendingPartialWithdrawals.length; i++) {
145
- const withdrawal = allPendingPartialWithdrawals
146
- ? allPendingPartialWithdrawals[i]
147
- : stateElectra.pendingPartialWithdrawals.getReadonly(i);
148
- if (withdrawal.withdrawableEpoch > epoch || withdrawals.length === partialWithdrawalBound) {
149
- break;
107
+ else if (balance > MIN_ACTIVATION_BALANCE) {
108
+ withdrawableBalance =
109
+ balance - MIN_ACTIVATION_BALANCE < withdrawal.amount ? balance - MIN_ACTIVATION_BALANCE : withdrawal.amount;
150
110
  }
151
- const validator = validators.getReadonly(withdrawal.validatorIndex);
152
- const totalWithdrawn = withdrawnBalances.getOrDefault(withdrawal.validatorIndex);
153
- const balance = state.balances.get(withdrawal.validatorIndex) - totalWithdrawn;
154
- if (validator.exitEpoch === FAR_FUTURE_EPOCH &&
155
- validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
156
- balance > MIN_ACTIVATION_BALANCE) {
157
- const balanceOverMinActivationBalance = BigInt(balance - MIN_ACTIVATION_BALANCE);
158
- const withdrawableBalance = balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
159
- withdrawals.push({
111
+ if (withdrawableBalance > 0) {
112
+ builderWithdrawals.push({
160
113
  index: withdrawalIndex,
161
- validatorIndex: withdrawal.validatorIndex,
162
- address: validator.withdrawalCredentials.subarray(12),
163
- amount: withdrawableBalance,
114
+ validatorIndex: withdrawal.builderIndex,
115
+ address: withdrawal.feeRecipient,
116
+ amount: BigInt(withdrawableBalance),
164
117
  });
165
118
  withdrawalIndex++;
166
- withdrawnBalances.set(withdrawal.validatorIndex, totalWithdrawn + Number(withdrawableBalance));
119
+ balanceAfterWithdrawals.set(builderIndex, balance - withdrawableBalance);
167
120
  }
168
- processedPartialWithdrawalsCount++;
169
121
  }
122
+ processedCount++;
170
123
  }
171
- const withdrawalBound = Math.min(validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
172
- let n = 0;
124
+ return { builderWithdrawals, withdrawalIndex, processedCount };
125
+ }
126
+ function getPendingPartialWithdrawals(state, withdrawalIndex, numPriorWithdrawal, balanceAfterWithdrawals) {
127
+ const epoch = state.epochCtx.epoch;
128
+ const pendingPartialWithdrawals = [];
129
+ const validators = state.validators;
130
+ // In pre-gloas, partialWithdrawalBound == MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP
131
+ const partialWithdrawalBound = Math.min(numPriorWithdrawal + MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP, MAX_WITHDRAWALS_PER_PAYLOAD - 1);
132
+ // MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP = 8, PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728 so we should only call getAllReadonly() if it makes sense
133
+ // pendingPartialWithdrawals comes from EIP-7002 smart contract where it takes fee so it's more likely than not validator is in correct condition to withdraw
134
+ // also we may break early if withdrawableEpoch > epoch
135
+ const allPendingPartialWithdrawals = state.pendingPartialWithdrawals.length <= partialWithdrawalBound
136
+ ? state.pendingPartialWithdrawals.getAllReadonly()
137
+ : null;
138
+ // EIP-7002: Execution layer triggerable withdrawals
139
+ let processedCount = 0;
140
+ for (let i = 0; i < state.pendingPartialWithdrawals.length; i++) {
141
+ const withdrawal = allPendingPartialWithdrawals
142
+ ? allPendingPartialWithdrawals[i]
143
+ : state.pendingPartialWithdrawals.getReadonly(i);
144
+ if (withdrawal.withdrawableEpoch > epoch ||
145
+ pendingPartialWithdrawals.length + numPriorWithdrawal === partialWithdrawalBound) {
146
+ break;
147
+ }
148
+ const validatorIndex = withdrawal.validatorIndex;
149
+ const validator = validators.getReadonly(validatorIndex);
150
+ let balance = balanceAfterWithdrawals.get(validatorIndex);
151
+ if (balance === undefined) {
152
+ balance = state.balances.get(validatorIndex);
153
+ balanceAfterWithdrawals.set(validatorIndex, balance);
154
+ }
155
+ if (validator.exitEpoch === FAR_FUTURE_EPOCH &&
156
+ validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
157
+ balance > MIN_ACTIVATION_BALANCE) {
158
+ const balanceOverMinActivationBalance = BigInt(balance - MIN_ACTIVATION_BALANCE);
159
+ const withdrawableBalance = balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
160
+ pendingPartialWithdrawals.push({
161
+ index: withdrawalIndex,
162
+ validatorIndex,
163
+ address: validator.withdrawalCredentials.subarray(12),
164
+ amount: withdrawableBalance,
165
+ });
166
+ withdrawalIndex++;
167
+ balanceAfterWithdrawals.set(validatorIndex, balance - Number(withdrawableBalance));
168
+ }
169
+ processedCount++;
170
+ }
171
+ return { pendingPartialWithdrawals, withdrawalIndex, processedCount };
172
+ }
173
+ function getValidatorsSweepWithdrawals(fork, state, withdrawalIndex, numPriorWithdrawal, balanceAfterWithdrawals) {
174
+ const sweepWithdrawals = [];
175
+ const epoch = state.epochCtx.epoch;
176
+ const { validators, balances, nextWithdrawalValidatorIndex } = state;
177
+ const isPostElectra = fork >= ForkSeq.electra;
178
+ const validatorsLimit = Math.min(state.validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
179
+ let processedCount = 0;
173
180
  // Just run a bounded loop max iterating over all withdrawals
174
181
  // however breaks out once we have MAX_WITHDRAWALS_PER_PAYLOAD
175
- for (n = 0; n < withdrawalBound; n++) {
182
+ for (let n = 0; n < validatorsLimit; n++) {
183
+ if (sweepWithdrawals.length + numPriorWithdrawal === MAX_WITHDRAWALS_PER_PAYLOAD) {
184
+ break;
185
+ }
176
186
  // Get next validator in turn
177
187
  const validatorIndex = (nextWithdrawalValidatorIndex + n) % validators.length;
178
188
  const validator = validators.getReadonly(validatorIndex);
179
- const withdrawnBalance = withdrawnBalances.getOrDefault(validatorIndex);
180
- const balance = isPostElectra
181
- ? // Deduct partially withdrawn balance already queued above
182
- balances.get(validatorIndex) - withdrawnBalance
183
- : balances.get(validatorIndex);
189
+ let balance = balanceAfterWithdrawals.get(validatorIndex);
190
+ if (balance === undefined) {
191
+ balance = balances.get(validatorIndex);
192
+ balanceAfterWithdrawals.set(validatorIndex, balance);
193
+ }
184
194
  const { withdrawableEpoch, withdrawalCredentials, effectiveBalance } = validator;
185
195
  const hasWithdrawableCredentials = isPostElectra
186
196
  ? hasExecutionWithdrawalCredential(withdrawalCredentials)
@@ -188,37 +198,74 @@ export function getExpectedWithdrawals(fork, state) {
188
198
  // early skip for balance = 0 as its now more likely that validator has exited/slashed with
189
199
  // balance zero than not have withdrawal credentials set
190
200
  if (balance === 0 || !hasWithdrawableCredentials) {
201
+ processedCount++;
191
202
  continue;
192
203
  }
193
204
  // capella full withdrawal
194
205
  if (withdrawableEpoch <= epoch) {
195
- withdrawals.push({
206
+ sweepWithdrawals.push({
196
207
  index: withdrawalIndex,
197
208
  validatorIndex,
198
209
  address: validator.withdrawalCredentials.subarray(12),
199
210
  amount: BigInt(balance),
200
211
  });
201
212
  withdrawalIndex++;
202
- withdrawnBalances.set(validatorIndex, withdrawnBalance + balance);
213
+ balanceAfterWithdrawals.set(validatorIndex, 0);
203
214
  }
204
215
  else if (effectiveBalance === (isPostElectra ? getMaxEffectiveBalance(withdrawalCredentials) : MAX_EFFECTIVE_BALANCE) &&
205
216
  balance > effectiveBalance) {
206
217
  // capella partial withdrawal
207
218
  const partialAmount = balance - effectiveBalance;
208
- withdrawals.push({
219
+ sweepWithdrawals.push({
209
220
  index: withdrawalIndex,
210
221
  validatorIndex,
211
222
  address: validator.withdrawalCredentials.subarray(12),
212
223
  amount: BigInt(partialAmount),
213
224
  });
214
225
  withdrawalIndex++;
215
- withdrawnBalances.set(validatorIndex, withdrawnBalance + partialAmount);
216
- }
217
- // Break if we have enough to pack the block
218
- if (withdrawals.length >= MAX_WITHDRAWALS_PER_PAYLOAD) {
219
- break;
226
+ balanceAfterWithdrawals.set(validatorIndex, balance - partialAmount);
220
227
  }
228
+ processedCount++;
229
+ }
230
+ return { sweepWithdrawals, processedCount };
231
+ }
232
+ function applyWithdrawals(state, withdrawals) {
233
+ for (const withdrawal of withdrawals) {
234
+ decreaseBalance(state, withdrawal.validatorIndex, Number(withdrawal.amount));
235
+ }
236
+ }
237
+ export function getExpectedWithdrawals(fork, state) {
238
+ if (fork < ForkSeq.capella) {
239
+ throw new Error(`getExpectedWithdrawals not supported at forkSeq=${fork} < ForkSeq.capella`);
240
+ }
241
+ let withdrawalIndex = state.nextWithdrawalIndex;
242
+ const expectedWithdrawals = [];
243
+ // Map to track balances after applying withdrawals
244
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-get_balance_after_withdrawals
245
+ const balanceAfterWithdrawals = new Map();
246
+ // partialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
247
+ let processedPartialWithdrawalsCount = 0;
248
+ // builderWithdrawalsCount is withdrawals coming from builder payments since Gloas (EIP-7732)
249
+ let processedBuilderWithdrawalsCount = 0;
250
+ if (fork >= ForkSeq.gloas) {
251
+ const { builderWithdrawals, withdrawalIndex: newWithdrawalIndex, processedCount, } = getBuilderWithdrawals(state, withdrawalIndex, balanceAfterWithdrawals);
252
+ expectedWithdrawals.push(...builderWithdrawals);
253
+ withdrawalIndex = newWithdrawalIndex;
254
+ processedBuilderWithdrawalsCount = processedCount;
255
+ }
256
+ if (fork >= ForkSeq.electra) {
257
+ const { pendingPartialWithdrawals, withdrawalIndex: newWithdrawalIndex, processedCount, } = getPendingPartialWithdrawals(state, withdrawalIndex, expectedWithdrawals.length, balanceAfterWithdrawals);
258
+ expectedWithdrawals.push(...pendingPartialWithdrawals);
259
+ withdrawalIndex = newWithdrawalIndex;
260
+ processedPartialWithdrawalsCount = processedCount;
221
261
  }
222
- return { withdrawals, sampledValidators: n, processedPartialWithdrawalsCount, processedBuilderWithdrawalsCount };
262
+ const { sweepWithdrawals, processedCount: processedValidatorSweepCount } = getValidatorsSweepWithdrawals(fork, state, withdrawalIndex, expectedWithdrawals.length, balanceAfterWithdrawals);
263
+ expectedWithdrawals.push(...sweepWithdrawals);
264
+ return {
265
+ expectedWithdrawals,
266
+ processedBuilderWithdrawalsCount,
267
+ processedPartialWithdrawalsCount,
268
+ processedValidatorSweepCount,
269
+ };
223
270
  }
224
271
  //# sourceMappingURL=processWithdrawals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processWithdrawals.js","sourceRoot":"","sources":["../../src/block/processWithdrawals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,gBAAgB,E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IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;IAE9C,OAAO;QACL,mBAAmB;QACnB,gCAAgC;QAChC,gCAAgC;QAChC,4BAA4B;KAC7B,CAAC;AACJ,CAAC"}
@@ -1,10 +1,9 @@
1
1
  import { BeaconConfig } from "@lodestar/config";
2
- import { SignedBeaconBlock, SignedBlindedBeaconBlock, phase0 } from "@lodestar/types";
2
+ import { SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, phase0 } from "@lodestar/types";
3
3
  import { Index2PubkeyCache } from "../cache/pubkeyCache.js";
4
- import { CachedBeaconStateAllForks } from "../types.js";
5
4
  import { ISignatureSet } from "../util/signatureSets.js";
6
5
  export declare function verifyProposerSignature(config: BeaconConfig, index2pubkey: Index2PubkeyCache, signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock): boolean;
7
6
  export declare function getBlockProposerSignatureSet(config: BeaconConfig, index2pubkey: Index2PubkeyCache, signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock): ISignatureSet;
8
- export declare function getBlockHeaderProposerSignatureSetByParentStateSlot(index2pubkey: Index2PubkeyCache, parentState: CachedBeaconStateAllForks, signedBlockHeader: phase0.SignedBeaconBlockHeader): ISignatureSet;
9
- export declare function getBlockHeaderProposerSignatureSetByHeaderSlot(index2pubkey: Index2PubkeyCache, headState: CachedBeaconStateAllForks, signedBlockHeader: phase0.SignedBeaconBlockHeader): ISignatureSet;
7
+ export declare function getBlockHeaderProposerSignatureSetByParentStateSlot(config: BeaconConfig, index2pubkey: Index2PubkeyCache, parentStateSlot: Slot, signedBlockHeader: phase0.SignedBeaconBlockHeader): ISignatureSet;
8
+ export declare function getBlockHeaderProposerSignatureSetByHeaderSlot(config: BeaconConfig, index2pubkey: Index2PubkeyCache, signedBlockHeader: phase0.SignedBeaconBlockHeader): ISignatureSet;
10
9
  //# sourceMappingURL=proposer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proposer.d.ts","sourceRoot":"","sources":["../../src/signatureSets/propos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AiB,EAC/B,WAAW,EAAE,iBAAiB,GAAG,wBAAwB,GACxD,OAAO,CAGT;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,iBAAiB,EAC/B,WAAW,EAAE,iBAAiB,GAAG,wBAAwB,GACxD,aAAa,CAgBf;AAED,wBAAgB,mDAAmD,CACjE,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,iBAAiB,EAC/B,eAAe,EAAE,IAAI,EACrB,iBAAiB,EAAE,MAAM,CAAC,uBAAuB,iBAGlD;AAED,wBAAgB,8CAA8C,CAC5D,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,iBAAiB,EAC/B,iBAAiB,EAAE,MAAM,CAAC,uBAAuB,iBAGlD"}
@@ -21,14 +21,13 @@ export function getBlockProposerSignatureSet(config, index2pubkey, signedBlock)
21
21
  signature: signedBlock.signature,
22
22
  };
23
23
  }
24
- export function getBlockHeaderProposerSignatureSetByParentStateSlot(index2pubkey, parentState, signedBlockHeader) {
25
- return getBlockHeaderProposerSignatureSet(index2pubkey, parentState, signedBlockHeader, parentState.slot);
24
+ export function getBlockHeaderProposerSignatureSetByParentStateSlot(config, index2pubkey, parentStateSlot, signedBlockHeader) {
25
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, parentStateSlot);
26
26
  }
27
- export function getBlockHeaderProposerSignatureSetByHeaderSlot(index2pubkey, headState, signedBlockHeader) {
28
- return getBlockHeaderProposerSignatureSet(index2pubkey, headState, signedBlockHeader, signedBlockHeader.message.slot);
27
+ export function getBlockHeaderProposerSignatureSetByHeaderSlot(config, index2pubkey, signedBlockHeader) {
28
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, signedBlockHeader.message.slot);
29
29
  }
30
- function getBlockHeaderProposerSignatureSet(index2pubkey, state, signedBlockHeader, domainSlot) {
31
- const { config } = state;
30
+ function getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, domainSlot) {
32
31
  const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
33
32
  return {
34
33
  type: SignatureSetType.single,
@@ -1 +1 @@
1
- {"version":3,"file":"proposer.js","sourceRoot":"","sources":["../../src/signatureSets/proposer.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAoD,oBAAoB,EAAU,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAGrH,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAgB,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAE7F,MAAM,UAAU,uBAAuB,CACrC,MAAoB,EACpB,YAA+B,EAC/B,WAAyD;IAEzD,MAAM,YAAY,GAAG,4BAA4B,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IACrF,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,MAAoB,EACpB,YAA+B,EAC/B,WAAyD;IAEzD,oHAAoH;IACpH,0GAA0G;IAC1G,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAC;IAE9E,MAAM,SAAS,GAAG,oBAAoB,CAAC,WAAW,CAAC,OAAO,CAAC;QACzD,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,kBAAkB;QAC/E,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC;IAE9D,OAAO;QACL,IAAI,EAAE,gBAAgB,CAAC,MAAM;QAC7B,MAAM,EAAE,YAAY,CAAC,WAAW,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AAkC,CAAC,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,8CAA8C,CAC5D,MAAoB,EACpB,YAA+B,EAC/B,iBAAiD;IAEjD,OAAO,kCAAkC,CAAC,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACrH,CAAC;AAED,SAAS,kCAAkC,CACzC,MAAoB,EACpB,YAA+B,EAC/B,iBAAiD,EACjD,UAAgB;IAEhB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,sBAAsB,EAAE,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpG,OAAO;QACL,IAAI,EAAE,gBAAgB,CAAC,MAAM;QAC7B,MAAM,EAAE,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,aAAa,CAAC;QAC7D,WAAW,EAAE,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC;QAChG,SAAS,EAAE,iBAAiB,CAAC,SAAS;KACvC,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.39.0-dev.86298a43e6",
14
+ "version": "1.39.0-dev.95389042f8",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -43,15 +43,15 @@
43
43
  "scripts": {
44
44
  "clean": "rm -rf lib && rm -f *.tsbuildinfo",
45
45
  "build": "tsc -p tsconfig.build.json",
46
- "build:watch": "yarn run build --watch",
47
- "build:release": "yarn clean && yarn build",
46
+ "build:watch": "pnpm run build --watch",
47
+ "build:release": "pnpm clean && pnpm build",
48
48
  "check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"",
49
49
  "check-types": "tsc",
50
50
  "lint": "biome check src/ test/",
51
- "lint:fix": "yarn run lint --write",
52
- "test": "yarn test:unit",
51
+ "lint:fix": "pnpm run lint --write",
52
+ "test": "pnpm test:unit",
53
53
  "test:unit": "vitest run --project unit --project unit-minimal",
54
- "check-readme": "typescript-docs-verifier"
54
+ "check-readme": "pnpm exec ts-node ../../scripts/check_readme.ts"
55
55
  },
56
56
  "types": "lib/index.d.ts",
57
57
  "dependencies": {
@@ -62,17 +62,20 @@
62
62
  "@chainsafe/pubkey-index-map": "^3.0.0",
63
63
  "@chainsafe/ssz": "^1.2.2",
64
64
  "@chainsafe/swap-or-not-shuffle": "^1.2.1",
65
- "@lodestar/config": "1.39.0-dev.86298a43e6",
66
- "@lodestar/params": "1.39.0-dev.86298a43e6",
67
- "@lodestar/types": "1.39.0-dev.86298a43e6",
68
- "@lodestar/utils": "1.39.0-dev.86298a43e6",
65
+ "@lodestar/config": "^1.39.0-dev.95389042f8",
66
+ "@lodestar/params": "^1.39.0-dev.95389042f8",
67
+ "@lodestar/types": "^1.39.0-dev.95389042f8",
68
+ "@lodestar/utils": "^1.39.0-dev.95389042f8",
69
69
  "bigint-buffer": "^1.1.5"
70
70
  },
71
+ "devDependencies": {
72
+ "@lodestar/api": "^1.39.0-dev.95389042f8"
73
+ },
71
74
  "keywords": [
72
75
  "ethereum",
73
76
  "eth-consensus",
74
77
  "beacon",
75
78
  "blockchain"
76
79
  ],
77
- "gitHead": "55dd258fb9d9a8eaad756c34d331ebe0ab71995f"
80
+ "gitHead": "91cd15e1cf60dd7d4fca43db6d92caf78ab64b17"
78
81
  }
@@ -9,7 +9,7 @@ import {
9
9
  MIN_ACTIVATION_BALANCE,
10
10
  } from "@lodestar/params";
11
11
  import {ValidatorIndex, capella, ssz} from "@lodestar/types";
12
- import {MapDef, toRootHex} from "@lodestar/utils";
12
+ import {toRootHex} from "@lodestar/utils";
13
13
  import {CachedBeaconStateCapella, CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
14
14
  import {isBuilderPaymentWithdrawable, isParentBlockFull} from "../util/gloas.ts";
15
15
  import {
@@ -30,13 +30,11 @@ export function processWithdrawals(
30
30
  return;
31
31
  }
32
32
 
33
- // processedPartialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
34
33
  // processedBuilderWithdrawalsCount is withdrawals coming from builder payment since gloas (EIP-7732)
35
- const {
36
- withdrawals: expectedWithdrawals,
37
- processedPartialWithdrawalsCount,
38
- processedBuilderWithdrawalsCount,
39
- } = getExpectedWithdrawals(fork, state);
34
+ // processedPartialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
35
+ // processedValidatorSweepCount is withdrawals coming from validator sweep
36
+ const {expectedWithdrawals, processedBuilderWithdrawalsCount, processedPartialWithdrawalsCount} =
37
+ getExpectedWithdrawals(fork, state);
40
38
  const numWithdrawals = expectedWithdrawals.length;
41
39
 
42
40
  // After gloas, withdrawals are verified later in processExecutionPayloadEnvelope
@@ -68,12 +66,10 @@ export function processWithdrawals(
68
66
  }
69
67
  }
70
68
 
71
- for (let i = 0; i < numWithdrawals; i++) {
72
- const withdrawal = expectedWithdrawals[i];
73
- decreaseBalance(state, withdrawal.validatorIndex, Number(withdrawal.amount));
74
- }
69
+ applyWithdrawals(state, expectedWithdrawals);
75
70
 
76
71
  if (fork >= ForkSeq.electra) {
72
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/electra/beacon-chain.md#new-update_pending_partial_withdrawals
77
73
  const stateElectra = state as CachedBeaconStateElectra;
78
74
  stateElectra.pendingPartialWithdrawals = stateElectra.pendingPartialWithdrawals.sliceFrom(
79
75
  processedPartialWithdrawalsCount
@@ -97,13 +93,14 @@ export function processWithdrawals(
97
93
  ...remainingWithdrawals,
98
94
  ]);
99
95
  }
100
-
101
96
  // Update the nextWithdrawalIndex
97
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-update_next_withdrawal_index
102
98
  const latestWithdrawal = expectedWithdrawals.at(-1);
103
99
  if (latestWithdrawal) {
104
100
  state.nextWithdrawalIndex = latestWithdrawal.index + 1;
105
101
  }
106
102
 
103
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-update_next_withdrawal_validator_index
107
104
  // Update the nextWithdrawalValidatorIndex
108
105
  if (latestWithdrawal && expectedWithdrawals.length === MAX_WITHDRAWALS_PER_PAYLOAD) {
109
106
  // All slots filled, nextWithdrawalValidatorIndex should be validatorIndex having next turn
@@ -116,142 +113,163 @@ export function processWithdrawals(
116
113
  }
117
114
  }
118
115
 
119
- export function getExpectedWithdrawals(
120
- fork: ForkSeq,
121
- state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas
122
- ): {
123
- withdrawals: capella.Withdrawal[];
124
- sampledValidators: number;
125
- processedPartialWithdrawalsCount: number;
126
- processedBuilderWithdrawalsCount: number;
127
- } {
128
- if (fork < ForkSeq.capella) {
129
- throw new Error(`getExpectedWithdrawals not supported at forkSeq=${fork} < ForkSeq.capella`);
130
- }
131
-
116
+ function getBuilderWithdrawals(
117
+ state: CachedBeaconStateGloas,
118
+ withdrawalIndex: number,
119
+ balanceAfterWithdrawals: Map<ValidatorIndex, number>
120
+ ): {builderWithdrawals: capella.Withdrawal[]; withdrawalIndex: number; processedCount: number} {
121
+ const builderWithdrawals: capella.Withdrawal[] = [];
132
122
  const epoch = state.epochCtx.epoch;
133
- let withdrawalIndex = state.nextWithdrawalIndex;
134
- const {validators, balances, nextWithdrawalValidatorIndex} = state;
135
-
136
- const withdrawals: capella.Withdrawal[] = [];
137
- const withdrawnBalances = new MapDef<ValidatorIndex, number>(() => 0);
138
- const isPostElectra = fork >= ForkSeq.electra;
139
- const isPostGloas = fork >= ForkSeq.gloas;
140
- // partialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
141
- let processedPartialWithdrawalsCount = 0;
142
- // builderWithdrawalsCount is withdrawals coming from builder payments since Gloas (EIP-7732)
143
- let processedBuilderWithdrawalsCount = 0;
144
-
145
- if (isPostGloas) {
146
- const stateGloas = state as CachedBeaconStateGloas;
147
-
148
- const allBuilderPendingWithdrawals =
149
- stateGloas.builderPendingWithdrawals.length <= MAX_WITHDRAWALS_PER_PAYLOAD
150
- ? stateGloas.builderPendingWithdrawals.getAllReadonly()
151
- : null;
123
+ const allBuilderPendingWithdrawals =
124
+ state.builderPendingWithdrawals.length <= MAX_WITHDRAWALS_PER_PAYLOAD
125
+ ? state.builderPendingWithdrawals.getAllReadonly()
126
+ : null;
127
+
128
+ let processedCount = 0;
129
+ for (let i = 0; i < state.builderPendingWithdrawals.length; i++) {
130
+ const withdrawal = allBuilderPendingWithdrawals
131
+ ? allBuilderPendingWithdrawals[i]
132
+ : state.builderPendingWithdrawals.getReadonly(i);
133
+
134
+ if (withdrawal.withdrawableEpoch > epoch || builderWithdrawals.length === MAX_WITHDRAWALS_PER_PAYLOAD) {
135
+ break;
136
+ }
152
137
 
153
- for (let i = 0; i < stateGloas.builderPendingWithdrawals.length; i++) {
154
- const withdrawal = allBuilderPendingWithdrawals
155
- ? allBuilderPendingWithdrawals[i]
156
- : stateGloas.builderPendingWithdrawals.getReadonly(i);
138
+ if (isBuilderPaymentWithdrawable(state, withdrawal)) {
139
+ const builderIndex = withdrawal.builderIndex;
140
+ const builder = state.validators.get(withdrawal.builderIndex);
157
141
 
158
- if (withdrawal.withdrawableEpoch > epoch || withdrawals.length + 1 === MAX_WITHDRAWALS_PER_PAYLOAD) {
159
- break;
142
+ let balance = balanceAfterWithdrawals.get(builderIndex);
143
+ if (balance === undefined) {
144
+ balance = state.balances.get(builderIndex);
145
+ balanceAfterWithdrawals.set(builderIndex, balance);
160
146
  }
161
147
 
162
- if (isBuilderPaymentWithdrawable(stateGloas, withdrawal)) {
163
- const totalWithdrawn = withdrawnBalances.getOrDefault(withdrawal.builderIndex);
164
- const balance = state.balances.get(withdrawal.builderIndex) - totalWithdrawn;
165
- const builder = state.validators.get(withdrawal.builderIndex);
166
-
167
- let withdrawableBalance = 0;
148
+ let withdrawableBalance = 0;
168
149
 
169
- if (builder.slashed) {
170
- withdrawableBalance = balance < withdrawal.amount ? balance : withdrawal.amount;
171
- } else if (balance > MIN_ACTIVATION_BALANCE) {
172
- withdrawableBalance =
173
- balance - MIN_ACTIVATION_BALANCE < withdrawal.amount ? balance - MIN_ACTIVATION_BALANCE : withdrawal.amount;
174
- }
150
+ if (builder.slashed) {
151
+ withdrawableBalance = balance < withdrawal.amount ? balance : withdrawal.amount;
152
+ } else if (balance > MIN_ACTIVATION_BALANCE) {
153
+ withdrawableBalance =
154
+ balance - MIN_ACTIVATION_BALANCE < withdrawal.amount ? balance - MIN_ACTIVATION_BALANCE : withdrawal.amount;
155
+ }
175
156
 
176
- if (withdrawableBalance > 0) {
177
- withdrawals.push({
178
- index: withdrawalIndex,
179
- validatorIndex: withdrawal.builderIndex,
180
- address: withdrawal.feeRecipient,
181
- amount: BigInt(withdrawableBalance),
182
- });
183
- withdrawalIndex++;
184
- withdrawnBalances.set(withdrawal.builderIndex, totalWithdrawn + withdrawableBalance);
185
- }
157
+ if (withdrawableBalance > 0) {
158
+ builderWithdrawals.push({
159
+ index: withdrawalIndex,
160
+ validatorIndex: withdrawal.builderIndex,
161
+ address: withdrawal.feeRecipient,
162
+ amount: BigInt(withdrawableBalance),
163
+ });
164
+ withdrawalIndex++;
165
+ balanceAfterWithdrawals.set(builderIndex, balance - withdrawableBalance);
186
166
  }
187
- processedBuilderWithdrawalsCount++;
188
167
  }
168
+ processedCount++;
189
169
  }
190
170
 
191
- if (isPostElectra) {
192
- // In pre-gloas, partialWithdrawalBound == MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP
193
- const partialWithdrawalBound = Math.min(
194
- withdrawals.length + MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
195
- MAX_WITHDRAWALS_PER_PAYLOAD - 1
196
- );
197
- const stateElectra = state as CachedBeaconStateElectra;
171
+ return {builderWithdrawals, withdrawalIndex, processedCount};
172
+ }
198
173
 
199
- // MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP = 8, PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728 so we should only call getAllReadonly() if it makes sense
200
- // pendingPartialWithdrawals comes from EIP-7002 smart contract where it takes fee so it's more likely than not validator is in correct condition to withdraw
201
- // also we may break early if withdrawableEpoch > epoch
202
- const allPendingPartialWithdrawals =
203
- stateElectra.pendingPartialWithdrawals.length <= partialWithdrawalBound
204
- ? stateElectra.pendingPartialWithdrawals.getAllReadonly()
205
- : null;
206
-
207
- // EIP-7002: Execution layer triggerable withdrawals
208
- for (let i = 0; i < stateElectra.pendingPartialWithdrawals.length; i++) {
209
- const withdrawal = allPendingPartialWithdrawals
210
- ? allPendingPartialWithdrawals[i]
211
- : stateElectra.pendingPartialWithdrawals.getReadonly(i);
212
- if (withdrawal.withdrawableEpoch > epoch || withdrawals.length === partialWithdrawalBound) {
213
- break;
214
- }
174
+ function getPendingPartialWithdrawals(
175
+ state: CachedBeaconStateElectra,
176
+ withdrawalIndex: number,
177
+ numPriorWithdrawal: number,
178
+ balanceAfterWithdrawals: Map<ValidatorIndex, number>
179
+ ): {pendingPartialWithdrawals: capella.Withdrawal[]; withdrawalIndex: number; processedCount: number} {
180
+ const epoch = state.epochCtx.epoch;
181
+ const pendingPartialWithdrawals: capella.Withdrawal[] = [];
182
+ const validators = state.validators;
183
+
184
+ // In pre-gloas, partialWithdrawalBound == MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP
185
+ const partialWithdrawalBound = Math.min(
186
+ numPriorWithdrawal + MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
187
+ MAX_WITHDRAWALS_PER_PAYLOAD - 1
188
+ );
189
+
190
+ // MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP = 8, PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728 so we should only call getAllReadonly() if it makes sense
191
+ // pendingPartialWithdrawals comes from EIP-7002 smart contract where it takes fee so it's more likely than not validator is in correct condition to withdraw
192
+ // also we may break early if withdrawableEpoch > epoch
193
+ const allPendingPartialWithdrawals =
194
+ state.pendingPartialWithdrawals.length <= partialWithdrawalBound
195
+ ? state.pendingPartialWithdrawals.getAllReadonly()
196
+ : null;
197
+
198
+ // EIP-7002: Execution layer triggerable withdrawals
199
+ let processedCount = 0;
200
+ for (let i = 0; i < state.pendingPartialWithdrawals.length; i++) {
201
+ const withdrawal = allPendingPartialWithdrawals
202
+ ? allPendingPartialWithdrawals[i]
203
+ : state.pendingPartialWithdrawals.getReadonly(i);
204
+ if (
205
+ withdrawal.withdrawableEpoch > epoch ||
206
+ pendingPartialWithdrawals.length + numPriorWithdrawal === partialWithdrawalBound
207
+ ) {
208
+ break;
209
+ }
215
210
 
216
- const validator = validators.getReadonly(withdrawal.validatorIndex);
217
- const totalWithdrawn = withdrawnBalances.getOrDefault(withdrawal.validatorIndex);
218
- const balance = state.balances.get(withdrawal.validatorIndex) - totalWithdrawn;
219
-
220
- if (
221
- validator.exitEpoch === FAR_FUTURE_EPOCH &&
222
- validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
223
- balance > MIN_ACTIVATION_BALANCE
224
- ) {
225
- const balanceOverMinActivationBalance = BigInt(balance - MIN_ACTIVATION_BALANCE);
226
- const withdrawableBalance =
227
- balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
228
- withdrawals.push({
229
- index: withdrawalIndex,
230
- validatorIndex: withdrawal.validatorIndex,
231
- address: validator.withdrawalCredentials.subarray(12),
232
- amount: withdrawableBalance,
233
- });
234
- withdrawalIndex++;
235
- withdrawnBalances.set(withdrawal.validatorIndex, totalWithdrawn + Number(withdrawableBalance));
236
- }
237
- processedPartialWithdrawalsCount++;
211
+ const validatorIndex = withdrawal.validatorIndex;
212
+ const validator = validators.getReadonly(validatorIndex);
213
+ let balance = balanceAfterWithdrawals.get(validatorIndex);
214
+ if (balance === undefined) {
215
+ balance = state.balances.get(validatorIndex);
216
+ balanceAfterWithdrawals.set(validatorIndex, balance);
238
217
  }
218
+
219
+ if (
220
+ validator.exitEpoch === FAR_FUTURE_EPOCH &&
221
+ validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
222
+ balance > MIN_ACTIVATION_BALANCE
223
+ ) {
224
+ const balanceOverMinActivationBalance = BigInt(balance - MIN_ACTIVATION_BALANCE);
225
+ const withdrawableBalance =
226
+ balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
227
+ pendingPartialWithdrawals.push({
228
+ index: withdrawalIndex,
229
+ validatorIndex,
230
+ address: validator.withdrawalCredentials.subarray(12),
231
+ amount: withdrawableBalance,
232
+ });
233
+ withdrawalIndex++;
234
+ balanceAfterWithdrawals.set(validatorIndex, balance - Number(withdrawableBalance));
235
+ }
236
+ processedCount++;
239
237
  }
240
238
 
241
- const withdrawalBound = Math.min(validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
242
- let n = 0;
239
+ return {pendingPartialWithdrawals, withdrawalIndex, processedCount};
240
+ }
241
+
242
+ function getValidatorsSweepWithdrawals(
243
+ fork: ForkSeq,
244
+ state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas,
245
+ withdrawalIndex: number,
246
+ numPriorWithdrawal: number,
247
+ balanceAfterWithdrawals: Map<ValidatorIndex, number>
248
+ ): {sweepWithdrawals: capella.Withdrawal[]; processedCount: number} {
249
+ const sweepWithdrawals: capella.Withdrawal[] = [];
250
+ const epoch = state.epochCtx.epoch;
251
+ const {validators, balances, nextWithdrawalValidatorIndex} = state;
252
+ const isPostElectra = fork >= ForkSeq.electra;
253
+
254
+ const validatorsLimit = Math.min(state.validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
255
+ let processedCount = 0;
243
256
  // Just run a bounded loop max iterating over all withdrawals
244
257
  // however breaks out once we have MAX_WITHDRAWALS_PER_PAYLOAD
245
- for (n = 0; n < withdrawalBound; n++) {
258
+ for (let n = 0; n < validatorsLimit; n++) {
259
+ if (sweepWithdrawals.length + numPriorWithdrawal === MAX_WITHDRAWALS_PER_PAYLOAD) {
260
+ break;
261
+ }
262
+
246
263
  // Get next validator in turn
247
264
  const validatorIndex = (nextWithdrawalValidatorIndex + n) % validators.length;
248
265
 
249
266
  const validator = validators.getReadonly(validatorIndex);
250
- const withdrawnBalance = withdrawnBalances.getOrDefault(validatorIndex);
251
- const balance = isPostElectra
252
- ? // Deduct partially withdrawn balance already queued above
253
- balances.get(validatorIndex) - withdrawnBalance
254
- : balances.get(validatorIndex);
267
+ let balance = balanceAfterWithdrawals.get(validatorIndex);
268
+ if (balance === undefined) {
269
+ balance = balances.get(validatorIndex);
270
+ balanceAfterWithdrawals.set(validatorIndex, balance);
271
+ }
272
+
255
273
  const {withdrawableEpoch, withdrawalCredentials, effectiveBalance} = validator;
256
274
  const hasWithdrawableCredentials = isPostElectra
257
275
  ? hasExecutionWithdrawalCredential(withdrawalCredentials)
@@ -259,40 +277,117 @@ export function getExpectedWithdrawals(
259
277
  // early skip for balance = 0 as its now more likely that validator has exited/slashed with
260
278
  // balance zero than not have withdrawal credentials set
261
279
  if (balance === 0 || !hasWithdrawableCredentials) {
280
+ processedCount++;
262
281
  continue;
263
282
  }
264
283
 
265
284
  // capella full withdrawal
266
285
  if (withdrawableEpoch <= epoch) {
267
- withdrawals.push({
286
+ sweepWithdrawals.push({
268
287
  index: withdrawalIndex,
269
288
  validatorIndex,
270
289
  address: validator.withdrawalCredentials.subarray(12),
271
290
  amount: BigInt(balance),
272
291
  });
273
292
  withdrawalIndex++;
274
- withdrawnBalances.set(validatorIndex, withdrawnBalance + balance);
293
+ balanceAfterWithdrawals.set(validatorIndex, 0);
275
294
  } else if (
276
295
  effectiveBalance === (isPostElectra ? getMaxEffectiveBalance(withdrawalCredentials) : MAX_EFFECTIVE_BALANCE) &&
277
296
  balance > effectiveBalance
278
297
  ) {
279
298
  // capella partial withdrawal
280
299
  const partialAmount = balance - effectiveBalance;
281
- withdrawals.push({
300
+ sweepWithdrawals.push({
282
301
  index: withdrawalIndex,
283
302
  validatorIndex,
284
303
  address: validator.withdrawalCredentials.subarray(12),
285
304
  amount: BigInt(partialAmount),
286
305
  });
287
306
  withdrawalIndex++;
288
- withdrawnBalances.set(validatorIndex, withdrawnBalance + partialAmount);
307
+ balanceAfterWithdrawals.set(validatorIndex, balance - partialAmount);
289
308
  }
309
+ processedCount++;
310
+ }
290
311
 
291
- // Break if we have enough to pack the block
292
- if (withdrawals.length >= MAX_WITHDRAWALS_PER_PAYLOAD) {
293
- break;
294
- }
312
+ return {sweepWithdrawals, processedCount};
313
+ }
314
+
315
+ function applyWithdrawals(
316
+ state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas,
317
+ withdrawals: capella.Withdrawal[]
318
+ ): void {
319
+ for (const withdrawal of withdrawals) {
320
+ decreaseBalance(state, withdrawal.validatorIndex, Number(withdrawal.amount));
295
321
  }
322
+ }
296
323
 
297
- return {withdrawals, sampledValidators: n, processedPartialWithdrawalsCount, processedBuilderWithdrawalsCount};
324
+ export function getExpectedWithdrawals(
325
+ fork: ForkSeq,
326
+ state: CachedBeaconStateCapella | CachedBeaconStateElectra | CachedBeaconStateGloas
327
+ ): {
328
+ expectedWithdrawals: capella.Withdrawal[];
329
+ processedBuilderWithdrawalsCount: number;
330
+ processedPartialWithdrawalsCount: number;
331
+ processedValidatorSweepCount: number;
332
+ } {
333
+ if (fork < ForkSeq.capella) {
334
+ throw new Error(`getExpectedWithdrawals not supported at forkSeq=${fork} < ForkSeq.capella`);
335
+ }
336
+
337
+ let withdrawalIndex = state.nextWithdrawalIndex;
338
+
339
+ const expectedWithdrawals: capella.Withdrawal[] = [];
340
+ // Map to track balances after applying withdrawals
341
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.0/specs/capella/beacon-chain.md#new-get_balance_after_withdrawals
342
+ const balanceAfterWithdrawals = new Map<ValidatorIndex, number>();
343
+ // partialWithdrawalsCount is withdrawals coming from EL since electra (EIP-7002)
344
+ let processedPartialWithdrawalsCount = 0;
345
+ // builderWithdrawalsCount is withdrawals coming from builder payments since Gloas (EIP-7732)
346
+ let processedBuilderWithdrawalsCount = 0;
347
+
348
+ if (fork >= ForkSeq.gloas) {
349
+ const {
350
+ builderWithdrawals,
351
+ withdrawalIndex: newWithdrawalIndex,
352
+ processedCount,
353
+ } = getBuilderWithdrawals(state as CachedBeaconStateGloas, withdrawalIndex, balanceAfterWithdrawals);
354
+
355
+ expectedWithdrawals.push(...builderWithdrawals);
356
+ withdrawalIndex = newWithdrawalIndex;
357
+ processedBuilderWithdrawalsCount = processedCount;
358
+ }
359
+
360
+ if (fork >= ForkSeq.electra) {
361
+ const {
362
+ pendingPartialWithdrawals,
363
+ withdrawalIndex: newWithdrawalIndex,
364
+ processedCount,
365
+ } = getPendingPartialWithdrawals(
366
+ state as CachedBeaconStateElectra,
367
+ withdrawalIndex,
368
+ expectedWithdrawals.length,
369
+ balanceAfterWithdrawals
370
+ );
371
+
372
+ expectedWithdrawals.push(...pendingPartialWithdrawals);
373
+ withdrawalIndex = newWithdrawalIndex;
374
+ processedPartialWithdrawalsCount = processedCount;
375
+ }
376
+
377
+ const {sweepWithdrawals, processedCount: processedValidatorSweepCount} = getValidatorsSweepWithdrawals(
378
+ fork,
379
+ state,
380
+ withdrawalIndex,
381
+ expectedWithdrawals.length,
382
+ balanceAfterWithdrawals
383
+ );
384
+
385
+ expectedWithdrawals.push(...sweepWithdrawals);
386
+
387
+ return {
388
+ expectedWithdrawals,
389
+ processedBuilderWithdrawalsCount,
390
+ processedPartialWithdrawalsCount,
391
+ processedValidatorSweepCount,
392
+ };
298
393
  }
@@ -2,7 +2,6 @@ import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
3
3
  import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
4
4
  import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
- import {CachedBeaconStateAllForks} from "../types.js";
6
5
  import {computeSigningRoot} from "../util/index.js";
7
6
  import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
8
7
 
@@ -38,28 +37,28 @@ export function getBlockProposerSignatureSet(
38
37
  }
39
38
 
40
39
  export function getBlockHeaderProposerSignatureSetByParentStateSlot(
40
+ config: BeaconConfig,
41
41
  index2pubkey: Index2PubkeyCache,
42
- parentState: CachedBeaconStateAllForks,
42
+ parentStateSlot: Slot,
43
43
  signedBlockHeader: phase0.SignedBeaconBlockHeader
44
44
  ) {
45
- return getBlockHeaderProposerSignatureSet(index2pubkey, parentState, signedBlockHeader, parentState.slot);
45
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, parentStateSlot);
46
46
  }
47
47
 
48
48
  export function getBlockHeaderProposerSignatureSetByHeaderSlot(
49
+ config: BeaconConfig,
49
50
  index2pubkey: Index2PubkeyCache,
50
- headState: CachedBeaconStateAllForks,
51
51
  signedBlockHeader: phase0.SignedBeaconBlockHeader
52
52
  ) {
53
- return getBlockHeaderProposerSignatureSet(index2pubkey, headState, signedBlockHeader, signedBlockHeader.message.slot);
53
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, signedBlockHeader.message.slot);
54
54
  }
55
55
 
56
56
  function getBlockHeaderProposerSignatureSet(
57
+ config: BeaconConfig,
57
58
  index2pubkey: Index2PubkeyCache,
58
- state: CachedBeaconStateAllForks,
59
59
  signedBlockHeader: phase0.SignedBeaconBlockHeader,
60
60
  domainSlot: Slot
61
61
  ): ISignatureSet {
62
- const {config} = state;
63
62
  const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
64
63
 
65
64
  return {