Skip to content

Commit 8ce90cc

Browse files
committed
Drop HeadTracker
1 parent f22e5b0 commit 8ce90cc

File tree

7 files changed

+16
-268
lines changed

7 files changed

+16
-268
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use crate::eth1_finalization_cache::{Eth1FinalizationCache, Eth1FinalizationData
3030
use crate::events::ServerSentEventHandler;
3131
use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, PreparePayloadHandle};
3232
use crate::fork_choice_signal::{ForkChoiceSignalRx, ForkChoiceSignalTx, ForkChoiceWaitResult};
33-
use crate::head_tracker::HeadTracker;
3433
use crate::historical_blocks::HistoricalBlockError;
3534
use crate::light_client_finality_update_verification::{
3635
Error as LightClientFinalityUpdateError, VerifiedLightClientFinalityUpdate,
@@ -53,7 +52,6 @@ use crate::observed_blob_sidecars::ObservedBlobSidecars;
5352
use crate::observed_block_producers::ObservedBlockProducers;
5453
use crate::observed_operations::{ObservationOutcome, ObservedOperations};
5554
use crate::observed_slashable::ObservedSlashable;
56-
use crate::persisted_beacon_chain::{PersistedBeaconChain, DUMMY_CANONICAL_HEAD_BLOCK_ROOT};
5755
use crate::persisted_fork_choice::PersistedForkChoice;
5856
use crate::pre_finalization_cache::PreFinalizationBlockCache;
5957
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
@@ -113,9 +111,7 @@ use std::marker::PhantomData;
113111
use std::sync::Arc;
114112
use std::time::{Duration, Instant};
115113
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
116-
use store::{
117-
DatabaseBlock, Error as DBError, HotColdDB, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
118-
};
114+
use store::{DatabaseBlock, Error as DBError, HotColdDB, KeyValueStore, StoreOp};
119115
use task_executor::{ShutdownReason, TaskExecutor};
120116
use tokio_stream::Stream;
121117
use tree_hash::TreeHash;
@@ -446,8 +442,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
446442
/// A handler for events generated by the beacon chain. This is only initialized when the
447443
/// HTTP server is enabled.
448444
pub event_handler: Option<ServerSentEventHandler<T::EthSpec>>,
449-
/// Used to track the heads of the beacon chain.
450-
pub(crate) head_tracker: Arc<HeadTracker>,
451445
/// A cache dedicated to block processing.
452446
pub(crate) snapshot_cache: TimeoutRwLock<SnapshotCache<T::EthSpec>>,
453447
/// Caches the attester shuffling for a given epoch and shuffling key root.
@@ -609,9 +603,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
609603
pub fn persist_head_and_fork_choice(&self) -> Result<(), Error> {
610604
let mut batch = vec![];
611605

612-
let _head_timer = metrics::start_timer(&metrics::PERSIST_HEAD);
613-
batch.push(self.persist_head_in_batch());
614-
615606
let _fork_choice_timer = metrics::start_timer(&metrics::PERSIST_FORK_CHOICE);
616607
batch.push(self.persist_fork_choice_in_batch());
617608

@@ -620,31 +611,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
620611
Ok(())
621612
}
622613

623-
/// Return a `PersistedBeaconChain` without reference to a `BeaconChain`.
624-
pub fn make_persisted_head(
625-
genesis_block_root: Hash256,
626-
head_tracker: &HeadTracker,
627-
) -> PersistedBeaconChain {
628-
PersistedBeaconChain {
629-
_canonical_head_block_root: DUMMY_CANONICAL_HEAD_BLOCK_ROOT,
630-
genesis_block_root,
631-
ssz_head_tracker: head_tracker.to_ssz_container(),
632-
}
633-
}
634-
635-
/// Return a database operation for writing the beacon chain head to disk.
636-
pub fn persist_head_in_batch(&self) -> KeyValueStoreOp {
637-
Self::persist_head_in_batch_standalone(self.genesis_block_root, &self.head_tracker)
638-
}
639-
640-
pub fn persist_head_in_batch_standalone(
641-
genesis_block_root: Hash256,
642-
head_tracker: &HeadTracker,
643-
) -> KeyValueStoreOp {
644-
Self::make_persisted_head(genesis_block_root, head_tracker)
645-
.as_kv_store_op(BEACON_CHAIN_DB_KEY)
646-
}
647-
648614
/// Load fork choice from disk, returning `None` if it isn't found.
649615
pub fn load_fork_choice(
650616
store: BeaconStore<T>,
@@ -1338,11 +1304,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
13381304
///
13391305
/// Returns `(block_root, block_slot)`.
13401306
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
1341-
self.head_tracker.heads()
1307+
todo!();
1308+
// self.head_tracker.heads()
13421309
}
13431310

1311+
/// Only used in tests
13441312
pub fn knows_head(&self, block_hash: &SignedBeaconBlockHash) -> bool {
1345-
self.head_tracker.contains_head((*block_hash).into())
1313+
let block_hash = (*block_hash).into();
1314+
self.heads().iter().any(|head| head.0 == block_hash)
13461315
}
13471316

13481317
/// Returns the `BeaconState` at the given slot.
@@ -3533,9 +3502,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
35333502
);
35343503
});
35353504

