Merge commit '036b797b2c1831352f937356576b3c78c65220ad' into eip4844

This commit is contained in:
Diva M 2023-04-04 11:53:55 -05:00
commit 905322394b
No known key found for this signature in database
GPG Key ID: 1BAE5E01126680FE
27 changed files with 1335 additions and 616 deletions

794
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -102,7 +102,7 @@ eth2_hashing = { path = "crypto/eth2_hashing" }
tree_hash = { path = "consensus/tree_hash" }
tree_hash_derive = { path = "consensus/tree_hash_derive" }
eth2_serde_utils = { path = "consensus/serde_utils" }
arbitrary = { git = "https://github.com/michaelsproul/arbitrary", rev="a572fd8743012a4f1ada5ee5968b1b3619c427ba" }
arbitrary = { git = "https://github.com/michaelsproul/arbitrary", rev="f002b99989b561ddce62e4cf2887b0f8860ae991" }
[patch."https://github.com/ralexstokes/mev-rs"]
mev-rs = { git = "https://github.com/ralexstokes//mev-rs", rev = "7813d4a4a564e0754e9aaab2d95520ba437c3889" }

View File

@ -1,6 +1,6 @@
[package]
name = "beacon_node"
version = "4.0.1-rc.0"
version = "4.0.1"
authors = ["Paul Hauner <paul@paulhauner.com>", "Age Manning <Age@AgeManning.com"]
edition = "2021"

View File

@ -438,6 +438,46 @@ pub struct BeaconChain<T: BeaconChainTypes> {
type BeaconBlockAndState<T, Payload> = (BeaconBlock<T, Payload>, BeaconState<T>);
impl<T: BeaconChainTypes> BeaconChain<T> {
/// Checks if a block is finalized.
/// The finalization check is done with the block slot. The block root is used to verify that
/// the finalized slot is in the canonical chain.
pub fn is_finalized_block(
&self,
block_root: &Hash256,
block_slot: Slot,
) -> Result<bool, Error> {
let finalized_slot = self
.canonical_head
.cached_head()
.finalized_checkpoint()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let is_canonical = self
.block_root_at_slot(block_slot, WhenSlotSkipped::None)?
.map_or(false, |canonical_root| block_root == &canonical_root);
Ok(block_slot <= finalized_slot && is_canonical)
}
/// Checks if a state is finalized.
/// The finalization check is done with the slot. The state root is used to verify that
/// the finalized state is in the canonical chain.
pub fn is_finalized_state(
&self,
state_root: &Hash256,
state_slot: Slot,
) -> Result<bool, Error> {
let finalized_slot = self
.canonical_head
.cached_head()
.finalized_checkpoint()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let is_canonical = self
.state_root_at_slot(state_slot)?
.map_or(false, |canonical_root| state_root == &canonical_root);
Ok(state_slot <= finalized_slot && is_canonical)
}
/// Persists the head tracker and fork choice.
///
/// We do it atomically even though no guarantees need to be made about blocks from

View File

@ -77,8 +77,8 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
// query is within permitted bounds to prevent potential OOM errors.
if (end_epoch - start_epoch).as_usize() > MAX_REQUEST_RANGE_EPOCHS {
return Err(custom_bad_request(format!(
"end_epoch must not exceed start_epoch by more than 100 epochs. start: {}, end: {}",
query.start_epoch, query.end_epoch
"end_epoch must not exceed start_epoch by more than {} epochs. start: {}, end: {}",
MAX_REQUEST_RANGE_EPOCHS, query.start_epoch, query.end_epoch
)));
}

View File

@ -114,8 +114,10 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
)?;
(state, execution_optimistic)
} else {
StateId::from_slot(request_epoch.start_slot(T::EthSpec::slots_per_epoch()))
.state(chain)?
let (state, execution_optimistic, _finalized) =
StateId::from_slot(request_epoch.start_slot(T::EthSpec::slots_per_epoch()))
.state(chain)?;
(state, execution_optimistic)
};
// Sanity-check the state lookup.

View File

