@@ -33,7 +33,6 @@ use crate::events::ServerSentEventHandler;
33
33
use crate :: execution_payload:: { get_execution_payload, NotifyExecutionLayer , PreparePayloadHandle } ;
34
34
use crate :: fork_choice_signal:: { ForkChoiceSignalRx , ForkChoiceSignalTx , ForkChoiceWaitResult } ;
35
35
use crate :: graffiti_calculator:: GraffitiCalculator ;
36
- use crate :: head_tracker:: { HeadTracker , HeadTrackerReader , SszHeadTracker } ;
37
36
use crate :: kzg_utils:: reconstruct_blobs;
38
37
use crate :: light_client_finality_update_verification:: {
39
38
Error as LightClientFinalityUpdateError , VerifiedLightClientFinalityUpdate ,
@@ -458,8 +457,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
458
457
/// A handler for events generated by the beacon chain. This is only initialized when the
459
458
/// HTTP server is enabled.
460
459
pub event_handler : Option < ServerSentEventHandler < T :: EthSpec > > ,
461
- /// Used to track the heads of the beacon chain.
462
- pub ( crate ) head_tracker : Arc < HeadTracker > ,
463
460
/// Caches the attester shuffling for a given epoch and shuffling key root.
464
461
pub shuffling_cache : RwLock < ShufflingCache > ,
465
462
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -620,50 +617,30 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
620
617
pub fn persist_head_and_fork_choice ( & self ) -> Result < ( ) , Error > {
621
618
let mut batch = vec ! [ ] ;
622
619
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
-
632
620
let _fork_choice_timer = metrics:: start_timer ( & metrics:: PERSIST_FORK_CHOICE ) ;
633
621
batch. push ( self . persist_fork_choice_in_batch ( ) ) ;
634
622
635
623
self . store . hot_db . do_atomically ( batch) ?;
636
- drop ( head_tracker) ;
637
624
638
625
Ok ( ( ) )
639
626
}
640
627
641
628
/// 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 {
646
630
PersistedBeaconChain {
647
631
_canonical_head_block_root : DUMMY_CANONICAL_HEAD_BLOCK_ROOT ,
648
632
genesis_block_root,
649
- ssz_head_tracker : SszHeadTracker :: from_map ( head_tracker_reader ) ,
633
+ ssz_head_tracker : < _ > :: default ( ) ,
650
634
}
651
635
}
652
636
653
637
/// 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 )
659
640
}
660
641
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 )
667
644
}
668
645
669
646
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1457,12 +1434,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
1457
1434
///
1458
1435
/// Returns `(block_root, block_slot)`.
1459
1436
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 ( )
1461
1445
}
1462
1446
1463
1447
/// Only used in tests.
1464
1448
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) )
1466
1452
}
1467
1453
1468
1454
/// Returns the `BeaconState` at the given slot.
@@ -4024,9 +4010,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4024
4010
// about it.
4025
4011
let block_time_imported = timestamp_now ( ) ;
4026
4012
4027
- let parent_root = block. parent_root ( ) ;
4028
- let slot = block. slot ( ) ;
4029
-
4030
4013
let current_eth1_finalization_data = Eth1FinalizationData {
4031
4014
eth1_data : state. eth1_data ( ) . clone ( ) ,
4032
4015
eth1_deposit_index : state. eth1_deposit_index ( ) ,
@@ -4047,9 +4030,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4047
4030
} ) ;
4048
4031
}
4049
4032
4050
- self . head_tracker
4051
- . register_block ( block_root, parent_root, slot) ;
4052
-
4053
4033
metrics:: stop_timer ( db_write_timer) ;
4054
4034
4055
4035
metrics:: inc_counter ( & metrics:: BLOCK_PROCESSING_SUCCESSES ) ;
0 commit comments