Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson committed Apr 11, 2022
1 parent efbe421 commit 96ae578
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
11 changes: 10 additions & 1 deletion beacon_node/http_api/src/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl BlockId {
}

/// Returns the `block` along with the `execution_optimistic` value identified by `self`.
pub fn block_and_is_execution_optimistic<T: BeaconChainTypes>(
pub fn block_and_execution_optimistic<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<(SignedBeaconBlock<T::EthSpec>, bool), warp::Rejection> {
Expand All @@ -139,6 +139,15 @@ impl BlockId {
};
Ok((block, execution_optimistic))
}

/// Convenience function to compute `execution_optimistic` when `block` is not desired.
pub fn is_execution_optimistic<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
) -> Result<bool, warp::Rejection> {
self.block_and_execution_optimistic(chain)
.map(|(_, execution_optimistic)| execution_optimistic)
}
}

impl FromStr for BlockId {
Expand Down
11 changes: 5 additions & 6 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ pub fn serve<T: BeaconChainTypes>(
blocking_json_task(move || {
let root = block_id.root(&chain)?;
let (block, execution_optimistic) =
BlockId::from_root(root).block_and_is_execution_optimistic(&chain)?;
BlockId::from_root(root).block_and_execution_optimistic(&chain)?;

let canonical = chain
.block_root_at_slot(block.slot(), WhenSlotSkipped::None)
Expand Down Expand Up @@ -1245,7 +1245,7 @@ pub fn serve<T: BeaconChainTypes>(
accept_header: Option<api_types::Accept>| {
blocking_task(move || {
let (block, execution_optimistic) =
block_id.block_and_is_execution_optimistic(&chain)?;
block_id.block_and_execution_optimistic(&chain)?;
let fork_name = block
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
Expand Down Expand Up @@ -1282,7 +1282,7 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (block, execution_optimistic) =
block_id.block_and_is_execution_optimistic(&chain)?;
block_id.block_and_execution_optimistic(&chain)?;

Ok(api_types::GenericResponse::from(api_types::RootData::from(
block.canonical_root(),
Expand All @@ -1299,7 +1299,7 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let (block, execution_optimistic) =
block_id.block_and_is_execution_optimistic(&chain)?;
block_id.block_and_execution_optimistic(&chain)?;

Ok(
api_types::GenericResponse::from(block.message().body().attestations().clone())
Expand Down Expand Up @@ -1770,8 +1770,7 @@ pub fn serve<T: BeaconChainTypes>(
None
} else if endpoint_version == V2 {
BlockId::from_root(root)
.block_and_is_execution_optimistic(&chain)
.map(|(_, execution_optimistic)| execution_optimistic)
.is_execution_optimistic(&chain)
.ok()
} else {
return Err(unsupported_version_rejection(endpoint_version));
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/state_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl StateId {
func(&state, execution_optimistic)
}

/// Convienience function to compute `execution_optimistic` when `state` is not desired.
/// Convenience function to compute `execution_optimistic` when `state` is not desired.
pub fn is_execution_optimistic<T: BeaconChainTypes>(
&self,
chain: &BeaconChain<T>,
Expand Down

0 comments on commit 96ae578

Please sign in to comment.