Skip to content

Commit 29ad4fc

Browse files
committed
Drop head tracker for summaries dag
1 parent 7e0cdde commit 29ad4fc

File tree

11 files changed

+708
-554
lines changed

11 files changed

+708
-554
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

+17-37
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::events::ServerSentEventHandler;
3333
use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, PreparePayloadHandle};
3434
use crate::fork_choice_signal::{ForkChoiceSignalRx, ForkChoiceSignalTx, ForkChoiceWaitResult};
3535
use crate::graffiti_calculator::GraffitiCalculator;
36-
use crate::head_tracker::{HeadTracker, HeadTrackerReader, SszHeadTracker};
3736
use crate::light_client_finality_update_verification::{
3837
Error as LightClientFinalityUpdateError, VerifiedLightClientFinalityUpdate,
3938
};
@@ -456,8 +455,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
456455
/// A handler for events generated by the beacon chain. This is only initialized when the
457456
/// HTTP server is enabled.
458457
pub event_handler: Option<ServerSentEventHandler<T::EthSpec>>,
459-
/// Used to track the heads of the beacon chain.
460-
pub(crate) head_tracker: Arc<HeadTracker>,
461458
/// Caches the attester shuffling for a given epoch and shuffling key root.
462459
pub shuffling_cache: RwLock<ShufflingCache>,
463460
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -618,50 +615,30 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
618615
pub fn persist_head_and_fork_choice(&self) -> Result<(), Error> {
619616
let mut batch = vec![];
620617

621-
let _head_timer = metrics::start_timer(&metrics::PERSIST_HEAD);
622-
623-
// Hold a lock to head_tracker until it has been persisted to disk. Otherwise there's a race
624-
// condition with the pruning thread which can result in a block present in the head tracker
625-
// but absent in the DB. This inconsistency halts pruning and dramastically increases disk
626-
// size. Ref: https://github.com/sigp/lighthouse/issues/4773
627-
let head_tracker = self.head_tracker.0.read();
628-
batch.push(self.persist_head_in_batch(&head_tracker));
629-
630618
let _fork_choice_timer = metrics::start_timer(&metrics::PERSIST_FORK_CHOICE);
631619
batch.push(self.persist_fork_choice_in_batch());
632620

633621
self.store.hot_db.do_atomically(batch)?;
634-
drop(head_tracker);
635622

636623
Ok(())
637624
}
638625

639626
/// Return a `PersistedBeaconChain` without reference to a `BeaconChain`.
640-
pub fn make_persisted_head(
641-
genesis_block_root: Hash256,
642-
head_tracker_reader: &HeadTrackerReader,
643-
) -> PersistedBeaconChain {
627+
pub fn make_persisted_head(genesis_block_root: Hash256) -> PersistedBeaconChain {
644628
PersistedBeaconChain {
645629
_canonical_head_block_root: DUMMY_CANONICAL_HEAD_BLOCK_ROOT,
646630
genesis_block_root,
647-
ssz_head_tracker: SszHeadTracker::from_map(head_tracker_reader),
631+
ssz_head_tracker: <_>::default(),
648632
}
649633
}
650634

651635
/// Return a database operation for writing the beacon chain head to disk.
652-
pub fn persist_head_in_batch(
653-
&self,
654-
head_tracker_reader: &HeadTrackerReader,
655-
) -> KeyValueStoreOp {
656-
Self::persist_head_in_batch_standalone(self.genesis_block_root, head_tracker_reader)
636+
pub fn persist_head_in_batch(&self) -> KeyValueStoreOp {
637+
Self::persist_head_in_batch_standalone(self.genesis_block_root)
657638
}
658639

659-
pub fn persist_head_in_batch_standalone(
660-
genesis_block_root: Hash256,
661-
head_tracker_reader: &HeadTrackerReader,
662-
) -> KeyValueStoreOp {
663-
Self::make_persisted_head(genesis_block_root, head_tracker_reader)
664-
.as_kv_store_op(BEACON_CHAIN_DB_KEY)
640+
pub fn persist_head_in_batch_standalone(genesis_block_root: Hash256) -> KeyValueStoreOp {
641+
Self::make_persisted_head(genesis_block_root).as_kv_store_op(BEACON_CHAIN_DB_KEY)
665642
}
666643

667644
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1405,12 +1382,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
14051382
///
14061383
/// Returns `(block_root, block_slot)`.
14071384
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
1408-
self.head_tracker.heads()
1385+
let head_slot = self.canonical_head.cached_head().head_slot();
1386+
self.canonical_head
1387+
.fork_choice_read_lock()
1388+
.proto_array()
1389+
.viable_heads::<T::EthSpec>(head_slot)
1390+
.iter()
1391+
.map(|node| (node.root, node.slot))
1392+
.collect()
14091393
}
14101394

14111395
/// Only used in tests.
14121396
pub fn knows_head(&self, block_hash: &SignedBeaconBlockHash) -> bool {
1413-
self.head_tracker.contains_head((*block_hash).into())
1397+
self.heads()
1398+
.iter()
1399+
.any(|head| head.0 == Into::<Hash256>::into(*block_hash))
14141400
}
14151401

14161402
/// Returns the `BeaconState` at the given slot.
@@ -3989,9 +3975,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
39893975
// about it.
39903976
let block_time_imported = timestamp_now();
39913977

3992-
let parent_root = block.parent_root();
3993-
let slot = block.slot();
3994-
39953978
let current_eth1_finalization_data = Eth1FinalizationData {
39963979
eth1_data: state.eth1_data().clone(),
39973980
eth1_deposit_index: state.eth1_deposit_index(),
@@ -4012,9 +3995,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40123995
});
40133996
}
40143997

