Moves copy into SSZ container
This commit is contained in:
parent
5f8edd6b55
commit
c26fffc154
|
@ -25,8 +25,6 @@ from dataclasses import (
|
||||||
field,
|
field,
|
||||||
)
|
)
|
||||||
|
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from eth2spec.utils.ssz.ssz_impl import (
|
from eth2spec.utils.ssz.ssz_impl import (
|
||||||
hash_tree_root,
|
hash_tree_root,
|
||||||
signing_root,
|
signing_root,
|
||||||
|
@ -60,8 +58,6 @@ from dataclasses import (
|
||||||
field,
|
field,
|
||||||
)
|
)
|
||||||
|
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from eth2spec.utils.ssz.ssz_impl import (
|
from eth2spec.utils.ssz.ssz_impl import (
|
||||||
hash_tree_root,
|
hash_tree_root,
|
||||||
signing_root,
|
signing_root,
|
||||||
|
|
|
@ -86,7 +86,8 @@ def get_genesis_store(genesis_state: BeaconState) -> Store:
|
||||||
blocks={root: genesis_block},
|
blocks={root: genesis_block},
|
||||||
states={root: genesis_state},
|
states={root: genesis_state},
|
||||||
time=genesis_state.genesis_time,
|
time=genesis_state.genesis_time,
|
||||||
justified_root=root, finalized_root=root,
|
justified_root=root,
|
||||||
|
finalized_root=root,
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ def on_block(store: Store, block: BeaconBlock) -> None:
|
||||||
# Check block is a descendant of the finalized block
|
# Check block is a descendant of the finalized block
|
||||||
assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root
|
assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root
|
||||||
# Check block slot against Unix time
|
# Check block slot against Unix time
|
||||||
pre_state = deepcopy(store.states[block.parent_root])
|
pre_state = store.states[block.parent_root].copy()
|
||||||
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
|
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
|
||||||
# Check the block is valid and compute the post-state
|
# Check the block is valid and compute the post-state
|
||||||
state = state_transition(pre_state, block)
|
state = state_transition(pre_state, block)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import copy
|
||||||
from types import GeneratorType
|
from types import GeneratorType
|
||||||
from typing import (
|
from typing import (
|
||||||
List,
|
List,
|
||||||
|
@ -151,6 +152,9 @@ class Container(object):
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.hash_tree_root())
|
return hash(self.hash_tree_root())
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
return copy.deepcopy(self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields_dict(cls):
|
def get_fields_dict(cls):
|
||||||
return dict(cls.__annotations__)
|
return dict(cls.__annotations__)
|
||||||
|
|
Loading…
Reference in New Issue