From ed748a7d769e3d81697a2df92f1638cccf9c5057 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sat, 15 Jun 2019 15:09:50 +0100 Subject: [PATCH] Address Danny's comments --- scripts/build_spec.py | 2 +- specs/core/0_beacon-chain.md | 14 +++++++------- specs/core/0_fork-choice.md | 4 ++-- test_libs/pyspec/eth2spec/test/helpers/block.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index e25147a7f..eae9b60d5 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -62,7 +62,6 @@ from eth2spec.utils.bls import ( from eth2spec.utils.hash_function import hash ''' -BYTE_TYPES = [4, 32, 48, 96] NEW_TYPES = { 'Slot': 'int', 'Epoch': 'int', @@ -70,6 +69,7 @@ NEW_TYPES = { 'ValidatorIndex': 'int', 'Gwei': 'int', } +BYTE_TYPES = [4, 32, 48, 96] SUNDRY_FUNCTIONS = ''' def get_ssz_type_by_name(name: str) -> Container: return globals()[name] diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b4049bb30..367a1cceb 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -493,7 +493,7 @@ class BeaconState(Container): slot: Slot fork: Fork # History - parent_block_header: BeaconBlockHeader + latest_block_header: BeaconBlockHeader block_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT] historical_roots: List[Hash] @@ -1152,7 +1152,7 @@ def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, genesis state = BeaconState( genesis_time=genesis_time, eth1_data=genesis_eth1_data, - parent_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), + latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), ) # Process genesis deposits @@ -1212,11 +1212,11 @@ def process_slot(state: BeaconState) -> None: state.state_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_state_root # Cache latest block header state root - if state.parent_block_header.state_root == ZERO_HASH: - state.parent_block_header.state_root = previous_state_root + if state.latest_block_header.state_root == ZERO_HASH: + state.latest_block_header.state_root = previous_state_root # Cache block root - previous_block_root = signing_root(state.parent_block_header) + previous_block_root = signing_root(state.latest_block_header) state.block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_block_root ``` @@ -1556,9 +1556,9 @@ def process_block_header(state: BeaconState, block: BeaconBlock) -> None: # Verify that the slots match assert block.slot == state.slot # Verify that the parent matches - assert block.parent_root == signing_root(state.parent_block_header) + assert block.parent_root == signing_root(state.latest_block_header) # Save current block as the new latest block - state.parent_block_header = BeaconBlockHeader( + state.latest_block_header = BeaconBlockHeader( slot=block.slot, parent_root=block.parent_root, body_root=hash_tree_root(block.body), diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 739c06d59..8103bbeb2 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -68,8 +68,8 @@ def get_ancestor(store: Store, block: BeaconBlock, slot: Slot) -> BeaconBlock: return get_ancestor(store, store.get_parent(block), slot) ``` -* Let `get_attestation(store: Store, index: ValidatorIndex) -> Attestation` be the attestation with the highest slot number in `store` from the validator with the given `index`. If several such attestations exist, use the one the validator `v` observed first. -* Let `get_attestation_target(store: Store, index: ValidatorIndex) -> BeaconBlock` be the target block in the attestation `get_attestation(store, index)`. +* Let `get_latest_attestation(store: Store, index: ValidatorIndex) -> Attestation` be the attestation with the highest slot number in `store` from the validator with the given `index`. If several such attestations exist, use the one the validator `v` observed first. +* Let `get_attestation_target(store: Store, index: ValidatorIndex) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, index)`. * Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` return the child blocks of the given `block`. * Let `justified_head_state` be the resulting `BeaconState` object from processing the chain up to the `justified_head`. * The `head` is `lmd_ghost(store, justified_head_state, justified_head)` where the function `lmd_ghost` is defined below. Note that the implementation below is suboptimal; there are implementations that compute the head in time logarithmic in slot count. diff --git a/test_libs/pyspec/eth2spec/test/helpers/block.py b/test_libs/pyspec/eth2spec/test/helpers/block.py index 03f8d5b7e..16249fe93 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/block.py +++ b/test_libs/pyspec/eth2spec/test/helpers/block.py @@ -58,7 +58,7 @@ def build_empty_block(spec, state, slot=None, signed=False): empty_block = spec.BeaconBlock() empty_block.slot = slot empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index - previous_block_header = deepcopy(state.parent_block_header) + previous_block_header = deepcopy(state.latest_block_header) if previous_block_header.state_root == spec.ZERO_HASH: previous_block_header.state_root = state.hash_tree_root() empty_block.parent_root = signing_root(previous_block_header)