From 1638a7aa6235942b6c07f020ec92e05ca8aec6d8 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 16 Jun 2019 09:22:05 -0400 Subject: [PATCH] Alias zero hash to genesis in find head --- beacon_node/beacon_chain/src/fork_choice.rs | 14 ++++++++++++++ beacon_node/beacon_chain/src/test_utils.rs | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/beacon_node/beacon_chain/src/fork_choice.rs b/beacon_node/beacon_chain/src/fork_choice.rs index fbe8e3996..0d132386d 100644 --- a/beacon_node/beacon_chain/src/fork_choice.rs +++ b/beacon_node/beacon_chain/src/fork_choice.rs @@ -18,12 +18,18 @@ pub enum Error { pub struct ForkChoice { backend: T::LmdGhost, + /// Used for resolving the `0x00..00` alias back to genesis. + /// + /// Does not necessarily need to be the _actual_ genesis, it suffices to be the finalized root + /// whenever the struct was instantiated. + genesis_block_root: Hash256, } impl ForkChoice { pub fn new(store: Arc, genesis_block_root: Hash256) -> Self { Self { backend: T::LmdGhost::new(store, genesis_block_root), + genesis_block_root, } } @@ -41,11 +47,19 @@ impl ForkChoice { } else { state.finalized_root }; + let block = chain .store .get::(&block_root)? .ok_or_else(|| Error::MissingBlock(block_root))?; + // Resolve the `0x00.. 00` alias back to genesis + let block_root = if block_root == Hash256::zero() { + self.genesis_block_root + } else { + block_root + }; + let state = chain .store .get::>(&block.state_root)? diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index be370ff65..ece0a2fa2 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -142,6 +142,8 @@ mod test { MinimalEthSpec, > = BeaconChainHarness::new(VALIDATOR_COUNT); - harness.extend_canonical_chain(); + for _ in 0..MinimalEthSpec::slots_per_epoch() * 2 { + harness.extend_canonical_chain(); + } } }