@ -4,13 +4,15 @@ use eth2::types::BlockId as CoreBlockId;
use std::fmt;
use std::str::FromStr;
use std::sync::Arc;
use types::{BlobsSidecar, Hash256, SignedBeaconBlock, SignedBlindedBeaconBlock, Slot};
use types::{BlobsSidecar, EthSpec, Hash256, SignedBeaconBlock, SignedBlindedBeaconBlock, Slot};
/// Wraps `eth2::types::BlockId` and provides a simple way to obtain a block or root for a given
/// `BlockId`.
#[derive(Debug)]
pub struct BlockId(pub CoreBlockId);
type Finalized = bool;
impl BlockId {
pub fn from_slot(slot: Slot) -> Self {
Self(CoreBlockId::Slot(slot))
@ -24,7 +26,7 @@ impl BlockId {
pub fn root<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(Hash256, ExecutionOptimistic), warp::Rejection> {
) -> Result<(Hash256, ExecutionOptimistic, Finalized), warp::Rejection> {
match &self.0 {
CoreBlockId::Head => {
let (cached_head, execution_status) = chain
@ -34,22 +36,23 @@ impl BlockId {
Ok((
cached_head.head_block_root(),
execution_status.is_optimistic_or_invalid(),
false,
))
}
CoreBlockId::Genesis => Ok((chain.genesis_block_root, false)),
CoreBlockId::Genesis => Ok((chain.genesis_block_root, false, true)),
CoreBlockId::Finalized => {
let finalized_checkpoint =
chain.canonical_head.cached_head().finalized_checkpoint();
let (_slot, execution_optimistic) =
checkpoint_slot_and_execution_optimistic(chain, finalized_checkpoint)?;
Ok((finalized_checkpoint.root, execution_optimistic))
Ok((finalized_checkpoint.root, execution_optimistic, true))
}
CoreBlockId::Justified => {
let justified_checkpoint =
chain.canonical_head.cached_head().justified_checkpoint();
let (_slot, execution_optimistic) =
checkpoint_slot_and_execution_optimistic(chain, justified_checkpoint)?;
Ok((justified_checkpoint.root, execution_optimistic))
Ok((justified_checkpoint.root, execution_optimistic, false))
}
CoreBlockId::Slot(slot) => {
let execution_optimistic = chain
@ -66,7 +69,14 @@ impl BlockId {
))
})
})?;
Ok((root, execution_optimistic))
let finalized = *slot
<= chain
.canonical_head
.cached_head()
.finalized_checkpoint()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
Ok((root, execution_optimistic, finalized))
}
CoreBlockId::Root(root) => {
// This matches the behaviour of other consensus clients (e.g. Teku).
@ -88,7 +98,20 @@ impl BlockId {
.is_optimistic_or_invalid_block(root)
.map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?;
Ok((*root, execution_optimistic))
let blinded_block = chain
.get_blinded_block(root)
.map_err(warp_utils::reject::beacon_chain_error)?
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
root
))
})?;
let block_slot = blinded_block.slot();
let finalized = chain
.is_finalized_block(root, block_slot)
.map_err(warp_utils::reject::beacon_chain_error)?;
Ok((*root, execution_optimistic, finalized))
} else {
Err(warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
@ -103,7 +126,14 @@ impl BlockId {
pub fn blinded_block<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(SignedBlindedBeaconBlock<T::EthSpec>, ExecutionOptimistic), warp::Rejection> {
) -> Result<
(
SignedBlindedBeaconBlock<T::EthSpec>,
ExecutionOptimistic,
Finalized,
),
warp::Rejection,
> {
match &self.0 {
CoreBlockId::Head => {
let (cached_head, execution_status) = chain
@ -113,10 +143,11 @@ impl BlockId {
Ok((
cached_head.snapshot.beacon_block.clone_as_blinded(),
execution_status.is_optimistic_or_invalid(),
false,
))
}
CoreBlockId::Slot(slot) => {
let (root, execution_optimistic) = self.root(chain)?;
let (root, execution_optimistic, finalized) = self.root(chain)?;
chain
.get_blinded_block(&root)
.map_err(warp_utils::reject::beacon_chain_error)
@ -128,7 +159,7 @@ impl BlockId {
slot
)));
}
Ok((block, execution_optimistic))
Ok((block, execution_optimistic, finalized))
}
None => Err(warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
@ -137,7 +168,7 @@ impl BlockId {
})
}
_ => {
let (root, execution_optimistic) = self.root(chain)?;
let (root, execution_optimistic, finalized) = self.root(chain)?;
let block = chain
.get_blinded_block(&root)
.map_err(warp_utils::reject::beacon_chain_error)
@ -149,7 +180,7 @@ impl BlockId {
))
})
})?;
Ok((block, execution_optimistic))
Ok((block, execution_optimistic, finalized))
}
}
}
@ -158,7 +189,14 @@ impl BlockId {
pub async fn full_block<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(Arc<SignedBeaconBlock<T::EthSpec>>, ExecutionOptimistic), warp::Rejection> {
) -> Result<
(
Arc<SignedBeaconBlock<T::EthSpec>>,
ExecutionOptimistic,
Finalized,
),
warp::Rejection,
> {
match &self.0 {
CoreBlockId::Head => {
let (cached_head, execution_status) = chain
@ -168,10 +206,11 @@ impl BlockId {
Ok((
cached_head.snapshot.beacon_block.clone(),
execution_status.is_optimistic_or_invalid(),
false,
))
}
CoreBlockId::Slot(slot) => {
let (root, execution_optimistic) = self.root(chain)?;
let (root, execution_optimistic, finalized) = self.root(chain)?;
chain
.get_block(&root)
.await
@ -184,7 +223,7 @@ impl BlockId {
slot
)));
}
Ok((Arc::new(block), execution_optimistic))
Ok((Arc::new(block), execution_optimistic, finalized))
}
None => Err(warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
@ -193,14 +232,14 @@ impl BlockId {
})
}
_ => {
let (root, execution_optimistic) = self.root(chain)?;
let (root, execution_optimistic, finalized) = self.root(chain)?;
chain
.get_block(&root)
.await
.map_err(warp_utils::reject::beacon_chain_error)
.and_then(|block_opt| {
block_opt
.map(|block| (Arc::new(block), execution_optimistic))
.map(|block| (Arc::new(block), execution_optimistic, finalized))
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",

View File

@ -30,7 +30,8 @@ use beacon_chain::{
pub use block_id::BlockId;
use directory::DEFAULT_ROOT_DIR;
use eth2::types::{
self as api_types, EndpointVersion, SkipRandaoVerification, ValidatorId, ValidatorStatus,
self as api_types, EndpointVersion, ForkChoice, ForkChoiceNode, SkipRandaoVerification,
ValidatorId, ValidatorStatus,
};
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_version::version_with_platform;
@ -62,7 +63,7 @@ use types::{
SyncCommitteeMessage, SyncContributionData,
};
use version::{
add_consensus_version_header, execution_optimistic_fork_versioned_response,
add_consensus_version_header, execution_optimistic_finalized_fork_versioned_response,
fork_versioned_response, inconsistent_fork_rejection, unsupported_version_rejection, V1, V2,
};
use warp::http::StatusCode;
@ -521,12 +522,13 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (root, execution_optimistic) = state_id.root(&chain)?;
let (root, execution_optimistic, finalized) = state_id.root(&chain)?;
Ok(root)
.map(api_types::RootData::from)
.map(api_types::GenericResponse::from)
.map(|resp| resp.add_execution_optimistic(execution_optimistic))
.map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
})
})
});
@ -537,11 +539,12 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (fork, execution_optimistic) =
state_id.fork_and_execution_optimistic(&chain)?;
Ok(api_types::ExecutionOptimisticResponse {
let (fork, execution_optimistic, finalized) =
state_id.fork_and_execution_optimistic_and_finalized(&chain)?;
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data: fork,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
});
@ -553,23 +556,26 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (data, execution_optimistic) = state_id.map_state_and_execution_optimistic(
&chain,
|state, execution_optimistic| {
Ok((
api_types::FinalityCheckpointsData {
previous_justified: state.previous_justified_checkpoint(),
current_justified: state.current_justified_checkpoint(),
finalized: state.finalized_checkpoint(),
},
execution_optimistic,
))
},
)?;
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic, finalized| {
Ok((
api_types::FinalityCheckpointsData {
previous_justified: state.previous_justified_checkpoint(),
current_justified: state.current_justified_checkpoint(),
finalized: state.finalized_checkpoint(),
},
execution_optimistic,
finalized,
))
},
)?;
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
});
@ -586,10 +592,10 @@ pub fn serve<T: BeaconChainTypes>(
query_res: Result<api_types::ValidatorBalancesQuery, warp::Rejection>| {
blocking_json_task(move || {
let query = query_res?;
let (data, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
Ok((
state
.validators()
@ -617,13 +623,15 @@ pub fn serve<T: BeaconChainTypes>(
})
.collect::<Vec<_>>(),
execution_optimistic,
finalized,
))
},
)?;
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
@ -641,10 +649,10 @@ pub fn serve<T: BeaconChainTypes>(
query_res: Result<api_types::ValidatorsQuery, warp::Rejection>| {
blocking_json_task(move || {
let query = query_res?;
let (data, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let epoch = state.current_epoch();
let far_future_epoch = chain.spec.far_future_epoch;
@ -694,13 +702,15 @@ pub fn serve<T: BeaconChainTypes>(
})
.collect::<Vec<_>>(),
execution_optimistic,
finalized,
))
},
)?;
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
@ -719,10 +729,10 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId| {
blocking_json_task(move || {
let (data, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let index_opt = match &validator_id {
ValidatorId::PublicKey(pubkey) => {
state.validators().iter().position(|v| v.pubkey == *pubkey)
@ -756,13 +766,15 @@ pub fn serve<T: BeaconChainTypes>(
))
})?,
execution_optimistic,
finalized,
))
},
)?;
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
@ -777,10 +789,10 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, query: api_types::CommitteesQuery| {
blocking_json_task(move || {
let (data, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let current_epoch = state.current_epoch();
let epoch = query.epoch.unwrap_or(current_epoch);
@ -936,12 +948,13 @@ pub fn serve<T: BeaconChainTypes>(
}
}
Ok((response, execution_optimistic))
Ok((response, execution_optimistic, finalized))
},
)?;
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
@ -958,10 +971,10 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
query: api_types::SyncCommitteesQuery| {
blocking_json_task(move || {
let (sync_committee, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (sync_committee, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let current_epoch = state.current_epoch();
let epoch = query.epoch.unwrap_or(current_epoch);
Ok((
@ -971,9 +984,10 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(|e| match e {
BeaconStateError::SyncCommitteeNotKnown { .. } => {
warp_utils::reject::custom_bad_request(format!(
"state at epoch {} has no sync committee for epoch {}",
current_epoch, epoch
))
"state at epoch {} has no \
sync committee for epoch {}",
current_epoch, epoch
))
}
BeaconStateError::IncorrectStateVariant => {
warp_utils::reject::custom_bad_request(format!(
@ -984,6 +998,7 @@ pub fn serve<T: BeaconChainTypes>(
e => warp_utils::reject::beacon_state_error(e),
})?,
execution_optimistic,
finalized,
))
},
)?;
@ -1005,7 +1020,7 @@ pub fn serve<T: BeaconChainTypes>(
};
Ok(api_types::GenericResponse::from(response)
.add_execution_optimistic(execution_optimistic))
.add_execution_optimistic_finalized(execution_optimistic, finalized))
})
},
);
@ -1019,23 +1034,23 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, query: api_types::RandaoQuery| {
blocking_json_task(move || {
let (randao, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
let (randao, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let epoch = query.epoch.unwrap_or_else(|| state.current_epoch());
let randao = *state.get_randao_mix(epoch).map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"epoch out of range: {e:?}"
))
})?;
Ok((randao, execution_optimistic))
Ok((randao, execution_optimistic, finalized))
},
)?;
Ok(
api_types::GenericResponse::from(api_types::RandaoMix { randao })
.add_execution_optimistic(execution_optimistic),
.add_execution_optimistic_finalized(execution_optimistic, finalized),
)
})
},
@ -1057,72 +1072,73 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|query: api_types::HeadersQuery, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (root, block, execution_optimistic) = match (query.slot, query.parent_root)
{
// No query parameters, return the canonical head block.
(None, None) => {
let (cached_head, execution_status) = chain
.canonical_head
.head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?;
(
cached_head.head_block_root(),
cached_head.snapshot.beacon_block.clone_as_blinded(),
execution_status.is_optimistic_or_invalid(),
)
}
// Only the parent root parameter, do a forwards-iterator lookup.
(None, Some(parent_root)) => {
let (parent, execution_optimistic) =
BlockId::from_root(parent_root).blinded_block(&chain)?;
let (root, _slot) = chain
.forwards_iter_block_roots(parent.slot())
.map_err(warp_utils::reject::beacon_chain_error)?
// Ignore any skip-slots immediately following the parent.
.find(|res| {
res.as_ref().map_or(false, |(root, _)| *root != parent_root)
})
.transpose()
.map_err(warp_utils::reject::beacon_chain_error)?
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"child of block with root {}",
parent_root
))
})?;
BlockId::from_root(root)
.blinded_block(&chain)
// Ignore this `execution_optimistic` since the first value has
// more information about the original request.
.map(|(block, _execution_optimistic)| {
(root, block, execution_optimistic)
})?
}
// Slot is supplied, search by slot and optionally filter by
// parent root.
(Some(slot), parent_root_opt) => {
let (root, execution_optimistic) =
BlockId::from_slot(slot).root(&chain)?;
// Ignore the second `execution_optimistic`, the first one is the
// most relevant since it knows that we queried by slot.
let (block, _execution_optimistic) =
BlockId::from_root(root).blinded_block(&chain)?;
// If the parent root was supplied, check that it matches the block
// obtained via a slot lookup.
if let Some(parent_root) = parent_root_opt {
if block.parent_root() != parent_root {
return Err(warp_utils::reject::custom_not_found(format!(
"no canonical block at slot {} with parent root {}",
slot, parent_root
)));
}
let (root, block, execution_optimistic, finalized) =
match (query.slot, query.parent_root) {
// No query parameters, return the canonical head block.
(None, None) => {
let (cached_head, execution_status) = chain
.canonical_head
.head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?;
(
cached_head.head_block_root(),
cached_head.snapshot.beacon_block.clone_as_blinded(),
execution_status.is_optimistic_or_invalid(),
false,
)
}
// Only the parent root parameter, do a forwards-iterator lookup.
(None, Some(parent_root)) => {
let (parent, execution_optimistic, _parent_finalized) =
BlockId::from_root(parent_root).blinded_block(&chain)?;
let (root, _slot) = chain
.forwards_iter_block_roots(parent.slot())
.map_err(warp_utils::reject::beacon_chain_error)?
// Ignore any skip-slots immediately following the parent.
.find(|res| {
res.as_ref().map_or(false, |(root, _)| *root != parent_root)
})
.transpose()
.map_err(warp_utils::reject::beacon_chain_error)?
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"child of block with root {}",
parent_root
))
})?;
(root, block, execution_optimistic)
}
};
BlockId::from_root(root)
.blinded_block(&chain)
// Ignore this `execution_optimistic` since the first value has
// more information about the original request.
.map(|(block, _execution_optimistic, finalized)| {
(root, block, execution_optimistic, finalized)
})?
}
// Slot is supplied, search by slot and optionally filter by
// parent root.
(Some(slot), parent_root_opt) => {
let (root, execution_optimistic, finalized) =
BlockId::from_slot(slot).root(&chain)?;
// Ignore the second `execution_optimistic`, the first one is the
// most relevant since it knows that we queried by slot.
let (block, _execution_optimistic, _finalized) =
BlockId::from_root(root).blinded_block(&chain)?;
// If the parent root was supplied, check that it matches the block
// obtained via a slot lookup.
if let Some(parent_root) = parent_root_opt {
if block.parent_root() != parent_root {
return Err(warp_utils::reject::custom_not_found(format!(
"no canonical block at slot {} with parent root {}",
slot, parent_root
)));
}
}
(root, block, execution_optimistic, finalized)
}
};
let data = api_types::BlockHeaderData {
root,
@ -1134,7 +1150,7 @@ pub fn serve<T: BeaconChainTypes>(
};
Ok(api_types::GenericResponse::from(vec![data])
.add_execution_optimistic(execution_optimistic))
.add_execution_optimistic_finalized(execution_optimistic, finalized))
})
},
);
@ -1152,10 +1168,10 @@ pub fn serve<T: BeaconChainTypes>(
.and(chain_filter.clone())
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (root, execution_optimistic) = block_id.root(&chain)?;
let (root, execution_optimistic, finalized) = block_id.root(&chain)?;
// Ignore the second `execution_optimistic` since the first one has more
// information about the original request.
let (block, _execution_optimistic) =
let (block, _execution_optimistic, _finalized) =
BlockId::from_root(root).blinded_block(&chain)?;
let canonical = chain
@ -1172,8 +1188,9 @@ pub fn serve<T: BeaconChainTypes>(
},
};
Ok(api_types::ExecutionOptimisticResponse {
Ok(api_types::ExecutionOptimisticFinalizedResponse {
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
data,
})
})
@ -1258,7 +1275,8 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
accept_header: Option<api_types::Accept>| {
async move {
let (block, execution_optimistic) = block_id.full_block(&chain).await?;
let (block, execution_optimistic, finalized) =
block_id.full_block(&chain).await?;
let fork_name = block
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
@ -1274,10 +1292,11 @@ pub fn serve<T: BeaconChainTypes>(
e
))
}),
_ => execution_optimistic_fork_versioned_response(
_ => execution_optimistic_finalized_fork_versioned_response(
endpoint_version,
fork_name,
execution_optimistic,
finalized,
block,
)
.map(|res| warp::reply::json(&res).into_response()),
@ -1294,12 +1313,11 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (block, execution_optimistic) = block_id.blinded_block(&chain)?;
let (block, execution_optimistic, finalized) = block_id.blinded_block(&chain)?;
Ok(api_types::GenericResponse::from(api_types::RootData::from(
block.canonical_root(),
))
.add_execution_optimistic(execution_optimistic))
.add_execution_optimistic_finalized(execution_optimistic, finalized))
})
});
@ -1310,11 +1328,10 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (block, execution_optimistic) = block_id.blinded_block(&chain)?;
let (block, execution_optimistic, finalized) = block_id.blinded_block(&chain)?;
Ok(
api_types::GenericResponse::from(block.message().body().attestations().clone())
.add_execution_optimistic(execution_optimistic),
.add_execution_optimistic_finalized(execution_optimistic, finalized),
)
})
});
@ -1332,7 +1349,8 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
accept_header: Option<api_types::Accept>| {
blocking_response_task(move || {
let (block, execution_optimistic) = block_id.blinded_block(&chain)?;
let (block, execution_optimistic, finalized) =
block_id.blinded_block(&chain)?;
let fork_name = block
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
@ -1350,10 +1368,11 @@ pub fn serve<T: BeaconChainTypes>(
}),
_ => {
// Post as a V2 endpoint so we return the fork version.
execution_optimistic_fork_versioned_response(
execution_optimistic_finalized_fork_versioned_response(
V2,
fork_name,
execution_optimistic,
finalized,
block,
)
.map(|res| warp::reply::json(&res).into_response())
@ -1894,11 +1913,13 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::end())
.and_then(|chain: Arc<BeaconChain<T>>, block_id: BlockId| {
blocking_json_task(move || {
let (rewards, execution_optimistic) =
let (rewards, execution_optimistic, finalized) =
standard_block_rewards::compute_beacon_block_rewards(chain, block_id)?;
Ok(rewards)
.map(api_types::GenericResponse::from)
.map(|resp| resp.add_execution_optimistic(execution_optimistic))
.map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
})
})
});
@ -1977,14 +1998,16 @@ pub fn serve<T: BeaconChainTypes>(
validators: Vec<ValidatorId>,
log: Logger| {
blocking_json_task(move || {
let (rewards, execution_optimistic) =
let (rewards, execution_optimistic, finalized) =
sync_committee_rewards::compute_sync_committee_rewards(
chain, block_id, validators, log,
)?;
Ok(rewards)
.map(api_types::GenericResponse::from)
.map(|resp| resp.add_execution_optimistic(execution_optimistic))
.map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
})
})
},
);
@ -2067,7 +2090,7 @@ pub fn serve<T: BeaconChainTypes>(
// We can ignore the optimistic status for the "fork" since it's a
// specification constant that doesn't change across competing heads of the
// beacon chain.
let (state, _execution_optimistic) = state_id.state(&chain)?;
let (state, _execution_optimistic, _finalized) = state_id.state(&chain)?;
let fork_name = state
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
@ -2085,16 +2108,17 @@ pub fn serve<T: BeaconChainTypes>(
))
})
}
_ => state_id.map_state_and_execution_optimistic(
_ => state_id.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic| {
|state, execution_optimistic, finalized| {
let fork_name = state
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
let res = execution_optimistic_fork_versioned_response(
let res = execution_optimistic_finalized_fork_versioned_response(
endpoint_version,
fork_name,
execution_optimistic,
finalized,
&state,
)?;
Ok(add_consensus_version_header(
@ -2144,6 +2168,58 @@ pub fn serve<T: BeaconChainTypes>(
},
);
// GET debug/fork_choice
let get_debug_fork_choice = eth_v1
.and(warp::path("debug"))
.and(warp::path("fork_choice"))
.and(warp::path::end())
.and(chain_filter.clone())
.and_then(|chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let beacon_fork_choice = chain.canonical_head.fork_choice_read_lock();
let proto_array = beacon_fork_choice.proto_array().core_proto_array();
let fork_choice_nodes = proto_array
.nodes
.iter()
.map(|node| {
let execution_status = if node.execution_status.is_execution_enabled() {
Some(node.execution_status.to_string())
} else {
None
};
ForkChoiceNode {
slot: node.slot,
block_root: node.root,
parent_root: node
.parent
.and_then(|index| proto_array.nodes.get(index))
.map(|parent| parent.root),
justified_epoch: node
.justified_checkpoint
.map(|checkpoint| checkpoint.epoch),
finalized_epoch: node
.finalized_checkpoint
.map(|checkpoint| checkpoint.epoch),
weight: node.weight,
validity: execution_status,
execution_block_hash: node
.execution_status
.block_hash()
.map(|block_hash| block_hash.into_root()),
}
})
.collect::<Vec<_>>();
Ok(ForkChoice {
justified_checkpoint: proto_array.justified_checkpoint,
finalized_checkpoint: proto_array.finalized_checkpoint,
fork_choice_nodes,
})
})
});
/*
* node
*/
@ -3426,7 +3502,7 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
blocking_response_task(move || {
// This debug endpoint provides no indication of optimistic status.
let (state, _execution_optimistic) = state_id.state(&chain)?;
let (state, _execution_optimistic, _finalized) = state_id.state(&chain)?;
Response::builder()
.status(200)
.header("Content-Type", "application/ssz")
@ -3707,6 +3783,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_config_deposit_contract)
.uor(get_debug_beacon_states)
.uor(get_debug_beacon_heads)
.uor(get_debug_fork_choice)
.uor(get_node_identity)
.uor(get_node_version)
.uor(get_node_syncing)

View File

@ -209,7 +209,9 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_chain_error)?;
(state, execution_optimistic)
} else {
StateId::from_slot(epoch.start_slot(T::EthSpec::slots_per_epoch())).state(chain)?
let (state, execution_optimistic, _finalized) =
StateId::from_slot(epoch.start_slot(T::EthSpec::slots_per_epoch())).state(chain)?;
(state, execution_optimistic)
};
// Ensure the state lookup was correct.

View File

@ -10,8 +10,8 @@ use warp_utils::reject::beacon_chain_error;
pub fn compute_beacon_block_rewards<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_id: BlockId,
) -> Result<(StandardBlockReward, ExecutionOptimistic), warp::Rejection> {
let (block, execution_optimistic) = block_id.blinded_block(&chain)?;
) -> Result<(StandardBlockReward, ExecutionOptimistic, bool), warp::Rejection> {
let (block, execution_optimistic, finalized) = block_id.blinded_block(&chain)?;
let block_ref = block.message();
@ -23,5 +23,5 @@ pub fn compute_beacon_block_rewards<T: BeaconChainTypes>(
.compute_beacon_block_reward(block_ref, block_root, &mut state)
.map_err(beacon_chain_error)?;
Ok((rewards, execution_optimistic))
Ok((rewards, execution_optimistic, finalized))
}

View File

@ -10,6 +10,9 @@ use types::{BeaconState, Checkpoint, EthSpec, Fork, Hash256, Slot};
#[derive(Debug)]
pub struct StateId(pub CoreStateId);
// More clarity when returning if the state is finalized or not in the root function.
type Finalized = bool;
impl StateId {
pub fn from_slot(slot: Slot) -> Self {
Self(CoreStateId::Slot(slot))
@ -19,8 +22,8 @@ impl StateId {
pub fn root<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(Hash256, ExecutionOptimistic), warp::Rejection> {
let (slot, execution_optimistic) = match &self.0 {
) -> Result<(Hash256, ExecutionOptimistic, Finalized), warp::Rejection> {
let (slot, execution_optimistic, finalized) = match &self.0 {
CoreStateId::Head => {
let (cached_head, execution_status) = chain
.canonical_head
@ -29,24 +32,36 @@ impl StateId {
return Ok((
cached_head.head_state_root(),
execution_status.is_optimistic_or_invalid(),
false,
));
}
CoreStateId::Genesis => return Ok((chain.genesis_state_root, false)),
CoreStateId::Genesis => return Ok((chain.genesis_state_root, false, true)),
CoreStateId::Finalized => {
let finalized_checkpoint =
chain.canonical_head.cached_head().finalized_checkpoint();
checkpoint_slot_and_execution_optimistic(chain, finalized_checkpoint)?
let (slot, execution_optimistic) =
checkpoint_slot_and_execution_optimistic(chain, finalized_checkpoint)?;
(slot, execution_optimistic, true)
}
CoreStateId::Justified => {
let justified_checkpoint =
chain.canonical_head.cached_head().justified_checkpoint();
checkpoint_slot_and_execution_optimistic(chain, justified_checkpoint)?
let (slot, execution_optimistic) =
checkpoint_slot_and_execution_optimistic(chain, justified_checkpoint)?;
(slot, execution_optimistic, false)
}
CoreStateId::Slot(slot) => (
*slot,
chain
.is_optimistic_or_invalid_head()
.map_err(warp_utils::reject::beacon_chain_error)?,
*slot
<= chain
.canonical_head
.cached_head()
.finalized_checkpoint()
.epoch
.start_slot(T::EthSpec::slots_per_epoch()),
),
CoreStateId::Root(root) => {
if let Some(hot_summary) = chain
@ -61,7 +76,10 @@ impl StateId {
.is_optimistic_or_invalid_block_no_fallback(&hot_summary.latest_block_root)
.map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?;
return Ok((*root, execution_optimistic));
let finalized = chain
.is_finalized_state(root, hot_summary.slot)
.map_err(warp_utils::reject::beacon_chain_error)?;
return Ok((*root, execution_optimistic, finalized));
} else if let Some(_cold_state_slot) = chain
.store
.load_cold_state_slot(root)
@ -77,7 +95,7 @@ impl StateId {
.is_optimistic_or_invalid_block_no_fallback(&finalized_root)
.map_err(BeaconChainError::ForkChoiceError)
.map_err(warp_utils::reject::beacon_chain_error)?;
return Ok((*root, execution_optimistic));
return Ok((*root, execution_optimistic, true));
} else {
return Err(warp_utils::reject::custom_not_found(format!(
"beacon state for state root {}",
@ -94,7 +112,7 @@ impl StateId {
warp_utils::reject::custom_not_found(format!("beacon state at slot {}", slot))
})?;
Ok((root, execution_optimistic))
Ok((root, execution_optimistic, finalized))
}
/// Return the `fork` field of the state identified by `self`.
@ -103,9 +121,25 @@ impl StateId {
&self,
chain: &BeaconChain<T>,
) -> Result<(Fork, bool), warp::Rejection> {
self.map_state_and_execution_optimistic(chain, |state, execution_optimistic| {
Ok((state.fork(), execution_optimistic))
})
self.map_state_and_execution_optimistic_and_finalized(
chain,
|state, execution_optimistic, _finalized| Ok((state.fork(), execution_optimistic)),
)
}
/// Return the `fork` field of the state identified by `self`.
/// Also returns the `execution_optimistic` value of the state.
/// Also returns the `finalized` value of the state.
pub fn fork_and_execution_optimistic_and_finalized<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(Fork, bool, bool), warp::Rejection> {
self.map_state_and_execution_optimistic_and_finalized(
chain,
|state, execution_optimistic, finalized| {
Ok((state.fork(), execution_optimistic, finalized))
},
)
}
/// Convenience function to compute `fork` when `execution_optimistic` isn't desired.
@ -121,8 +155,8 @@ impl StateId {
pub fn state<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(BeaconState<T::EthSpec>, ExecutionOptimistic), warp::Rejection> {
let ((state_root, execution_optimistic), slot_opt) = match &self.0 {
) -> Result<(BeaconState<T::EthSpec>, ExecutionOptimistic, Finalized), warp::Rejection> {
let ((state_root, execution_optimistic, finalized), slot_opt) = match &self.0 {
CoreStateId::Head => {
let (cached_head, execution_status) = chain
.canonical_head
@ -134,6 +168,7 @@ impl StateId {
.beacon_state
.clone_with_only_committee_caches(),
execution_status.is_optimistic_or_invalid(),
false,
));
}
CoreStateId::Slot(slot) => (self.root(chain)?, Some(*slot)),
@ -152,24 +187,25 @@ impl StateId {
})
})?;
Ok((state, execution_optimistic))
Ok((state, execution_optimistic, finalized))
}
/// Map a function across the `BeaconState` identified by `self`.
///
/// The optimistic status of the requested state is also provided to the `func` closure.
/// The optimistic and finalization status of the requested state is also provided to the `func`
/// closure.
///
/// This function will avoid instantiating/copying a new state when `self` points to the head
/// of the chain.
pub fn map_state_and_execution_optimistic<T: BeaconChainTypes, F, U>(
pub fn map_state_and_execution_optimistic_and_finalized<T: BeaconChainTypes, F, U>(
&self,
chain: &BeaconChain<T>,
func: F,
) -> Result<U, warp::Rejection>
where
F: Fn(&BeaconState<T::EthSpec>, bool) -> Result<U, warp::Rejection>,
F: Fn(&BeaconState<T::EthSpec>, bool, bool) -> Result<U, warp::Rejection>,
{
let (state, execution_optimistic) = match &self.0 {
let (state, execution_optimistic, finalized) = match &self.0 {
CoreStateId::Head => {
let (head, execution_status) = chain
.canonical_head
@ -178,12 +214,13 @@ impl StateId {
return func(
&head.snapshot.beacon_state,
execution_status.is_optimistic_or_invalid(),
false,
);
}
_ => self.state(chain)?,
};
func(&state, execution_optimistic)
func(&state, execution_optimistic, finalized)
}
}

View File

@ -13,8 +13,8 @@ pub fn compute_sync_committee_rewards<T: BeaconChainTypes>(
block_id: BlockId,
validators: Vec<ValidatorId>,
log: Logger,
) -> Result<(Option<Vec<SyncCommitteeReward>>, ExecutionOptimistic), warp::Rejection> {
let (block, execution_optimistic) = block_id.blinded_block(&chain)?;
) -> Result<(Option<Vec<SyncCommitteeReward>>, ExecutionOptimistic, bool), warp::Rejection> {
let (block, execution_optimistic, finalized) = block_id.blinded_block(&chain)?;
let mut state = get_state_before_applying_block(chain.clone(), &block)?;
@ -44,7 +44,7 @@ pub fn compute_sync_committee_rewards<T: BeaconChainTypes>(
)
};
Ok((data, execution_optimistic))
Ok((data, execution_optimistic, finalized))
}
pub fn get_state_before_applying_block<T: BeaconChainTypes>(

View File

@ -18,7 +18,7 @@ fn end_of_epoch_state<T: BeaconChainTypes>(
let target_slot = epoch.end_slot(T::EthSpec::slots_per_epoch());
// The execution status is not returned, any functions which rely upon this method might return
// optimistic information without explicitly declaring so.
let (state, _execution_status) = StateId::from_slot(target_slot).state(chain)?;
let (state, _execution_status, _finalized) = StateId::from_slot(target_slot).state(chain)?;
Ok(state)
}

View File

@ -1,9 +1,8 @@
use crate::api_types::fork_versioned_response::ExecutionOptimisticFinalizedForkVersionedResponse;
use crate::api_types::EndpointVersion;
use eth2::CONSENSUS_VERSION_HEADER;
use serde::Serialize;
use types::{
ExecutionOptimisticForkVersionedResponse, ForkName, ForkVersionedResponse, InconsistentFork,
};
use types::{ForkName, ForkVersionedResponse, InconsistentFork};
use warp::reply::{self, Reply, Response};
pub const V1: EndpointVersion = EndpointVersion(1);
@ -27,12 +26,13 @@ pub fn fork_versioned_response<T: Serialize>(
})
}
pub fn execution_optimistic_fork_versioned_response<T: Serialize>(
pub fn execution_optimistic_finalized_fork_versioned_response<T: Serialize>(
endpoint_version: EndpointVersion,
fork_name: ForkName,
execution_optimistic: bool,
finalized: bool,
data: T,
) -> Result<ExecutionOptimisticForkVersionedResponse<T>, warp::reject::Rejection> {
) -> Result<ExecutionOptimisticFinalizedForkVersionedResponse<T>, warp::reject::Rejection> {
let fork_name = if endpoint_version == V1 {
None
} else if endpoint_version == V2 {
@ -40,9 +40,10 @@ pub fn execution_optimistic_fork_versioned_response<T: Serialize>(
} else {
return Err(unsupported_version_rejection(endpoint_version));
};
Ok(ExecutionOptimisticForkVersionedResponse {
Ok(ExecutionOptimisticFinalizedForkVersionedResponse {
version: fork_name,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
data,
})
}

View File

@ -8,7 +8,7 @@ use environment::null_logger;
use eth2::{
mixin::{RequestAccept, ResponseForkName, ResponseOptional},
reqwest::RequestBuilder,
types::{BlockId as CoreBlockId, StateId as CoreStateId, *},
types::{BlockId as CoreBlockId, ForkChoiceNode, StateId as CoreStateId, *},
BeaconNodeHttpClient, Error, StatusCode, Timeouts,
};
use execution_layer::test_utils::TestingBuilder;
@ -462,6 +462,264 @@ impl ApiTester {
self
}
// finalization tests
pub async fn test_beacon_states_root_finalized(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_root = state_id.root(&self.chain);
let state = state_id.state(&self.chain);
// if .root or .state fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
// occurs after the state_root and state calls, and that the state_root and state calls
// were correct.
if state_root.is_err() || state.is_err() {
continue;
}
// now that we know the state is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_states_root(state_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (state_root, _, _) = state_root.unwrap();
let (state, _, _) = state.unwrap();
let state_slot = state.slot();
let expected = self
.chain
.is_finalized_state(&state_root, state_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", state_id);
}
self
}
pub async fn test_beacon_states_fork_finalized(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_root = state_id.root(&self.chain);
let state = state_id.state(&self.chain);
// if .root or .state fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
// occurs after the state_root and state calls, and that the state_root and state calls
// were correct.
if state_root.is_err() || state.is_err() {
continue;
}
// now that we know the state is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_states_fork(state_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (state_root, _, _) = state_root.unwrap();
let (state, _, _) = state.unwrap();
let state_slot = state.slot();
let expected = self
.chain
.is_finalized_state(&state_root, state_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", state_id);
}
self
}
pub async fn test_beacon_states_finality_checkpoints_finalized(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_root = state_id.root(&self.chain);
let state = state_id.state(&self.chain);
// if .root or .state fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
// occurs after the state_root and state calls, and that the state_root and state calls
// were correct.
if state_root.is_err() || state.is_err() {
continue;
}
// now that we know the state is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_states_finality_checkpoints(state_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (state_root, _, _) = state_root.unwrap();
let (state, _, _) = state.unwrap();
let state_slot = state.slot();
let expected = self
.chain
.is_finalized_state(&state_root, state_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", state_id);
}
self
}
pub async fn test_beacon_headers_block_id_finalized(self) -> Self {
for block_id in self.interesting_block_ids() {
let block_root = block_id.root(&self.chain);
let block = block_id.full_block(&self.chain).await;
// if .root or .state fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
// occurs after the state_root and state calls, and that the state_root and state calls
// were correct.
if block_root.is_err() || block.is_err() {
continue;
}
// now that we know the block is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_headers_block_id(block_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (block_root, _, _) = block_root.unwrap();
let (block, _, _) = block.unwrap();
let block_slot = block.slot();
let expected = self
.chain
.is_finalized_block(&block_root, block_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", block_id);
}
self
}
pub async fn test_beacon_blocks_finalized<T: EthSpec>(self) -> Self {
for block_id in self.interesting_block_ids() {
let block_root = block_id.root(&self.chain);
let block = block_id.full_block(&self.chain).await;
// if .root or .full_block fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_block
// occurs after those calls, and that they were correct.
if block_root.is_err() || block.is_err() {
continue;
}
// now that we know the block is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_blocks::<MainnetEthSpec>(block_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (block_root, _, _) = block_root.unwrap();
let (block, _, _) = block.unwrap();
let block_slot = block.slot();
let expected = self
.chain
.is_finalized_block(&block_root, block_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", block_id);
}
self
}
pub async fn test_beacon_blinded_blocks_finalized<T: EthSpec>(self) -> Self {
for block_id in self.interesting_block_ids() {
let block_root = block_id.root(&self.chain);
let block = block_id.full_block(&self.chain).await;
// if .root or .full_block fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_block
// occurs after those calls, and that they were correct.
if block_root.is_err() || block.is_err() {
continue;
}
// now that we know the block is valid, we can unwrap() everything we need
let result = self
.client
.get_beacon_blinded_blocks::<MainnetEthSpec>(block_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (block_root, _, _) = block_root.unwrap();
let (block, _, _) = block.unwrap();
let block_slot = block.slot();
let expected = self
.chain
.is_finalized_block(&block_root, block_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", block_id);
}
self
}
pub async fn test_debug_beacon_states_finalized(self) -> Self {
for state_id in self.interesting_state_ids() {
let state_root = state_id.root(&self.chain);
let state = state_id.state(&self.chain);
// if .root or .state fail, skip the test. those would be errors outside the scope
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
// occurs after the state_root and state calls, and that the state_root and state calls
// were correct.
if state_root.is_err() || state.is_err() {
continue;
}
// now that we know the state is valid, we can unwrap() everything we need
let result = self
.client
.get_debug_beacon_states::<MainnetEthSpec>(state_id.0)
.await
.unwrap()
.unwrap()
.finalized
.unwrap();
let (state_root, _, _) = state_root.unwrap();
let (state, _, _) = state.unwrap();
let state_slot = state.slot();
let expected = self
.chain
.is_finalized_state(&state_root, state_slot)
.unwrap();
assert_eq!(result, expected, "{:?}", state_id);
}
self
}
pub async fn test_beacon_states_root(self) -> Self {
for state_id in self.interesting_state_ids() {
let result = self
@ -474,7 +732,7 @@ impl ApiTester {
let expected = state_id
.root(&self.chain)
.ok()
.map(|(root, _execution_optimistic)| root);
.map(|(root, _execution_optimistic, _finalized)| root);
assert_eq!(result, expected, "{:?}", state_id);
}
@ -508,15 +766,13 @@ impl ApiTester {
.unwrap()
.map(|res| res.data);
let expected =
state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| FinalityCheckpointsData {
previous_justified: state.previous_justified_checkpoint(),
current_justified: state.current_justified_checkpoint(),
finalized: state.finalized_checkpoint(),
});
let expected = state_id.state(&self.chain).ok().map(
|(state, _execution_optimistic, _finalized)| FinalityCheckpointsData {
previous_justified: state.previous_justified_checkpoint(),
current_justified: state.current_justified_checkpoint(),
finalized: state.finalized_checkpoint(),
},
);
assert_eq!(result, expected, "{:?}", state_id);
}
@ -529,7 +785,9 @@ impl ApiTester {
for validator_indices in self.interesting_validator_indices() {
let state_opt = state_id.state(&self.chain).ok();
let validators: Vec<Validator> = match state_opt.as_ref() {
Some((state, _execution_optimistic)) => state.validators().clone().into(),
Some((state, _execution_optimistic, _finalized)) => {
state.validators().clone().into()
}
None => vec![],
};
let validator_index_ids = validator_indices
@ -568,7 +826,7 @@ impl ApiTester {
.unwrap()
.map(|res| res.data);
let expected = state_opt.map(|(state, _execution_optimistic)| {
let expected = state_opt.map(|(state, _execution_optimistic, _finalized)| {
let mut validators = Vec::with_capacity(validator_indices.len());
for i in validator_indices {
@ -598,7 +856,7 @@ impl ApiTester {
let state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
let validators: Vec<Validator> = match state_opt.as_ref() {
Some(state) => state.validators().clone().into(),
None => vec![],
@ -688,7 +946,7 @@ impl ApiTester {
let state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
let validators = match state_opt.as_ref() {
Some(state) => state.validators().clone().into(),
None => vec![],
@ -743,7 +1001,7 @@ impl ApiTester {
let mut state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
let epoch_opt = state_opt.as_ref().map(|state| state.current_epoch());
let results = self
@ -790,7 +1048,7 @@ impl ApiTester {
let mut state_opt = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
let epoch_opt = state_opt.as_ref().map(|state| state.current_epoch());
let result = self
@ -900,7 +1158,7 @@ impl ApiTester {
let block_root_opt = block_id
.root(&self.chain)
.ok()
.map(|(root, _execution_optimistic)| root);
.map(|(root, _execution_optimistic, _finalized)| root);
if let CoreBlockId::Slot(slot) = block_id.0 {
if block_root_opt.is_none() {
@ -914,7 +1172,7 @@ impl ApiTester {
.full_block(&self.chain)
.await
.ok()
.map(|(block, _execution_optimistic)| block);
.map(|(block, _execution_optimistic, _finalized)| block);
if block_opt.is_none() && result.is_none() {
continue;
@ -960,7 +1218,7 @@ impl ApiTester {
let expected = block_id
.root(&self.chain)
.ok()
.map(|(root, _execution_optimistic)| root);
.map(|(root, _execution_optimistic, _finalized)| root);
if let CoreBlockId::Slot(slot) = block_id.0 {
if expected.is_none() {
assert!(SKIPPED_SLOTS.contains(&slot.as_u64()));
@ -1007,7 +1265,7 @@ impl ApiTester {
.full_block(&self.chain)
.await
.ok()
.map(|(block, _execution_optimistic)| block);
.map(|(block, _execution_optimistic, _finalized)| block);
if let CoreBlockId::Slot(slot) = block_id.0 {
if expected.is_none() {
@ -1091,7 +1349,7 @@ impl ApiTester {
let expected = block_id
.blinded_block(&self.chain)
.ok()
.map(|(block, _execution_optimistic)| block);
.map(|(block, _execution_optimistic, _finalized)| block);
if let CoreBlockId::Slot(slot) = block_id.0 {
if expected.is_none() {
@ -1172,7 +1430,7 @@ impl ApiTester {
.map(|res| res.data);
let expected = block_id.full_block(&self.chain).await.ok().map(
|(block, _execution_optimistic)| {
|(block, _execution_optimistic, _finalized)| {
block.message().body().attestations().clone().into()
},
);
@ -1593,7 +1851,7 @@ impl ApiTester {
let mut expected = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
expected.as_mut().map(|state| state.drop_all_caches());
if let (Some(json), Some(expected)) = (&result_json, &expected) {
@ -1679,6 +1937,59 @@ impl ApiTester {
self
}
pub async fn test_get_debug_fork_choice(self) -> Self {
let result = self.client.get_debug_fork_choice().await.unwrap();
let beacon_fork_choice = self.chain.canonical_head.fork_choice_read_lock();
let expected_proto_array = beacon_fork_choice.proto_array().core_proto_array();
assert_eq!(
result.justified_checkpoint,
expected_proto_array.justified_checkpoint
);
assert_eq!(
result.finalized_checkpoint,
expected_proto_array.finalized_checkpoint
);
let expected_fork_choice_nodes: Vec<ForkChoiceNode> = expected_proto_array
.nodes
.iter()
.map(|node| {
let execution_status = if node.execution_status.is_execution_enabled() {
Some(node.execution_status.to_string())
} else {
None
};
ForkChoiceNode {
slot: node.slot,
block_root: node.root,
parent_root: node
.parent
.and_then(|index| expected_proto_array.nodes.get(index))
.map(|parent| parent.root),
justified_epoch: node.justified_checkpoint.map(|checkpoint| checkpoint.epoch),
finalized_epoch: node.finalized_checkpoint.map(|checkpoint| checkpoint.epoch),
weight: node.weight,
validity: execution_status,
execution_block_hash: node
.execution_status
.block_hash()
.map(|block_hash| block_hash.into_root()),
}
})
.collect();
assert_eq!(result.fork_choice_nodes, expected_fork_choice_nodes);
// need to drop beacon_fork_choice here, else borrow checker will complain
// that self cannot be moved out since beacon_fork_choice borrowed self.chain
// and might still live after self is moved out
drop(beacon_fork_choice);
self
}
fn validator_count(&self) -> usize {
self.chain.head_snapshot().beacon_state.validators().len()
}
@ -3604,7 +3915,7 @@ impl ApiTester {
let mut expected = state_id
.state(&self.chain)
.ok()
.map(|(state, _execution_optimistic)| state);
.map(|(state, _execution_optimistic, _finalized)| state);
expected.as_mut().map(|state| state.drop_all_caches());
assert_eq!(result, expected, "{:?}", state_id);
@ -4012,6 +4323,20 @@ async fn beacon_get() {
.await
.test_beacon_genesis()
.await
.test_beacon_states_root_finalized()
.await
.test_beacon_states_fork_finalized()
.await
.test_beacon_states_finality_checkpoints_finalized()
.await
.test_beacon_headers_block_id_finalized()
.await
.test_beacon_blocks_finalized::<MainnetEthSpec>()
.await
.test_beacon_blinded_blocks_finalized::<MainnetEthSpec>()
.await
.test_debug_beacon_states_finalized()
.await
.test_beacon_states_root()
.await
.test_beacon_states_fork()
@ -4148,6 +4473,8 @@ async fn debug_get() {
.test_get_debug_beacon_states()
.await
.test_get_debug_beacon_heads()
.await
.test_get_debug_fork_choice()
.await;
}

View File

@ -207,7 +207,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
let local_node_id = local_enr.node_id();
info!(log, "ENR Initialised"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq(), "id"=> %local_enr.node_id(),
"ip4" => ?local_enr.ip4(), "udp4"=> ?local_enr.udp4(), "tcp4" => ?local_enr.tcp6()
"ip4" => ?local_enr.ip4(), "udp4"=> ?local_enr.udp4(), "tcp4" => ?local_enr.tcp4(), "tcp6" => ?local_enr.tcp6(), "udp6" => ?local_enr.udp6()
);
let listen_socket = match config.listen_addrs() {
crate::listen_addr::ListenAddress::V4(v4_addr) => v4_addr.udp_socket_addr(),

View File

@ -2179,7 +2179,7 @@ fn no_state_root_iter() -> Option<std::iter::Empty<Result<(Hash256, Slot), Error
/// Allows full reconstruction by replaying blocks.
#[derive(Debug, Clone, Copy, Default, Encode, Decode)]
pub struct HotStateSummary {
slot: Slot,
pub slot: Slot,
pub latest_block_root: Hash256,
epoch_boundary_state_root: Hash256,
}

View File

@ -1,6 +1,6 @@
[package]
name = "boot_node"
version = "4.0.1-rc.0"
version = "4.0.1"
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2021"

View File

@ -29,6 +29,7 @@ use std::fmt;
use std::iter::Iterator;
use std::path::PathBuf;
use std::time::Duration;
use store::fork_versioned_response::ExecutionOptimisticFinalizedForkVersionedResponse;
pub const V1: EndpointVersion = EndpointVersion(1);
pub const V2: EndpointVersion = EndpointVersion(2);
@ -338,7 +339,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_root(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<RootData>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<RootData>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -357,7 +358,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_fork(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<Fork>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Fork>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -376,7 +377,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_states_finality_checkpoints(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticResponse<FinalityCheckpointsData>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<FinalityCheckpointsData>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -396,7 +397,8 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
ids: Option<&[ValidatorId]>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<ValidatorBalanceData>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<ValidatorBalanceData>>>, Error>
{
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -426,7 +428,7 @@ impl BeaconNodeHttpClient {
state_id: StateId,
ids: Option<&[ValidatorId]>,
statuses: Option<&[ValidatorStatus]>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<ValidatorData>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<ValidatorData>>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -466,7 +468,7 @@ impl BeaconNodeHttpClient {
slot: Option<Slot>,
index: Option<u64>,
epoch: Option<Epoch>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<CommitteeData>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<CommitteeData>>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -499,7 +501,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
epoch: Option<Epoch>,
) -> Result<ExecutionOptimisticResponse<SyncCommitteeByValidatorIndices>, Error> {
) -> Result<ExecutionOptimisticFinalizedResponse<SyncCommitteeByValidatorIndices>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -522,7 +524,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
epoch: Option<Epoch>,
) -> Result<Option<ExecutionOptimisticResponse<RandaoMix>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<RandaoMix>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -547,7 +549,7 @@ impl BeaconNodeHttpClient {
&self,
state_id: StateId,
validator_id: &ValidatorId,
) -> Result<Option<ExecutionOptimisticResponse<ValidatorData>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<ValidatorData>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -568,7 +570,7 @@ impl BeaconNodeHttpClient {
&self,
slot: Option<Slot>,
parent_root: Option<Hash256>,
) -> Result<Option<ExecutionOptimisticResponse<Vec<BlockHeaderData>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<BlockHeaderData>>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -595,7 +597,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_headers_block_id(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<BlockHeaderData>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<BlockHeaderData>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -688,7 +690,10 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks<T: EthSpec>(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<SignedBeaconBlock<T>>>, Error> {
) -> Result<
Option<ExecutionOptimisticFinalizedForkVersionedResponse<SignedBeaconBlock<T>>>,
Error,
> {
let path = self.get_beacon_blocks_path(block_id)?;
let response = match self.get_response(path, |b| b).await.optional()? {
Some(res) => res,
@ -721,8 +726,10 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blinded_blocks<T: EthSpec>(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<SignedBlindedBeaconBlock<T>>>, Error>
{
) -> Result<
Option<ExecutionOptimisticFinalizedForkVersionedResponse<SignedBlindedBeaconBlock<T>>>,
Error,
> {
let path = self.get_beacon_blinded_blocks_path(block_id)?;
let response = match self.get_response(path, |b| b).await.optional()? {
Some(res) => res,
@ -790,7 +797,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks_root(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<RootData>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<RootData>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -809,7 +816,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks_attestations<T: EthSpec>(
&self,
block_id: BlockId,
) -> Result<Option<ExecutionOptimisticResponse<Vec<Attestation<T>>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedResponse<Vec<Attestation<T>>>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
@ -1297,7 +1304,8 @@ impl BeaconNodeHttpClient {
pub async fn get_debug_beacon_states<T: EthSpec>(
&self,
state_id: StateId,
) -> Result<Option<ExecutionOptimisticForkVersionedResponse<BeaconState<T>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedForkVersionedResponse<BeaconState<T>>>, Error>
{
let path = self.get_debug_beacon_states_path(state_id)?;
self.get_opt(path).await
}
@ -1364,6 +1372,18 @@ impl BeaconNodeHttpClient {
self.get(path).await
}
/// `GET v1/debug/fork_choice`
pub async fn get_debug_fork_choice(&self) -> Result<ForkChoice, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("debug")
.push("fork_choice");
self.get(path).await
}
/// `GET validator/duties/proposer/{epoch}`
pub async fn get_validator_duties_proposer(
&self,
@ -1705,7 +1725,7 @@ impl BeaconNodeHttpClient {
&self,
epoch: Epoch,
indices: &[u64],
) -> Result<ExecutionOptimisticResponse<Vec<SyncDuty>>, Error> {
) -> Result<ExecutionOptimisticFinalizedResponse<Vec<SyncDuty>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()

View File

@ -200,6 +200,14 @@ pub struct ExecutionOptimisticResponse<T: Serialize + serde::de::DeserializeOwne
pub data: T,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(bound = "T: Serialize + serde::de::DeserializeOwned")]
pub struct ExecutionOptimisticFinalizedResponse<T: Serialize + serde::de::DeserializeOwned> {
pub execution_optimistic: Option<bool>,
pub finalized: Option<bool>,
pub data: T,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(bound = "T: Serialize + serde::de::DeserializeOwned")]
pub struct GenericResponse<T: Serialize + serde::de::DeserializeOwned> {
@ -222,6 +230,18 @@ impl<T: Serialize + serde::de::DeserializeOwned> GenericResponse<T> {
data: self.data,
}
}
pub fn add_execution_optimistic_finalized(
self,
execution_optimistic: bool,
finalized: bool,
) -> ExecutionOptimisticFinalizedResponse<T> {
ExecutionOptimisticFinalizedResponse {
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
data: self.data,
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
@ -1228,6 +1248,25 @@ impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
})
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ForkChoice {
pub justified_checkpoint: Checkpoint,
pub finalized_checkpoint: Checkpoint,
pub fork_choice_nodes: Vec<ForkChoiceNode>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct ForkChoiceNode {
pub slot: Slot,
pub block_root: Hash256,
pub parent_root: Option<Hash256>,
pub justified_epoch: Option<Epoch>,
pub finalized_epoch: Option<Epoch>,
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub weight: u64,
pub validity: Option<String>,
pub execution_block_hash: Option<Hash256>,
}
#[cfg(test)]
mod tests {

View File

@ -17,8 +17,8 @@ pub const VERSION: &str = git_version!(
// NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol"
],
prefix = "Lighthouse/v4.0.1-rc.0-",
fallback = "Lighthouse/v4.0.1-rc.0"
prefix = "Lighthouse/v4.0.1-",
fallback = "Lighthouse/v4.0.1"
);
/// Returns `VERSION`, but with platform information appended to the end.

View File

@ -10,7 +10,10 @@ use crate::{
use serde_derive::{Deserialize, Serialize};
use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use std::collections::{BTreeSet, HashMap};
use std::{
collections::{BTreeSet, HashMap},
fmt,
};
use types::{
AttestationShufflingId, ChainSpec, Checkpoint, Epoch, EthSpec, ExecutionBlockHash, Hash256,
Slot,
@ -125,6 +128,17 @@ impl ExecutionStatus {
}
}
impl fmt::Display for ExecutionStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ExecutionStatus::Valid(_) => write!(f, "valid"),
ExecutionStatus::Invalid(_) => write!(f, "invalid"),
ExecutionStatus::Optimistic(_) => write!(f, "optimistic"),
ExecutionStatus::Irrelevant(_) => write!(f, "irrelevant"),
}
}
}
/// A block that is to be applied to the fork choice.
///
/// A simplified version of `types::BeaconBlock`.

View File

@ -5,6 +5,46 @@ use serde_json::value::Value;
use std::sync::Arc;
// Deserialize is only implemented for types that implement ForkVersionDeserialize
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct ExecutionOptimisticFinalizedForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ForkName>,
pub execution_optimistic: Option<bool>,
pub finalized: Option<bool>,
pub data: T,
}
impl<'de, F> serde::Deserialize<'de> for ExecutionOptimisticFinalizedForkVersionedResponse<F>
where
F: ForkVersionDeserialize,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Helper {
version: Option<ForkName>,
execution_optimistic: Option<bool>,
finalized: Option<bool>,
data: serde_json::Value,
}
let helper = Helper::deserialize(deserializer)?;
let data = match helper.version {
Some(fork_name) => F::deserialize_by_fork::<'de, D>(helper.data, fork_name)?,
None => serde_json::from_value(helper.data).map_err(serde::de::Error::custom)?,
};
Ok(ExecutionOptimisticFinalizedForkVersionedResponse {
version: helper.version,
execution_optimistic: helper.execution_optimistic,
finalized: helper.finalized,
data,
})
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct ExecutionOptimisticForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]

View File

@ -1,7 +1,7 @@
[package]
name = "lcli"
description = "Lighthouse CLI (modeled after zcli)"
version = "4.0.1-rc.0"
version = "4.0.1"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2021"

View File

@ -1,7 +1,7 @@
# `lcli` requires the full project to be in scope, so this should be built either:
# - from the `lighthouse` dir with the command: `docker build -f ./lcli/Dockerflie .`
# - from the current directory with the command: `docker build -f ./Dockerfile ../`
FROM rust:1.65.0-bullseye AS builder
FROM rust:1.66.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake clang libclang-dev protobuf-compiler
COPY . lighthouse
ARG PORTABLE

View File

@ -1,6 +1,6 @@
[package]
name = "lighthouse"
version = "4.0.1-rc.0"
version = "4.0.1"
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2021"
autotests = false

View File

@ -989,7 +989,23 @@ impl InitializedValidators {
let cache =
KeyCache::open_or_create(&self.validators_dir).map_err(Error::UnableToOpenKeyCache)?;
let mut key_cache = self.decrypt_key_cache(cache, &mut key_stores).await?;
// Check if there is at least one local definition.
let has_local_definitions = self.definitions.as_slice().iter().any(|def| {
matches!(
def.signing_definition,
SigningDefinition::LocalKeystore { .. }
)
});
// Only decrypt cache when there is at least one local definition.
// Decrypting cache is a very expensive operation which is never used for web3signer.
let mut key_cache = if has_local_definitions {
self.decrypt_key_cache(cache, &mut key_stores).await?
} else {
// Assign an empty KeyCache if all definitions are of the Web3Signer type.
KeyCache::new()
};
let mut disabled_uuids = HashSet::new();
for def in self.definitions.as_slice() {
@ -1115,13 +1131,16 @@ impl InitializedValidators {
);
}
}
for uuid in disabled_uuids {
key_cache.remove(&uuid);
if has_local_definitions {
for uuid in disabled_uuids {
key_cache.remove(&uuid);
}
}
let validators_dir = self.validators_dir.clone();
let log = self.log.clone();
if key_cache.is_modified() {
if has_local_definitions && key_cache.is_modified() {
tokio::task::spawn_blocking(move || {
match key_cache.save(validators_dir) {
Err(e) => warn!(