Address Danny's comments
This commit is contained in:
parent
a6230425b8
commit
ed748a7d76
|
@ -62,7 +62,6 @@ from eth2spec.utils.bls import (
|
||||||
|
|
||||||
from eth2spec.utils.hash_function import hash
|
from eth2spec.utils.hash_function import hash
|
||||||
'''
|
'''
|
||||||
BYTE_TYPES = [4, 32, 48, 96]
|
|
||||||
NEW_TYPES = {
|
NEW_TYPES = {
|
||||||
'Slot': 'int',
|
'Slot': 'int',
|
||||||
'Epoch': 'int',
|
'Epoch': 'int',
|
||||||
|
@ -70,6 +69,7 @@ NEW_TYPES = {
|
||||||
'ValidatorIndex': 'int',
|
'ValidatorIndex': 'int',
|
||||||
'Gwei': 'int',
|
'Gwei': 'int',
|
||||||
}
|
}
|
||||||
|
BYTE_TYPES = [4, 32, 48, 96]
|
||||||
SUNDRY_FUNCTIONS = '''
|
SUNDRY_FUNCTIONS = '''
|
||||||
def get_ssz_type_by_name(name: str) -> Container:
|
def get_ssz_type_by_name(name: str) -> Container:
|
||||||
return globals()[name]
|
return globals()[name]
|
||||||
|
|
|
@ -493,7 +493,7 @@ class BeaconState(Container):
|
||||||
slot: Slot
|
slot: Slot
|
||||||
fork: Fork
|
fork: Fork
|
||||||
# History
|
# History
|
||||||
parent_block_header: BeaconBlockHeader
|
latest_block_header: BeaconBlockHeader
|
||||||
block_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT]
|
block_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT]
|
||||||
state_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT]
|
state_roots: Vector[Hash, SLOTS_PER_HISTORICAL_ROOT]
|
||||||
historical_roots: List[Hash]
|
historical_roots: List[Hash]
|
||||||
|
@ -1152,7 +1152,7 @@ def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, genesis
|
||||||
state = BeaconState(
|
state = BeaconState(
|
||||||
genesis_time=genesis_time,
|
genesis_time=genesis_time,
|
||||||
eth1_data=genesis_eth1_data,
|
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
|
# 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
|
state.state_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_state_root
|
||||||
|
|
||||||
# Cache latest block header state root
|
# Cache latest block header state root
|
||||||
if state.parent_block_header.state_root == ZERO_HASH:
|
if state.latest_block_header.state_root == ZERO_HASH:
|
||||||
state.parent_block_header.state_root = previous_state_root
|
state.latest_block_header.state_root = previous_state_root
|
||||||
|
|
||||||
# Cache block 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
|
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
|
# Verify that the slots match
|
||||||
assert block.slot == state.slot
|
assert block.slot == state.slot
|
||||||
# Verify that the parent matches
|
# 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
|
# Save current block as the new latest block
|
||||||
state.parent_block_header = BeaconBlockHeader(
|
state.latest_block_header = BeaconBlockHeader(
|
||||||
slot=block.slot,
|
slot=block.slot,
|
||||||
parent_root=block.parent_root,
|
parent_root=block.parent_root,
|
||||||
body_root=hash_tree_root(block.body),
|
body_root=hash_tree_root(block.body),
|
||||||
|
|
|
@ -68,8 +68,8 @@ def get_ancestor(store: Store, block: BeaconBlock, slot: Slot) -> BeaconBlock:
|
||||||
return get_ancestor(store, store.get_parent(block), slot)
|
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_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_attestation(store, index)`.
|
* 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 `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`.
|
* 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.
|
* 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.
|
||||||
|
|
|
@ -58,7 +58,7 @@ def build_empty_block(spec, state, slot=None, signed=False):
|
||||||
empty_block = spec.BeaconBlock()
|
empty_block = spec.BeaconBlock()
|
||||||
empty_block.slot = slot
|
empty_block.slot = slot
|
||||||
empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index
|
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:
|
if previous_block_header.state_root == spec.ZERO_HASH:
|
||||||
previous_block_header.state_root = state.hash_tree_root()
|
previous_block_header.state_root = state.hash_tree_root()
|
||||||
empty_block.parent_root = signing_root(previous_block_header)
|
empty_block.parent_root = signing_root(previous_block_header)
|
||||||
|
|
Loading…
Reference in New Issue