From e1b9cf97e2304905f8100602e99672ac759709df Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 3 Mar 2022 14:02:52 -0700 Subject: [PATCH] add withdrawal index to wihdrawal transaction --- specs/capella/beacon-chain.md | 7 ++++++- specs/capella/fork.md | 1 + .../epoch_processing/test_process_full_withdrawals.py | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 38cda0f2f..f1171a7d5 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -27,6 +27,7 @@ We define the following Python custom types for type hinting and readability: | Name | SSZ equivalent | Description | | - | - | - | | `TransactionType` | `Bytes1` | an EIP-2718 type | +| `WithdrawalIndex` | `uint64` | an index of a `WithdrawalTransaction`| ## Preset @@ -40,7 +41,7 @@ We define the following Python custom types for type hinting and readability: | Name | Value | Description | | - | - | - | -| `TX_TYPE_WITHDRAWAL` | `TransactionType('0x05')` | EIP-2718 TX Type | +| `TX_TYPE_WITHDRAWAL` | `TransactionType('0x03')` | EIP-2718 TX Type | | `MAX_WITHDRAWAL_TRANSACTIONS_PER_PAYLOAD` | `uint64(2**4)` (= 16) | Maximum amount of withdrawal transactions allowed in each payload | ## Configuration @@ -106,6 +107,7 @@ class BeaconState(Container): # Execution latest_execution_payload_header: ExecutionPayloadHeader # Withdrawals + withdrawal_index: WithdrawalIndex withdrawal_receipts: List[WithdrawalTransaction, WITHDRAWAL_TRANSACTION_LIMIT] # [New in Capella] ``` @@ -167,6 +169,7 @@ as well as in the `BeaconState`'s `withdrawal_receipts` queue. ```python class WithdrawalTransaction(Container): + index: WithdrawalIndex address: ExecutionAddress amount: Gwei ``` @@ -183,9 +186,11 @@ def withdraw(state: BeaconState, index: ValidatorIndex, amount: Gwei) -> None: decrease_balance(state, index, amount) # Create a corresponding withdrawal receipt receipt = WithdrawalTransaction( + index=state.withdrawal_index, address=state.validators[index].withdrawal_credentials[12:], amount=amount, ) + state.withdrawal_index = WithdrawalIndex(state.withdrawal_index + 1) state.withdrawal_receipts.append(receipt) ``` diff --git a/specs/capella/fork.md b/specs/capella/fork.md index 17c0171df..9bb0bb552 100644 --- a/specs/capella/fork.md +++ b/specs/capella/fork.md @@ -83,6 +83,7 @@ def upgrade_to_capella(pre: bellatrix.BeaconState) -> BeaconState: # Execution-layer latest_execution_payload_header=pre.latest_execution_payload_header, # Withdrawals + withdrawal_index=WithdrawalIndex(0), withdrawal_receipts=[], ) diff --git a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py index ef7b7c8ac..5da1c7ece 100644 --- a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py @@ -17,6 +17,7 @@ def set_validator_withdrawable(spec, state, index, withdrawable_epoch=None): def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None): + pre_withdrawal_index = state.withdrawal_index pre_withdrawal_receipts = state.withdrawal_receipts to_be_withdrawn_indices = [ index for index, validator in enumerate(state.validators) @@ -34,6 +35,7 @@ def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None): assert state.balances[index] == 0 assert len(state.withdrawal_receipts) == len(pre_withdrawal_receipts) + num_expected_withdrawals + assert state.withdrawal_index == pre_withdrawal_index + num_expected_withdrawals @with_capella_and_later @@ -63,8 +65,11 @@ def test_single_withdrawal(spec, state): # Make one validator withdrawable set_validator_withdrawable(spec, state, 0) + assert state.withdrawal_index == 0 yield from run_process_full_withdrawals(spec, state, 1) + assert state.withdrawal_index == 1 + @with_capella_and_later @spec_state_test