Skip to content

Commit 242bdfc

Browse files
authored
Add instrumentation to recompute_head_at_slot (#8049)
Co-Authored-By: Eitan Seri- Levi <[email protected]>
1 parent aba3627 commit 242bdfc

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use fork_choice::{
4747
ResetPayloadStatuses,
4848
};
4949
use itertools::process_results;
50+
use lighthouse_tracing::SPAN_RECOMPUTE_HEAD;
5051
use logging::crit;
5152
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockUpgradableReadGuard, RwLockWriteGuard};
5253
use slot_clock::SlotClock;
@@ -57,6 +58,7 @@ use store::{
5758
Error as StoreError, KeyValueStore, KeyValueStoreOp, StoreConfig, iter::StateRootsIterator,
5859
};
5960
use task_executor::{JoinHandle, ShutdownReason};
61+
use tracing::info_span;
6062
use tracing::{debug, error, info, instrument, warn};
6163
use types::*;
6264

@@ -383,6 +385,7 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
383385
///
384386
/// This function is **not safe** to be public. See the module-level documentation for more
385387
/// information about protecting from deadlocks.
388+
#[instrument(skip_all)]
386389
fn cached_head_write_lock(&self) -> RwLockWriteGuard<'_, CachedHead<T::EthSpec>> {
387390
self.cached_head.write()
388391
}
@@ -402,6 +405,7 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
402405
}
403406

404407
/// Access a write-lock for fork choice.
408+
#[instrument(skip_all)]
405409
pub fn fork_choice_write_lock(&self) -> RwLockWriteGuard<'_, BeaconForkChoice<T>> {
406410
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_WRITE_LOCK_AQUIRE_TIMES);
407411
self.fork_choice.write()
@@ -509,13 +513,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
509513
/// situation can be rectified. We avoid returning an error here so that calling functions
510514
/// can't abort block import because an error is returned here.
511515
pub async fn recompute_head_at_slot(self: &Arc<Self>, current_slot: Slot) {
516+
let span = info_span!(
517+
SPAN_RECOMPUTE_HEAD,
518+
slot = %current_slot
519+
);
520+
512521
metrics::inc_counter(&metrics::FORK_CHOICE_REQUESTS);
513522
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_TIMES);
514523

515524
let chain = self.clone();
516525
match self
517526
.spawn_blocking_handle(
518-
move || chain.recompute_head_at_slot_internal(current_slot),
527+
move || {
528+
let _guard = span.enter();
529+
chain.recompute_head_at_slot_internal(current_slot)
530+
},
519531
"recompute_head_internal",
520532
)
521533
.await
@@ -773,6 +785,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
773785
}
774786

775787
/// Perform updates to caches and other components after the canonical head has been changed.
788+
#[instrument(skip_all)]
776789
fn after_new_head(
777790
self: &Arc<Self>,
778791
old_cached_head: &CachedHead<T::EthSpec>,
@@ -911,6 +924,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
911924
///
912925
/// This function will take a write-lock on `canonical_head.fork_choice`, therefore it would be
913926
/// unwise to hold any lock on fork choice while calling this function.
927+
#[instrument(skip_all)]
914928
fn after_finalization(
915929
self: &Arc<Self>,
916930
new_cached_head: &CachedHead<T::EthSpec>,
@@ -1046,6 +1060,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
10461060
///
10471061
/// This function is called whilst holding a write-lock on the `canonical_head`. To ensure dead-lock
10481062
/// safety, **do not take any other locks inside this function**.
1063+
#[instrument(skip_all)]
10491064
fn check_finalized_payload_validity<T: BeaconChainTypes>(
10501065
chain: &BeaconChain<T>,
10511066
finalized_proto_block: &ProtoBlock,
@@ -1129,6 +1144,7 @@ fn perform_debug_logging<T: BeaconChainTypes>(
11291144
}
11301145
}
11311146

1147+
#[instrument(skip_all)]
11321148
fn spawn_execution_layer_updates<T: BeaconChainTypes>(
11331149
chain: Arc<BeaconChain<T>>,
11341150
forkchoice_update_params: ForkchoiceUpdateParameters,

beacon_node/lighthouse_tracing/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub const SPAN_PROCESS_RPC_BLOBS: &str = "process_rpc_blobs";
2727
pub const SPAN_PROCESS_RPC_CUSTODY_COLUMNS: &str = "process_rpc_custody_columns";
2828
pub const SPAN_PROCESS_CHAIN_SEGMENT: &str = "process_chain_segment";
2929

30+
/// Fork choice root spans
31+
pub const SPAN_RECOMPUTE_HEAD: &str = "recompute_head_at_slot";
32+
3033
/// RPC methods root spans
3134
pub const SPAN_HANDLE_BLOCKS_BY_RANGE_REQUEST: &str = "handle_blocks_by_range_request";
3235
pub const SPAN_HANDLE_BLOBS_BY_RANGE_REQUEST: &str = "handle_blobs_by_range_request";

beacon_node/store/src/hot_cold_store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
656656
}
657657

658658
/// Fetch a full block with execution payload from the store.
659+
#[instrument(skip_all)]
659660
pub fn get_full_block(
660661
&self,
661662
block_root: &Hash256,

consensus/state_processing/src/all_caches.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::common::update_progressive_balances_cache::initialize_progressive_balances_cache;
22
use crate::epoch_cache::initialize_epoch_cache;
3+
use tracing::instrument;
34
use types::{
45
BeaconState, ChainSpec, EpochCacheError, EthSpec, FixedBytesExtended, Hash256, RelativeEpoch,
56
};
@@ -23,6 +24,7 @@ pub trait AllCaches {
2324
}
2425

2526
impl<E: EthSpec> AllCaches for BeaconState<E> {
27+
#[instrument(skip_all)]
2628
fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), EpochCacheError> {
2729
self.build_caches(spec)?;
2830
initialize_epoch_cache(self, spec)?;

0 commit comments

Comments
 (0)