mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Merge commit '036b797b2c1831352f937356576b3c78c65220ad' into eip4844
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user