3536-
self.head_tracker
3537-
.register_block(block_root, parent_root, slot);
3538-
35393505
metrics::stop_timer(db_write_timer);
35403506

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

beacon_node/beacon_chain/src/builder.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::eth1_chain::{CachingEth1Backend, SszEth1};
55
use crate::eth1_finalization_cache::Eth1FinalizationCache;
66
use crate::fork_choice_signal::ForkChoiceSignalTx;
77
use crate::fork_revert::{reset_fork_choice_to_finalization, revert_to_fork_boundary};
8-
use crate::head_tracker::HeadTracker;
98
use crate::migrate::{BackgroundMigrator, MigratorConfig};
109
use crate::persisted_beacon_chain::PersistedBeaconChain;
1110
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
@@ -87,7 +86,6 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
8786
event_handler: Option<ServerSentEventHandler<T::EthSpec>>,
8887
slot_clock: Option<T::SlotClock>,
8988
shutdown_sender: Option<Sender<ShutdownReason>>,
90-
head_tracker: Option<HeadTracker>,
9189
validator_pubkey_cache: Option<ValidatorPubkeyCache<T>>,
9290
spec: ChainSpec,
9391
chain_config: ChainConfig,
@@ -129,7 +127,6 @@ where
129127
event_handler: None,
130128
slot_clock: None,
131129
shutdown_sender: None,
132-
head_tracker: None,
133130
validator_pubkey_cache: None,
134131
spec: TEthSpec::default_spec(),
135132
chain_config: ChainConfig::default(),
@@ -317,10 +314,6 @@ where
317314

318315
self.genesis_block_root = Some(chain.genesis_block_root);
319316
self.genesis_state_root = Some(genesis_block.state_root());
320-
self.head_tracker = Some(
321-
HeadTracker::from_ssz_container(&chain.ssz_head_tracker)
322-
.map_err(|e| format!("Failed to decode head tracker for database: {:?}", e))?,
323-
);
324317
self.validator_pubkey_cache = Some(pubkey_cache);
325318
self.fork_choice = Some(fork_choice);
326319

@@ -662,7 +655,6 @@ where
662655
.genesis_state_root
663656
.ok_or("Cannot build without a genesis state root")?;
664657
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
665-
let head_tracker = Arc::new(self.head_tracker.unwrap_or_default());
666658

667659
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();
668660
let mut validator_monitor = ValidatorMonitor::new(
@@ -716,8 +708,6 @@ where
716708
&log,
717709
)?;
718710

719-
// Update head tracker.
720-
head_tracker.register_block(block_root, block.parent_root(), block.slot());
721711
(block_root, block, true)
722712
}
723713
Err(e) => return Err(descriptive_db_error("head block", &e)),
@@ -805,11 +795,6 @@ where
805795
//
806796
// This *must* be stored before constructing the `BeaconChain`, so that its `Drop` instance
807797
// doesn't write a `PersistedBeaconChain` without the rest of the batch.
808-
self.pending_io_batch.push(BeaconChain::<
809-
Witness<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>,
810-
>::persist_head_in_batch_standalone(
811-
genesis_block_root, &head_tracker
812-
));
813798
self.pending_io_batch.push(BeaconChain::<
814799
Witness<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>,
815800
>::persist_fork_choice_in_batch_standalone(
@@ -897,7 +882,6 @@ where
897882
fork_choice_signal_tx,
898883
fork_choice_signal_rx,
899884
event_handler: self.event_handler,
900-
head_tracker,
901885
snapshot_cache: TimeoutRwLock::new(SnapshotCache::new(
902886
DEFAULT_SNAPSHOT_CACHE_SIZE,
903887
head_for_snapshot_cache,

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
10621062
self.store_migrator.process_finalization(
10631063
new_finalized_state_root.into(),
10641064
new_view.finalized_checkpoint,
1065-
self.head_tracker.clone(),
1065+
todo!(),
1066+
// self.head_tracker.clone(),
10661067
)?;
10671068

10681069
// Prune blobs in the background.

beacon_node/beacon_chain/src/head_tracker.rs

Lines changed: 0 additions & 207 deletions
This file was deleted.

0 commit comments

Comments
 (0)