Skip to content

Commit f70e543

Browse files
committed
Fix anchor archives
1 parent 8657b08 commit f70e543

File tree

5 files changed

+44
-35
lines changed

5 files changed

+44
-35
lines changed

beacon_node/beacon_chain/src/schema_change/migration_schema_v22.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::sync::Arc;
33
use store::chunked_iter::ChunkedVectorIter;
44
use store::{
55
chunked_vector::BlockRootsChunked,
6-
metadata::{
7-
SchemaVersion, ANCHOR_FOR_ARCHIVE_NODE, ANCHOR_UNINITIALIZED, STATE_UPPER_LIMIT_NO_RETAIN,
8-
},
6+
metadata::{SchemaVersion, ANCHOR_UNINITIALIZED, STATE_UPPER_LIMIT_NO_RETAIN},
97
partial_beacon_state::PartialBeaconState,
108
AnchorInfo, DBColumn, Error, HotColdDB, KeyValueStore, KeyValueStoreOp,
119
};
@@ -48,7 +46,13 @@ pub fn upgrade_to_v22<T: BeaconChainTypes>(
4846
// If the anchor was uninitialized in the old schema (`None`), this represents a full archive
4947
// node.
5048
let effective_anchor = if old_anchor == ANCHOR_UNINITIALIZED {
51-
ANCHOR_FOR_ARCHIVE_NODE
49+
AnchorInfo {
50+
anchor_slot: Slot::new(0),
51+
oldest_block_slot: Slot::new(0),
52+
oldest_block_parent: Hash256::ZERO,
53+
state_upper_limit: Slot::new(0),
54+
state_lower_limit: Slot::new(0),
55+
}
5256
} else {
5357
old_anchor.clone()
5458
};

beacon_node/store/src/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl StoreItem for OnDiskStoreConfig {
247247
mod test {
248248
use super::*;
249249
use crate::{
250-
metadata::{ANCHOR_FOR_ARCHIVE_NODE, ANCHOR_UNINITIALIZED, STATE_UPPER_LIMIT_NO_RETAIN},
250+
metadata::{ANCHOR_UNINITIALIZED, STATE_UPPER_LIMIT_NO_RETAIN},
251251
AnchorInfo, Split,
252252
};
253253
use ssz::DecodeError;
@@ -291,8 +291,15 @@ mod test {
291291
slot: Slot::new(32),
292292
..Default::default()
293293
};
294+
let anchor = AnchorInfo {
295+
anchor_slot: Slot::new(0),
296+
oldest_block_slot: Slot::new(0),
297+
oldest_block_parent: Hash256::ZERO,
298+
state_upper_limit: Slot::new(0),
299+
state_lower_limit: Slot::new(0),
300+
};
294301
assert!(store_config
295-
.check_compatibility(&on_disk_config, &split, &ANCHOR_FOR_ARCHIVE_NODE)
302+
.check_compatibility(&on_disk_config, &split, &anchor)
296303
.is_err());
297304
}
298305

beacon_node/store/src/hot_cold_store.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::historic_state_cache::HistoricStateCache;
66
use crate::iter::{BlockRootsIterator, ParentRootBlockIterator, RootsIterator};
77
use crate::memory_store::MemoryStore;
88
use crate::metadata::{
9-
AnchorInfo, BlobInfo, CompactionTimestamp, DataColumnInfo, SchemaVersion,
10-
ANCHOR_FOR_ARCHIVE_NODE, ANCHOR_INFO_KEY, ANCHOR_UNINITIALIZED, BLOB_INFO_KEY,
11-
COMPACTION_TIMESTAMP_KEY, CONFIG_KEY, CURRENT_SCHEMA_VERSION, DATA_COLUMN_INFO_KEY,
12-
SCHEMA_VERSION_KEY, SPLIT_KEY, STATE_UPPER_LIMIT_NO_RETAIN,
9+
AnchorInfo, BlobInfo, CompactionTimestamp, DataColumnInfo, SchemaVersion, ANCHOR_INFO_KEY,
10+
ANCHOR_UNINITIALIZED, BLOB_INFO_KEY, COMPACTION_TIMESTAMP_KEY, CONFIG_KEY,
11+
CURRENT_SCHEMA_VERSION, DATA_COLUMN_INFO_KEY, SCHEMA_VERSION_KEY, SPLIT_KEY,
12+
STATE_UPPER_LIMIT_NO_RETAIN,
1313
};
1414
use crate::state_cache::{PutStateOutcome, StateCache};
1515
use crate::{
@@ -2536,17 +2536,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
25362536
} else {
25372537
next_snapshot_slot
25382538
};
2539-
let anchor_info = if state_upper_limit == 0 && anchor_slot == 0 {
2540-
// Genesis archive node: no anchor because we *will* store all states.
2541-
ANCHOR_FOR_ARCHIVE_NODE
2542-
} else {
2543-
AnchorInfo {
2544-
anchor_slot,
2545-
oldest_block_slot,
2546-
oldest_block_parent,
2547-
state_upper_limit,
2548-
state_lower_limit: self.spec.genesis_slot,
2549-
}
2539+
let anchor_info = AnchorInfo {
2540+
anchor_slot,
2541+
oldest_block_slot,
2542+
oldest_block_parent,
2543+
state_upper_limit,
2544+
state_lower_limit: self.spec.genesis_slot,
25502545
};
25512546
self.compare_and_set_anchor_info(ANCHOR_UNINITIALIZED, anchor_info)
25522547
}

beacon_node/store/src/metadata.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ pub const DATA_COLUMN_INFO_KEY: Hash256 = Hash256::repeat_byte(7);
2222
/// State upper limit value used to indicate that a node is not storing historic states.
2323
pub const STATE_UPPER_LIMIT_NO_RETAIN: Slot = Slot::new(u64::MAX);
2424

25-
/// The `AnchorInfo` encoding full availability of all historic blocks & states.
26-
pub const ANCHOR_FOR_ARCHIVE_NODE: AnchorInfo = AnchorInfo {
27-
anchor_slot: Slot::new(0),
28-
oldest_block_slot: Slot::new(0),
29-
oldest_block_parent: Hash256::ZERO,
30-
state_upper_limit: Slot::new(0),
31-
state_lower_limit: Slot::new(0),
32-
};
33-
3425
/// The `AnchorInfo` encoding an uninitialized anchor.
3526
///
3627
/// This value should never exist except on initial start-up prior to the anchor being initialised
@@ -153,6 +144,21 @@ impl AnchorInfo {
153144
pub fn full_state_pruning_enabled(&self) -> bool {
154145
self.state_lower_limit == 0 && self.state_upper_limit == STATE_UPPER_LIMIT_NO_RETAIN
155146
}
147+
148+
/// Compute the correct `AnchorInfo` for an archive node created from the current node.
149+
///
150+
/// This method ensures that the `anchor_slot` which is used for the hot database's diff grid is
151+
/// preserved.
152+
pub fn as_archive_anchor(&self) -> Self {
153+
Self {
154+
// Anchor slot MUST be the same. It is immutable.
155+
anchor_slot: self.anchor_slot,
156+
oldest_block_slot: Slot::new(0),
157+
oldest_block_parent: Hash256::ZERO,
158+
state_upper_limit: Slot::new(0),
159+
state_lower_limit: Slot::new(0),
160+
}
161+
}
156162
}
157163

158164
impl StoreItem for AnchorInfo {

beacon_node/store/src/reconstruct.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Implementation of historic state reconstruction (given complete block history).
22
use crate::hot_cold_store::{HotColdDB, HotColdDBError};
3-
use crate::metadata::ANCHOR_FOR_ARCHIVE_NODE;
43
use crate::metrics;
54
use crate::{Error, ItemStore};
65
use itertools::{process_results, Itertools};
@@ -145,10 +144,8 @@ where
145144
});
146145
}
147146

148-
self.compare_and_set_anchor_info_with_write(
149-
old_anchor,
150-
ANCHOR_FOR_ARCHIVE_NODE,
151-
)?;
147+
let new_anchor = old_anchor.as_archive_anchor();
148+
self.compare_and_set_anchor_info_with_write(old_anchor, new_anchor)?;
152149

153150
return Ok(());
154151
} else {

0 commit comments

Comments
 (0)