From 427a53cdaea3573af17ccfef4c339a3e96fd0535 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 1 May 2019 09:24:51 +0100 Subject: [PATCH 1/3] Remove get_state_root from state transition doc Remove `get_state_root` from the state transition function spec because it is not used by the state transition function. --- specs/core/0_beacon-chain.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 55791e25f5..d7b5f61ee6 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -68,7 +68,6 @@ - [`get_crosslink_committees_at_slot`](#get_crosslink_committees_at_slot) - [`get_block_root_at_slot`](#get_block_root_at_slot) - [`get_block_root`](#get_block_root) - - [`get_state_root`](#get_state_root) - [`get_randao_mix`](#get_randao_mix) - [`get_active_index_root`](#get_active_index_root) - [`generate_seed`](#generate_seed) @@ -868,18 +867,6 @@ def get_block_root(state: BeaconState, return get_block_root_at_slot(state, get_epoch_start_slot(epoch)) ``` -### `get_state_root` - -```python -def get_state_root(state: BeaconState, - slot: Slot) -> Bytes32: - """ - Return the state root at a recent ``slot``. - """ - assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT - return state.latest_state_roots[slot % SLOTS_PER_HISTORICAL_ROOT] -``` - ### `get_randao_mix` ```python From b6b4d3cbafb44f176ad236abaebf304dac5365bc Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Wed, 1 May 2019 09:30:08 +0100 Subject: [PATCH 2/3] Add get_state_root in tests --- test_libs/pyspec/tests/test_sanity.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test_libs/pyspec/tests/test_sanity.py b/test_libs/pyspec/tests/test_sanity.py index b7d31f122a..cdc60aa0ae 100644 --- a/test_libs/pyspec/tests/test_sanity.py +++ b/test_libs/pyspec/tests/test_sanity.py @@ -9,6 +9,7 @@ from eth2spec.phase0.spec import ( # constants ZERO_HASH, + SLOTS_PER_HISTORICAL_ROOT, # SSZ Deposit, Transfer, @@ -17,7 +18,6 @@ get_active_validator_indices, get_beacon_proposer_index, get_block_root_at_slot, - get_state_root, get_current_epoch, get_domain, advance_slot, @@ -51,6 +51,14 @@ pytestmark = pytest.mark.sanity +def get_state_root(state, slot) -> bytes: + """ + Return the state root at a recent ``slot``. + """ + assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT + return state.latest_state_roots[slot % SLOTS_PER_HISTORICAL_ROOT] + + def test_slot_transition(state): test_state = deepcopy(state) cache_state(test_state) From 5f341ae493da8e908012c8a5cd629ea020ba0cbe Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 1 May 2019 17:06:02 +0800 Subject: [PATCH 3/3] Move `get_state_root` to `pyspec/tests/helpers.py` --- test_libs/pyspec/tests/helpers.py | 8 ++++++++ test_libs/pyspec/tests/test_sanity.py | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test_libs/pyspec/tests/helpers.py b/test_libs/pyspec/tests/helpers.py index 63e4cd710f..b7c2c52599 100644 --- a/test_libs/pyspec/tests/helpers.py +++ b/test_libs/pyspec/tests/helpers.py @@ -410,3 +410,11 @@ def next_epoch(state): block = build_empty_block_for_next_slot(state) block.slot += spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH) state_transition(state, block) + + +def get_state_root(state, slot) -> bytes: + """ + Return the state root at a recent ``slot``. + """ + assert slot < state.slot <= slot + spec.SLOTS_PER_HISTORICAL_ROOT + return state.latest_state_roots[slot % spec.SLOTS_PER_HISTORICAL_ROOT] diff --git a/test_libs/pyspec/tests/test_sanity.py b/test_libs/pyspec/tests/test_sanity.py index cdc60aa0ae..1b4d20f4c5 100644 --- a/test_libs/pyspec/tests/test_sanity.py +++ b/test_libs/pyspec/tests/test_sanity.py @@ -38,6 +38,7 @@ build_deposit_data, build_empty_block_for_next_slot, fill_aggregate_attestation, + get_state_root, get_valid_attestation, get_valid_attester_slashing, get_valid_proposer_slashing, @@ -51,14 +52,6 @@ pytestmark = pytest.mark.sanity -def get_state_root(state, slot) -> bytes: - """ - Return the state root at a recent ``slot``. - """ - assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT - return state.latest_state_roots[slot % SLOTS_PER_HISTORICAL_ROOT] - - def test_slot_transition(state): test_state = deepcopy(state) cache_state(test_state)