Skip to content

adapt sv2-apps with channels_sv2::server::share_accounting keeping track of rejected shares#491

Merged
plebhash merged 5 commits into
stratum-mining:mainfrom
plebhash:2026-05-08-refine-server-share-accounting
May 18, 2026
Merged

adapt sv2-apps with channels_sv2::server::share_accounting keeping track of rejected shares#491
plebhash merged 5 commits into
stratum-mining:mainfrom
plebhash:2026-05-08-refine-server-share-accounting

Conversation

@plebhash

@plebhash plebhash commented May 8, 2026

Copy link
Copy Markdown
Member

companion stratum-mining/stratum#2149


adds two new fields to ExtendedChannelInfo and StandardChannelInfo:

  • pub shares_rejected: u32
  • pub shares_rejected_by_reason: HashMap<String, u32>

@plebhash plebhash changed the title channels_sv2::server::share_accounting keeps track of rejected shares adapt sv2-apps with channels_sv2::server::share_accounting keeping track of rejected shares May 8, 2026
Comment thread stratum-apps/src/monitoring/snapshot_cache.rs
Comment thread stratum-apps/src/monitoring/prometheus_metrics.rs
Comment thread stratum-apps/src/monitoring/openapi.json
@plebhash
plebhash force-pushed the 2026-05-08-refine-server-share-accounting branch from bfcb912 to 8a1422d Compare May 8, 2026 22:03
@plebhash
plebhash marked this pull request as draft May 8, 2026 22:03
@gimballock

Copy link
Copy Markdown
Contributor

All of these changes seem to follow the correct conventions and processes, only nit i found was in the companion PR regarding use of &str instead of String to save some memory allocations.

@plebhash
plebhash force-pushed the 2026-05-08-refine-server-share-accounting branch from 8a1422d to 054864a Compare May 11, 2026 21:59
@plebhash

Copy link
Copy Markdown
Member Author

All of these changes seem to follow the correct conventions and processes, only nit i found was in the companion PR regarding use of &str instead of String to save some memory allocations.

thanks @gimballock !

so I assume this also includes prometheus_metrics.rs and snapshot_cache.rs right?

@gimballock

gimballock commented May 11, 2026

Copy link
Copy Markdown
Contributor

All of these changes seem to follow the correct conventions and processes, only nit i found was in the companion PR regarding use of &str instead of String to save some memory allocations.

thanks @gimballock !

so I assume this also includes prometheus_metrics.rs and snapshot_cache.rs right?

You're following the conventions correctly:

  • Add GaugeVec field to PrometheusMetrics
  • Register with the extra label dimension
  • Update in update_metrics() loop with with_label_values
  • Track label sets in PreviousPrometheusLabelSets and clean stale ones

But let me deploy this now to verify the metrics actually show up in grafana..

  • The rejection metric is lazy loading so i don't see it, idk how to trigger a rejection right now
  • Also it could be useful to include a shares submitted metric (sum of accepted + rejected)

The lazy-loaded metrics will cause issues for alerting and make associated grafana panels fail to load until first share rejection, so that one is high priority.

@plebhash
plebhash force-pushed the 2026-05-08-refine-server-share-accounting branch 11 times, most recently from 3f70070 to 3ae9eff Compare May 15, 2026 02:27

@GitGab19 GitGab19 left a comment

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.

LGTM, apart from a minor thing on the Prometheus metrics cache, for which I'd like to get a confirmation from @gimballock on.

Comment thread stratum-apps/src/monitoring/snapshot_cache.rs
@gimballock

gimballock commented May 15, 2026

Copy link
Copy Markdown
Contributor

Heads up: sv2_*_shares_rejected_total lazy-loads and never appears in /metrics until the first rejection (verified empirically on testnet4 — panels and alerts silently broken with zero rejections). Opened plebhash#3 against this branch with a +122/-0 fix that pre-seeds the spec-defined ERROR_CODE_SUBMIT_SHARES_* constants to 0, plus a regression test. Verified live on testnet4 after rebuild.

@plebhash

Copy link
Copy Markdown
Member Author

thanks @gimballock

cherry-picked the commit from plebhash#3 with a small adaptation:

SPEC_REJECTION_CODES as a variable name is a bit misleading, soon the spec will no longer suggest error codes, see stratum-mining/sv2-spec#194

renamed to SHARE_REJECTION_CODES

@plebhash
plebhash force-pushed the 2026-05-08-refine-server-share-accounting branch 2 times, most recently from 0b91c4f to 22446f6 Compare May 15, 2026 23:55

@GitGab19 GitGab19 left a comment

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.

LGTM

plebhash and others added 5 commits May 18, 2026 13:16
…d_total

Fixes a GaugeVec lazy-loading bug where sv2_*_shares_rejected_total never
appears in /metrics until the first rejection occurs, breaking Grafana
panels and alerting rules during normal (zero-rejection) operation.

Pre-seeds every SubmitSharesError.error_code value defined by mining_sv2
to 0 on every snapshot refresh. Constants come from PR stratum-mining#495 — single
source of truth, no string duplication.

Schema and PreviousPrometheusLabelSets are unchanged; cleanup happens
naturally when channels disappear. +122 lines, -0 lines, purely additive.

Includes regression test shares_rejected_metric_emitted_with_zero_rejections
which fails on this branch's HEAD and passes with the seed. Verified live
on testnet4 slot2: all 7 codes appear at 0 immediately after rebuild.
@plebhash
plebhash force-pushed the 2026-05-08-refine-server-share-accounting branch from 22446f6 to 0f3f70b Compare May 18, 2026 16:16
@plebhash
plebhash marked this pull request as ready for review May 18, 2026 16:17
@plebhash
plebhash merged commit d40821c into stratum-mining:main May 18, 2026
13 of 14 checks passed
@plebhash
plebhash deleted the 2026-05-08-refine-server-share-accounting branch May 18, 2026 19:02
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.

5 participants