4015-
self.head_tracker
4016-
.register_block(block_root, parent_root, slot);
4017-
40183998
metrics::stop_timer(db_write_timer);
40193999

40204000
metrics::inc_counter(&metrics::BLOCK_PROCESSING_SUCCESSES);

beacon_node/beacon_chain/src/builder.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::eth1_finalization_cache::Eth1FinalizationCache;
88
use crate::fork_choice_signal::ForkChoiceSignalTx;
99
use crate::fork_revert::{reset_fork_choice_to_finalization, revert_to_fork_boundary};
1010
use crate::graffiti_calculator::{GraffitiCalculator, GraffitiOrigin};
11-
use crate::head_tracker::HeadTracker;
1211
use crate::light_client_server_cache::LightClientServerCache;
1312
use crate::migrate::{BackgroundMigrator, MigratorConfig};
1413
use crate::observed_data_sidecars::ObservedDataSidecars;
@@ -91,7 +90,6 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
9190
slot_clock: Option<T::SlotClock>,
9291
shutdown_sender: Option<Sender<ShutdownReason>>,
9392
light_client_server_tx: Option<Sender<LightClientProducerEvent<T::EthSpec>>>,
94-
head_tracker: Option<HeadTracker>,
9593
validator_pubkey_cache: Option<ValidatorPubkeyCache<T>>,
9694
spec: Arc<ChainSpec>,
9795
chain_config: ChainConfig,
@@ -135,7 +133,6 @@ where
135133
slot_clock: None,
136134
shutdown_sender: None,
137135
light_client_server_tx: None,
138-
head_tracker: None,
139136
validator_pubkey_cache: None,
140137
spec: Arc::new(E::default_spec()),
141138
chain_config: ChainConfig::default(),
@@ -324,10 +321,6 @@ where
324321

325322
self.genesis_block_root = Some(chain.genesis_block_root);
326323
self.genesis_state_root = Some(genesis_block.state_root());
327-
self.head_tracker = Some(
328-
HeadTracker::from_ssz_container(&chain.ssz_head_tracker)
329-
.map_err(|e| format!("Failed to decode head tracker for database: {:?}", e))?,
330-
);
331324
self.validator_pubkey_cache = Some(pubkey_cache);
332325
self.fork_choice = Some(fork_choice);
333326

@@ -724,7 +717,6 @@ where
724717
.genesis_state_root
725718
.ok_or("Cannot build without a genesis state root")?;
726719
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
727-
let head_tracker = Arc::new(self.head_tracker.unwrap_or_default());
728720
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();
729721

730722
let mut validator_monitor = ValidatorMonitor::new(
@@ -769,8 +761,6 @@ where
769761
&log,
770762
)?;
771763

772-
// Update head tracker.
773-
head_tracker.register_block(block_root, block.parent_root(), block.slot());
774764
(block_root, block, true)
775765
}
776766
Err(e) => return Err(descriptive_db_error("head block", &e)),
@@ -826,12 +816,7 @@ where
826816
})?;
827817

828818
let migrator_config = self.store_migrator_config.unwrap_or_default();
829-
let store_migrator = BackgroundMigrator::new(
830-
store.clone(),
831-
migrator_config,
832-
genesis_block_root,
833-
log.clone(),
834-
);
819+
let store_migrator = BackgroundMigrator::new(store.clone(), migrator_config, log.clone());
835820

836821
if let Some(slot) = slot_clock.now() {
837822
validator_monitor.process_valid_state(
@@ -856,11 +841,10 @@ where
856841
//
857842
// This *must* be stored before constructing the `BeaconChain`, so that its `Drop` instance
858843
// doesn't write a `PersistedBeaconChain` without the rest of the batch.
859-
let head_tracker_reader = head_tracker.0.read();
860844
self.pending_io_batch.push(BeaconChain::<
861845
Witness<TSlotClock, TEth1Backend, E, THotStore, TColdStore>,
862846
>::persist_head_in_batch_standalone(
863-
genesis_block_root, &head_tracker_reader
847+
genesis_block_root
864848
));
865849
self.pending_io_batch.push(BeaconChain::<
866850
Witness<TSlotClock, TEth1Backend, E, THotStore, TColdStore>,
@@ -871,7 +855,6 @@ where
871855
.hot_db
872856
.do_atomically(self.pending_io_batch)
873857
.map_err(|e| format!("Error writing chain & metadata to disk: {:?}", e))?;
874-
drop(head_tracker_reader);
875858

876859
let genesis_validators_root = head_snapshot.beacon_state.genesis_validators_root();
877860
let genesis_time = head_snapshot.beacon_state.genesis_time();
@@ -952,7 +935,6 @@ where
952935
fork_choice_signal_tx,
953936
fork_choice_signal_rx,
954937
event_handler: self.event_handler,
955-
head_tracker,
956938
shuffling_cache: RwLock::new(ShufflingCache::new(
957939
shuffling_cache_size,
958940
head_shuffling_ids,

beacon_node/beacon_chain/src/canonical_head.rs

-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
992992
self.store_migrator.process_finalization(
993993
new_finalized_state_root.into(),
994994
new_view.finalized_checkpoint,
995-
self.head_tracker.clone(),
996995
)?;
997996

998997
// Prune blobs in the background.

0 commit comments

Comments
 (0)