From 1c8d57eeb721b6f5d5ba35dea2c31cd0f3c7cf8b Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 27 Oct 2022 10:33:38 +0200 Subject: [PATCH 1/6] Historical batches This PR, a continuation of replaces `historical_roots` with `historical_block_roots`. By keeping an accumulator of historical block roots in the state, it becomes possible to validate the entire block history that led up to that particular state without executing the transitions, and without checking them one by one in backwards order using a parent chain. This is interesting for archival purposes as well as when implementing sync protocols that can verify chunks of blocks quickly, meaning they can be downloaded in any order. It's also useful as it provides a canonical hash by which such chunks of blocks can be named, with a direct reference in the state. In this PR, `historical_roots` is frozen at its current value and `historical_batches` are computed from the merge epoch onwards. After this PR, `block_batch_root` in the state can be used to verify an era of blocks against the state with a simple root check. The `historical_roots` values on the other hand can be used to verify that a constant distributed with clients is valid for a particular state, and therefore extends the block validation all the way back to genesis without backfilling `block_batch_root` and without introducing any new security assumptions in the client. As far as naming goes, it's convenient to talk about an "era" being 8192 slots ~= 1.14 days. The 8192 number comes from the SLOTS_PER_HISTORICAL_ROOT constant. With multiple easily verifable blocks in a file, it becomes trivial to offload block history to out-of-protocol transfer methods (bittorrent / ftp / whatever) - including execution payloads, paving the way for a future in which clients purge block history in p2p. This PR can be applied along with the merge which simplifies payload distribution from the get-go. Both execution and consensus clients benefit because from the merge onwards, they both need to be able to supply ranges of blocks in the sync protocol from what effectively is "cold storage". Another possibility is to include it in a future cleanup PR - this complicates the "cold storage" mode above by not covering exection payloads from start. --- specs/capella/beacon-chain.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 3b6dc4453..d80b70610 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -21,6 +21,7 @@ - [`Withdrawal`](#withdrawal) - [`BLSToExecutionChange`](#blstoexecutionchange) - [`SignedBLSToExecutionChange`](#signedblstoexecutionchange) + - [`HistoricalBatchSummary`](#historicalbatchsummary) - [Extended Containers](#extended-containers) - [`ExecutionPayload`](#executionpayload) - [`ExecutionPayloadHeader`](#executionpayloadheader) @@ -37,6 +38,7 @@ - [Epoch processing](#epoch-processing) - [Full withdrawals](#full-withdrawals) - [Partial withdrawals](#partial-withdrawals) + - [Historical batches updates](#historical-batches-updates) - [Block processing](#block-processing) - [New `process_withdrawals`](#new-process_withdrawals) - [Modified `process_execution_payload`](#modified-process_execution_payload) @@ -132,6 +134,18 @@ class SignedBLSToExecutionChange(Container): signature: BLSSignature ``` +#### `HistoricalBatchSummary` + +```python +class HistoricalBatchSummary(Container): + """ + `HistoricalBatchSummary` matches the components of the phase0 HistoricalBatch + making the two hash_tree_root-compatible. + """ + block_batch_root: Root + state_batch_root: Root +``` + ### Extended Containers #### `ExecutionPayload` @@ -213,7 +227,8 @@ class BeaconState(Container): latest_block_header: BeaconBlockHeader block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] - historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] + historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Merge, replaced by historical_batches + historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # Valid from Merge onwards # Eth1 eth1_data: Eth1Data eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH] @@ -320,7 +335,7 @@ def process_epoch(state: BeaconState) -> None: process_effective_balance_updates(state) process_slashings_reset(state) process_randao_mixes_reset(state) - process_historical_roots_update(state) + process_historical_batches_update(state) process_participation_flag_updates(state) process_sync_committee_updates(state) process_full_withdrawals(state) # [New in Capella] @@ -367,6 +382,21 @@ def process_partial_withdrawals(state: BeaconState) -> None: state.next_partial_withdrawal_validator_index = validator_index ``` +#### Historical batches updates + +*Note*: The function `process_historical_batches_update` replaces `process_historical_roots_update` in phase0. + +```python +def process_historical_batches_update(state: BeaconState) -> None: + # Set historical block root accumulator + next_epoch = Epoch(get_current_epoch(state) + 1) + if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: + historical_batch = HistoricalBatchSummary( + block_batch_root=hash_tree_root(state.block_roots), + state_batch_root=hash_tree_root(state.state_roots)) + state.historical_batches.append(historical_batch) +``` + ### Block processing ```python From 4d1b487b21082cea70c1a0664c1ad0304300f6cc Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 27 Oct 2022 10:38:09 +0200 Subject: [PATCH 2/6] move field last avoids changing "header" fields in state --- specs/capella/beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index d80b70610..433ccba57 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -228,7 +228,6 @@ class BeaconState(Container): block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Merge, replaced by historical_batches - historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # Valid from Merge onwards # Eth1 eth1_data: Eth1Data eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH] @@ -259,6 +258,8 @@ class BeaconState(Container): withdrawal_queue: List[Withdrawal, WITHDRAWAL_QUEUE_LIMIT] # [New in Capella] next_withdrawal_index: WithdrawalIndex # [New in Capella] next_partial_withdrawal_validator_index: ValidatorIndex # [New in Capella] + # Deep history + historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # Valid from Merge onwards ``` ## Helpers From 84592f101b0113f9c5be339eadb15d56128dd3ca Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 16 Dec 2022 00:49:14 +0800 Subject: [PATCH 3/6] Add tests for `process_historical_batches_update` --- setup.py | 1 + specs/capella/beacon-chain.md | 42 +++++++++++++++++-- .../test/capella/epoch_processing/__init__.py | 0 .../test_process_historical_batches_update.py | 27 ++++++++++++ .../test/eip4844/epoch_processing/__init__.py | 0 .../test_process_historical_batches_update.py | 23 ++++++++++ .../eth2spec/test/helpers/epoch_processing.py | 10 ++++- .../test_process_historical_roots_update.py | 8 +++- .../test/phase0/sanity/test_blocks.py | 22 ++++++++-- .../eth2spec/test/phase0/sanity/test_slots.py | 33 +++++++++++++++ tests/generators/epoch_processing/main.py | 14 ++++--- 11 files changed, 163 insertions(+), 17 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/capella/epoch_processing/__init__.py create mode 100644 tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py create mode 100644 tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/__init__.py create mode 100644 tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py diff --git a/setup.py b/setup.py index be8be6d90..b2f2ac8e3 100644 --- a/setup.py +++ b/setup.py @@ -660,6 +660,7 @@ def get_empty_list_result(fn): # type: ignore process_withdrawals = no_op(process_withdrawals) process_bls_to_execution_change = no_op(process_bls_to_execution_change) get_expected_withdrawals = get_empty_list_result(get_expected_withdrawals) +process_historical_batches_update = no_op(process_historical_batches_update) # diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 8dfb96b9f..baa06398d 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -30,6 +30,8 @@ - [`is_fully_withdrawable_validator`](#is_fully_withdrawable_validator) - [`is_partially_withdrawable_validator`](#is_partially_withdrawable_validator) - [Beacon chain state transition function](#beacon-chain-state-transition-function) + - [Epoch processing](#epoch-processing) + - [Historical batches updates](#historical-batches-updates) - [Block processing](#block-processing) - [New `get_expected_withdrawals`](#new-get_expected_withdrawals) - [New `process_withdrawals`](#new-process_withdrawals) @@ -209,7 +211,7 @@ class BeaconState(Container): latest_block_header: BeaconBlockHeader block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] - historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Merge, replaced by historical_batches + historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Merge, replaced by historical_batches # Eth1 eth1_data: Eth1Data eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH] @@ -239,8 +241,8 @@ class BeaconState(Container): # Withdrawals next_withdrawal_index: WithdrawalIndex # [New in Capella] next_withdrawal_validator_index: ValidatorIndex # [New in Capella] - # Deep history - historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # Valid from Merge onwards + # Deep history valid from Capella onwards + historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # [New in Capella] ``` ## Helpers @@ -285,6 +287,40 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) -> ## Beacon chain state transition function +### Epoch processing + +*Note*: The function `process_historical_batches_update` replaces `process_historical_roots_update` in Bellatrix. + +```python +def process_epoch(state: BeaconState) -> None: + process_justification_and_finalization(state) + process_inactivity_updates(state) + process_rewards_and_penalties(state) + process_registry_updates(state) + process_slashings(state) + process_eth1_data_reset(state) + process_effective_balance_updates(state) + process_slashings_reset(state) + process_randao_mixes_reset(state) + process_historical_batches_update(state) # [Modified in Capella] + process_participation_flag_updates(state) + process_sync_committee_updates(state) +``` + +#### Historical batches updates + +```python +def process_historical_batches_update(state: BeaconState) -> None: + # Set historical block root accumulator. + next_epoch = Epoch(get_current_epoch(state) + 1) + if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: + historical_batch = HistoricalBatchSummary( + block_batch_root=hash_tree_root(state.block_roots), + state_batch_root=hash_tree_root(state.state_roots), + ) + state.historical_batches.append(historical_batch) +``` + ### Block processing ```python diff --git a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/__init__.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py new file mode 100644 index 000000000..ba049272b --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py @@ -0,0 +1,27 @@ +from eth2spec.test.context import ( + CAPELLA, + spec_state_test, + with_phases, +) +from eth2spec.test.helpers.epoch_processing import ( + run_epoch_processing_with +) + + +def run_process_historical_batches_update(spec, state): + yield from run_epoch_processing_with(spec, state, 'process_historical_batches_update') + + +@with_phases([CAPELLA]) +@spec_state_test +def test_historical_batches_accumulator(spec, state): + # skip ahead to near the end of the historical batch period (excl block before epoch processing) + state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1 + pre_historical_batches = state.historical_batches.copy() + + yield from run_process_historical_batches_update(spec, state) + + assert len(state.historical_batches) == len(pre_historical_batches) + 1 + summary = state.historical_batches[len(state.historical_batches) - 1] + assert summary.block_batch_root == state.block_roots.hash_tree_root() + assert summary.state_batch_root == state.state_roots.hash_tree_root() diff --git a/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/__init__.py b/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py b/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py new file mode 100644 index 000000000..f6e6f2ce7 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py @@ -0,0 +1,23 @@ +from eth2spec.test.context import ( + spec_state_test, + with_eip4844_and_later, +) +from eth2spec.test.helpers.epoch_processing import ( + run_epoch_processing_with +) + + +def run_process_historical_batches_update(spec, state): + yield from run_epoch_processing_with(spec, state, 'process_historical_batches_update') + + +@with_eip4844_and_later +@spec_state_test +def test_no_op(spec, state): + # skip ahead to near the end of the historical batch period (excl block before epoch processing) + state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1 + historical_batches_len = len(state.historical_batches) + + yield from run_process_historical_batches_update(spec, state) + + assert len(state.historical_batches) == historical_batches_len diff --git a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py index ed61f8bdb..399222841 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py +++ b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py @@ -1,5 +1,8 @@ -from eth2spec.test.helpers.forks import is_post_altair +from eth2spec.test.helpers.forks import ( + is_post_altair, + is_post_capella, +) def get_process_calls(spec): @@ -22,7 +25,10 @@ def get_process_calls(spec): 'process_effective_balance_updates', 'process_slashings_reset', 'process_randao_mixes_reset', - 'process_historical_roots_update', + # Capella replaced `process_historical_roots_update` with `process_historical_batches_update` + 'process_historical_batches_update' if is_post_capella(spec) else ( + 'process_historical_roots_update' + ), # Altair replaced `process_participation_record_updates` with `process_participation_flag_updates` 'process_participation_flag_updates' if is_post_altair(spec) else ( 'process_participation_record_updates' diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_historical_roots_update.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_historical_roots_update.py index 02ce7ccba..f03d0bd98 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_historical_roots_update.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_historical_roots_update.py @@ -1,4 +1,8 @@ -from eth2spec.test.context import spec_state_test, with_all_phases +from eth2spec.test.context import ( + PHASE0, ALTAIR, BELLATRIX, + spec_state_test, + with_phases, +) from eth2spec.test.helpers.epoch_processing import ( run_epoch_processing_with ) @@ -8,7 +12,7 @@ def run_process_historical_roots_update(spec, state): yield from run_epoch_processing_with(spec, state, 'process_historical_roots_update') -@with_all_phases +@with_phases([PHASE0, ALTAIR, BELLATRIX]) @spec_state_test def test_historical_root_accumulator(spec, state): # skip ahead to near the end of the historical roots period (excl block before epoch processing) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index 1e9dd2d48..8b35e814f 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -29,8 +29,8 @@ from eth2spec.test.helpers.sync_committee import ( compute_committee_indices, compute_sync_committee_participant_reward_and_penalty, ) -from eth2spec.test.helpers.constants import PHASE0, MINIMAL -from eth2spec.test.helpers.forks import is_post_altair, is_post_bellatrix +from eth2spec.test.helpers.constants import PHASE0, EIP4844, MINIMAL +from eth2spec.test.helpers.forks import is_post_altair, is_post_bellatrix, is_post_capella from eth2spec.test.context import ( spec_test, spec_state_test, dump_skipping_message, with_phases, with_all_phases, single_phase, @@ -1026,7 +1026,10 @@ def test_balance_driven_status_transitions(spec, state): @always_bls def test_historical_batch(spec, state): state.slot += spec.SLOTS_PER_HISTORICAL_ROOT - (state.slot % spec.SLOTS_PER_HISTORICAL_ROOT) - 1 - pre_historical_roots_len = len(state.historical_roots) + pre_historical_roots = state.historical_roots.copy() + + if is_post_capella(spec): + pre_historical_batches = state.historical_batches.copy() yield 'pre', state @@ -1038,7 +1041,18 @@ def test_historical_batch(spec, state): assert state.slot == block.slot assert spec.get_current_epoch(state) % (spec.SLOTS_PER_HISTORICAL_ROOT // spec.SLOTS_PER_EPOCH) == 0 - assert len(state.historical_roots) == pre_historical_roots_len + 1 + + # check history update + if is_post_capella(spec): + # Frozen `historical_roots` + assert state.historical_roots == pre_historical_roots + if spec.fork == EIP4844: + # TODO: no-op for now in EIP4844 testnet + assert state.historical_batches == pre_historical_batches + else: + assert len(state.historical_batches) == len(pre_historical_batches) + 1 + else: + assert len(state.historical_roots) == len(pre_historical_roots) + 1 @with_all_phases diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py index 3fa57f0f1..0010898f8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py @@ -1,3 +1,9 @@ +from eth2spec.test.helpers.constants import ( + EIP4844, +) +from eth2spec.test.helpers.forks import ( + is_post_capella, +) from eth2spec.test.helpers.state import get_state_root from eth2spec.test.context import ( spec_state_test, @@ -61,3 +67,30 @@ def test_over_epoch_boundary(spec, state): yield 'slots', int(slots) spec.process_slots(state, state.slot + slots) yield 'post', state + + +@with_all_phases +@spec_state_test +def test_historical_accumulator(spec, state): + pre_historical_roots = state.historical_roots.copy() + + if is_post_capella(spec): + pre_historical_batches = state.historical_batches.copy() + + yield 'pre', state + slots = spec.SLOTS_PER_HISTORICAL_ROOT + yield 'slots', int(slots) + spec.process_slots(state, state.slot + slots) + yield 'post', state + + # check history update + if is_post_capella(spec): + # Frozen `historical_roots` + assert state.historical_roots == pre_historical_roots + if spec.fork == EIP4844: + # TODO: no-op for now in EIP4844 testnet + assert state.historical_batches == pre_historical_batches + else: + assert len(state.historical_batches) == len(pre_historical_batches) + 1 + else: + assert len(state.historical_roots) == len(pre_historical_roots) + 1 diff --git a/tests/generators/epoch_processing/main.py b/tests/generators/epoch_processing/main.py index 84421e749..f8430bc7e 100644 --- a/tests/generators/epoch_processing/main.py +++ b/tests/generators/epoch_processing/main.py @@ -27,13 +27,15 @@ if __name__ == "__main__": # so no additional tests required. bellatrix_mods = altair_mods - # No epoch-processing changes in Capella and previous testing repeats with new types, - # so no additional tests required. - capella_mods = bellatrix_mods + _new_capella_mods = {key: 'eth2spec.test.capella.epoch_processing.test_process_' + key for key in [ + 'historical_batches_update', + ]} + capella_mods = combine_mods(_new_capella_mods, bellatrix_mods) - # No epoch-processing changes in EIP4844 and previous testing repeats with new types, - # so no additional tests required. - eip4844_mods = capella_mods + _new_eip4844_mods = {key: 'eth2spec.test.eip4844.epoch_processing.test_process_' + key for key in [ + 'historical_batches_update', + ]} + eip4844_mods = combine_mods(_new_eip4844_mods, capella_mods) # TODO Custody Game testgen is disabled for now # custody_game_mods = {**{key: 'eth2spec.test.custody_game.epoch_processing.test_process_' + key for key in [ From b6ac1fa099b074e6566d221775df73d3a39dcd52 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 20 Dec 2022 07:46:18 +0100 Subject: [PATCH 4/6] Update specs/capella/beacon-chain.md Co-authored-by: Danny Ryan --- specs/capella/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index baa06398d..e869d0e5f 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -211,7 +211,7 @@ class BeaconState(Container): latest_block_header: BeaconBlockHeader block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] - historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Merge, replaced by historical_batches + historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Capella, replaced by historical_batches # Eth1 eth1_data: Eth1Data eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH] From 1cfabcbe54378284319bc6f38c45484b6cefd3fb Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 2 Jan 2023 23:07:00 +0800 Subject: [PATCH 5/6] Rename `HistoricalBatchSummary` -> `HistoricalSummary` and `historical_batches` -> `historical_summaries` --- setup.py | 2 +- specs/capella/beacon-chain.md | 26 +++++++++---------- .../test_process_historical_batches_update.py | 14 +++++----- .../test_process_historical_batches_update.py | 10 +++---- .../eth2spec/test/helpers/epoch_processing.py | 4 +-- .../test/phase0/sanity/test_blocks.py | 6 ++--- .../eth2spec/test/phase0/sanity/test_slots.py | 6 ++--- tests/generators/epoch_processing/main.py | 4 +-- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/setup.py b/setup.py index b2f2ac8e3..f95f85284 100644 --- a/setup.py +++ b/setup.py @@ -660,7 +660,7 @@ def get_empty_list_result(fn): # type: ignore process_withdrawals = no_op(process_withdrawals) process_bls_to_execution_change = no_op(process_bls_to_execution_change) get_expected_withdrawals = get_empty_list_result(get_expected_withdrawals) -process_historical_batches_update = no_op(process_historical_batches_update) +process_historical_summaries_update = no_op(process_historical_summaries_update) # diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index e869d0e5f..5d322ca92 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -18,7 +18,7 @@ - [`Withdrawal`](#withdrawal) - [`BLSToExecutionChange`](#blstoexecutionchange) - [`SignedBLSToExecutionChange`](#signedblstoexecutionchange) - - [`HistoricalBatchSummary`](#historicalbatchsummary) + - [`HistoricalSummary`](#historicalsummary) - [Extended Containers](#extended-containers) - [`ExecutionPayload`](#executionpayload) - [`ExecutionPayloadHeader`](#executionpayloadheader) @@ -31,7 +31,7 @@ - [`is_partially_withdrawable_validator`](#is_partially_withdrawable_validator) - [Beacon chain state transition function](#beacon-chain-state-transition-function) - [Epoch processing](#epoch-processing) - - [Historical batches updates](#historical-batches-updates) + - [Historical summaries updates](#historical-summaries-updates) - [Block processing](#block-processing) - [New `get_expected_withdrawals`](#new-get_expected_withdrawals) - [New `process_withdrawals`](#new-process_withdrawals) @@ -118,12 +118,12 @@ class SignedBLSToExecutionChange(Container): signature: BLSSignature ``` -#### `HistoricalBatchSummary` +#### `HistoricalSummary` ```python -class HistoricalBatchSummary(Container): +class HistoricalSummary(Container): """ - `HistoricalBatchSummary` matches the components of the phase0 HistoricalBatch + `HistoricalSummary` matches the components of the phase0 `HistoricalBatch` making the two hash_tree_root-compatible. """ block_batch_root: Root @@ -211,7 +211,7 @@ class BeaconState(Container): latest_block_header: BeaconBlockHeader block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT] - historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Capella, replaced by historical_batches + historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] # Frozen in Capella, replaced by historical_summaries # Eth1 eth1_data: Eth1Data eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH] @@ -242,7 +242,7 @@ class BeaconState(Container): next_withdrawal_index: WithdrawalIndex # [New in Capella] next_withdrawal_validator_index: ValidatorIndex # [New in Capella] # Deep history valid from Capella onwards - historical_batches: List[HistoricalBatchSummary, HISTORICAL_ROOTS_LIMIT] # [New in Capella] + historical_summaries: List[HistoricalSummary, HISTORICAL_ROOTS_LIMIT] # [New in Capella] ``` ## Helpers @@ -289,7 +289,7 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) -> ### Epoch processing -*Note*: The function `process_historical_batches_update` replaces `process_historical_roots_update` in Bellatrix. +*Note*: The function `process_historical_summaries_update` replaces `process_historical_roots_update` in Bellatrix. ```python def process_epoch(state: BeaconState) -> None: @@ -302,23 +302,23 @@ def process_epoch(state: BeaconState) -> None: process_effective_balance_updates(state) process_slashings_reset(state) process_randao_mixes_reset(state) - process_historical_batches_update(state) # [Modified in Capella] + process_historical_summaries_update(state) # [Modified in Capella] process_participation_flag_updates(state) process_sync_committee_updates(state) ``` -#### Historical batches updates +#### Historical summaries updates ```python -def process_historical_batches_update(state: BeaconState) -> None: +def process_historical_summaries_update(state: BeaconState) -> None: # Set historical block root accumulator. next_epoch = Epoch(get_current_epoch(state) + 1) if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: - historical_batch = HistoricalBatchSummary( + historical_summary = HistoricalSummary( block_batch_root=hash_tree_root(state.block_roots), state_batch_root=hash_tree_root(state.state_roots), ) - state.historical_batches.append(historical_batch) + state.historical_summaries.append(historical_summary) ``` ### Block processing diff --git a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py index ba049272b..16620b38d 100644 --- a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py +++ b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py @@ -8,20 +8,20 @@ from eth2spec.test.helpers.epoch_processing import ( ) -def run_process_historical_batches_update(spec, state): - yield from run_epoch_processing_with(spec, state, 'process_historical_batches_update') +def run_process_historical_summaries_update(spec, state): + yield from run_epoch_processing_with(spec, state, 'process_historical_summaries_update') @with_phases([CAPELLA]) @spec_state_test -def test_historical_batches_accumulator(spec, state): +def test_historical_summaries_accumulator(spec, state): # skip ahead to near the end of the historical batch period (excl block before epoch processing) state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1 - pre_historical_batches = state.historical_batches.copy() + pre_historical_summaries = state.historical_summaries.copy() - yield from run_process_historical_batches_update(spec, state) + yield from run_process_historical_summaries_update(spec, state) - assert len(state.historical_batches) == len(pre_historical_batches) + 1 - summary = state.historical_batches[len(state.historical_batches) - 1] + assert len(state.historical_summaries) == len(pre_historical_summaries) + 1 + summary = state.historical_summaries[len(state.historical_summaries) - 1] assert summary.block_batch_root == state.block_roots.hash_tree_root() assert summary.state_batch_root == state.state_roots.hash_tree_root() diff --git a/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py b/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py index f6e6f2ce7..21865ae38 100644 --- a/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py +++ b/tests/core/pyspec/eth2spec/test/eip4844/epoch_processing/test_process_historical_batches_update.py @@ -7,8 +7,8 @@ from eth2spec.test.helpers.epoch_processing import ( ) -def run_process_historical_batches_update(spec, state): - yield from run_epoch_processing_with(spec, state, 'process_historical_batches_update') +def run_process_historical_summaries_update(spec, state): + yield from run_epoch_processing_with(spec, state, 'process_historical_summaries_update') @with_eip4844_and_later @@ -16,8 +16,8 @@ def run_process_historical_batches_update(spec, state): def test_no_op(spec, state): # skip ahead to near the end of the historical batch period (excl block before epoch processing) state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1 - historical_batches_len = len(state.historical_batches) + historical_summaries_len = len(state.historical_summaries) - yield from run_process_historical_batches_update(spec, state) + yield from run_process_historical_summaries_update(spec, state) - assert len(state.historical_batches) == historical_batches_len + assert len(state.historical_summaries) == historical_summaries_len diff --git a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py index 399222841..44b42aff9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py +++ b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py @@ -25,8 +25,8 @@ def get_process_calls(spec): 'process_effective_balance_updates', 'process_slashings_reset', 'process_randao_mixes_reset', - # Capella replaced `process_historical_roots_update` with `process_historical_batches_update` - 'process_historical_batches_update' if is_post_capella(spec) else ( + # Capella replaced `process_historical_roots_update` with `process_historical_summaries_update` + 'process_historical_summaries_update' if is_post_capella(spec) else ( 'process_historical_roots_update' ), # Altair replaced `process_participation_record_updates` with `process_participation_flag_updates` diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index 8b35e814f..71c7798a1 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -1029,7 +1029,7 @@ def test_historical_batch(spec, state): pre_historical_roots = state.historical_roots.copy() if is_post_capella(spec): - pre_historical_batches = state.historical_batches.copy() + pre_historical_summaries = state.historical_summaries.copy() yield 'pre', state @@ -1048,9 +1048,9 @@ def test_historical_batch(spec, state): assert state.historical_roots == pre_historical_roots if spec.fork == EIP4844: # TODO: no-op for now in EIP4844 testnet - assert state.historical_batches == pre_historical_batches + assert state.historical_summaries == pre_historical_summaries else: - assert len(state.historical_batches) == len(pre_historical_batches) + 1 + assert len(state.historical_summaries) == len(pre_historical_summaries) + 1 else: assert len(state.historical_roots) == len(pre_historical_roots) + 1 diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py index 0010898f8..7b860159a 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_slots.py @@ -75,7 +75,7 @@ def test_historical_accumulator(spec, state): pre_historical_roots = state.historical_roots.copy() if is_post_capella(spec): - pre_historical_batches = state.historical_batches.copy() + pre_historical_summaries = state.historical_summaries.copy() yield 'pre', state slots = spec.SLOTS_PER_HISTORICAL_ROOT @@ -89,8 +89,8 @@ def test_historical_accumulator(spec, state): assert state.historical_roots == pre_historical_roots if spec.fork == EIP4844: # TODO: no-op for now in EIP4844 testnet - assert state.historical_batches == pre_historical_batches + assert state.historical_summaries == pre_historical_summaries else: - assert len(state.historical_batches) == len(pre_historical_batches) + 1 + assert len(state.historical_summaries) == len(pre_historical_summaries) + 1 else: assert len(state.historical_roots) == len(pre_historical_roots) + 1 diff --git a/tests/generators/epoch_processing/main.py b/tests/generators/epoch_processing/main.py index f8430bc7e..58beb0fd2 100644 --- a/tests/generators/epoch_processing/main.py +++ b/tests/generators/epoch_processing/main.py @@ -28,12 +28,12 @@ if __name__ == "__main__": bellatrix_mods = altair_mods _new_capella_mods = {key: 'eth2spec.test.capella.epoch_processing.test_process_' + key for key in [ - 'historical_batches_update', + 'historical_summaries_update', ]} capella_mods = combine_mods(_new_capella_mods, bellatrix_mods) _new_eip4844_mods = {key: 'eth2spec.test.eip4844.epoch_processing.test_process_' + key for key in [ - 'historical_batches_update', + 'historical_summaries_update', ]} eip4844_mods = combine_mods(_new_eip4844_mods, capella_mods) From dcacb7164f812d1a7161f956615a5123ed266202 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 3 Jan 2023 21:50:06 +0800 Subject: [PATCH 6/6] Rename `block_batch_root` to `block_summary_root` and `state_batch_root` to `state_summary_root` --- specs/capella/beacon-chain.md | 8 ++++---- .../test_process_historical_batches_update.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 5d322ca92..bd7a2c50c 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -126,8 +126,8 @@ class HistoricalSummary(Container): `HistoricalSummary` matches the components of the phase0 `HistoricalBatch` making the two hash_tree_root-compatible. """ - block_batch_root: Root - state_batch_root: Root + block_summary_root: Root + state_summary_root: Root ``` ### Extended Containers @@ -315,8 +315,8 @@ def process_historical_summaries_update(state: BeaconState) -> None: next_epoch = Epoch(get_current_epoch(state) + 1) if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: historical_summary = HistoricalSummary( - block_batch_root=hash_tree_root(state.block_roots), - state_batch_root=hash_tree_root(state.state_roots), + block_summary_root=hash_tree_root(state.block_roots), + state_summary_root=hash_tree_root(state.state_roots), ) state.historical_summaries.append(historical_summary) ``` diff --git a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py index 16620b38d..f1f8292eb 100644 --- a/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py +++ b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_historical_batches_update.py @@ -23,5 +23,5 @@ def test_historical_summaries_accumulator(spec, state): assert len(state.historical_summaries) == len(pre_historical_summaries) + 1 summary = state.historical_summaries[len(state.historical_summaries) - 1] - assert summary.block_batch_root == state.block_roots.hash_tree_root() - assert summary.state_batch_root == state.state_roots.hash_tree_root() + assert summary.block_summary_root == state.block_roots.hash_tree_root() + assert summary.state_summary_root == state.state_roots.hash_tree_root()