Skip to content

Commit 8931141

Browse files
michaelsprouldapplion
authored andcommitted
Abolish temporary states concept
1 parent abb3c3f commit 8931141

File tree

8 files changed

+15
-101
lines changed

8 files changed

+15
-101
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
36793679
state,
36803680
parent_block,
36813681
parent_eth1_finalization_data,
3682-
confirmed_state_roots,
36833682
consensus_context,
36843683
data_column_recv,
36853684
} = import_data;
@@ -3704,7 +3703,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37043703
block,
37053704
block_root,
37063705
state,
3707-
confirmed_state_roots,
37083706
payload_verification_outcome.payload_verification_status,
37093707
parent_block,
37103708
parent_eth1_finalization_data,
@@ -3743,7 +3741,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37433741
signed_block: AvailableBlock<T::EthSpec>,
37443742
block_root: Hash256,
37453743
mut state: BeaconState<T::EthSpec>,
3746-
confirmed_state_roots: Vec<Hash256>,
37473744
payload_verification_status: PayloadVerificationStatus,
37483745
parent_block: SignedBlindedBeaconBlock<T::EthSpec>,
37493746
parent_eth1_finalization_data: Eth1FinalizationData,
@@ -3945,11 +3942,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
39453942

39463943
let block = signed_block.message();
39473944
let db_write_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_DB_WRITE);
3948-
ops.extend(
3949-
confirmed_state_roots
3950-
.into_iter()
3951-
.map(StoreOp::DeleteStateTemporaryFlag),
3952-
);
39533945
ops.push(StoreOp::PutBlock(block_root, signed_block.clone()));
39543946
ops.push(StoreOp::PutState(block.state_root(), &state));
39553947

beacon_node/beacon_chain/src/block_verification.rs

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

14361436
let catchup_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CATCHUP_STATE);
14371437

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

1443-
let mut confirmed_state_roots =
1444-
if block.slot() > state.slot() && state.slot() > parent.beacon_block.slot() {
1445-
// Advanced pre-state. Delete its temporary flag.
1446-
let pre_state_root = state.update_tree_hash_cache()?;
1447-
vec![pre_state_root]
1448-
} else {
1449-
// Pre state is either unadvanced, or should not be stored long-term because there
1450-
// is no skipped slot between `parent` and `block`.
1451-
vec![]
1452-
};
1453-
14541440
// The block must have a higher slot than its parent.
14551441
if block.slot() <= parent.beacon_block.slot() {
14561442
return Err(BlockError::BlockIsNotLaterThanParent {
@@ -1497,38 +1483,29 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
14971483
// processing, but we get early access to it.
14981484
let state_root = state.update_tree_hash_cache()?;
14991485

1500-
// Store the state immediately, marking it as temporary, and staging the deletion
1501-
// of its temporary status as part of the larger atomic operation.
1486+
// Store the state immediately.
15021487
let txn_lock = chain.store.hot_db.begin_rw_transaction();
15031488
let state_already_exists =
15041489
chain.store.load_hot_state_summary(&state_root)?.is_some();
15051490

15061491
let state_batch = if state_already_exists {
1507-
// If the state exists, it could be temporary or permanent, but in neither case
1508-
// should we rewrite it or store a new temporary flag for it. We *will* stage
1509-
// the temporary flag for deletion because it's OK to double-delete the flag,
1510-
// and we don't mind if another thread gets there first.
1492+
// If the state exists, we do not need to re-write it.
15111493
vec![]
15121494
} else {
1513-
vec![
1514-
if state.slot() % T::EthSpec::slots_per_epoch() == 0 {
1515-
StoreOp::PutState(state_root, &state)
1516-
} else {
1517-
StoreOp::PutStateSummary(
1518-
state_root,
1519-
HotStateSummary::new(&state_root, &state)?,
1520-
)
1521-
},
1522-
StoreOp::PutStateTemporaryFlag(state_root),
1523-
]
1495+
vec![if state.slot() % T::EthSpec::slots_per_epoch() == 0 {
1496+
StoreOp::PutState(state_root, &state)
1497+
} else {
1498+
StoreOp::PutStateSummary(
1499+
state_root,
1500+
HotStateSummary::new(&state_root, &state)?,
1501+
)
1502+
}]
15241503
};
15251504
chain
15261505
.store
15271506
.do_atomically_with_block_and_blobs_cache(state_batch)?;
15281507
drop(txn_lock);
15291508

1530-
confirmed_state_roots.push(state_root);
1531-
15321509
state_root
15331510
};
15341511

@@ -1705,7 +1682,6 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
17051682
state,
17061683
parent_block: parent.beacon_block,
17071684
parent_eth1_finalization_data,
1708-
confirmed_state_roots,
17091685
consensus_context,
17101686
data_column_recv: None,
17111687
},

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ pub struct BlockImportData<E: EthSpec> {
345345
pub state: BeaconState<E>,
346346
pub parent_block: SignedBeaconBlock<E, BlindedPayload<E>>,
347347
pub parent_eth1_finalization_data: Eth1FinalizationData,
348-
pub confirmed_state_roots: Vec<Hash256>,
349348
pub consensus_context: ConsensusContext<E>,
350349
#[derivative(PartialEq = "ignore")]
351350
/// An optional receiver for `DataColumnSidecarList`.
@@ -369,7 +368,6 @@ impl<E: EthSpec> BlockImportData<E> {
369368
eth1_data: <_>::default(),
370369
eth1_deposit_index: 0,
371370
},
372-
confirmed_state_roots: vec![],
373371
consensus_context: ConsensusContext::new(Slot::new(0)),
374372
data_column_recv: None,
375373
}

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,6 @@ mod test {
881881
state,
882882
parent_block,
883883
parent_eth1_finalization_data,
884-
confirmed_state_roots: vec![],
885884
consensus_context,
886885
data_column_recv: None,
887886
};
@@ -1272,7 +1271,6 @@ mod pending_components_tests {
12721271
eth1_data: Default::default(),
12731272
eth1_deposit_index: 0,
12741273
},
1275-
confirmed_state_roots: vec![],
12761274
consensus_context: ConsensusContext::new(Slot::new(0)),
12771275
data_column_recv: None,
12781276
},

