Skip to content

Commit 7df1ce3

Browse files
authored
Merge pull request #3818 from mkalinin/deposit-queue
eip6110: Queue deposit requests and apply them during epoch processing
2 parents 233afd5 + ad42273 commit 7df1ce3

File tree

25 files changed

+1519
-712
lines changed

25 files changed

+1519
-712
lines changed

presets/mainnet/electra.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000
1010
# State list lengths
1111
# ---------------------------------------------------------------
1212
# `uint64(2**27)` (= 134,217,728)
13-
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
13+
PENDING_DEPOSITS_LIMIT: 134217728
1414
# `uint64(2**27)` (= 134,217,728)
1515
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728
1616
# `uint64(2**18)` (= 262,144)
@@ -43,3 +43,8 @@ MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16
4343
# ---------------------------------------------------------------
4444
# 2**3 ( = 8) pending withdrawals
4545
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8
46+
47+
# Pending deposits processing
48+
# ---------------------------------------------------------------
49+
# 2**4 ( = 4) pending deposits
50+
MAX_PENDING_DEPOSITS_PER_EPOCH: 16

presets/minimal/electra.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000
1010
# State list lengths
1111
# ---------------------------------------------------------------
1212
# `uint64(2**27)` (= 134,217,728)
13-
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
13+
PENDING_DEPOSITS_LIMIT: 134217728
1414
# [customized] `uint64(2**6)` (= 64)
1515
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 64
1616
# [customized] `uint64(2**6)` (= 64)
@@ -43,3 +43,8 @@ MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 2
4343
# ---------------------------------------------------------------
4444
# 2**1 ( = 2) pending withdrawals
4545
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 2
46+
47+
# Pending deposits processing
48+
# ---------------------------------------------------------------
49+
# 2**4 ( = 4) pending deposits
50+
MAX_PENDING_DEPOSITS_PER_EPOCH: 16

specs/_features/eip7732/beacon-chain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class BeaconState(Container):
270270
earliest_exit_epoch: Epoch
271271
consolidation_balance_to_consume: Gwei
272272
earliest_consolidation_epoch: Epoch
273-
pending_balance_deposits: List[PendingBalanceDeposit, PENDING_BALANCE_DEPOSITS_LIMIT]
273+
pending_deposits: List[PendingDeposit, PENDING_DEPOSITS_LIMIT]
274274
pending_partial_withdrawals: List[PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT]
275275
pending_consolidations: List[PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT]
276276
# PBS

specs/_features/eip7732/fork.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def upgrade_to_eip7732(pre: electra.BeaconState) -> BeaconState:
126126
earliest_exit_epoch=pre.earliest_exit_epoch,
127127
consolidation_balance_to_consume=pre.consolidation_balance_to_consume,
128128
earliest_consolidation_epoch=pre.earliest_consolidation_epoch,
129-
pending_balance_deposits=pre.pending_balance_deposits,
129+
pending_deposits=pre.pending_deposits,
130130
pending_partial_withdrawals=pre.pending_partial_withdrawals,
131131
pending_consolidations=pre.pending_consolidations,
132132
# ePBS

specs/electra/beacon-chain.md

Lines changed: 197 additions & 75 deletions
Large diffs are not rendered by default.

specs/electra/fork.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
133133
earliest_exit_epoch=earliest_exit_epoch,
134134
consolidation_balance_to_consume=0,
135135
earliest_consolidation_epoch=compute_activation_exit_epoch(get_current_epoch(pre)),
136-
pending_balance_deposits=[],
136+
pending_deposits=[],
137137
pending_partial_withdrawals=[],
138138
pending_consolidations=[],
139139
)
@@ -157,9 +157,15 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
157157
validator = post.validators[index]
158158
validator.effective_balance = 0
159159
validator.activation_eligibility_epoch = FAR_FUTURE_EPOCH
160-
post.pending_balance_deposits.append(
161-
PendingBalanceDeposit(index=index, amount=balance)
162-
)
160+
# Use bls.G2_POINT_AT_INFINITY as a signature field placeholder
161+
# and GENESIS_SLOT to distinguish from a pending deposit request
162+
post.pending_deposits.append(PendingDeposit(
163+
pubkey=validator.pubkey,
164+
withdrawal_credentials=validator.withdrawal_credentials,
165+
amount=balance,
166+
signature=bls.G2_POINT_AT_INFINITY,
167+
slot=GENESIS_SLOT,
168+
))
163169

164170
# Ensure early adopters of compounding credentials go through the activation churn
165171
for index, validator in enumerate(post.validators):

tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_deposit.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ def test_success_top_up_to_withdrawn_validator(spec, state):
3232
yield from run_deposit_processing(spec, state, deposit, validator_index)
3333

3434
if is_post_electra(spec):
35-
pending_balance_deposits_len = len(state.pending_balance_deposits)
36-
pending_balance_deposit = state.pending_balance_deposits[pending_balance_deposits_len - 1]
37-
assert pending_balance_deposit.amount == amount
38-
assert pending_balance_deposit.index == validator_index
35+
pending_deposits_len = len(state.pending_deposits)
36+
pending_deposit = state.pending_deposits[pending_deposits_len - 1]
37+
assert pending_deposit.pubkey == deposit.data.pubkey
38+
assert pending_deposit.withdrawal_credentials == deposit.data.withdrawal_credentials
39+
assert pending_deposit.amount == deposit.data.amount
40+
assert pending_deposit.signature == deposit.data.signature
41+
assert pending_deposit.slot == spec.GENESIS_SLOT
3942
else:
4043
assert state.balances[validator_index] == amount
4144
assert state.validators[validator_index].effective_balance == 0
@@ -47,7 +50,7 @@ def test_success_top_up_to_withdrawn_validator(spec, state):
4750
if is_post_electra(spec):
4851
has_execution_withdrawal = spec.has_execution_withdrawal_credential(validator)
4952
is_withdrawable = validator.withdrawable_epoch <= current_epoch
50-
has_non_zero_balance = pending_balance_deposit.amount > 0
53+
has_non_zero_balance = pending_deposit.amount > 0
5154
# NOTE: directly compute `is_fully_withdrawable_validator` conditions here
5255
# to work around how the epoch processing changed balance updates
5356
assert has_execution_withdrawal and is_withdrawable and has_non_zero_balance

tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ def test_top_up_and_partial_withdrawable_validator(spec, state):
365365
yield 'post', state
366366

367367
if is_post_electra(spec):
368-
assert state.pending_balance_deposits[0].amount == amount
369-
assert state.pending_balance_deposits[0].index == validator_index
368+
assert state.pending_deposits[0].pubkey == deposit.data.pubkey
369+
assert state.pending_deposits[0].withdrawal_credentials == deposit.data.withdrawal_credentials
370+
assert state.pending_deposits[0].amount == deposit.data.amount
371+
assert state.pending_deposits[0].signature == deposit.data.signature
372+
assert state.pending_deposits[0].slot == spec.GENESIS_SLOT
370373
else:
371374
# Since withdrawals happen before deposits, it becomes partially withdrawable after state transition.
372375
validator = state.validators[validator_index]
@@ -405,7 +408,7 @@ def test_top_up_to_fully_withdrawn_validator(spec, state):
405408

406409
balance = state.balances[validator_index]
407410
if is_post_electra(spec):
408-
balance += state.pending_balance_deposits[0].amount
411+
balance += state.pending_deposits[0].amount
409412

410413
assert spec.is_fully_withdrawable_validator(
411414
state.validators[validator_index],

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation_request.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,12 +1148,19 @@ def run_consolidation_processing(spec, state, consolidation, success=True):
11481148
assert state.pending_consolidations == pre_pending_consolidations + [expected_new_pending_consolidation]
11491149
# Check excess balance is queued if the target switched to compounding
11501150
if pre_target_withdrawal_credentials[:1] == spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX:
1151-
assert state.validators[target_index].withdrawal_credentials == (
1152-
spec.COMPOUNDING_WITHDRAWAL_PREFIX + pre_target_withdrawal_credentials[1:])
1151+
post_target_withdrawal_credentials = (
1152+
spec.COMPOUNDING_WITHDRAWAL_PREFIX + pre_target_withdrawal_credentials[1:]
1153+
)
1154+
assert state.validators[target_index].withdrawal_credentials == post_target_withdrawal_credentials
11531155
assert state.balances[target_index] == spec.MIN_ACTIVATION_BALANCE
11541156
if pre_target_balance > spec.MIN_ACTIVATION_BALANCE:
1155-
assert state.pending_balance_deposits == [spec.PendingBalanceDeposit(
1156-
index=target_index, amount=(pre_target_balance - spec.MIN_ACTIVATION_BALANCE))]
1157+
assert len(state.pending_deposits) == 1
1158+
pending_deposit = state.pending_deposits[0]
1159+
assert pending_deposit.pubkey == target_validator.pubkey
1160+
assert pending_deposit.withdrawal_credentials == post_target_withdrawal_credentials
1161+
assert pending_deposit.amount == (pre_target_balance - spec.MIN_ACTIVATION_BALANCE)
1162+
assert pending_deposit.signature == spec.G2_POINT_AT_INFINITY
1163+
assert pending_deposit.slot == spec.GENESIS_SLOT
11571164
else:
11581165
assert state.balances[target_index] == pre_target_balance
11591166
else:
@@ -1194,14 +1201,20 @@ def run_switch_to_compounding_processing(spec, state, consolidation, success=Tru
11941201
# Check source address in the consolidation fits the withdrawal credentials
11951202
assert state.validators[source_index].withdrawal_credentials[12:] == consolidation.source_address
11961203
# Check that the source has switched to compounding
1197-
assert state.validators[source_index].withdrawal_credentials == (
1204+
post_withdrawal_credentials = (
11981205
spec.COMPOUNDING_WITHDRAWAL_PREFIX + pre_withdrawal_credentials[1:]
11991206
)
1207+
assert state.validators[source_index].withdrawal_credentials == post_withdrawal_credentials
12001208
# Check excess balance is queued
12011209
assert state.balances[source_index] == spec.MIN_ACTIVATION_BALANCE
12021210
if pre_balance > spec.MIN_ACTIVATION_BALANCE:
1203-
assert state.pending_balance_deposits == [spec.PendingBalanceDeposit(
1204-
index=source_index, amount=(pre_balance - spec.MIN_ACTIVATION_BALANCE))]
1211+
assert len(state.pending_deposits) == 1
1212+
pending_deposit = state.pending_deposits[0]
1213+
assert pending_deposit.pubkey == source_validator.pubkey
1214+
assert pending_deposit.withdrawal_credentials == post_withdrawal_credentials
1215+
assert pending_deposit.amount == (pre_balance - spec.MIN_ACTIVATION_BALANCE)
1216+
assert pending_deposit.signature == spec.G2_POINT_AT_INFINITY
1217+
assert pending_deposit.slot == spec.GENESIS_SLOT
12051218
# Check no consolidation has been initiated
12061219
assert state.validators[source_index].exit_epoch == spec.FAR_FUTURE_EPOCH
12071220
assert state.pending_consolidations == pre_pending_consolidations

0 commit comments

Comments
 (0)