Skip to content

Conversation

@yacovm
Copy link
Contributor

@yacovm yacovm commented Jun 24, 2025

Why this should be merged

We have a metric that measures the time between building the block to accepting it. However it uses the block's timestamp. This value includes the time the VM builds a block as we need to compute the time and insert the time into the block before we build it.

To better compute the time between right before the block builder releases the block to the network and the block's acceptance it can be useful if we can estimate the time skew between the local time and the block's timestamp.

How this works

After the snowman engine builds a block, compute the difference between the current real time to the block's timestamp and publish it via a metrics gauge. Then we can use a monitor that divides this accumulated number (because it's a gauge that only adds) to the number of blocks built to get the average time skew.

How this was tested

I ran a modified local network and sent some Ethereum transactions to the C chain and then probed the metrics endpoint on the HTTP endpoint:

➜  ethcli git:(main) ✗ curl  -s "http://localhost:9650/ext/metrics" | grep skew | grep 'chain="C"'
avalanche_snowman_block_time_skew{chain="C"} 4.92657e+08
➜  ethcli git:(main) ✗ curl  -s "http://localhost:9660/ext/metrics" | grep skew | grep 'chain="C"'
avalanche_snowman_block_time_skew{chain="C"} 0
➜  ethcli git:(main) ✗ curl  -s "http://localhost:9670/ext/metrics" | grep skew | grep 'chain="C"'
avalanche_snowman_block_time_skew{chain="C"} 5.2301e+08

Need to be documented in RELEASES.md?

Copilot AI review requested due to automatic review settings June 24, 2025 19:29
@yacovm yacovm requested a review from StephenButtolph as a code owner June 24, 2025 19:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new metric to record the time skew between the current time and the block’s timestamp. The key changes include:

  • Adding a new prometheus gauge (blockTimeSkew) in the metrics struct.
  • Initializing and registering the blockTimeSkew metric in newMetrics.
  • Capturing and recording the time skew in the buildBlocks function.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
snow/engine/snowman/metrics.go New gauge added and registered for block time skew.
snow/engine/snowman/engine.go Captures and adds the block time skew to the gauge.

@yacovm yacovm marked this pull request as draft June 24, 2025 19:36
@yacovm yacovm marked this pull request as ready for review June 24, 2025 19:53
Comment on lines 116 to 119
blockTimeSkew: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "block_time_skew",
Help: "The differences between the current time and the block's timestamp",
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include (either in the name or the help text) that this is specifically for blocks built by the node? Perhaps making the name blks_built_time_skew to align more the with the existing blks_built metric (which is used to actually get the time skew per block)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and changed the description too

Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
@StephenButtolph StephenButtolph added this pull request to the merge queue Jun 26, 2025
Merged via the queue into master with commit a0b02ae Jun 26, 2025
52 of 53 checks passed
@StephenButtolph StephenButtolph deleted the blktimeskew branch June 26, 2025 18:02
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego Jun 26, 2025
mpignatelli12 pushed a commit that referenced this pull request Jul 1, 2025
Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants