diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2103542de..6b514d569 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2810,6 +2810,8 @@ impl BeaconChain { return Ok(()); } + let lag_timer = metrics::start_timer(&metrics::FORK_CHOICE_SET_HEAD_LAG_TIMES); + // At this point we know that the new head block is not the same as the previous one metrics::inc_counter(&metrics::FORK_CHOICE_CHANGED_HEAD); @@ -2913,12 +2915,6 @@ impl BeaconChain { .slot() .epoch(T::EthSpec::slots_per_epoch()); - if is_epoch_transition || is_reorg { - self.persist_head_and_fork_choice()?; - self.op_pool.prune_attestations(self.epoch()?); - self.persist_op_pool()?; - } - let update_head_timer = metrics::start_timer(&metrics::UPDATE_HEAD_TIMES); // These fields are used for server-sent events @@ -2934,6 +2930,8 @@ impl BeaconChain { .start_slot(T::EthSpec::slots_per_epoch()); let head_proposer_index = new_head.beacon_block.message().proposer_index(); + drop(lag_timer); + // Update the snapshot that stores the head of the chain at the time it received the // block. *self @@ -2984,6 +2982,11 @@ impl BeaconChain { ); }); + if is_epoch_transition || is_reorg { + self.persist_head_and_fork_choice()?; + self.op_pool.prune_attestations(self.epoch()?); + } + if new_finalized_checkpoint.epoch != old_finalized_checkpoint.epoch { // Due to race conditions, it's technically possible that the head we load here is // different to the one earlier in this function. diff --git a/beacon_node/beacon_chain/src/metrics.rs b/beacon_node/beacon_chain/src/metrics.rs index 6b27dfcfc..ebedef992 100644 --- a/beacon_node/beacon_chain/src/metrics.rs +++ b/beacon_node/beacon_chain/src/metrics.rs @@ -261,6 +261,10 @@ lazy_static! { "beacon_fork_choice_process_attestation_seconds", "Time taken to add an attestation to fork choice" ); + pub static ref FORK_CHOICE_SET_HEAD_LAG_TIMES: Result = try_create_histogram( + "beacon_fork_choice_set_head_lag_times", + "Time taken between finding the head and setting the canonical head value" + ); pub static ref BALANCES_CACHE_HITS: Result = try_create_int_counter("beacon_balances_cache_hits_total", "Count of times balances cache fulfils request"); pub static ref BALANCES_CACHE_MISSES: Result =