bd39cc8e26
## Issue Addressed
- Resolves #1616
## Proposed Changes
If we look at the function which persists fork choice and the canonical head to disk:
1db8daae0c/beacon_node/beacon_chain/src/beacon_chain.rs (L234-L280)
There is a race-condition which might cause the canonical head and fork choice values to be out-of-sync.
I believe this is the cause of #1616. I managed to recreate the issue and produce a database that was unable to sync under the `master` branch but able to sync with this branch.
These new changes solve the issue by ignoring the persisted `canonical_head_block_root` value and instead getting fork choice to generate it. This ensures that the canonical head is in-sync with fork choice.
## Additional Info
This is hotfix method that leaves some crusty code hanging around. Once this PR is merged (to satisfy the v0.2.x users) we should later update and merge #1638 so we can have a clean fix for the v0.3.x versions.
34 lines
951 B
Rust
34 lines
951 B
Rust
use crate::head_tracker::SszHeadTracker;
|
|
use ssz::{Decode, Encode};
|
|
use ssz_derive::{Decode, Encode};
|
|
use store::{DBColumn, Error as StoreError, StoreItem};
|
|
use types::Hash256;
|
|
|
|
#[derive(Clone, Encode, Decode)]
|
|
pub struct PersistedBeaconChain {
|
|
/// This value is ignored to resolve the issue described here:
|
|
///
|
|
/// https://github.com/sigp/lighthouse/pull/1639
|
|
///
|
|
/// The following PR will clean-up and remove this field:
|
|
///
|
|
/// https://github.com/sigp/lighthouse/pull/1638
|
|
pub canonical_head_block_root: Hash256,
|
|
pub genesis_block_root: Hash256,
|
|
pub ssz_head_tracker: SszHeadTracker,
|
|
}
|
|
|
|
impl StoreItem for PersistedBeaconChain {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconChain
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
|
|
Self::from_ssz_bytes(bytes).map_err(Into::into)
|
|
}
|
|
}
|