Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ use std::time::Duration;
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
use store::{
BlobSidecarListFromRoot, DBColumn, DatabaseBlock, Error as DBError, HotColdDB, HotStateSummary,
KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
KeyValueStore, KeyValueStoreOp, PayloadStatusFilter, StoreItem, StoreOp,
};
use task_executor::{RayonPoolType, ShutdownReason, TaskExecutor};
use tokio_stream::Stream;
Expand Down Expand Up @@ -2019,7 +2019,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} else {
let (advanced_state_root, mut state) = self
.store
.get_advanced_hot_state(beacon_block_root, request_slot, beacon_state_root)?
.get_advanced_hot_state(
beacon_block_root,
request_slot,
beacon_state_root,
// TODO(gloas): The payload status does not change the shuffling nor the
// justification checkpoint
PayloadStatusFilter::Any,
)?
.ok_or(Error::MissingBeaconState(beacon_state_root))?;
if state.current_epoch() < request_epoch {
partial_state_advance(
Expand Down Expand Up @@ -4613,12 +4620,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

// Atomically read some values from the head whilst avoiding holding cached head `Arc` any
// longer than necessary.
let (head_slot, head_block_root, head_state_root) = {
let (head_slot, head_block_root, head_state_root, head_payload_status) = {
let head = self.canonical_head.cached_head();
(
head.head_slot(),
head.head_block_root(),
head.head_state_root(),
if head.snapshot.beacon_state.is_parent_block_full() {
PayloadStatusFilter::Full
} else {
PayloadStatusFilter::Empty
},
)
};
let (state, state_root_opt) = if head_slot < slot {
Expand All @@ -4637,7 +4649,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// state cache thanks to the state advance timer.
let (state_root, state) = self
.store
.get_advanced_hot_state(head_block_root, slot, head_state_root)
.get_advanced_hot_state(
head_block_root,
slot,
head_state_root,
head_payload_status,
)
.map_err(BlockProductionError::FailedToLoadState)?
.ok_or(BlockProductionError::UnableToProduceAtSlot(slot))?;
(state, Some(state_root))
Expand Down Expand Up @@ -4741,7 +4758,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

let (state_root, state) = self
.store
.get_advanced_hot_state_from_cache(re_org_parent_block, slot)
.get_advanced_hot_state_from_cache(
re_org_parent_block,
slot,
// TODO(gloas): Use the correct payload status for the re-org parent.
PayloadStatusFilter::Any,
)
.or_else(|| {
warn!(reason = "no state in cache", "Not attempting re-org");
None
Expand Down Expand Up @@ -4878,7 +4900,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.ok_or(Error::MissingBeaconBlock(parent_block_root))?;
let (state_root, state) = self
.store
.get_advanced_hot_state(parent_block_root, proposal_slot, block.state_root())?
.get_advanced_hot_state(
parent_block_root,
proposal_slot,
block.state_root(),
// TODO(gloas): The post-state of the block and payload have the same proposers?
PayloadStatusFilter::Any,
)?
.ok_or(Error::MissingBeaconState(block.state_root()))?;
(Cow::Owned(state), state_root)
};
Expand Down Expand Up @@ -6907,7 +6935,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} else {
let (state_root, state) = self
.store
.get_advanced_hot_state(head_block_root, target_slot, head_block.state_root)?
.get_advanced_hot_state(
head_block_root,
target_slot,
head_block.state_root,
// TODO(gloas): The post-state of the block and payload have the same shuffling?
PayloadStatusFilter::Any,
)?
.ok_or(Error::MissingBeaconState(head_block.state_root))?;
(state, state_root)
};
Expand Down
9 changes: 8 additions & 1 deletion beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{BeaconChainError, metrics};
use kzg::{Error as KzgError, Kzg, KzgCommitment};
use ssz_derive::{Decode, Encode};
use std::time::Duration;
use store::PayloadStatusFilter;
use tracing::{debug, instrument};
use tree_hash::TreeHash;
use types::data::BlobIdentifier;
Expand Down Expand Up @@ -510,7 +511,13 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
);
chain
.store
.get_advanced_hot_state(block_parent_root, blob_slot, parent_block.state_root)
.get_advanced_hot_state(
block_parent_root,
blob_slot,
parent_block.state_root,
// TODO(gloas): The post-state of the block and payload have the same proposers
PayloadStatusFilter::Any,
)
.map_err(|e| GossipBlobError::BeaconChainError(Box::new(e.into())))?
.ok_or_else(|| {
GossipBlobError::BeaconChainError(Box::new(BeaconChainError::DBInconsistent(
Expand Down
9 changes: 7 additions & 2 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use std::fmt::Debug;
use std::fs;
use std::io::Write;
use std::sync::Arc;
use store::{Error as DBError, KeyValueStore};
use store::{Error as DBError, KeyValueStore, PayloadStatusFilter};
use strum::AsRefStr;
use task_executor::JoinHandle;
use tracing::{Instrument, Span, debug, debug_span, error, info_span, instrument};
Expand Down Expand Up @@ -1935,7 +1935,12 @@ fn load_parent<T: BeaconChainTypes, B: AsBlock<T::EthSpec>>(
// prior to the finalized slot (which is invalid and inaccessible in our DB schema).
let (parent_state_root, state) = chain
.store
.get_advanced_hot_state(root, block.slot(), parent_block.state_root())?
.get_advanced_hot_state(
root,
block.slot(),
parent_block.state_root(),
PayloadStatusFilter::Any,
)?
.ok_or_else(|| {
BeaconChainError::DBInconsistent(
format!("Missing state for parent block {root:?}",),
Expand Down
9 changes: 7 additions & 2 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use state_processing::{AllCaches, per_slot_processing};
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Duration;
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp, PayloadStatusFilter};
use task_executor::{ShutdownReason, TaskExecutor};
use tracing::{debug, error, info};
use tree_hash::TreeHash;
Expand Down Expand Up @@ -805,7 +805,12 @@ where
};

let (_head_state_root, head_state) = store
.get_advanced_hot_state(head_block_root, current_slot, head_block.state_root())
.get_advanced_hot_state(
head_block_root,
current_slot,
head_block.state_root(),
PayloadStatusFilter::Any,
)
.map_err(|e| descriptive_db_error("head state", &e))?
.ok_or("Head state not found in store")?;

Expand Down
11 changes: 9 additions & 2 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ use state_processing::AllCaches;
use std::sync::Arc;
use std::time::Duration;
use store::{
Error as StoreError, KeyValueStore, KeyValueStoreOp, StoreConfig, iter::StateRootsIterator,
Error as StoreError, KeyValueStore, KeyValueStoreOp, PayloadStatusFilter, StoreConfig,
iter::StateRootsIterator,
};
use task_executor::{JoinHandle, ShutdownReason};
use tracing::info_span;
Expand Down Expand Up @@ -306,7 +307,12 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
.ok_or(Error::MissingBeaconBlock(beacon_block_root))?;
let current_slot = fork_choice.fc_store().get_current_slot();
let (_, beacon_state) = store
.get_advanced_hot_state(beacon_block_root, current_slot, beacon_block.state_root())?
.get_advanced_hot_state(
beacon_block_root,
current_slot,
beacon_block.state_root(),
PayloadStatusFilter::Any,
)?
.ok_or(Error::MissingBeaconState(beacon_block.state_root()))?;

let snapshot = BeaconSnapshot {
Expand Down Expand Up @@ -679,6 +685,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
new_view.head_block_root,
current_slot,
beacon_block.state_root(),
PayloadStatusFilter::Any,
)?
.ok_or(Error::MissingBeaconState(beacon_block.state_root()))?;

Expand Down
9 changes: 8 additions & 1 deletion beacon_node/beacon_chain/src/data_column_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ssz_types::VariableList;
use std::iter;
use std::marker::PhantomData;
use std::sync::Arc;
use store::PayloadStatusFilter;
use tracing::{debug, instrument};
use types::data::ColumnIndex;
use types::{
Expand Down Expand Up @@ -709,7 +710,13 @@ fn verify_proposer_and_signature<T: BeaconChainTypes>(
);
chain
.store
.get_advanced_hot_state(block_parent_root, column_slot, parent_block.state_root)
.get_advanced_hot_state(
block_parent_root,
column_slot,
parent_block.state_root,
// TODO(gloas): The post-state of the block and payload have the same proposers?
PayloadStatusFilter::Any,
)
.map_err(|e| GossipDataColumnError::BeaconChainError(Box::new(e.into())))?
.ok_or_else(|| {
GossipDataColumnError::BeaconChainError(Box::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
);
} else {
// 1. Store snapshot or diff at this slot (if required).
let storage_strategy = db.hot_storage_strategy(slot)?;
let storage_strategy = db.hot_storage_strategy(slot, Slot::new(0), false)?;
debug!(
%slot,
?state_root,
Expand Down Expand Up @@ -394,6 +394,8 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
slot,
latest_block_root: old_summary.latest_block_root,
latest_block_slot: old_summary.latest_block_slot,
// TODO(gloas): this migration is using the previous type
latest_block_is_full: false,
previous_state_root,
diff_base_state,
};
Expand Down
20 changes: 17 additions & 3 deletions beacon_node/beacon_chain/src/state_advance_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use store::PayloadStatusFilter;
use task_executor::TaskExecutor;
use tokio::time::{Instant, sleep, sleep_until};
use tracing::{Instrument, debug, debug_span, error, instrument, warn};
Expand Down Expand Up @@ -272,14 +273,27 @@ fn advance_head<T: BeaconChainTypes>(beacon_chain: &Arc<BeaconChain<T>>) -> Resu
}
}

let (head_block_root, head_block_state_root) = {
let (head_block_root, head_block_state_root, head_payload_status) = {
let snapshot = beacon_chain.head_snapshot();
(snapshot.beacon_block_root, snapshot.beacon_state_root())
(
snapshot.beacon_block_root,
snapshot.beacon_state_root(),
if snapshot.beacon_state.is_parent_block_full() {
PayloadStatusFilter::Full
} else {
PayloadStatusFilter::Empty
},
)
};

let (head_state_root, mut state) = beacon_chain
.store
.get_advanced_hot_state(head_block_root, current_slot, head_block_state_root)?
.get_advanced_hot_state(
head_block_root,
current_slot,
head_block_state_root,
head_payload_status,
)?
.ok_or(Error::HeadMissingFromSnapshotCache(head_block_root))?;

let initial_slot = state.slot();
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3797,7 +3797,12 @@ async fn process_blocks_and_attestations_for_unaligned_checkpoint() {
let (split_state_root, mut advanced_split_state) = harness
.chain
.store
.get_advanced_hot_state(split.block_root, split.slot, split.state_root)
.get_advanced_hot_state(
split.block_root,
split.slot,
split.state_root,
store::PayloadStatusFilter::Full,
)
.unwrap()
.unwrap();
complete_state_advance(
Expand Down
Loading
Loading