From 0345b2284a8756acd58a3dd0b0029c459c41f710 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Tue, 18 Oct 2022 15:35:06 +0100 Subject: [PATCH 1/2] Add validator_index to Withdrawal. --- specs/capella/beacon-chain.md | 2 ++ .../test/capella/block_processing/test_process_withdrawals.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 40592a9bd..5a5fd42e8 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -111,6 +111,7 @@ We define the following Python custom types for type hinting and readability: ```python class Withdrawal(Container): index: WithdrawalIndex + validator_index: ValidatorIndex address: ExecutionAddress amount: Gwei ``` @@ -275,6 +276,7 @@ def withdraw_balance(state: BeaconState, validator_index: ValidatorIndex, amount # Create a corresponding withdrawal receipt withdrawal = Withdrawal( index=state.next_withdrawal_index, + validator_index=validator_index, address=ExecutionAddress(state.validators[validator_index].withdrawal_credentials[12:]), amount=amount, ) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py index 26ace24b3..29b1bb7c9 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py @@ -13,6 +13,7 @@ def prepare_withdrawal_queue(spec, state, num_withdrawals): for i in range(num_withdrawals): withdrawal = spec.Withdrawal( index=i + 5, + validator_index=i + 1000, address=b'\x42' * 20, amount=200000 + i, ) @@ -110,6 +111,7 @@ def test_fail_empty_queue_non_empty_withdrawals(spec, state): execution_payload = build_empty_execution_payload(spec, state) withdrawal = spec.Withdrawal( index=0, + validator_index=0, address=b'\x30' * 20, amount=420, ) From d0133796288e893c3c69cc21f4a01c80a7de5ecb Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 19 Oct 2022 10:27:01 -0500 Subject: [PATCH 2/2] Ensure `validator_index` is in validator set --- .../test/capella/block_processing/test_process_withdrawals.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py index 73ee9fb39..9bf70b56d 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py @@ -9,11 +9,11 @@ from eth2spec.test.helpers.state import next_slot def prepare_withdrawal_queue(spec, state, num_withdrawals): pre_queue_len = len(state.withdrawal_queue) - + validator_len = len(state.validators) for i in range(num_withdrawals): withdrawal = spec.Withdrawal( index=i + 5, - validator_index=i + 1000, + validator_index=(i + 1000) % validator_len, address=b'\x42' * 20, amount=200000 + i, )