Skip to content

Paolo/txpool metrics#1619

Open
paologalligit wants to merge 2 commits into
masterfrom
paolo/txpool-metrics
Open

Paolo/txpool metrics#1619
paologalligit wants to merge 2 commits into
masterfrom
paolo/txpool-metrics

Conversation

@paologalligit

Copy link
Copy Markdown
Member

Description

This updates txpool metrics so txpool_current_tx_count represents the current pool contents by source, type, and status, instead of mixing add/remove deltas with synthetic sources like washed or n/a.

Txs now track their source explicitly — local, remote, or fill — and their status (executable / non_executable) is reflected on the gauge label.

Wash removals decrement the current-count gauge using the removed tx's real labels and also increment a separate txpool_washed_tx_count{source,type} counter.

TxObject.executable is now atomic.Bool so the metric helper can read it safely from concurrent Remove and wash paths.

The internal wash() return surface is collapsed to a single removed int; the per-type breakdown now lives only on the counter.

NOTE — Backward-incompatible changes

Dashboards / alerts:

  • txpool_current_tx_count gains a new status label (executable | non_executable). Existing grafana queries that sums or groups the gauge must use sum without(status) to reproduce the old totals; otherwise series will double-count or appear as separate rows.
  • source="washed" and source="n/a" are no longer emitted on txpool_current_tx_count. Any panel or alert filtering on those values will go silent. The per-source/per-type wash rate now lives on the new txpool_washed_tx_count{source,type} counter — switch wash dashboards to rate(txpool_washed_tx_count[...]).
  • Filled (sync-replayed) txs now report source="fill" instead of source="remote".

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@paologalligit paologalligit requested a review from a team as a code owner May 25, 2026 08:53
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
txpool/tx_pool.go 90.90% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread txpool/tx_object.go
executable bool // don't touch this value, will be updated by the pool
// executable is updated by the pool. Accessed concurrently from wash, Remove and
// metric helpers
executable atomic.Bool

@libotony libotony May 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My understading is executable does not have a race condition as it is well managed in the pool, it's fine for the metrics handler to have a snapshot of this value, no need to mark it atomic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's a tiny chance of a race condition in:

  • wash(): while running Executable() it writes o.payer = &payer and o.cost = prepaid.
  • if packer packed that tx, then it calls Remove(): it calls RemoveByHash, which reads txObj.Payer() and txObj.Cost() under the map lock, but the TxObject fields aren't covered by that lock.

It looks a very rare case, but probably it should be addressed. I can revert the atomic bool and introduce this fix in a follow-up PR, if you prefere

@paologalligit paologalligit requested a review from libotony May 25, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants