Alias zero hash to genesis in find head
This commit is contained in:
parent
8fb6ffffe2
commit
1638a7aa62
@ -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)?
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user