Alias zero hash to genesis in find head

This commit is contained in:
Paul Hauner 2019-06-16 09:22:05 -04:00
parent 8fb6ffffe2
commit 1638a7aa62
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 17 additions and 1 deletions

View File

@ -18,12 +18,18 @@ pub enum Error {
pub struct ForkChoice<T: BeaconChainTypes> {
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<T: BeaconChainTypes> ForkChoice<T> {
pub fn new(store: Arc<T::Store>, genesis_block_root: Hash256) -> Self {
Self {
backend: T::LmdGhost::new(store, genesis_block_root),
genesis_block_root,
}
}
@ -41,11 +47,19 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
} else {
state.finalized_root
};
let block = chain
.store
.get::<BeaconBlock>(&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::<BeaconState<T::EthSpec>>(&block.state_root)?

View File

@ -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();
}
}
}