Skip to content

Commit be105d1

Browse files
committed
Drop head tracker for summaries dag
1 parent 95cec45 commit be105d1

File tree

11 files changed

+708
-600
lines changed

11 files changed

+708
-600
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 17 additions & 37 deletions
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::kzg_utils::reconstruct_blobs;
3837
use crate::light_client_finality_update_verification::{
3938
Error as LightClientFinalityUpdateError, VerifiedLightClientFinalityUpdate,
@@ -458,8 +457,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
458457
/// A handler for events generated by the beacon chain. This is only initialized when the
459458
/// HTTP server is enabled.
460459
pub event_handler: Option<ServerSentEventHandler<T::EthSpec>>,
461-
/// Used to track the heads of the beacon chain.
462-
pub(crate) head_tracker: Arc<HeadTracker>,
463460
/// Caches the attester shuffling for a given epoch and shuffling key root.
464461
pub shuffling_cache: RwLock<ShufflingCache>,
465462
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -620,50 +617,30 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
620617
pub fn persist_head_and_fork_choice(&self) -> Result<(), Error> {
621618
let mut batch = vec![];
622619

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

635623
self.store.hot_db.do_atomically(batch)?;
636-
drop(head_tracker);
637624

638625
Ok(())
639626
}
640627

641628
/// Return a `PersistedBeaconChain` without reference to a `BeaconChain`.
642-
pub fn make_persisted_head(
643-
genesis_block_root: Hash256,
644-
head_tracker_reader: &HeadTrackerReader,
645-
) -> PersistedBeaconChain {
629+
pub fn make_persisted_head(genesis_block_root: Hash256) -> PersistedBeaconChain {
646630
PersistedBeaconChain {
647631
_canonical_head_block_root: DUMMY_CANONICAL_HEAD_BLOCK_ROOT,
648632
genesis_block_root,
649-
ssz_head_tracker: SszHeadTracker::from_map(head_tracker_reader),
633+
ssz_head_tracker: <_>::default(),
650634
}
651635
}
652636

653637
/// Return a database operation for writing the beacon chain head to disk.
654-
pub fn persist_head_in_batch(
655-
&self,
656-
head_tracker_reader: &HeadTrackerReader,
657-
) -> KeyValueStoreOp {
658-
Self::persist_head_in_batch_standalone(self.genesis_block_root, head_tracker_reader)
638+
pub fn persist_head_in_batch(&self) -> KeyValueStoreOp {
639+
Self::persist_head_in_batch_standalone(self.genesis_block_root)
659640
}
660641

661-
pub fn persist_head_in_batch_standalone(
662-
genesis_block_root: Hash256,
663-
head_tracker_reader: &HeadTrackerReader,
664-
) -> KeyValueStoreOp {
665-
Self::make_persisted_head(genesis_block_root, head_tracker_reader)
666-
.as_kv_store_op(BEACON_CHAIN_DB_KEY)
642+
pub fn persist_head_in_batch_standalone(genesis_block_root: Hash256) -> KeyValueStoreOp {
643+
Self::make_persisted_head(genesis_block_root).as_kv_store_op(BEACON_CHAIN_DB_KEY)
667644
}
668645

669646
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1457,12 +1434,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
14571434
///
14581435
/// Returns `(block_root, block_slot)`.
14591436
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
1460-
self.head_tracker.heads()
1437+
let head_slot = self.canonical_head.cached_head().head_slot();
1438+
self.canonical_head
1439+
.fork_choice_read_lock()
1440+
.proto_array()
1441+
.viable_heads::<T::EthSpec>(head_slot)
1442+
.iter()
1443+
.map(|node| (node.root, node.slot))
1444+
.collect()
14611445
}
14621446

14631447
/// Only used in tests.
14641448
pub fn knows_head(&self, block_hash: &SignedBeaconBlockHash) -> bool {
1465-
self.head_tracker.contains_head((*block_hash).into())
1449+
self.heads()
1450+
.iter()
1451+
.any(|head| head.0 == Into::<Hash256>::into(*block_hash))
14661452
}
14671453

14681454
/// Returns the `BeaconState` at the given slot.
@@ -4024,9 +4010,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40244010
// about it.
40254011
let block_time_imported = timestamp_now();
40264012

4027-
let parent_root = block.parent_root();
4028-
let slot = block.slot();
4029-
40304013
let current_eth1_finalization_data = Eth1FinalizationData {
40314014
eth1_data: state.eth1_data().clone(),
40324015
eth1_deposit_index: state.eth1_deposit_index(),
@@ -4047,9 +4030,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40474030
});
40484031
}
40494032

4050-
self.head_tracker
4051-
.register_block(block_root, parent_root, slot);
4052-
40534033
metrics::stop_timer(db_write_timer);
40544034

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

beacon_node/beacon_chain/src/builder.rs

Lines changed: 2 additions & 20 deletions
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::kzg_utils::blobs_to_data_column_sidecars;
1312
use crate::light_client_server_cache::LightClientServerCache;
1413
use crate::migrate::{BackgroundMigrator, MigratorConfig};
@@ -92,7 +91,6 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
9291
slot_clock: Option<T::SlotClock>,
9392
shutdown_sender: Option<Sender<ShutdownReason>>,
9493
light_client_server_tx: Option<Sender<LightClientProducerEvent<T::EthSpec>>>,
95-
head_tracker: Option<HeadTracker>,
9694
validator_pubkey_cache: Option<ValidatorPubkeyCache<T>>,
9795
spec: Arc<ChainSpec>,
9896
chain_config: ChainConfig,
@@ -136,7 +134,6 @@ where
136134
slot_clock: None,
137135
shutdown_sender: None,
138136
light_client_server_tx: None,
139-
head_tracker: None,
140137
validator_pubkey_cache: None,
141138
spec: Arc::new(E::default_spec()),
142139
chain_config: ChainConfig::default(),
@@ -325,10 +322,6 @@ where
325322

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

@@ -746,7 +739,6 @@ where
746739
.genesis_state_root
747740
.ok_or("Cannot build without a genesis state root")?;
748741
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
749-
let head_tracker = Arc::new(self.head_tracker.unwrap_or_default());
750742
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();
751743

752744
let mut validator_monitor = ValidatorMonitor::new(
@@ -791,8 +783,6 @@ where
791783
&log,
792784
)?;
793785

794-
// Update head tracker.
795-
head_tracker.register_block(block_root, block.parent_root(), block.slot());
796786
(block_root, block, true)
797787
}
798788
Err(e) => return Err(descriptive_db_error("head block", &e)),
@@ -848,12 +838,7 @@ where
848838
})?;
849839

