From 628891df1d29920173284f89200b661d4aa2987b Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 21 Oct 2020 23:15:30 +0000 Subject: [PATCH] fix genesis state root provided to HTTP server (#1783) ## Issue Addressed Resolves #1776 ## Proposed Changes The beacon chain builder was using the canonical head's state root for the `genesis_state_root` field. ## Additional Info --- beacon_node/beacon_chain/src/builder.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index 0c99c35f8..8d1fec9e7 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -80,6 +80,7 @@ pub struct BeaconChainBuilder { store_migrator_config: Option, pub genesis_time: Option, genesis_block_root: Option, + genesis_state_root: Option, #[allow(clippy::type_complexity)] fork_choice: Option< ForkChoice, T::EthSpec>, @@ -122,6 +123,7 @@ where store_migrator_config: None, genesis_time: None, genesis_block_root: None, + genesis_state_root: None, fork_choice: None, op_pool: None, eth1_chain: None, @@ -291,6 +293,7 @@ where .map_err(|e| format!("Unable to open persisted pubkey cache: {:?}", e))?; self.genesis_block_root = Some(chain.genesis_block_root); + self.genesis_state_root = Some(genesis_block.state_root()); self.head_tracker = Some( HeadTracker::from_ssz_container(&chain.ssz_head_tracker) .map_err(|e| format!("Failed to decode head tracker for database: {:?}", e))?, @@ -320,6 +323,7 @@ where let beacon_state_root = beacon_block.message.state_root; let beacon_block_root = beacon_block.canonical_root(); + self.genesis_state_root = Some(beacon_state_root); self.genesis_block_root = Some(beacon_block_root); store @@ -439,6 +443,9 @@ where let genesis_block_root = self .genesis_block_root .ok_or_else(|| "Cannot build without a genesis block root".to_string())?; + let genesis_state_root = self + .genesis_state_root + .ok_or_else(|| "Cannot build without a genesis state root".to_string())?; let current_slot = if slot_clock .is_prior_to_genesis() @@ -544,9 +551,9 @@ where observed_attester_slashings: <_>::default(), eth1_chain: self.eth1_chain, genesis_validators_root: canonical_head.beacon_state.genesis_validators_root, - genesis_state_root: canonical_head.beacon_state_root, canonical_head: TimeoutRwLock::new(canonical_head.clone()), genesis_block_root, + genesis_state_root, fork_choice: RwLock::new(fork_choice), event_handler: self .event_handler