fix(tree): update metrics only on canonical/side chain changes #3671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bug this PR fixes was introduced in #3507.
During the live sync on every new FCU or payload, blockchain tree processes new update, modifies the canonical or side chain, and updates metrics (which are common for both blockchain tree and pipeline syncs).
But during the pipeline sync, blockchain tree can't do any updates, so it buffers the block for further processing when the pipeline finishes. However, it still updates metrics:
reth/crates/blockchain-tree/src/shareable.rs
Lines 44 to 49 in 1330fc1
Since we didn't modify the actual tree and only buffered a block, the metrics will get updated with the current state of blockchain tree:
reth/crates/blockchain-tree/src/blockchain_tree.rs
Lines 1088 to 1096 in 1330fc1
The problem arises when we do an update to metrics during the pipeline sync (initial or on large range of missing blocks):
0
, because we don't have any canonical chain in the blockchain tree yet.0
by blockchain tree.This produces such dashboard (notice spiky chart which demonstrates the behaviour with
0 -> pipeline sync metric -> 0 -> pipeline sync metric
metric value):This PR fixes this behaviour by updating the blockchain tree metrics ONLY during the actual modification of the blockchain tree, i.e. doesn't update metrics during the block buffering.