850840
let migrator_config = self.store_migrator_config.unwrap_or_default();
851-
let store_migrator = BackgroundMigrator::new(
852-
store.clone(),
853-
migrator_config,
854-
genesis_block_root,
855-
log.clone(),
856-
);
841+
let store_migrator = BackgroundMigrator::new(store.clone(), migrator_config, log.clone());
857842

858843
if let Some(slot) = slot_clock.now() {
859844
validator_monitor.process_valid_state(
@@ -878,11 +863,10 @@ where
878863
//
879864
// This *must* be stored before constructing the `BeaconChain`, so that its `Drop` instance
880865
// doesn't write a `PersistedBeaconChain` without the rest of the batch.
881-
let head_tracker_reader = head_tracker.0.read();
882866
self.pending_io_batch.push(BeaconChain::<
883867
Witness<TSlotClock, TEth1Backend, E, THotStore, TColdStore>,
884868
>::persist_head_in_batch_standalone(
885-
genesis_block_root, &head_tracker_reader
869+
genesis_block_root
886870
));
887871
self.pending_io_batch.push(BeaconChain::<
888872
Witness<TSlotClock, TEth1Backend, E, THotStore, TColdStore>,
@@ -893,7 +877,6 @@ where
893877
.hot_db
894878
.do_atomically(self.pending_io_batch)
895879
.map_err(|e| format!("Error writing chain & metadata to disk: {:?}", e))?;
896-
drop(head_tracker_reader);
897880

898881
let genesis_validators_root = head_snapshot.beacon_state.genesis_validators_root();
899882
let genesis_time = head_snapshot.beacon_state.genesis_time();
@@ -974,7 +957,6 @@ where
974957
fork_choice_signal_tx,
975958
fork_choice_signal_rx,
976959
event_handler: self.event_handler,
977-
head_tracker,
978960
shuffling_cache: RwLock::new(ShufflingCache::new(
979961
shuffling_cache_size,
980962
head_shuffling_ids,

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 0 additions & 1 deletion
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)