Skip to content

3.x.x: cap a block proof's acknowledgement wait at the share commit timeout instead of 60 s (#574) - #577

Merged
djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b574-ack-wait-cap
Sep 29, 2026
Merged

djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b574-ack-wait-cap

Conversation

@djh58

@djh58 djh58 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Caps a captured or block-only proof's acknowledgement wait at share_commit_timeout (15 s by default) instead of max(share_commit_timeout, 60 s). A captured (#478) proof's miner no longer sits silent for up to a minute while its frontend lands the block. The bound only ends the wait: no step that offers the block or credits the share can be cancelled by it.

Change

  • Block-only proofs. block_only_ack_timeout is now share_commit_timeout itself. It comes from config::block_only_ack_timeout, which both Config::from_env and the tests call. It bounds a captured, deferred or below-target block proof's wait for its enqueue and landing.
  • Block-carrying share-pass appends. These follow a plain share's ladder: the share deadline, plus share_commit_grace once COMMIT is in flight. They are never refused, so they run on past an unknown answer. A found block is never served worse than a plain share.
  • Probe and enqueue survive the bound. The duplicate probe and the candidate enqueue of a block-only proof run in one spawned task. Neither the bound nor a cancelled submission stops it; only the wait is bounded. This was found in review: with the shorter bound, a probe queued on a saturated pool could run out the bound and answer ledger-confirmation-failed with nothing enqueued, so the block was lost. A probe error is still a definite failure.
  • Audit of the block path after the acknowledgement clock starts:
    • the block-carrying append runs in a task the answer never aborts;
    • the probe and enqueue now do too;
    • the disposition poll only reads;
    • the landing runs in the candidate loop.
  • Reply at the cap (documented in the metrics guide): the one every share still pending at its deadline already gets. That is Stratum error 20, message "share outcome is not yet known", reason_id ledger-outcome-unknown. Only the wait ends there. The append or landing runs on, the block is offered and landed, and the share is credited once when that commits.
  • Log: the existing WARN share outcome unknown at the acknowledgement deadline already names the block hash, share id and phase. It now adds elapsed_ms.
  • Metric: new counter qbit_prism_block_proof_ack_capped_total{path}, with path = share or block_only. Both series start at zero. It is in the registry, census, contract test, metadata and generated inventory.
  • No new alert. The reply already counts in qbit_prism_rejections_total{reason_id="ledger-outcome-unknown"}, which PrismShareAppendFailures warns on; the counter says why.

Operator impact

  • What miners see. A block proof still pending at the cap now gets the existing pending-outcome error (20, ledger-outcome-unknown) after 15 s instead of 60 s. Some miner UIs and rental marketplaces count that as a reject, although the share is credited later, once the landing commits. Before this change, the same proof was either accepted after up to 60 s of silence or got the same error at 60 s.
  • PrismShareAppendFailures can now fire on a slow landing alone. It warns (never pages) when any ledger-confirmation-failed or ledger-outcome-unknown rejection occurred in the last 5 minutes, held for 3 minutes. A captured or block-carrying proof whose landing or append takes more than 15 s is enough, where before it needed more than 60 s. Expect at most about one warning per found block while landings are slower than 15 s: one captured proof per affected session per block, as the issue measured. Every such rejection is also counted in qbit_prism_block_proof_ack_capped_total. To keep the warning for real append failures only, ops can subtract that counter's increase from the rule's. This PR does not change the rule.
  • Root cause. The fix for slow landings themselves is taking settlement off ORDER_LOCK, which is tracked separately. This PR only bounds how long a miner waits for one.

Worth a reviewer's look

  • Unit-test contract change. Three existing unit tests pinned the old behaviour and are updated. Two of them required a bounded or cancelled block-only probe to fail definitely without enqueuing (block_only_initial_probe_sql_error_cancel_and_original_deadline, clock_and_block_only_duplicate_checkouts_are_lazy_and_cancel_once). The block now reaches the outbox anyway, and the pool-checkout accounting records the probe's checkout when it succeeds rather than a cancellation failure.
  • Follow-up. block_only_ack_timeout is now redundant with share_commit_timeout. Removing the field touches about 13 test fixtures owned by other lanes, so it is left for a follow-up issue.

Tests

The new binary b574_ack_cap holds four gated tests, listed in test/prism-gated-tests.txt. Both frontends take the block-only bound from config::block_only_ack_timeout with a 3 s share commit timeout. A one-shot trigger or function holds one database step until the test releases it. "Answered at the cap" means the answer came between 3 s and 5 s (2 s of slack, below the 5 s grace), with reply 20 / ledger-outcome-unknown.

Test Held step While held After release
a_captured_proof_is_answered_at_the_cap_and_credited_after_its_landing the landing's offer_reserved → offered record, after the node accepted the block answered at the cap; share uncredited; path="block_only" = 1 the block lands submitted; the deferred share is credited exactly once
a_captured_proof_whose_probe_outlasts_the_cap_is_still_enqueued_and_credited the pre-enqueue duplicate probe answered at the cap; nothing enqueued yet; path="block_only" = 1 the block is enqueued, lands, and the share is credited once
a_block_carrying_share_append_is_answered_at_the_cap_and_credited_once the append's candidate insert, before COMMIT answered at the share deadline; share uncredited; path="share" = 1 the append commits the share once; landing adds no second credit
a_block_carrying_append_whose_commit_is_in_flight_gets_the_share_grace inside the append's COMMIT (a deferred constraint trigger), released 1 s past the deadline not answered at the deadline accepted within the grace; one late confirmation; not counted as capped; credited once

Mutants (each fails at least one test):

  • The probe bounded again: ledger-confirmation-failed, and the block is never enqueued.
  • No grace for a committing block-carrying append: that proof is answered unknown at 4.0 s.
  • Grace for every block-carrying append: not answered within 5 s.
  • The 60 s floor restored: not answered within 5 s.
  • The counter dropped: "not counted once on the … path".

Other runs (private PostgreSQL 16, fsync on):

CI runtime added: about 20 s, for the one new binary with four tests of about 4 s each plus fixture setup.

Checks

  • cargo clippy --locked -p qbit-prism-server --lib --tests -- -D warnings: clean.
  • cargo fmt --all --check: clean.
  • python3 scripts/generate_prism_metrics.py: regenerated.

Closes #574

🤖 Generated with Claude Code

