@@ -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 :: light_client_finality_update_verification:: {
38
37
Error as LightClientFinalityUpdateError , VerifiedLightClientFinalityUpdate ,
39
38
} ;
@@ -456,8 +455,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
456
455
/// A handler for events generated by the beacon chain. This is only initialized when the
457
456
/// HTTP server is enabled.
458
457
pub event_handler : Option < ServerSentEventHandler < T :: EthSpec > > ,
459
- /// Used to track the heads of the beacon chain.
460
- pub ( crate ) head_tracker : Arc < HeadTracker > ,
461
458
/// Caches the attester shuffling for a given epoch and shuffling key root.
462
459
pub shuffling_cache : RwLock < ShufflingCache > ,
463
460
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -618,50 +615,30 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
618
615
pub fn persist_head_and_fork_choice ( & self ) -> Result < ( ) , Error > {
619
616
let mut batch = vec ! [ ] ;
620
617
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
-
630
618
let _fork_choice_timer = metrics:: start_timer ( & metrics:: PERSIST_FORK_CHOICE ) ;
631
619
batch. push ( self . persist_fork_choice_in_batch ( ) ) ;
632
620
633
621
self . store . hot_db . do_atomically ( batch) ?;
634
- drop ( head_tracker) ;
635
622
636
623
Ok ( ( ) )
637
624
}
638
625
639
626
/// 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 {
644
628
PersistedBeaconChain {
645
629
_canonical_head_block_root : DUMMY_CANONICAL_HEAD_BLOCK_ROOT ,
646
630
genesis_block_root,
647
- ssz_head_tracker : SszHeadTracker :: from_map ( head_tracker_reader ) ,
631
+ ssz_head_tracker : < _ > :: default ( ) ,
648
632
}
649
633
}
650
634
651
635
/// 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 )
657
638
}
658
639
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 )
665
642
}
666
643
667
644
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1405,12 +1382,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
1405
1382
///
1406
1383
/// Returns `(block_root, block_slot)`.
1407
1384
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 ( )
1409
1393
}
1410
1394
1411
1395
/// Only used in tests.
1412
1396
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) )
1414
1400
}
1415
1401
1416
1402
/// Returns the `BeaconState` at the given slot.
@@ -3989,9 +3975,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
3989
3975
// about it.
3990
3976
let block_time_imported = timestamp_now ( ) ;
3991
3977
3992
- let parent_root = block. parent_root ( ) ;
3993
- let slot = block. slot ( ) ;
3994
-
3995
3978
let current_eth1_finalization_data = Eth1FinalizationData {
3996
3979
eth1_data : state. eth1_data ( ) . clone ( ) ,
3997
3980
eth1_deposit_index : state. eth1_deposit_index ( ) ,
@@ -4012,9 +3995,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4012
3995
} ) ;
4013
3996
}
4014
3997
4015
- self . head_tracker
4016
- . register_block ( block_root, parent_root, slot) ;
4017
-
4018
3998
metrics:: stop_timer ( db_write_timer) ;
4019
3999
4020
4000
metrics:: inc_counter ( & metrics:: BLOCK_PROCESSING_SUCCESSES ) ;
0 commit comments