Skip to content

Commit 1c81c93

Browse files
committed
Merge remote-tracking branch 'origin/drop-headtracker' into tree-states-hot-rebase
2 parents 5b8680a + 11cfa1c commit 1c81c93

File tree

4 files changed

+13
-96
lines changed

4 files changed

+13
-96
lines changed

beacon_node/beacon_chain/src/state_advance_timer.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::sync::{
2323
atomic::{AtomicBool, Ordering},
2424
Arc,
2525
};
26-
use store::KeyValueStore;
2726
use task_executor::TaskExecutor;
2827
use tokio::time::{sleep, sleep_until, Instant};
2928
use tracing::{debug, error, warn};
@@ -297,7 +296,7 @@ fn advance_head<T: BeaconChainTypes>(beacon_chain: &Arc<BeaconChain<T>>) -> Resu
297296
// Protect against advancing a state more than a single slot.
298297
//
299298
// Advancing more than one slot without storing the intermediate state would corrupt the
300-
// database. Future works might store temporary, intermediate states inside this function.
299+
// database. Future works might store intermediate states inside this function.
301300
match state.slot().cmp(&state.latest_block_header().slot) {
302301
std::cmp::Ordering::Equal => (),
303302
std::cmp::Ordering::Greater => {
@@ -432,20 +431,13 @@ fn advance_head<T: BeaconChainTypes>(beacon_chain: &Arc<BeaconChain<T>>) -> Resu
432431
);
433432
}
434433

435-
// Write the advanced state to the database with a temporary flag that will be deleted when
436-
// a block is imported on top of this state. We should delete this once we bring in the DB
437-
// changes from tree-states that allow us to prune states without temporary flags.
434+
// Write the advanced state to the database.
435+
// We no longer use a transaction lock here when checking whether the state exists, because
436+
// even if we race with the deletion of this state by the finalization pruning code, the worst
437+
// case is we end up with a finalized state stored, that will get pruned the next time pruning
438+
// runs.
438439
let advanced_state_root = state.update_tree_hash_cache()?;
439-
let txn_lock = beacon_chain.store.hot_db.begin_rw_transaction();
440-
let state_already_exists = beacon_chain
441-
.store
442-
.load_hot_state_summary(&advanced_state_root)?
443-
.is_some();
444-
let temporary = !state_already_exists;
445-
beacon_chain
446-
.store
447-
.put_state_possibly_temporary(&advanced_state_root, &state, temporary)?;
448-
drop(txn_lock);
440+
beacon_chain.store.put_state(&advanced_state_root, &state)?;
449441

