Skip to content

Commit 83a8042

Browse files
authored
Merge pull request #4043 from lucassaldanha/rename-pending-withdrawal-field
Rename PartialPendingWithdrawal field `index` to `validator_index`
2 parents 31cd9cb + ca0801d commit 83a8042

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

specs/electra/beacon-chain.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class PendingDeposit(Container):
239239

240240
```python
241241
class PendingPartialWithdrawal(Container):
242-
index: ValidatorIndex
242+
validator_index: ValidatorIndex
243243
amount: Gwei
244244
withdrawable_epoch: Epoch
245245
```
@@ -586,7 +586,8 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei:
586586
```python
587587
def get_pending_balance_to_withdraw(state: BeaconState, validator_index: ValidatorIndex) -> Gwei:
588588
return sum(
589-
withdrawal.amount for withdrawal in state.pending_partial_withdrawals if withdrawal.index == validator_index
589+
withdrawal.amount for withdrawal in state.pending_partial_withdrawals
590+
if withdrawal.validator_index == validator_index
590591
)
591592
```
592593

@@ -1127,14 +1128,16 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal],
11271128
if withdrawal.withdrawable_epoch > epoch or len(withdrawals) == MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP:
11281129
break
11291130

1130-
validator = state.validators[withdrawal.index]
1131+
validator = state.validators[withdrawal.validator_index]
11311132
has_sufficient_effective_balance = validator.effective_balance >= MIN_ACTIVATION_BALANCE
1132-
has_excess_balance = state.balances[withdrawal.index] > MIN_ACTIVATION_BALANCE
1133+
has_excess_balance = state.balances[withdrawal.validator_index] > MIN_ACTIVATION_BALANCE
11331134
if validator.exit_epoch == FAR_FUTURE_EPOCH and has_sufficient_effective_balance and has_excess_balance:
1134-
withdrawable_balance = min(state.balances[withdrawal.index] - MIN_ACTIVATION_BALANCE, withdrawal.amount)
1135+
withdrawable_balance = min(
1136+
state.balances[withdrawal.validator_index] - MIN_ACTIVATION_BALANCE,
1137+
withdrawal.amount)
11351138
withdrawals.append(Withdrawal(
11361139
index=withdrawal_index,
1137-
validator_index=withdrawal.index,
1140+
validator_index=withdrawal.validator_index,
11381141
address=ExecutionAddress(validator.withdrawal_credentials[12:]),
11391142
amount=withdrawable_balance,
11401143
))
@@ -1569,7 +1572,7 @@ def process_withdrawal_request(
15691572
exit_queue_epoch = compute_exit_epoch_and_update_churn(state, to_withdraw)
15701573
withdrawable_epoch = Epoch(exit_queue_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY)
15711574
state.pending_partial_withdrawals.append(PendingPartialWithdrawal(
1572-
index=index,
1575+
validator_index=index,
15731576
amount=to_withdraw,
15741577
withdrawable_epoch=withdrawable_epoch,
15751578
))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ def test_incorrect_source_has_pending_withdrawal(spec, state):
999999

10001000
# Create pending withdrawal
10011001
pending_withdrawal = spec.PendingPartialWithdrawal(
1002-
index=0, amount=excess_balance, withdrawable_epoch=current_epoch
1002+
validator_index=0, amount=excess_balance, withdrawable_epoch=current_epoch
10031003
)
10041004
state.pending_partial_withdrawals.append(pending_withdrawal)
10051005

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def test_invalid_validator_has_pending_withdrawal(spec, state):
401401

402402
state.pending_partial_withdrawals.append(
403403
spec.PendingPartialWithdrawal(
404-
index=validator_index,
404+
validator_index=validator_index,
405405
amount=1,
406406
withdrawable_epoch=spec.compute_activation_exit_epoch(current_epoch),
407407
)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def run_withdrawal_request_processing(
8181
+ spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
8282
)
8383
expected_partial_withdrawal = spec.PendingPartialWithdrawal(
84-
index=validator_index,
84+
validator_index=validator_index,
8585
amount=expected_amount_to_withdraw,
8686
withdrawable_epoch=expected_withdrawable_epoch,
8787
)
@@ -196,7 +196,7 @@ def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state
196196

197197
# Fill the partial withdrawal queue to the max (with a different validator index)
198198
partial_withdrawal = spec.PendingPartialWithdrawal(
199-
index=1, amount=1, withdrawable_epoch=current_epoch
199+
validator_index=1, amount=1, withdrawable_epoch=current_epoch
200200
)
201201
state.pending_partial_withdrawals = [
202202
partial_withdrawal
@@ -471,7 +471,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals(spec, state):
471471

472472
# Add pending withdrawals
473473
partial_withdrawal = spec.PendingPartialWithdrawal(
474-
index=validator_index, amount=amount, withdrawable_epoch=current_epoch
474+
validator_index=validator_index, amount=amount, withdrawable_epoch=current_epoch
475475
)
476476
state.pending_partial_withdrawals = [partial_withdrawal] * 2
477477

@@ -513,7 +513,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
513513

514514
# Add many pending withdrawals
515515
partial_withdrawal = spec.PendingPartialWithdrawal(
516-
index=validator_index,
516+
validator_index=validator_index,
517517
amount=spec.EFFECTIVE_BALANCE_INCREMENT,
518518
withdrawable_epoch=current_epoch,
519519
)
@@ -661,7 +661,7 @@ def test_partial_withdrawal_queue_full(spec, state):
661661

662662
# Fill the partial withdrawal queue to the max
663663
partial_withdrawal = spec.PendingPartialWithdrawal(
664-
index=1, amount=1, withdrawable_epoch=current_epoch
664+
validator_index=1, amount=1, withdrawable_epoch=current_epoch
665665
)
666666
state.pending_partial_withdrawals = [
667667
partial_withdrawal
@@ -746,7 +746,7 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state):
746746

747747
# Add pending withdrawals totalling an amount equal to the excess balance
748748
partial_withdrawal = spec.PendingPartialWithdrawal(
749-
index=validator_index, amount=amount, withdrawable_epoch=current_epoch
749+
validator_index=validator_index, amount=amount, withdrawable_epoch=current_epoch
750750
)
751751
state.pending_partial_withdrawals = [partial_withdrawal] * 10
752752

@@ -951,7 +951,7 @@ def test_full_exit_request_has_partial_withdrawal(spec, state):
951951
state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
952952
state.pending_partial_withdrawals.append(
953953
spec.PendingPartialWithdrawal(
954-
index=validator_index,
954+
validator_index=validator_index,
955955
amount=1,
956956
withdrawable_epoch=spec.compute_activation_exit_epoch(current_epoch),
957957
)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def test_success_excess_balance_but_no_max_effective_balance_compounding(spec, s
9191
@with_electra_and_later
9292
@spec_state_test
9393
def test_pending_withdrawals_one_skipped_one_effective(spec, state):
94-
index_0 = 3
95-
index_1 = 5
94+
validator_index_0 = 3
95+
validator_index_1 = 5
9696

97-
pending_withdrawal_0 = prepare_pending_withdrawal(spec, state, index_0)
98-
pending_withdrawal_1 = prepare_pending_withdrawal(spec, state, index_1)
97+
pending_withdrawal_0 = prepare_pending_withdrawal(spec, state, validator_index_0)
98+
pending_withdrawal_1 = prepare_pending_withdrawal(spec, state, validator_index_1)
9999

100100
# If validator doesn't have an excess balance pending withdrawal is skipped
101-
state.balances[index_0] = spec.MIN_ACTIVATION_BALANCE
101+
state.balances[validator_index_0] = spec.MIN_ACTIVATION_BALANCE
102102

103103
execution_payload = build_empty_execution_payload(spec, state)
104104
assert state.pending_partial_withdrawals == [pending_withdrawal_0, pending_withdrawal_1]
@@ -155,7 +155,7 @@ def test_pending_withdrawals_exiting_validator(spec, state):
155155
validator_index = len(state.validators) // 2
156156

157157
pending_withdrawal = prepare_pending_withdrawal(spec, state, validator_index)
158-
spec.initiate_validator_exit(state, pending_withdrawal.index)
158+
spec.initiate_validator_exit(state, pending_withdrawal.validator_index)
159159

160160
execution_payload = build_empty_execution_payload(spec, state)
161161
yield from run_withdrawals_processing(spec, state, execution_payload, num_expected_withdrawals=0)
@@ -169,7 +169,7 @@ def test_pending_withdrawals_low_effective_balance(spec, state):
169169
validator_index = len(state.validators) // 2
170170

171171
pending_withdrawal = prepare_pending_withdrawal(spec, state, validator_index)
172-
state.validators[pending_withdrawal.index].effective_balance = (
172+
state.validators[pending_withdrawal.validator_index].effective_balance = (
173173
spec.MIN_ACTIVATION_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT
174174
)
175175

@@ -185,7 +185,7 @@ def test_pending_withdrawals_no_excess_balance(spec, state):
185185
validator_index = len(state.validators) // 2
186186

187187
pending_withdrawal = prepare_pending_withdrawal(spec, state, validator_index)
188-
state.balances[pending_withdrawal.index] = spec.MIN_ACTIVATION_BALANCE
188+
state.balances[pending_withdrawal.validator_index] = spec.MIN_ACTIVATION_BALANCE
189189

190190
execution_payload = build_empty_execution_payload(spec, state)
191191
yield from run_withdrawals_processing(spec, state, execution_payload, num_expected_withdrawals=0)

tests/core/pyspec/eth2spec/test/helpers/withdrawals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def prepare_pending_withdrawal(spec, state, validator_index,
120120
)
121121

122122
withdrawal = spec.PendingPartialWithdrawal(
123-
index=validator_index,
123+
validator_index=validator_index,
124124
amount=amount,
125125
withdrawable_epoch=withdrawable_epoch,
126126
)
@@ -238,7 +238,7 @@ def run_withdrawals_processing(spec, state, execution_payload, num_expected_with
238238
assert len(pending_withdrawal_requests) <= len(execution_payload.withdrawals)
239239
for index, request in enumerate(pending_withdrawal_requests):
240240
withdrawal = execution_payload.withdrawals[index]
241-
assert withdrawal.validator_index == request.index
241+
assert withdrawal.validator_index == request.validator_index
242242
assert withdrawal.amount == request.amount
243243

244244
return expected_withdrawals

0 commit comments

Comments
 (0)