703c33bdc7
## Issue Addressed Closes #1557 ## Proposed Changes Modify the pruning algorithm so that it mutates the head-tracker _before_ committing the database transaction to disk, and _only if_ all the heads to be removed are still present in the head-tracker (i.e. no concurrent mutations). In the process of writing and testing this I also had to make a few other changes: * Use internal mutability for all `BeaconChainHarness` functions (namely the RNG and the graffiti), in order to enable parallel calls (see testing section below). * Disable logging in harness tests unless the `test_logger` feature is turned on And chose to make some clean-ups: * Delete the `NullMigrator` * Remove type-based configuration for the migrator in favour of runtime config (simpler, less duplicated code) * Use the non-blocking migrator unless the blocking migrator is required. In the store tests we need the blocking migrator because some tests make asserts about the state of the DB after the migration has run. * Rename `validators_keypairs` -> `validator_keypairs` in the `BeaconChainHarness` ## Testing To confirm that the fix worked, I wrote a test using [Hiatus](https://crates.io/crates/hiatus), which can be found here: https://github.com/michaelsproul/lighthouse/tree/hiatus-issue-1557 That test can't be merged because it inserts random breakpoints everywhere, but if you check out that branch you can run the test with: ``` $ cd beacon_node/beacon_chain $ cargo test --release --test parallel_tests --features test_logger ``` It should pass, and the log output should show: ``` WARN Pruning deferred because of a concurrent mutation, message: this is expected only very rarely! ``` ## Additional Info This is a backwards-compatible change with no impact on consensus.
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
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;
|
|
|
|
/// Dummy value to use for the canonical head block root, see below.
|
|
pub const DUMMY_CANONICAL_HEAD_BLOCK_ROOT: Hash256 = Hash256::repeat_byte(0xff);
|
|
|
|
#[derive(Clone, Encode, Decode)]
|
|
pub struct PersistedBeaconChain {
|
|
/// This value is ignored to resolve the issue described here:
|
|
///
|
|
/// https://github.com/sigp/lighthouse/pull/1639
|
|
///
|
|
/// Its removal is tracked here:
|
|
///
|
|
/// https://github.com/sigp/lighthouse/issues/1784
|
|
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)
|
|
}
|
|
}
|