From 266a64c3934b5ef8582e4b1cdcc2570b64dd1240 Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Fri, 22 Nov 2024 09:27:55 +0700 Subject: [PATCH 1/5] remove `initialize_beacon_state_from_eth1` from post-altair forks --- .idea/.gitignore | 3 + .idea/consensus-specs.iml | 17 +++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 7 ++ docs/docs/templates/beacon-chain-template.md | 16 ----- specs/_features/eip7594/beacon-chain.md | 61 ----------------- specs/_features/whisk/beacon-chain.md | 22 ------ specs/altair/beacon-chain.md | 49 -------------- specs/capella/beacon-chain.md | 55 --------------- specs/deneb/beacon-chain.md | 56 ---------------- specs/electra/beacon-chain.md | 67 ------------------- 13 files changed, 45 insertions(+), 326 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/consensus-specs.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/consensus-specs.iml b/.idea/consensus-specs.iml new file mode 100644 index 0000000000..5195124935 --- /dev/null +++ b/.idea/consensus-specs.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..105ce2da2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..a48634ea73 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..4a1a1b45aa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..6b11edb947 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/docs/docs/templates/beacon-chain-template.md b/docs/docs/templates/beacon-chain-template.md index 4d22d3908e..02e95d4c4f 100644 --- a/docs/docs/templates/beacon-chain-template.md +++ b/docs/docs/templates/beacon-chain-template.md @@ -66,19 +66,3 @@ class CONTAINER_NAME(Container): ### Block processing - - - - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure testing only. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - ... -``` diff --git a/specs/_features/eip7594/beacon-chain.md b/specs/_features/eip7594/beacon-chain.md index 28031178e1..fd44068054 100644 --- a/specs/_features/eip7594/beacon-chain.md +++ b/specs/_features/eip7594/beacon-chain.md @@ -77,64 +77,3 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi excess_blob_gas=payload.excess_blob_gas, ) ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure EIP7594 testing only. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - fork = Fork( - previous_version=EIP7594_FORK_VERSION, # [Modified in EIP7594] for testing only - current_version=EIP7594_FORK_VERSION, # [Modified in EIP7594] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - deposit_requests_start_index=UNSET_DEPOSIT_REQUESTS_START_INDEX, - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process deposit balance updates - validator_pubkeys = [v.pubkey for v in state.validators] - for deposit in state.pending_deposits: - validator_index = ValidatorIndex(validator_pubkeys.index(deposit.pubkey)) - increase_balance(state, validator_index, deposit.amount) - state.pending_deposits = [] - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - validator.effective_balance = min( - balance - balance % EFFECTIVE_BALANCE_INCREMENT, get_max_effective_balance(validator)) - if validator.effective_balance >= MIN_ACTIVATION_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - # Initialize the execution payload header - state.latest_execution_payload_header = execution_payload_header - - return state -``` diff --git a/specs/_features/whisk/beacon-chain.md b/specs/_features/whisk/beacon-chain.md index 9c2cb389a3..88428e05de 100644 --- a/specs/_features/whisk/beacon-chain.md +++ b/specs/_features/whisk/beacon-chain.md @@ -436,25 +436,3 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex: assert state.latest_block_header.slot == state.slot # sanity check `process_block_header` has been called return state.latest_block_header.proposer_index ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified purely for Whisk testing. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - state_capella = capella.initialize_beacon_state_from_eth1( - eth1_block_hash, - eth1_timestamp, - deposits, - execution_payload_header, - ) - state = upgrade_to_whisk(state_capella) - state.fork.previous_version = WHISK_FORK_VERSION - state.fork.current_version = WHISK_FORK_VERSION - return state -``` diff --git a/specs/altair/beacon-chain.md b/specs/altair/beacon-chain.md index 4bad3b556e..62609dcc39 100644 --- a/specs/altair/beacon-chain.md +++ b/specs/altair/beacon-chain.md @@ -672,52 +672,3 @@ def process_sync_committee_updates(state: BeaconState) -> None: state.current_sync_committee = state.next_sync_committee state.next_sync_committee = get_next_sync_committee(state) ``` - -## Initialize state for pure Altair testnets and test vectors - -This helper function is only for initializing the state for pure Altair testnets and tests. - -*Note*: The function `initialize_beacon_state_from_eth1` is modified: (1) using `ALTAIR_FORK_VERSION` as the previous and current fork version, (2) utilizing the Altair `BeaconBlockBody` when constructing the initial `latest_block_header`, and (3) adding initial sync committees. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit]) -> BeaconState: - fork = Fork( - previous_version=ALTAIR_FORK_VERSION, # [Modified in Altair] for testing only - current_version=ALTAIR_FORK_VERSION, # [Modified in Altair] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) - if validator.effective_balance == MAX_EFFECTIVE_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # [New in Altair] Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - return state -``` diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 103530bf8b..b0191364ee 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -484,58 +484,3 @@ def process_bls_to_execution_change(state: BeaconState, + address_change.to_execution_address ) ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Capella testing only. -Modifications include: -1. Use `CAPELLA_FORK_VERSION` as the previous and current fork version. -2. Utilize the Capella `BeaconBlockBody` when constructing the initial `latest_block_header`. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - fork = Fork( - previous_version=CAPELLA_FORK_VERSION, # [Modified in Capella] for testing only - current_version=CAPELLA_FORK_VERSION, # [Modified in Capella] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) - if validator.effective_balance == MAX_EFFECTIVE_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - # Initialize the execution payload header - state.latest_execution_payload_header = execution_payload_header - - return state -``` diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index e1ac44d66d..5eacc89b8c 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -466,59 +466,3 @@ def process_registry_updates(state: BeaconState) -> None: validator = state.validators[index] validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Deneb testing only. - -The `BeaconState` initialization is unchanged, except for the use of the updated `deneb.BeaconBlockBody` type -when initializing the first body-root. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - fork = Fork( - previous_version=DENEB_FORK_VERSION, # [Modified in Deneb] for testing only - current_version=DENEB_FORK_VERSION, # [Modified in Deneb] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) - if validator.effective_balance == MAX_EFFECTIVE_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - # Initialize the execution payload header - # If empty, will initialize a chain that has not yet gone through the Merge transition - state.latest_execution_payload_header = execution_payload_header - - return state -``` diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 0e51a6e3dc..915ee2b1c1 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1666,70 +1666,3 @@ def process_consolidation_request( if has_eth1_withdrawal_credential(target_validator): switch_to_compounding_validator(state, target_index) ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Electra testing only. -Modifications include: -1. Use `ELECTRA_FORK_VERSION` as the previous and current fork version. -2. Utilize the Electra `BeaconBlockBody` when constructing the initial `latest_block_header`. -3. *[New in Electra:EIP6110]* Add `deposit_requests_start_index` variable to the genesis state initialization. -4. *[New in Electra:EIP7251]* Initialize new fields to support increasing the maximum effective balance. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - fork = Fork( - previous_version=ELECTRA_FORK_VERSION, # [Modified in Electra:EIP6110] for testing only - current_version=ELECTRA_FORK_VERSION, # [Modified in Electra:EIP6110] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - deposit_requests_start_index=UNSET_DEPOSIT_REQUESTS_START_INDEX, # [New in Electra:EIP6110] - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process deposit balance updates - validator_pubkeys = [v.pubkey for v in state.validators] - for deposit in state.pending_deposits: - validator_index = ValidatorIndex(validator_pubkeys.index(deposit.pubkey)) - increase_balance(state, validator_index, deposit.amount) - state.pending_deposits = [] - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - # [Modified in Electra:EIP7251] - validator.effective_balance = min( - balance - balance % EFFECTIVE_BALANCE_INCREMENT, get_max_effective_balance(validator)) - if validator.effective_balance >= MIN_ACTIVATION_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - # Initialize the execution payload header - state.latest_execution_payload_header = execution_payload_header - - return state -``` From d029ed309255b58446e8ec9aa369e1eab027cb4c Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Mon, 25 Nov 2024 15:30:14 +0700 Subject: [PATCH 2/5] remove `initialize_beacon_state_from_eth1` from bellatrix --- specs/_features/eip7594/beacon-chain.md | 1 - specs/_features/whisk/beacon-chain.md | 1 - specs/altair/beacon-chain.md | 1 - specs/bellatrix/beacon-chain.md | 60 ------------------- specs/capella/beacon-chain.md | 1 - specs/deneb/beacon-chain.md | 1 - specs/electra/beacon-chain.md | 1 - .../bellatrix/genesis/test_initialization.py | 20 ++----- 8 files changed, 6 insertions(+), 80 deletions(-) diff --git a/specs/_features/eip7594/beacon-chain.md b/specs/_features/eip7594/beacon-chain.md index fd44068054..7ba88aa882 100644 --- a/specs/_features/eip7594/beacon-chain.md +++ b/specs/_features/eip7594/beacon-chain.md @@ -13,7 +13,6 @@ - [Execution](#execution) - [Execution payload](#execution-payload) - [Modified `process_execution_payload`](#modified-process_execution_payload) -- [Testing](#testing) diff --git a/specs/_features/whisk/beacon-chain.md b/specs/_features/whisk/beacon-chain.md index 88428e05de..1b62b28b4d 100644 --- a/specs/_features/whisk/beacon-chain.md +++ b/specs/_features/whisk/beacon-chain.md @@ -25,7 +25,6 @@ - [`BeaconBlockBody`](#beaconblockbody) - [Deposits](#deposits) - [`get_beacon_proposer_index`](#get_beacon_proposer_index) -- [Testing](#testing) diff --git a/specs/altair/beacon-chain.md b/specs/altair/beacon-chain.md index 62609dcc39..0b7e47a8be 100644 --- a/specs/altair/beacon-chain.md +++ b/specs/altair/beacon-chain.md @@ -54,7 +54,6 @@ - [Slashings](#slashings) - [Participation flags updates](#participation-flags-updates) - [Sync committee updates](#sync-committee-updates) -- [Initialize state for pure Altair testnets and test vectors](#initialize-state-for-pure-altair-testnets-and-test-vectors) diff --git a/specs/bellatrix/beacon-chain.md b/specs/bellatrix/beacon-chain.md index 51d570fe2d..3a6c6a4b86 100644 --- a/specs/bellatrix/beacon-chain.md +++ b/specs/bellatrix/beacon-chain.md @@ -44,7 +44,6 @@ - [`process_execution_payload`](#process_execution_payload) - [Epoch processing](#epoch-processing) - [Slashings](#slashings) -- [Testing](#testing) @@ -441,62 +440,3 @@ def process_slashings(state: BeaconState) -> None: penalty = penalty_numerator // total_balance * increment decrease_balance(state, ValidatorIndex(index), penalty) ``` - -## Testing - -*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Bellatrix testing only. -Modifications include: -1. Use `BELLATRIX_FORK_VERSION` as the previous and current fork version. -2. Utilize the Bellatrix `BeaconBlockBody` when constructing the initial `latest_block_header`. -3. Initialize `latest_execution_payload_header`. - If `execution_payload_header == ExecutionPayloadHeader()`, then the Merge has not yet occurred. - Else, the Merge starts from genesis and the transition is incomplete. - -```python -def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, - eth1_timestamp: uint64, - deposits: Sequence[Deposit], - execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() - ) -> BeaconState: - fork = Fork( - previous_version=BELLATRIX_FORK_VERSION, # [Modified in Bellatrix] for testing only - current_version=BELLATRIX_FORK_VERSION, # [Modified in Bellatrix] - epoch=GENESIS_EPOCH, - ) - state = BeaconState( - genesis_time=eth1_timestamp + GENESIS_DELAY, - fork=fork, - eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), - latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy - ) - - # Process deposits - leaves = list(map(lambda deposit: deposit.data, deposits)) - for index, deposit in enumerate(deposits): - deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) - state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) - process_deposit(state, deposit) - - # Process activations - for index, validator in enumerate(state.validators): - balance = state.balances[index] - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) - if validator.effective_balance == MAX_EFFECTIVE_BALANCE: - validator.activation_eligibility_epoch = GENESIS_EPOCH - validator.activation_epoch = GENESIS_EPOCH - - # Set genesis validators root for domain separation and chain versioning - state.genesis_validators_root = hash_tree_root(state.validators) - - # Fill in sync committees - # Note: A duplicate committee is assigned for the current and next committee at genesis - state.current_sync_committee = get_next_sync_committee(state) - state.next_sync_committee = get_next_sync_committee(state) - - # [New in Bellatrix] Initialize the execution payload header - # If empty, will initialize a chain that has not yet gone through the Merge transition - state.latest_execution_payload_header = execution_payload_header - - return state -``` diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index b0191364ee..54ac8a6782 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -38,7 +38,6 @@ - [Modified `process_execution_payload`](#modified-process_execution_payload) - [Modified `process_operations`](#modified-process_operations) - [New `process_bls_to_execution_change`](#new-process_bls_to_execution_change) -- [Testing](#testing) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index 5eacc89b8c..43360f8b3e 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -42,7 +42,6 @@ - [Modified `process_voluntary_exit`](#modified-process_voluntary_exit) - [Epoch processing](#epoch-processing) - [Registry updates](#registry-updates) -- [Testing](#testing) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 915ee2b1c1..88731e6f17 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -106,7 +106,6 @@ - [Execution layer consolidation requests](#execution-layer-consolidation-requests) - [New `is_valid_switch_to_compounding_request`](#new-is_valid_switch_to_compounding_request) - [New `process_consolidation_request`](#new-process_consolidation_request) -- [Testing](#testing) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py b/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py index 140d8708ca..6b456c1183 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py @@ -14,7 +14,6 @@ get_sample_genesis_execution_payload_header, ) - def eth1_init_data(eth1_block_hash, eth1_timestamp): yield 'eth1', { 'eth1_block_hash': '0x' + eth1_block_hash.hex(), @@ -71,14 +70,10 @@ def test_initialize_pre_transition_empty_payload(spec): # initialize beacon_state *with* an *empty* execution_payload_header yield 'execution_payload_header', 'meta', True + state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) + state = spec.upgrade_to_bellatrix(state) execution_payload_header = spec.ExecutionPayloadHeader() - state = spec.initialize_beacon_state_from_eth1( - eth1_block_hash, - eth1_timestamp, - deposits, - execution_payload_header=execution_payload_header, - ) - + assert not spec.is_merge_transition_complete(state) yield 'execution_payload_header', execution_payload_header @@ -107,13 +102,10 @@ def test_initialize_post_transition(spec): # initialize beacon_state *with* an execution_payload_header yield 'execution_payload_header', 'meta', True + state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) + state = spec.upgrade_to_bellatrix(state) genesis_execution_payload_header = get_sample_genesis_execution_payload_header(spec) - state = spec.initialize_beacon_state_from_eth1( - eth1_block_hash, - eth1_timestamp, - deposits, - execution_payload_header=genesis_execution_payload_header, - ) + state.latest_execution_payload_header=genesis_execution_payload_header yield 'execution_payload_header', genesis_execution_payload_header From 518cb513fad3793fc994fad90a9e306ac2c63655 Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Wed, 27 Nov 2024 17:57:33 +0700 Subject: [PATCH 3/5] delete .idea files --- .idea/.gitignore | 3 --- .idea/consensus-specs.iml | 17 ----------------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 7 ------- 6 files changed, 45 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/consensus-specs.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d33521af..0000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/consensus-specs.iml b/.idea/consensus-specs.iml deleted file mode 100644 index 5195124935..0000000000 --- a/.idea/consensus-specs.iml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da2d..0000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a48634ea73..0000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 4a1a1b45aa..0000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 6b11edb947..0000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file From e7620583cfc3b63c66dd6f37f12105880d9b84b4 Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Fri, 29 Nov 2024 00:42:11 +0700 Subject: [PATCH 4/5] delete bellatrix test_initialization.py, update with_phases --- .../test/bellatrix/genesis/__init__.py | 0 .../bellatrix/genesis/test_initialization.py | 114 ------------------ .../phase0/genesis/test_initialization.py | 13 +- 3 files changed, 7 insertions(+), 120 deletions(-) delete mode 100644 tests/core/pyspec/eth2spec/test/bellatrix/genesis/__init__.py delete mode 100644 tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/genesis/__init__.py b/tests/core/pyspec/eth2spec/test/bellatrix/genesis/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py b/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py deleted file mode 100644 index 6b456c1183..0000000000 --- a/tests/core/pyspec/eth2spec/test/bellatrix/genesis/test_initialization.py +++ /dev/null @@ -1,114 +0,0 @@ -from eth2spec.test.context import ( - BELLATRIX, - single_phase, - spec_test, - with_presets, - with_phases, - with_bellatrix_and_later, -) -from eth2spec.test.helpers.constants import MINIMAL -from eth2spec.test.helpers.deposits import ( - prepare_full_genesis_deposits, -) -from eth2spec.test.helpers.genesis import ( - get_sample_genesis_execution_payload_header, -) - -def eth1_init_data(eth1_block_hash, eth1_timestamp): - yield 'eth1', { - 'eth1_block_hash': '0x' + eth1_block_hash.hex(), - 'eth1_timestamp': int(eth1_timestamp), - } - - -@with_phases([BELLATRIX]) -@spec_test -@single_phase -@with_presets([MINIMAL], reason="too slow") -def test_initialize_pre_transition_no_param(spec): - deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT - deposits, deposit_root, _ = prepare_full_genesis_deposits( - spec, - spec.MAX_EFFECTIVE_BALANCE, - deposit_count, - signed=True, - ) - - eth1_block_hash = b'\x12' * 32 - eth1_timestamp = spec.config.MIN_GENESIS_TIME - - yield from eth1_init_data(eth1_block_hash, eth1_timestamp) - yield 'deposits', deposits - - # initialize beacon_state *without* an execution_payload_header - yield 'execution_payload_header', 'meta', False - state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) - - assert not spec.is_merge_transition_complete(state) - - yield 'state', state - - -@with_bellatrix_and_later -@spec_test -@single_phase -@with_presets([MINIMAL], reason="too slow") -def test_initialize_pre_transition_empty_payload(spec): - deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT - deposits, deposit_root, _ = prepare_full_genesis_deposits( - spec, - spec.MAX_EFFECTIVE_BALANCE, - deposit_count, - signed=True, - ) - - eth1_block_hash = b'\x12' * 32 - eth1_timestamp = spec.config.MIN_GENESIS_TIME - - yield from eth1_init_data(eth1_block_hash, eth1_timestamp) - yield 'deposits', deposits - - # initialize beacon_state *with* an *empty* execution_payload_header - yield 'execution_payload_header', 'meta', True - state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) - state = spec.upgrade_to_bellatrix(state) - execution_payload_header = spec.ExecutionPayloadHeader() - - assert not spec.is_merge_transition_complete(state) - - yield 'execution_payload_header', execution_payload_header - - yield 'state', state - - -@with_bellatrix_and_later -@spec_test -@single_phase -@with_presets([MINIMAL], reason="too slow") -def test_initialize_post_transition(spec): - deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT - deposits, deposit_root, _ = prepare_full_genesis_deposits( - spec, - spec.MAX_EFFECTIVE_BALANCE, - deposit_count, - signed=True, - ) - - eth1_block_hash = b'\x12' * 32 - eth1_timestamp = spec.config.MIN_GENESIS_TIME - - yield from eth1_init_data(eth1_block_hash, eth1_timestamp) - yield 'deposits', deposits - - # initialize beacon_state *with* an execution_payload_header - yield 'execution_payload_header', 'meta', True - state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) - state = spec.upgrade_to_bellatrix(state) - genesis_execution_payload_header = get_sample_genesis_execution_payload_header(spec) - state.latest_execution_payload_header=genesis_execution_payload_header - - yield 'execution_payload_header', genesis_execution_payload_header - - assert spec.is_merge_transition_complete(state) - - yield 'state', state diff --git a/tests/core/pyspec/eth2spec/test/phase0/genesis/test_initialization.py b/tests/core/pyspec/eth2spec/test/phase0/genesis/test_initialization.py index ed584ed612..2a09617302 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/genesis/test_initialization.py +++ b/tests/core/pyspec/eth2spec/test/phase0/genesis/test_initialization.py @@ -1,8 +1,9 @@ from eth2spec.test.context import ( + PHASE0, single_phase, spec_test, with_presets, - with_all_phases, + with_phases, ) from eth2spec.test.helpers.constants import MINIMAL from eth2spec.test.helpers.deposits import ( @@ -26,7 +27,7 @@ def eth1_init_data(eth1_block_hash, eth1_timestamp): } -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -62,7 +63,7 @@ def test_initialize_beacon_state_from_eth1(spec): yield 'state', state -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -113,7 +114,7 @@ def test_initialize_beacon_state_some_small_balances(spec): yield 'state', state -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -162,7 +163,7 @@ def test_initialize_beacon_state_one_topup_activation(spec): yield 'state', state -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -189,7 +190,7 @@ def test_initialize_beacon_state_random_invalid_genesis(spec): yield 'state', state -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") From ea2e07e3084f04b9b6e09a4590c3703a76a84a65 Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Fri, 29 Nov 2024 13:41:23 +0700 Subject: [PATCH 5/5] Correct with_phases in test_validity.py --- .../eth2spec/test/phase0/genesis/test_validity.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/genesis/test_validity.py b/tests/core/pyspec/eth2spec/test/phase0/genesis/test_validity.py index d245b8fcf4..3304deebd8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/genesis/test_validity.py +++ b/tests/core/pyspec/eth2spec/test/phase0/genesis/test_validity.py @@ -1,8 +1,9 @@ from eth2spec.test.context import ( + PHASE0, spec_test, single_phase, with_presets, - with_all_phases, + with_phases, ) from eth2spec.test.helpers.constants import MINIMAL from eth2spec.test.helpers.deposits import ( @@ -43,7 +44,7 @@ def run_is_valid_genesis_state(spec, state, valid=True): assert is_valid == valid -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -56,7 +57,7 @@ def test_full_genesis_deposits(spec): yield from run_is_valid_genesis_state(spec, state) -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -70,7 +71,7 @@ def test_invalid_invalid_timestamp(spec): yield from run_is_valid_genesis_state(spec, state, valid=False) -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -84,7 +85,7 @@ def test_extra_balance(spec): yield from run_is_valid_genesis_state(spec, state) -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -107,7 +108,7 @@ def test_one_more_validator(spec): yield from run_is_valid_genesis_state(spec, state) -@with_all_phases +@with_phases([PHASE0]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow")