From c26fffc15481ca282c75307a122f2012f4090cd1 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Thu, 20 Jun 2019 20:55:28 +0200 Subject: [PATCH] Moves copy into SSZ container --- scripts/build_spec.py | 4 ---- specs/core/0_fork-choice.md | 5 +++-- test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 9232cf00b..a16fa79ac 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -25,8 +25,6 @@ from dataclasses import ( field, ) -from copy import deepcopy - from eth2spec.utils.ssz.ssz_impl import ( hash_tree_root, signing_root, @@ -60,8 +58,6 @@ from dataclasses import ( field, ) -from copy import deepcopy - from eth2spec.utils.ssz.ssz_impl import ( hash_tree_root, signing_root, diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 5a4a52db4..ba97398a2 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -86,7 +86,8 @@ def get_genesis_store(genesis_state: BeaconState) -> Store: blocks={root: genesis_block}, states={root: genesis_state}, 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 assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root # 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 # Check the block is valid and compute the post-state state = state_transition(pre_state, block) diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 64d50b579..077f94b49 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -1,3 +1,4 @@ +import copy from types import GeneratorType from typing import ( List, @@ -151,6 +152,9 @@ class Container(object): def __hash__(self): return hash(self.hash_tree_root()) + def copy(self): + return copy.deepcopy(self) + @classmethod def get_fields_dict(cls): return dict(cls.__annotations__)