Skip to content

Commit e47032e

Browse files
committed
Merge remote-tracking branch 'origin/unstable' into cell_proofs
# Conflicts: # beacon_node/beacon_chain/src/fetch_blobs.rs
2 parents d6197be + 47a85cd commit e47032e

39 files changed

+1199
-1060
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "beacon_node"
3-
version = "7.0.0-beta.5"
3+
version = "7.1.0-beta.0"
44
authors = [
55
"Paul Hauner <[email protected]>",
66
"Age Manning <[email protected]",

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, Prep
3434
use crate::fetch_blobs::EngineGetBlobsOutput;
3535
use crate::fork_choice_signal::{ForkChoiceSignalRx, ForkChoiceSignalTx, ForkChoiceWaitResult};
3636
use crate::graffiti_calculator::GraffitiCalculator;
37-
use crate::head_tracker::{HeadTracker, HeadTrackerReader, SszHeadTracker};
3837
use crate::kzg_utils::reconstruct_blobs;
3938
use crate::light_client_finality_update_verification::{
4039
Error as LightClientFinalityUpdateError, VerifiedLightClientFinalityUpdate,
@@ -58,7 +57,7 @@ use crate::observed_block_producers::ObservedBlockProducers;
5857
use crate::observed_data_sidecars::ObservedDataSidecars;
5958
use crate::observed_operations::{ObservationOutcome, ObservedOperations};
6059
use crate::observed_slashable::ObservedSlashable;
61-
use crate::persisted_beacon_chain::{PersistedBeaconChain, DUMMY_CANONICAL_HEAD_BLOCK_ROOT};
60+
use crate::persisted_beacon_chain::PersistedBeaconChain;
6261
use crate::persisted_fork_choice::PersistedForkChoice;
6362
use crate::pre_finalization_cache::PreFinalizationBlockCache;
6463
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
@@ -454,8 +453,6 @@ pub struct BeaconChain<T: BeaconChainTypes> {
454453
/// A handler for events generated by the beacon chain. This is only initialized when the
455454
/// HTTP server is enabled.
456455
pub event_handler: Option<ServerSentEventHandler<T::EthSpec>>,
457-
/// Used to track the heads of the beacon chain.
458-
pub(crate) head_tracker: Arc<HeadTracker>,
459456
/// Caches the attester shuffling for a given epoch and shuffling key root.
460457
pub shuffling_cache: RwLock<ShufflingCache>,
461458
/// A cache of eth1 deposit data at epoch boundaries for deposit finalization
@@ -607,57 +604,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
607604
})
608605
}
609606

610-
/// Persists the head tracker and fork choice.
607+
/// Return a database operation for writing the `PersistedBeaconChain` to disk.
611608
///
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)
661614
}
662615

663616
/// Load fork choice from disk, returning `None` if it isn't found.
@@ -1450,12 +1403,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
14501403
///
14511404
/// Returns `(block_root, block_slot)`.
14521405
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()
14591413
}
14601414

14611415
/// Returns the `BeaconState` at the given slot.
@@ -1735,8 +1689,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
17351689
let notif = ManualFinalizationNotification {
17361690
state_root: state_root.into(),
17371691
checkpoint,
1738-
head_tracker: self.head_tracker.clone(),
1739-
genesis_block_root: self.genesis_block_root,
17401692
};
17411693

17421694
self.store_migrator.process_manual_finalization(notif);
@@ -3763,7 +3715,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37633715
state,
37643716
parent_block,
37653717
parent_eth1_finalization_data,
3766-
confirmed_state_roots,
37673718
consensus_context,
37683719
} = import_data;
37693720

@@ -3787,7 +3738,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37873738
block,
37883739
block_root,
37893740
state,
3790-
confirmed_state_roots,
37913741
payload_verification_outcome.payload_verification_status,
37923742
parent_block,
37933743
parent_eth1_finalization_data,
@@ -3825,7 +3775,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
38253775
signed_block: AvailableBlock<T::EthSpec>,
38263776
block_root: Hash256,
38273777
mut state: BeaconState<T::EthSpec>,
3828-
confirmed_state_roots: Vec<Hash256>,
38293778
payload_verification_status: PayloadVerificationStatus,
38303779
parent_block: SignedBlindedBeaconBlock<T::EthSpec>,
38313780
parent_eth1_finalization_data: Eth1FinalizationData,
@@ -4013,11 +3962,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40133962

40143963
let block = signed_block.message();
40153964
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-
);
40213965
ops.push(StoreOp::PutBlock(block_root, signed_block.clone()));
40223966
ops.push(StoreOp::PutState(block.state_root(), &state));
40233967

@@ -4044,9 +3988,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40443988
// about it.
40453989
let block_time_imported = timestamp_now();
40463990

4047-
let parent_root = block.parent_root();
4048-
let slot = block.slot();
4049-
40503991
let current_eth1_finalization_data = Eth1FinalizationData {
40513992
eth1_data: state.eth1_data().clone(),
40523993
eth1_deposit_index: state.eth1_deposit_index(),
@@ -4067,9 +4008,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40674008
});
40684009
}
40694010