beacon_node/beacon_chain/src/data_availability_checker/state_lru_cache.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@ use crate::{
77
};
88
use lru::LruCache;
99
use parking_lot::RwLock;
10-
use ssz_derive::{Decode, Encode};
1110
use state_processing::BlockReplayer;
1211
use std::sync::Arc;
1312
use store::OnDiskConsensusContext;
1413
use types::beacon_block_body::KzgCommitments;
15-
use types::{ssz_tagged_signed_beacon_block, ssz_tagged_signed_beacon_block_arc};
1614
use types::{BeaconState, BlindedPayload, ChainSpec, Epoch, EthSpec, Hash256, SignedBeaconBlock};
1715

1816
/// This mirrors everything in the `AvailabilityPendingExecutedBlock`, except
1917
/// that it is much smaller because it contains only a state root instead of
2018
/// a full `BeaconState`.
21-
#[derive(Encode, Decode, Clone)]
19+
#[derive(Clone)]
2220
pub struct DietAvailabilityPendingExecutedBlock<E: EthSpec> {
23-
#[ssz(with = "ssz_tagged_signed_beacon_block_arc")]
2421
block: Arc<SignedBeaconBlock<E>>,
2522
state_root: Hash256,
26-
#[ssz(with = "ssz_tagged_signed_beacon_block")]
2723
parent_block: SignedBeaconBlock<E, BlindedPayload<E>>,
2824
parent_eth1_finalization_data: Eth1FinalizationData,
29-
confirmed_state_roots: Vec<Hash256>,
3025
consensus_context: OnDiskConsensusContext<E>,
3126
payload_verification_outcome: PayloadVerificationOutcome,
3227
}
@@ -103,7 +98,6 @@ impl<T: BeaconChainTypes> StateLRUCache<T> {
10398
state_root,
10499
parent_block: executed_block.import_data.parent_block,
105100
parent_eth1_finalization_data: executed_block.import_data.parent_eth1_finalization_data,
106-
confirmed_state_roots: executed_block.import_data.confirmed_state_roots,
107101
consensus_context: OnDiskConsensusContext::from_consensus_context(
108102
executed_block.import_data.consensus_context,
109103
),
@@ -132,7 +126,6 @@ impl<T: BeaconChainTypes> StateLRUCache<T> {
132126
state,
133127
parent_block: diet_executed_block.parent_block,
134128
parent_eth1_finalization_data: diet_executed_block.parent_eth1_finalization_data,
135-
confirmed_state_roots: diet_executed_block.confirmed_state_roots,
136129
consensus_context: diet_executed_block
137130
.consensus_context
138131
.into_consensus_context(),
@@ -221,7 +214,6 @@ impl<E: EthSpec> From<AvailabilityPendingExecutedBlock<E>>
221214
state_root: value.import_data.state.canonical_root().unwrap(),
222215
parent_block: value.import_data.parent_block,
223216
parent_eth1_finalization_data: value.import_data.parent_eth1_finalization_data,
224-
confirmed_state_roots: value.import_data.confirmed_state_roots,
225217
consensus_context: OnDiskConsensusContext::from_consensus_context(
226218
value.import_data.consensus_context,
227219
),

beacon_node/store/src/garbage_collection.rs

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

beacon_node/store/src/hot_cold_store.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,6 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
395395
}
396396
db.store_config()?;
397397

398-
// Run a garbage collection pass.
399-
db.remove_garbage()?;
400-
401398
// If configured, run a foreground compaction pass.
402399
if db.config.compact_on_init {
403400
info!(db.log, "Running foreground compaction");

beacon_node/store/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub mod config;
1414
pub mod consensus_context;
1515
pub mod errors;
1616
mod forwards_iter;
17-
mod garbage_collection;
1817
pub mod hdiff;
1918
pub mod historic_state_cache;
2019
pub mod hot_cold_store;
@@ -289,8 +288,10 @@ pub enum DBColumn {
289288
/// Mapping from state root to `ColdStateSummary` in the cold DB.
290289
#[strum(serialize = "bcs")]
291290
BeaconColdStateSummary,
292-
/// For the list of temporary states stored during block import,
293-
/// and then made non-temporary by the deletion of their state root from this column.
291+
/// DEPRECATED.
292+
///
293+
/// Previously used for the list of temporary states stored during block import, and then made
294+
/// non-temporary by the deletion of their state root from this column.
294295
#[strum(serialize = "bst")]
295296
BeaconStateTemporary,
296297
/// Execution payloads for blocks more recent than the finalized checkpoint.

0 commit comments

Comments
 (0)