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
9 changes: 6 additions & 3 deletions block_producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ impl<P: Preset, W: Wait> BlockProducer<P, W> {
let state = self
.producer_context
.controller
.preprocessed_state_at_current_slot()?;
.preprocessed_state_at_current_slot()?
.value;

// TODO(feature/electra): implement trait for types::combined::AttesterSlashing
let result = match slashing {
Expand Down Expand Up @@ -414,7 +415,8 @@ impl<P: Preset, W: Wait> BlockProducer<P, W> {
let state = self
.producer_context
.controller
.preprocessed_state_at_current_slot()?;
.preprocessed_state_at_current_slot()?
.value;

let outcome = match unphased::validate_proposer_slashing(
&self.producer_context.chain_config,
Expand Down Expand Up @@ -454,7 +456,8 @@ impl<P: Preset, W: Wait> BlockProducer<P, W> {
let state = self
.producer_context
.controller
.preprocessed_state_at_current_slot()?;
.preprocessed_state_at_current_slot()?
.value;

let result = match state.as_ref() {
BeaconState::Phase0(_)
Expand Down
13 changes: 10 additions & 3 deletions fork_choice_control/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,19 @@ where
.collect()
}

pub fn preprocessed_state_at_current_slot(&self) -> Result<Arc<BeaconState<P>>> {
pub fn preprocessed_state_at_current_slot(&self) -> Result<WithStatus<Arc<BeaconState<P>>>> {
let store = self.store_snapshot();
let head = store.head();

self.state_cache()
.state_at_slot(&store, head.block_root, store.slot())
let state = self
.state_cache()
.state_at_slot(&store, head.block_root, store.slot())?;

Ok(WithStatus {
value: state,
status: head.payload_status,
finalized: store.is_slot_finalized(head.slot()),
})
}

pub fn preprocessed_state_at_next_slot(&self) -> Result<Arc<BeaconState<P>>> {
Expand Down
3 changes: 3 additions & 0 deletions http_api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub enum Error {
ProposalSlotNotLaterThanStateSlot,
#[error("slot does not belong in epoch")]
SlotNotInEpoch,
#[error("state is in the future")]
StateInFuture,
#[error("state not found")]
StateNotFound,
#[error("head is not available")]
Expand Down Expand Up @@ -223,6 +225,7 @@ impl Error {
| Self::ExecutionPayloadNotAvailable
| Self::LivenessTrackingNotEnabled
| Self::SlotHeadNotAvailable
| Self::StateInFuture
| Self::TaskJoinFailed(_)
| Self::UnableToProduceAttestation { .. }
| Self::UnableToProduceBeaconBlock
Expand Down
19 changes: 6 additions & 13 deletions http_api/src/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ pub async fn submit_pool_sync_committees<P: Preset, W: Wait>(
State(api_to_p2p_tx): State<UnboundedSender<ApiToP2p<P>>>,
EthJson(json_vec): EthJson<Vec<Value>>,
) -> Result<(), Error> {
let state = controller.preprocessed_state_at_current_slot()?;
let state = controller.preprocessed_state_at_current_slot()?.value;

let Some(state) = state.post_altair() else {
return Ok(());
Expand Down Expand Up @@ -1736,7 +1736,7 @@ pub async fn beacon_state<P: Preset, W: Wait>(
value: state,
status,
finalized,
} = state_id::state(&state_id, &controller, &anchor_checkpoint_provider)?;
} = state_id::present_state(&state_id, &controller, &anchor_checkpoint_provider)?;

let version = state.phase();

Expand Down Expand Up @@ -1988,22 +1988,15 @@ pub async fn validator_proposer_duties<P: Preset, W: Wait>(
/// `POST /eth/v1/validator/duties/sync/{epoch}`
pub async fn validator_sync_committee_duties<P: Preset, W: Wait>(
State(controller): State<ApiController<P, W>>,
State(anchor_checkpoint_provider): State<AnchorCheckpointProvider<P>>,
EthPath(epoch): EthPath<Epoch>,
EthJson(validator_indices): EthJson<Vec<ValidatorIndex>>,
) -> Result<EthResponse<Vec<ValidatorSyncDutyResponse>>, Error> {
let start_slot = misc::compute_start_slot_at_epoch::<P>(epoch);

let WithStatus {
value: state,
status,
// `duties` responses are not supposed to contain a `finalized` field.
finalized: _,
} = state_id::state(
&StateId::Slot(start_slot),
&controller,
&anchor_checkpoint_provider,
)?;
} = controller.preprocessed_state_at_current_slot()?;

let Some(state) = state.post_altair() else {
return Ok(EthResponse::json(vec![]).execution_optimistic(status.is_optimistic()));
Expand Down Expand Up @@ -2421,7 +2414,7 @@ pub async fn validator_subscribe_to_beacon_committee<P: Preset, W: Wait>(
State(subnet_service_tx): State<UnboundedSender<ToSubnetService>>,
EthJson(subscriptions): EthJson<Vec<BeaconCommitteeSubscription>>,
) -> Result<(), Error> {
let state = controller.preprocessed_state_at_current_slot()?;
let state = controller.preprocessed_state_at_current_slot()?.value;
let (sender, receiver) = futures::channel::oneshot::channel();

subscriptions.iter().try_for_each(|subscription| {
Expand Down Expand Up @@ -2628,7 +2621,7 @@ pub async fn validator_liveness<P: Preset, W: Wait>(
EthJson(validators): EthJson<Vec<ValidatorIndex>>,
) -> Result<EthResponse<Vec<ValidatorLivenessResponse>>, Error> {
let api_to_liveness_tx = api_to_liveness_tx.ok_or(Error::LivenessTrackingNotEnabled)?;
let state = controller.preprocessed_state_at_current_slot()?;
let state = controller.preprocessed_state_at_current_slot()?.value;

accessors::attestation_epoch(&state, epoch).map_err(Error::InvalidEpoch)?;

Expand Down Expand Up @@ -3002,7 +2995,7 @@ async fn submit_attestations_to_pool<P: Preset, W: Wait>(
.into_iter()
.map(|target| {
if controller.head_block_root().value == target.root {
let state = controller.preprocessed_state_at_current_slot()?;
let state = controller.preprocessed_state_at_current_slot()?.value;

if accessors::get_current_epoch(&state) == target.epoch {
return Ok(state);
Expand Down
14 changes: 14 additions & 0 deletions http_api/src/state_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ use types::{combined::BeaconState, nonstandard::WithStatus, preset::Preset};

use crate::error::Error;

pub fn present_state<P: Preset, W: Wait>(
state_id: &StateId,
controller: &ApiController<P, W>,
anchor_checkpoint_provider: &AnchorCheckpointProvider<P>,
) -> Result<WithStatus<Arc<BeaconState<P>>>, Error> {
if let StateId::Slot(slot) = state_id {
if *slot > controller.slot() {
return Err(Error::StateInFuture);
}
}

state(state_id, controller, anchor_checkpoint_provider)
}

pub fn state<P: Preset, W: Wait>(
state_id: &StateId,
controller: &ApiController<P, W>,
Expand Down
2 changes: 1 addition & 1 deletion liveness_tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<P: Preset, W: Wait> LivenessTracker<P, W> {
let result = self
.controller
.preprocessed_state_at_current_slot()
.map(|state| self.process_attestation(&attestation, &state));
.map(|state| self.process_attestation(&attestation, &state.value));

if let Err(error) = result {
warn!("Error while tracking liveness from attestation: {error:?}");
Expand Down
2 changes: 1 addition & 1 deletion operation_pools/src/attestation_agg_pool/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<P: Preset, W: Wait> PoolTask for SetRegisteredValidatorsTask<P, W> {
} = self;

let beacon_state = match controller.preprocessed_state_at_current_slot() {
Ok(state) => state,
Ok(state) => state.value,
Err(error) => {
if let Some(StateCacheError::StateFarBehind { .. }) = error.downcast_ref() {
controller.head_state().value
Expand Down
2 changes: 1 addition & 1 deletion operation_pools/src/bls_to_execution_change_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<P: Preset, W: Wait> Service<P, W> {
&mut self,
signed_bls_to_execution_change: SignedBlsToExecutionChange,
) -> Result<ValidationOutcome> {
let state = self.controller.preprocessed_state_at_current_slot()?;
let state = self.controller.preprocessed_state_at_current_slot()?.value;

let Some(state) = state.post_capella() else {
warn!(
Expand Down
4 changes: 2 additions & 2 deletions operation_pools/src/sync_committee_agg_pool/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<P: Preset, W: Wait> HandleExternalContributionTask<P, W> {
}

let beacon_state = match controller.preprocessed_state_at_current_slot() {
Ok(beacon_state) => beacon_state,
Ok(beacon_state) => beacon_state.value,
Err(error) => {
debug!("cannot validate sync committee contribution: {error:?}");
return Ok(ValidationOutcome::Ignore(false));
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<P: Preset, W: Wait> HandleExternalMessageTask<P, W> {
}

let beacon_state = match controller.preprocessed_state_at_current_slot() {
Ok(beacon_state) => beacon_state,
Ok(beacon_state) => beacon_state.value,
Err(error) => {
debug!("cannot validate sync committee message: {error:?}");
return Ok(ValidationOutcome::Ignore(false));
Expand Down
2 changes: 1 addition & 1 deletion validator/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ async fn keymanager_create_voluntary_exit<P: Preset, W: Wait>(
EthPath(pubkey): EthPath<PublicKeyBytes>,
EthQuery(query): EthQuery<CreateVoluntaryExitQuery>,
) -> Result<EthResponse<SignedVoluntaryExit>, Error> {
let state = controller.preprocessed_state_at_current_slot()?;
let state = controller.preprocessed_state_at_current_slot()?.value;

let epoch = query
.epoch
Expand Down
2 changes: 1 addition & 1 deletion validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
let beacon_state = match slot_head.map(|sh| sh.beacon_state.clone_arc()) {
Some(state) => state,
None => match self.controller.preprocessed_state_at_current_slot() {
Ok(state) => state,
Ok(state) => state.value,
Err(error) => {
let is_too_many_empty_slots = matches!(
error.downcast_ref(),
Expand Down
Loading