…imeout instead of 60 s (#574)

A captured (#478) block proof's share is deferred to its block's landing,
and its Stratum answer waited for this frontend's own landing for up to
block_only_ack_timeout = max(share_commit_timeout, 60 s). The miner's
session can submit nothing else meanwhile, and some firmware or rental
marketplaces treat a long silence as a dead pool (#562 measured 16.6 s
with 8 s of landing delay).

- block_only_ack_timeout is now share_commit_timeout itself (15 s by
  default), derived by config::block_only_ack_timeout, which from_env and
  the new test share. It still bounds every block-bearing submission: a
  block-only, deferred or captured proof's wait for its enqueue and
  landing, and a share-pass append that carries the block.
- At the cap the proof gets the reply every share still pending at its
  deadline gets: Stratum error 20, "share outcome is not yet known",
  reason_id ledger-outcome-unknown. Only the wait ends there: the append
  or landing runs on, the block is offered and landed, and the share is
  credited once when that commits.
- The existing unknown-outcome WARN, which already names the block hash,
  share id and phase, now carries elapsed_ms.
- New counter qbit_prism_block_proof_ack_capped_total{path=share|block_only},
  both series zero at start. No new alert: the reply already counts in
  qbit_prism_rejections_total{reason_id="ledger-outcome-unknown"}, which
  PrismShareAppendFailures warns on; the counter says why.
- A candidate probe that runs out the bound before the enqueue is still a
  definite ledger-confirmation-failed and is not counted; the pool's own
  15 s acquire timeout already ended it at about the same time before.
- live_regtest's failover waits from #562 are unchanged: they count
  credits, which still follow the landing; only their comment changes.

Tests (gated, listed in test/prism-gated-tests.txt), in b574_ack_cap: a
one-shot trigger holds the block's write until the test releases it
(a captured proof at its offered record; a block-carrying share-pass
append at its candidate insert). Each proof is answered at the 3 s cap with
the pending-outcome reply while the write is held, uncredited, and counted
once on its path; after the release the share is credited exactly once and
the block lands. Mutants: restoring the 60 s floor in
config::block_only_ack_timeout fails both at the cap; dropping the counter
fails both.

Closes #574

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 29, 2026 14:52
…e, and give a block-carrying append the share grace (#574 review)

From the #577 review lanes:

- Block loss (adversarial lane). persist_block_only ran its duplicate probe
  under the acknowledgement bound, so once #574 shortened the bound to
  share_commit_timeout, a probe queued on a saturated pool or a slow leaf
  could run out the bound. The proof was then answered
  ledger-confirmation-failed with nothing enqueued, and the found block was
  never offered. The probe and the enqueue now run in one spawned task that
  neither the bound nor a cancelled submission stops. Only the wait for it is
  bounded: past the bound the proof is answered ledger-outcome-unknown,
  counted as capped, and the task is followed until the block reaches the
  outbox. A probe error is still a definite failure with its database error
  intact (EnqueueStep::ProbeFailed).
- Grace (all three lanes, coordinator decision A). A share-pass append that
  carries a found block now follows a plain share's ladder: the share
  deadline, plus share_commit_grace once COMMIT is in flight. It is never
  refused, so it runs on past an unknown answer. Before, #574 gave it 15 s
  with no grace, less than a plain share. block_only_ack_timeout now bounds
  only block-only proofs (captured, deferred, below-target), which stay
  capped at share_commit_timeout exactly.
- Audit of the block path after the acknowledgement clock starts:
  - the block-carrying append already ran in a task the answer does not
    abort;
  - the probe and enqueue now do too;
  - the disposition poll only reads;
  - the landing runs in the candidate loop.
  Nothing on the path is cancelled by the bound any more.
- Docs: the metrics guide no longer describes late block-carrying
  confirmations past a block-only bound; the counter's help and status
  describe both bounds. live_regtest's allowance is renamed
  landing_credit_seconds.

Tests:
- b574_ack_cap gains two gated tests:
  - a captured proof whose pre-enqueue probe is held past the cap is answered
    unknown at the cap and counted, and its block is enqueued after the
    release, lands, and credits the share once;
  - a block-carrying append held inside COMMIT past the deadline is accepted
    within the grace and counted as a late confirmation, not as capped.
- The answer-time slack is now 2 s, below the 5 s grace.
- Updated for the new contract:
  - commit_reconcile_candidate_bearing_append_is_never_refused: accepted
    within the grace while COMMIT is in flight; answered at the share
    deadline, not the block-only bound, while held before COMMIT;
  - the block-only acquire tests: a cancelled or bounded probe keeps
    waiting instead of failing, and the block still reaches the outbox.

Mutants, each failing at least one test:
- the probe bounded again: ledger-confirmation-failed, block never
  enqueued;
- no grace for a committing block-carrying append;
- grace for every block-carrying append;
- the 60 s floor;
- the counter dropped.

Refs #574

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…574 review)

The block-only proof's duplicate probe now takes its pool checkout inside
the spawned probe-and-enqueue task (ledger.acquire()) instead of on the
coordinator (self.ledger.acquire()). Split the persist_block_only census
entry accordingly; both stay delegated to Ledger::acquire, which meters
the checkout.

Refs #574

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58

djh58 commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

Deep-review ledger

Stakes: standard. No credit, payout or settlement logic changed. The PR changes the ack wait bound, the structure of the block-path tasks and one counter.

Lanes:

  • code-review (medium)
  • thermo-nuclear quality review
  • adversarial (Claude)

The cross-provider adversarial lane was not run: this work is limited to Claude models.

Head: 78b93a6. Every CI check is green, and no bot or human review comments are open.

# Source Finding Disposition
1 code-review, thermo, adversarial A share-pass append carrying a found block got the share deadline with no share_commit_grace, so it was served worse than a plain share. Fixed in 6aa9941. It now follows a plain share's ladder (deadline, plus grace once COMMIT is in flight). Captured and block-only proofs stay capped at exactly share_commit_timeout. Covered by a_block_carrying_append_whose_commit_is_in_flight_gets_the_share_grace; mutants for "no grace" and "grace always" each fail.
2 adversarial The shorter bound could time out the pre-enqueue duplicate probe. The proof was then answered ledger-confirmation-failed with nothing enqueued, and the found block was lost. Fixed in 6aa9941. The probe and enqueue run in one spawned task that neither the bound nor a cancelled submission stops; only the wait is bounded. Covered by a_captured_proof_whose_probe_outlasts_the_cap_is_still_enqueued_and_credited; the "probe bounded again" mutant fails it.
3 code-review, thermo, adversarial The metrics guide still described late block-carrying confirmations past a block-only bound. Fixed in 6aa9941.
4 adversarial The test could not tell the cap from cap + grace, and the enqueue-pending branch was never exercised. Fixed in 6aa9941. The answer slack is now 2 s, below the 5 s grace, and the probe-hold test drives enqueue-pending. The inline from_env mutant goes away with #580.
5 thermo Rename live_regtest's block_only_ack_seconds: it is now a landing-credit allowance. Fixed in 6aa9941 (landing_credit_seconds).
6 CI test_check_prism_pool_acquires failed: the probe's checkout moved into the spawned task. Fixed in 78b93a6. The census entry is split; both halves are still delegated to Ledger::acquire.
7 thermo block_only_ack_timeout and its identity function are redundant with share_commit_timeout. Deferred to #580. Removing it touches about 13 fixtures shared with concurrent work.
8 thermo Record the counter once in the caller, via a capped flag on SaveOutcome::Unknown. Rejected. The counts are equivalent. The three increments sit where the bound is actually known to have passed. Adding a field to Unknown would touch every test that constructs or matches it exhaustively, for no behaviour change.
9 code-review PrismShareAppendFailures can now fire on a slow landing alone. Rejected as a code change; documented. The PR body's operator-impact section gives the expected rate (about one warning per found block while landings exceed the bound). The new counter lets ops subtract capped answers from the rule. Changing the rule is outside this PR.
10 self-audit Graceful shutdown's abort after the 10 s drain can drop a submission still in its pre-start admission reads or candidate construction. A client disconnect does not cancel a submission. Deferred to #578 (same class: graceful-shutdown block drop).

Audit of the block path after the acknowledgement clock starts:

  • the block-carrying append runs in a task the answer never aborts;
  • the probe and enqueue run in a spawned, followed task;
  • the disposition poll only reads;
  • the landing runs in the candidate loop.

Nothing on the path can be cancelled by the bound.

@djh58
djh58 merged commit b4cb6e3 into 3.x.x Sep 29, 2026
21 checks passed
djh58 added a commit that referenced this pull request Sep 29, 2026
…s, and a per-PR Stratum transcript replay (#575) (#586)

* 3.x.x: nightly e2e for PostgreSQL disk exhaustion and wall-clock jumps, and a per-PR Stratum transcript replay (#575)

Three live_regtest scenarios for #575's item 5 and the automatable half of
item 3.

Disk exhaustion (nightly): the test's own PostgreSQL 16 keeps its whole
data directory on a small ext4 image mounted with fuse2fs through the
setuid fusermount helper, so no root is needed. Clients mine shares that
are not blocks on both servers while a ballast fills the filesystem to
ENOSPC, mine through the full state past the paging rules' `for`, then the
space is freed. It asserts that every acknowledged share is in the ledger,
that refusals are explicit (some with the reasons PrismShareAppendFailures
counts) and no ledger-confirmation-failed share is credited, that a paging
rule's condition (mirrored from docs/prism-native-alert-rules.json) holds
for its `for` on every server, and that both original server processes
accept shares again, land a block and keep carry integrity once space is
freed. The fill/release mechanism is a reusable DiskFullInjector for #554.

Clock jumps (nightly): both servers and a private PostgreSQL run under
libfaketime (realtime only). Each server jumps minutes and hours behind and
ahead; the database jumps two hours ahead and back while a found block's
submitblock is held mid-landing. It asserts that every acknowledged share
is credited once with a monotonic ledger clock, that every block is offered
exactly once, lands once and matches its audit bundle, and carry integrity.
A held block's answer may be ledger-outcome-unknown at the share commit
timeout (#577); it must still land and be credited once. A server more than
PRISM_TEMPLATE_MAX_AGE_SECONDS ahead of the node serves
no work (fail-safe) and PrismWorkRefreshStalledCritical fires; corrected,
it serves again. One outbox row is left in reconciliation after the
database clock steps back, which #581 tracks and the test pins.

Transcript replay (per PR, about 4 s): a JSON-lines Stratum transcript
format and harness that replays recorded client sessions against a live
server and checks each answer for compatibility, with a synthetic corpus
for cgminer, bmminer version rolling, NiceHash extranonce.subscribe,
Braiins mining.configure extensions and esp-miner suggest_difficulty.

The nightly job installs fuse2fs, fuse3, faketime and libfaketime, and the
three tests are named in test/e2e-scenarios.toml (#543).

Refs #575, #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: #575 e2e review fixes: every clock-jump share must be accepted, bounded disk-full phases, one Stratum session

Review follow-ups on the #575 scenarios; tests only.

- Clock jumps: every ordinary share a serving server mines must be
  accepted. Before, only the block was checked, so a server refusing every
  share after a clock step still passed. The one exception is the phase
  right after the database clock steps back, where the stale-job and
  ledger-confirmation-failed refusals #581 records are allowed.
- Clock jumps: each block's outbox row is given its reconciliation retry
  (10 s per attempt) to finish before it is checked. The nightly dispatch
  on this branch caught a row released into reconciliation by a
  post-offer step that lost a payout-revision race, checked mid-backoff.
- Disk exhaustion: every phase is bounded (a server that never accepts
  fails the test instead of hanging the job), and the full state ends
  when a paging rule has fired on each server, bounded, instead of a fixed
  200 s after the first refusal of either server.
- One StratumSession serves both the share client and the transcript
  replay; answers are typed (accepted, rejected, timed out, lost) instead
  of matched on error text.
- Rule mirrors, the sliding [5m] window and the `for` verdicts live in the
  alert-rules module; the submitblock proxy and the host-tool helpers get
  their own support files; impossible states are gone from the types.

Refs #575, #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant