Skip to content

Commit d7f6da6

Browse files
committed
Optimize head state case, fix formatting
1 parent 1d8068d commit d7f6da6

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

  • beacon_node/http_api/src

beacon_node/http_api/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,10 @@ pub fn serve<T: BeaconChainTypes>(
814814
None
815815
};
816816

817-
let committee_cache = if let Some(shuffling) =
817+
let committee_cache = if let Some(ref shuffling) =
818818
maybe_cached_shuffling
819819
{
820-
shuffling
820+
Cow::Borrowed(&**shuffling)
821821
} else {
822822
let possibly_built_cache =
823823
match RelativeEpoch::from_epoch(current_epoch, epoch) {
@@ -852,14 +852,17 @@ pub fn serve<T: BeaconChainTypes>(
852852
if epoch < current_epoch {
853853
warp_utils::reject::custom_bad_request(
854854
format!(
855-
"epoch out of bounds, try state at slot {}",
856-
first_subsequent_restore_point_slot,
857-
),
855+
"epoch out of bounds, \
856+
try state at slot {}",
857+
first_subsequent_restore_point_slot,
858+
),
858859
)
859860
} else {
860861
warp_utils::reject::custom_bad_request(
861-
"epoch out of bounds, too far in future".into(),
862-
)
862+
"epoch out of bounds, \
863+
too far in future"
864+
.into(),
865+
)
863866
}
864867
}
865868
_ => {
@@ -868,10 +871,8 @@ pub fn serve<T: BeaconChainTypes>(
868871
}
869872
})?;
870873

871-
let owned_cache = Arc::new(possibly_built_cache.into_owned());
872-
873874
// Attempt to write to the beacon cache (only if the cache
874-
// size is not the default value
875+
// size is not the default value).
875876
if chain.config.shuffling_cache_size
876877
!= beacon_chain::shuffling_cache::DEFAULT_CACHE_SIZE
877878
{
@@ -882,12 +883,12 @@ pub fn serve<T: BeaconChainTypes>(
882883
{
883884
cache_write.insert_committee_cache(
884885
shuffling_id,
885-
&owned_cache,
886+
&*possibly_built_cache,
886887
);
887888
}
888889
}
889890
}
890-
owned_cache
891+
possibly_built_cache
891892
};
892893

893894
// Use either the supplied slot or all slots in the epoch.

0 commit comments

Comments
 (0)