Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Dec 24, 2024
1 parent 4fa32cc commit fc623fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
7 changes: 1 addition & 6 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,7 @@ where
})?;

let migrator_config = self.store_migrator_config.unwrap_or_default();
let store_migrator = BackgroundMigrator::new(
store.clone(),
migrator_config,
genesis_block_root,
log.clone(),
);
let store_migrator = BackgroundMigrator::new(store.clone(), migrator_config, log.clone());

if let Some(slot) = slot_clock.now() {
validator_monitor.process_valid_state(
Expand Down
20 changes: 3 additions & 17 deletions beacon_node/beacon_chain/src/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::beacon_chain::BEACON_CHAIN_DB_KEY;
use crate::errors::BeaconChainError;
use crate::persisted_beacon_chain::{PersistedBeaconChain, DUMMY_CANONICAL_HEAD_BLOCK_ROOT};
use crate::summaries_dag::{
self, BlockSummariesDAG, DAGBlockSummary, DAGStateSummary, StateSummariesDAG,
};
Expand All @@ -13,7 +11,7 @@ use std::sync::{mpsc, Arc};
use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use store::hot_cold_store::{migrate_database, HotColdDBError};
use store::{DBColumn, Error, HotStateSummary, ItemStore, StoreItem, StoreOp};
use store::{DBColumn, Error, HotStateSummary, ItemStore, StoreOp};
pub use store::{HotColdDB, MemoryStore};
use types::{BeaconState, BeaconStateHash, Checkpoint, Epoch, EthSpec, Hash256, Slot};

Expand All @@ -39,8 +37,6 @@ pub struct BackgroundMigrator<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
prev_migration: Arc<Mutex<PrevMigration>>,
#[allow(clippy::type_complexity)]
tx_thread: Option<Mutex<(mpsc::Sender<Notification>, thread::JoinHandle<()>)>>,
/// Genesis block root, for persisting the `PersistedBeaconChain`.
genesis_block_root: Hash256,
log: Logger,
}

Expand Down Expand Up @@ -132,17 +128,11 @@ pub struct FinalizationNotification {
finalized_state_root: BeaconStateHash,
finalized_checkpoint: Checkpoint,
prev_migration: Arc<Mutex<PrevMigration>>,
genesis_block_root: Hash256,
}

impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Hot, Cold> {
/// Create a new `BackgroundMigrator` and spawn its thread if necessary.
pub fn new(
db: Arc<HotColdDB<E, Hot, Cold>>,
config: MigratorConfig,
genesis_block_root: Hash256,
log: Logger,
) -> Self {
pub fn new(db: Arc<HotColdDB<E, Hot, Cold>>, config: MigratorConfig, log: Logger) -> Self {
// Estimate last migration run from DB split slot.
let prev_migration = Arc::new(Mutex::new(PrevMigration {
epoch: db.get_split_slot().epoch(E::slots_per_epoch()),
Expand All @@ -157,7 +147,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
db,
tx_thread,
prev_migration,
genesis_block_root,
log,
}
}
Expand All @@ -176,7 +165,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
finalized_state_root,
finalized_checkpoint,
prev_migration: self.prev_migration.clone(),
genesis_block_root: self.genesis_block_root,
};

// Send to background thread if configured, otherwise run in foreground.
Expand Down Expand Up @@ -361,7 +349,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
finalized_state_root.into(),
&finalized_state,
notif.finalized_checkpoint,
notif.genesis_block_root,
log,
) {
Ok(PruningOutcome::Successful {
Expand Down Expand Up @@ -472,7 +459,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
new_finalized_state_hash: Hash256,
new_finalized_state: &BeaconState<E>,
new_finalized_checkpoint: Checkpoint,
genesis_block_root: Hash256,
log: &Logger,
) -> Result<PruningOutcome, BeaconChainError> {
let new_finalized_slot = new_finalized_checkpoint
Expand Down Expand Up @@ -532,7 +518,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
.iter()
.map(|block_root| {
let block = store
.get_blinded_block(&block_root)?
.get_blinded_block(block_root)?
.ok_or(PruningError::MissingBlindedBlock(*block_root))?;
Ok((
*block_root,
Expand Down
14 changes: 10 additions & 4 deletions beacon_node/beacon_chain/src/summaries_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl BlockSummariesDAG {

#[cfg(test)]
mod tests {
use super::{BlockSummariesDAG, DAGStateSummaryV22, Error, StateSummariesDAG};
use super::{BlockSummariesDAG, DAGBlockSummary, DAGStateSummaryV22, Error, StateSummariesDAG};
use bls::FixedBytesExtended;
use std::collections::HashMap;
use types::{Hash256, Slot};
Expand All @@ -292,6 +292,13 @@ mod tests {
Hash256::from_low_u64_le(n)
}

fn block_with_parent(parent_root: Hash256) -> DAGBlockSummary {
DAGBlockSummary {
slot: Slot::new(0),
parent_root,
}
}

#[test]
fn new_from_v22_empty() {
StateSummariesDAG::new_from_v22(vec![], HashMap::new(), Hash256::ZERO).unwrap();
Expand Down Expand Up @@ -321,9 +328,8 @@ mod tests {
let root_1 = root(1);
let root_2 = root(2);
let root_3 = root(3);
// (child, parent)
let parents = HashMap::from_iter([(root_1, root_2)]);
let dag = BlockSummariesDAG::new(parents);
let parents = vec![(root_1, block_with_parent(root_2))];
let dag = BlockSummariesDAG::new(&parents);

// root 1 is known and has no childs
assert_eq!(
Expand Down

0 comments on commit fc623fe

Please sign in to comment.