4070-
self.head_tracker
4071-
.register_block(block_root, parent_root, slot);
4072-
40734011
metrics::stop_timer(db_write_timer);
40744012

40754013
metrics::inc_counter(&metrics::BLOCK_PROCESSING_SUCCESSES);
@@ -7203,7 +7141,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
72037141
impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
72047142
fn drop(&mut self) {
72057143
let drop = || -> Result<(), Error> {
7206-
self.persist_head_and_fork_choice()?;
7144+
self.persist_fork_choice()?;
72077145
self.persist_op_pool()?;
72087146
self.persist_eth1_cache()
72097147
};

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,22 +1460,8 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
14601460

14611461
let catchup_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CATCHUP_STATE);
14621462

1463-
// Stage a batch of operations to be completed atomically if this block is imported
1464-
// successfully. If there is a skipped slot, we include the state root of the pre-state,
1465-
// which may be an advanced state that was stored in the DB with a `temporary` flag.
14661463
let mut state = parent.pre_state;
14671464

1468-
let mut confirmed_state_roots =
1469-
if block.slot() > state.slot() && state.slot() > parent.beacon_block.slot() {
1470-
// Advanced pre-state. Delete its temporary flag.
1471-
let pre_state_root = state.update_tree_hash_cache()?;
1472-
vec![pre_state_root]
1473-
} else {
1474-
// Pre state is either unadvanced, or should not be stored long-term because there
1475-
// is no skipped slot between `parent` and `block`.
1476-
vec![]
1477-
};
1478-
14791465
// The block must have a higher slot than its parent.
14801466
if block.slot() <= parent.beacon_block.slot() {
14811467
return Err(BlockError::BlockIsNotLaterThanParent {
@@ -1522,38 +1508,29 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
15221508
// processing, but we get early access to it.
15231509
let state_root = state.update_tree_hash_cache()?;
15241510

1525-
// Store the state immediately, marking it as temporary, and staging the deletion
1526-
// of its temporary status as part of the larger atomic operation.
1511+
// Store the state immediately.
15271512
let txn_lock = chain.store.hot_db.begin_rw_transaction();
15281513
let state_already_exists =
15291514
chain.store.load_hot_state_summary(&state_root)?.is_some();
15301515

15311516
let state_batch = if state_already_exists {
1532-
// If the state exists, it could be temporary or permanent, but in neither case
1533-
// should we rewrite it or store a new temporary flag for it. We *will* stage
1534-
// the temporary flag for deletion because it's OK to double-delete the flag,
1535-
// and we don't mind if another thread gets there first.
1517+
// If the state exists, we do not need to re-write it.
15361518
vec![]
15371519
} else {
1538-
vec![
1539-
if state.slot() % T::EthSpec::slots_per_epoch() == 0 {
1540-
StoreOp::PutState(state_root, &state)
1541-
} else {
1542-
StoreOp::PutStateSummary(
1543-
state_root,
1544-
HotStateSummary::new(&state_root, &state)?,
1545-
)
1546-
},
1547-
StoreOp::PutStateTemporaryFlag(state_root),
1548-
]
1520+
vec![if state.slot() % T::EthSpec::slots_per_epoch() == 0 {
1521+
StoreOp::PutState(state_root, &state)
1522+
} else {
1523+
StoreOp::PutStateSummary(
1524+
state_root,
1525+
HotStateSummary::new(&state_root, &state)?,
1526+
)
1527+
}]
15491528
};
15501529
chain
15511530
.store
15521531
.do_atomically_with_block_and_blobs_cache(state_batch)?;
15531532
drop(txn_lock);
15541533

1555-
confirmed_state_roots.push(state_root);
1556-
15571534
state_root
15581535
};
15591536

@@ -1720,7 +1697,6 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
17201697
state,
17211698
parent_block: parent.beacon_block,
17221699
parent_eth1_finalization_data,
1723-
confirmed_state_roots,
17241700
consensus_context,
17251701
},
17261702
payload_verification_handle,

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ pub struct BlockImportData<E: EthSpec> {
358358
pub state: BeaconState<E>,
359359
pub parent_block: SignedBeaconBlock<E, BlindedPayload<E>>,
360360
pub parent_eth1_finalization_data: Eth1FinalizationData,
361-
pub confirmed_state_roots: Vec<Hash256>,
362361
pub consensus_context: ConsensusContext<E>,
363362
}
364363

@@ -376,7 +375,6 @@ impl<E: EthSpec> BlockImportData<E> {
376375
eth1_data: <_>::default(),
377376
eth1_deposit_index: 0,
378377
},
379-
confirmed_state_roots: vec![],
380378
consensus_context: ConsensusContext::new(Slot::new(0)),
381379
}
382380
}

0 commit comments

Comments
 (0)