450442
debug!(
451443
?head_block_root,

beacon_node/store/src/database/leveldb_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ impl<E: EthSpec> LevelDB<E> {
195195
};
196196

197197
for (start_key, end_key) in [
198-
endpoints(DBColumn::BeaconStateTemporary),
199198
endpoints(DBColumn::BeaconState),
200199
endpoints(DBColumn::BeaconStateSummary),
201200
] {

beacon_node/store/src/hot_cold_store.rs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -944,26 +944,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
944944

945945
/// Store a state in the store.
946946
pub fn put_state(&self, state_root: &Hash256, state: &BeaconState<E>) -> Result<(), Error> {
947-
self.put_state_possibly_temporary(state_root, state, false)
948-
}
949-
950-
/// Store a state in the store.
951-
///
952-
/// The `temporary` flag indicates whether this state should be considered canonical.
953-
pub fn put_state_possibly_temporary(
954-
&self,
955-
state_root: &Hash256,
956-
state: &BeaconState<E>,
957-
temporary: bool,
958-
) -> Result<(), Error> {
959947
let mut ops: Vec<KeyValueStoreOp> = Vec::new();
960948
if state.slot() < self.get_split_slot() {
961949
self.store_cold_state(state_root, state, &mut ops)?;
962950
self.cold_db.do_atomically(ops)
963951
} else {
964-
if temporary {
965-
ops.push(TemporaryFlag.as_kv_store_op(*state_root));
966-
}
967952
self.store_hot_state(state_root, state, &mut ops)?;
968953
self.hot_db.do_atomically(ops)
969954
}
@@ -1208,17 +1193,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
12081193
key_value_batch.push(summary.as_kv_store_op(state_root));
12091194
}
12101195

1211-
StoreOp::PutStateTemporaryFlag(state_root) => {
1212-
key_value_batch.push(TemporaryFlag.as_kv_store_op(state_root));
1213-
}
1214-
1215-
StoreOp::DeleteStateTemporaryFlag(state_root) => {
1216-
key_value_batch.push(KeyValueStoreOp::DeleteKey(
1217-
TemporaryFlag::db_column(),
1218-
state_root.as_slice().to_vec(),
1219-
));
1220-
}
1221-
12221196
StoreOp::DeleteBlock(block_root) => {
12231197
key_value_batch.push(KeyValueStoreOp::DeleteKey(
12241198
DBColumn::BeaconBlock,
@@ -1248,13 +1222,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
12481222
state_root.as_slice().to_vec(),
12491223
));
12501224

1251-
// Delete the state temporary flag (if any). Temporary flags are commonly
1252-
// created by the state advance routine.
1253-
key_value_batch.push(KeyValueStoreOp::DeleteKey(
1254-
DBColumn::BeaconStateTemporary,
1255-
state_root.as_slice().to_vec(),
1256-
));
1257-
12581225
if let Some(slot) = slot {
12591226
match self.hot_storage_strategy(slot)? {
12601227
StorageStrategy::Snapshot => {
@@ -1440,10 +1407,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
14401407

14411408
StoreOp::PutStateSummary(_, _) => (),
14421409

1443-
StoreOp::PutStateTemporaryFlag(_) => (),
1444-
1445-
StoreOp::DeleteStateTemporaryFlag(_) => (),
1446-
14471410
StoreOp::DeleteBlock(block_root) => {
14481411
guard.delete_block(&block_root);
14491412
self.state_cache.lock().delete_block_states(&block_root);
@@ -1738,12 +1701,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
17381701
) -> Result<Option<(BeaconState<E>, Hash256)>, Error> {
17391702
metrics::inc_counter(&metrics::BEACON_STATE_HOT_GET_COUNT);
17401703

1741-
// If the state is marked as temporary, do not return it. It will become visible
1742-
// only once its transaction commits and deletes its temporary flag.
1743-
if self.load_state_temporary_flag(state_root)?.is_some() {
1744-
return Ok(None);
1745-
}
1746-
17471704
if let Some(HotStateSummary {
17481705
slot,
17491706
latest_block_root,
@@ -2804,17 +2761,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
28042761
.collect()
28052762
}
28062763

2807-
/// Load the temporary flag for a state root, if one exists.
2808-
///
2809-
/// Returns `Some` if the state is temporary, or `None` if the state is permanent or does not
2810-
/// exist -- you should call `load_hot_state_summary` to find out which.
2811-
pub fn load_state_temporary_flag(
2812-
&self,
2813-
state_root: &Hash256,
2814-
) -> Result<Option<TemporaryFlag>, Error> {
2815-
self.hot_db.get(state_root)
2816-
}
2817-
28182764
/// Run a compaction pass to free up space used by deleted states.
28192765
pub fn compact(&self) -> Result<(), Error> {
28202766
self.hot_db.compact()?;
@@ -3549,23 +3495,6 @@ impl StoreItem for ColdStateSummary {
35493495
}
35503496
}
35513497

3552-
#[derive(Debug, Clone, Copy, Default)]
3553-
pub struct TemporaryFlag;
3554-
3555-
impl StoreItem for TemporaryFlag {
3556-
fn db_column() -> DBColumn {
3557-
DBColumn::BeaconStateTemporary
3558-
}
3559-
3560-
fn as_store_bytes(&self) -> Vec<u8> {
3561-
vec![]
3562-
}
3563-
3564-
fn from_store_bytes(_: &[u8]) -> Result<Self, Error> {
3565-
Ok(TemporaryFlag)
3566-
}
3567-
}
3568-
35693498
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
35703499
pub struct BytesKey {
35713500
pub key: Vec<u8>,

beacon_node/store/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub use types::*;
4949

5050
const DATA_COLUMN_DB_KEY_SIZE: usize = 32 + 8;
5151

52+
// TODO: check that these are not used by any variant of `DBColumn` using strum_macros
53+
const _DEPRECATED_COLUMN_PREFIXES: &[&str] = &[
54+
// BeaconStateTemporary, deleted in Mar 2025.
55+
"bst",
56+
];
57+
5258
pub type ColumnIter<'a, K> = Box<dyn Iterator<Item = Result<(K, Vec<u8>), Error>> + 'a>;
5359
pub type ColumnKeyIter<'a, K> = Box<dyn Iterator<Item = Result<K, Error>> + 'a>;
5460

@@ -249,8 +255,6 @@ pub enum StoreOp<'a, E: EthSpec> {
249255
PutBlobs(Hash256, BlobSidecarList<E>),
250256
PutDataColumns(Hash256, DataColumnSidecarList<E>),
251257
PutStateSummary(Hash256, HotStateSummary),
252-
PutStateTemporaryFlag(Hash256),
253-
DeleteStateTemporaryFlag(Hash256),
254258
DeleteBlock(Hash256),
255259
DeleteBlobs(Hash256),
256260
DeleteDataColumns(Hash256, Vec<ColumnIndex>),
@@ -315,12 +319,6 @@ pub enum DBColumn {
315319
/// Mapping from state root to `ColdStateSummary` in the cold DB.
316320
#[strum(serialize = "bcs")]
317321
BeaconColdStateSummary,
318-
/// DEPRECATED.
319-
///
320-
/// Previously used for the list of temporary states stored during block import, and then made
321-
/// non-temporary by the deletion of their state root from this column.
322-
#[strum(serialize = "bst")]
323-
BeaconStateTemporary,
324322
/// Execution payloads for blocks more recent than the finalized checkpoint.
325323
#[strum(serialize = "exp")]
326324
ExecPayload,
@@ -422,7 +420,6 @@ impl DBColumn {
422420
| Self::BeaconStateHotSnapshot
423421
| Self::BeaconStateHotSummary
424422
| Self::BeaconColdStateSummary
425-
| Self::BeaconStateTemporary
426423
| Self::ExecPayload
427424
| Self::BeaconChain
428425
| Self::OpPool

0 commit comments

Comments
 (0)