Skip to content

Commit

Permalink
Use fast head in notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jun 28, 2022
1 parent 7199425 commit 7a44522
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions beacon_node/client/src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,10 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
current_sync_state = sync_state;
}

// Atomically collect info about the head, avoiding holding the `canonical_head` lock
// any longer than necessary.
let (head_slot, head_root, finalized_checkpoint) = {
let head_lock = beacon_chain.canonical_head.read();
(
head_lock.head_slot(),
head_lock.head_block_root(),
head_lock.finalized_checkpoint(),
)
};
let fast_head = beacon_chain.fast_canonical_head();
let head_slot = fast_head.head_block_slot;
let head_root = fast_head.head_block_root;
let finalized_checkpoint = fast_head.finalized_checkpoint;

metrics::set_gauge(&metrics::NOTIFIER_HEAD_SLOT, head_slot.as_u64() as i64);

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>| async move {
match *network_globals.sync_state.read() {
SyncState::SyncingFinalized { .. } => {
let head_slot = chain.fast_canonical_head().head_slot;
let head_slot = chain.fast_canonical_head().head_block_slot;

let current_slot =
chain.slot_clock.now_or_genesis().ok_or_else(|| {
Expand Down Expand Up @@ -1691,7 +1691,7 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|network_globals: Arc<NetworkGlobals<T::EthSpec>>, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
let head_slot = chain.fast_canonical_head().head_slot;
let head_slot = chain.fast_canonical_head().head_block_slot;
let current_slot = chain.slot_clock.now_or_genesis().ok_or_else(|| {
warp_utils::reject::custom_server_error("Unable to read slot clock".into())
})?;
Expand Down

0 comments on commit 7a44522

Please sign in to comment.