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> {
|
pub struct ForkChoice<T: BeaconChainTypes> {
|
||||||
backend: T::LmdGhost,
|
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> {
|
impl<T: BeaconChainTypes> ForkChoice<T> {
|
||||||
pub fn new(store: Arc<T::Store>, genesis_block_root: Hash256) -> Self {
|
pub fn new(store: Arc<T::Store>, genesis_block_root: Hash256) -> Self {
|
||||||
Self {
|
Self {
|
||||||
backend: T::LmdGhost::new(store, genesis_block_root),
|
backend: T::LmdGhost::new(store, genesis_block_root),
|
||||||
|
genesis_block_root,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,11 +47,19 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
|||||||
} else {
|
} else {
|
||||||
state.finalized_root
|
state.finalized_root
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = chain
|
let block = chain
|
||||||
.store
|
.store
|
||||||
.get::<BeaconBlock>(&block_root)?
|
.get::<BeaconBlock>(&block_root)?
|
||||||
.ok_or_else(|| Error::MissingBlock(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
|
let state = chain
|
||||||
.store
|
.store
|
||||||
.get::<BeaconState<T::EthSpec>>(&block.state_root)?
|
.get::<BeaconState<T::EthSpec>>(&block.state_root)?
|
||||||
|
@ -142,6 +142,8 @@ mod test {
|
|||||||
MinimalEthSpec,
|
MinimalEthSpec,
|
||||||
> = BeaconChainHarness::new(VALIDATOR_COUNT);
|
> = BeaconChainHarness::new(VALIDATOR_COUNT);
|
||||||
|
|
||||||
|
for _ in 0..MinimalEthSpec::slots_per_epoch() * 2 {
|
||||||
harness.extend_canonical_chain();
|
harness.extend_canonical_chain();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user