@@ -34,7 +34,6 @@ use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, Prep
34
34
use crate :: fetch_blobs:: EngineGetBlobsOutput ;
35
35
use crate :: fork_choice_signal:: { ForkChoiceSignalRx , ForkChoiceSignalTx , ForkChoiceWaitResult } ;
36
36
use crate :: graffiti_calculator:: GraffitiCalculator ;
37
- use crate :: head_tracker:: { HeadTracker , HeadTrackerReader , SszHeadTracker } ;
38
37
use crate :: kzg_utils:: reconstruct_blobs;
39
38
use crate :: light_client_finality_update_verification:: {
40
39
Error as LightClientFinalityUpdateError , VerifiedLightClientFinalityUpdate ,
@@ -58,7 +57,7 @@ use crate::observed_block_producers::ObservedBlockProducers;
58
57
use crate :: observed_data_sidecars:: ObservedDataSidecars ;
59
58
use crate :: observed_operations:: { ObservationOutcome , ObservedOperations } ;
60
59
use crate :: observed_slashable:: ObservedSlashable ;
61
- use crate :: persisted_beacon_chain:: { PersistedBeaconChain , DUMMY_CANONICAL_HEAD_BLOCK_ROOT } ;
60
+ use crate :: persisted_beacon_chain:: PersistedBeaconChain ;
62
61
use crate :: persisted_fork_choice:: PersistedForkChoice ;
63
62
use crate :: pre_finalization_cache:: PreFinalizationBlockCache ;
64
63
use crate :: shuffling_cache:: { BlockShufflingIds , ShufflingCache } ;
@@ -454,8 +453,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
454
453
/// A handler for events generated by the beacon chain. This is only initialized when the
455
454
/// HTTP server is enabled.
456
455
pub event_handler : Option < ServerSentEventHandler < T :: EthSpec > > ,
457
- /// Used to track the heads of the beacon chain.
458
- pub ( crate ) head_tracker : Arc < HeadTracker > ,
459
456
/// Caches the attester shuffling for a given epoch and shuffling key root.
460
457
pub shuffling_cache : RwLock < ShufflingCache > ,
461
458
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -607,57 +604,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
607
604
} )
608
605
}
609
606
610
- /// Persists the head tracker and fork choice .
607
+ /// Return a database operation for writing the `PersistedBeaconChain` to disk .
611
608
///
612
- /// We do it atomically even though no guarantees need to be made about blocks from
613
- /// the head tracker also being present in fork choice.
614
- pub fn persist_head_and_fork_choice ( & self ) -> Result < ( ) , Error > {
615
- let mut batch = vec ! [ ] ;
616
-
617
- let _head_timer = metrics:: start_timer ( & metrics:: PERSIST_HEAD ) ;
618
-
619
- // Hold a lock to head_tracker until it has been persisted to disk. Otherwise there's a race
620
- // condition with the pruning thread which can result in a block present in the head tracker
621
- // but absent in the DB. This inconsistency halts pruning and dramastically increases disk
622
- // size. Ref: https://github.com/sigp/lighthouse/issues/4773
623
- let head_tracker = self . head_tracker . 0 . read ( ) ;
624
- batch. push ( self . persist_head_in_batch ( & head_tracker) ) ;
625
-
626
- let _fork_choice_timer = metrics:: start_timer ( & metrics:: PERSIST_FORK_CHOICE ) ;
627
- batch. push ( self . persist_fork_choice_in_batch ( ) ) ;
628
-
629
- self . store . hot_db . do_atomically ( batch) ?;
630
- drop ( head_tracker) ;
631
-
632
- Ok ( ( ) )
633
- }
634
-
635
- /// Return a `PersistedBeaconChain` without reference to a `BeaconChain`.
636
- pub fn make_persisted_head (
637
- genesis_block_root : Hash256 ,
638
- head_tracker_reader : & HeadTrackerReader ,
639
- ) -> PersistedBeaconChain {
640
- PersistedBeaconChain {
641
- _canonical_head_block_root : DUMMY_CANONICAL_HEAD_BLOCK_ROOT ,
642
- genesis_block_root,
643
- ssz_head_tracker : SszHeadTracker :: from_map ( head_tracker_reader) ,
644
- }
645
- }
646
-
647
- /// Return a database operation for writing the beacon chain head to disk.
648
- pub fn persist_head_in_batch (
649
- & self ,
650
- head_tracker_reader : & HeadTrackerReader ,
651
- ) -> KeyValueStoreOp {
652
- Self :: persist_head_in_batch_standalone ( self . genesis_block_root , head_tracker_reader)
653
- }
654
-
655
- pub fn persist_head_in_batch_standalone (
656
- genesis_block_root : Hash256 ,
657
- head_tracker_reader : & HeadTrackerReader ,
658
- ) -> KeyValueStoreOp {
659
- Self :: make_persisted_head ( genesis_block_root, head_tracker_reader)
660
- . as_kv_store_op ( BEACON_CHAIN_DB_KEY )
609
+ /// These days the `PersistedBeaconChain` is only used to store the genesis block root, so it
610
+ /// should only ever be written once at startup. It used to be written more frequently, but
611
+ /// this is no longer necessary.
612
+ pub fn persist_head_in_batch_standalone ( genesis_block_root : Hash256 ) -> KeyValueStoreOp {
613
+ PersistedBeaconChain { genesis_block_root } . as_kv_store_op ( BEACON_CHAIN_DB_KEY )
661
614
}
662
615
663
616
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1450,12 +1403,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
1450
1403
///
1451
1404
/// Returns `(block_root, block_slot)`.
1452
1405
pub fn heads ( & self ) -> Vec < ( Hash256 , Slot ) > {
1453
- self . head_tracker . heads ( )
1454
- }
1455
-
1456
- /// Only used in tests.
1457
- pub fn knows_head ( & self , block_hash : & SignedBeaconBlockHash ) -> bool {
1458
- self . head_tracker . contains_head ( ( * block_hash) . into ( ) )
1406
+ self . canonical_head
1407
+ . fork_choice_read_lock ( )
1408
+ . proto_array ( )
1409
+ . heads_descended_from_finalization :: < T :: EthSpec > ( )
1410
+ . iter ( )
1411
+ . map ( |node| ( node. root , node. slot ) )
1412
+ . collect ( )
1459
1413
}
1460
1414
1461
1415
/// Returns the `BeaconState` at the given slot.
@@ -1735,8 +1689,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
1735
1689
let notif = ManualFinalizationNotification {
1736
1690
state_root : state_root. into ( ) ,
1737
1691
checkpoint,
1738
- head_tracker : self . head_tracker . clone ( ) ,
1739
- genesis_block_root : self . genesis_block_root ,
1740
1692
} ;
1741
1693
1742
1694
self . store_migrator . process_manual_finalization ( notif) ;
@@ -3763,7 +3715,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
3763
3715
state,
3764
3716
parent_block,
3765
3717
parent_eth1_finalization_data,
3766
- confirmed_state_roots,
3767
3718
consensus_context,
3768
3719
} = import_data;
3769
3720
@@ -3787,7 +3738,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
3787
3738
block,
3788
3739
block_root,
3789
3740
state,
3790
- confirmed_state_roots,
3791
3741
payload_verification_outcome. payload_verification_status ,
3792
3742
parent_block,
3793
3743
parent_eth1_finalization_data,
@@ -3825,7 +3775,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
3825
3775
signed_block : AvailableBlock < T :: EthSpec > ,
3826
3776
block_root : Hash256 ,
3827
3777
mut state : BeaconState < T :: EthSpec > ,
3828
- confirmed_state_roots : Vec < Hash256 > ,
3829
3778
payload_verification_status : PayloadVerificationStatus ,
3830
3779
parent_block : SignedBlindedBeaconBlock < T :: EthSpec > ,
3831
3780
parent_eth1_finalization_data : Eth1FinalizationData ,
@@ -4013,11 +3962,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4013
3962
4014
3963
let block = signed_block. message ( ) ;
4015
3964
let db_write_timer = metrics:: start_timer ( & metrics:: BLOCK_PROCESSING_DB_WRITE ) ;
4016
- ops. extend (
4017
- confirmed_state_roots
4018
- . into_iter ( )
4019
- . map ( StoreOp :: DeleteStateTemporaryFlag ) ,
4020
- ) ;
4021
3965
ops. push ( StoreOp :: PutBlock ( block_root, signed_block. clone ( ) ) ) ;
4022
3966
ops. push ( StoreOp :: PutState ( block. state_root ( ) , & state) ) ;
4023
3967
@@ -4044,9 +3988,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4044
3988
// about it.
4045
3989
let block_time_imported = timestamp_now ( ) ;
4046
3990
4047
- let parent_root = block. parent_root ( ) ;
4048
- let slot = block. slot ( ) ;
4049
-
4050
3991
let current_eth1_finalization_data = Eth1FinalizationData {
4051
3992
eth1_data : state. eth1_data ( ) . clone ( ) ,
4052
3993
eth1_deposit_index : state. eth1_deposit_index ( ) ,
@@ -4067,9 +4008,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4067
4008
} ) ;
4068
4009
}
4069
4010
4070
- self . head_tracker
4071
- . register_block ( block_root, parent_root, slot) ;
4072
-
4073
4011
metrics:: stop_timer ( db_write_timer) ;
4074
4012
4075
4013
metrics:: inc_counter ( & metrics:: BLOCK_PROCESSING_SUCCESSES ) ;
@@ -7203,7 +7141,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
7203
7141
impl < T : BeaconChainTypes > Drop for BeaconChain < T > {
7204
7142
fn drop ( & mut self ) {
7205
7143
let drop = || -> Result < ( ) , Error > {
7206
- self . persist_head_and_fork_choice ( ) ?;
7144
+ self . persist_fork_choice ( ) ?;
7207
7145
self . persist_op_pool ( ) ?;
7208
7146
self . persist_eth1_cache ( )
7209
7147
} ;
0 commit comments