Skip to content

3.x.x: live regtest: a qbitd stop or crash around submitblock offers each block once and lands or reconciles it (#521 scenario 4) - #523

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b521-live-node-outage
Sep 28, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b521-live-node-outage

Conversation

@djh58

@djh58 djh58 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Refs #521 (scenario 4: a qbitd outage or restart around submitblock).

What

Four new gated cases in live_regtest (tests/support/live_node_outage.rs, registered as node_outage_tests), plus one nightly-only #[ignore] variant. Shared support is untouched apart from the three-line mod registration in live_regtest.rs.

Both PRISM servers reach the real regtest qbitd through a JSON-RPC proxy owned by the test. The proxy forwards every call unchanged, records every submitblock, and can hold one call at one of two points:

  • before the request is forwarded, so the node has not seen the block;
  • after the node's accepting reply was read, so the node has the block and the offering server does not know yet.

While the call is held, all proxy traffic pauses. The test then either SIGSTOPs the node (later SIGCONT) or SIGKILLs it (later restarted on the same data directory and RPC port), and only then releases the call. A Stratum client in the test mines one block at a time, so each fault has exactly one block in flight.

case held block ends why
node_stopped_before_submitblock_lands_the_block_once_after_resume submitted (outcome unknown) the resumed node processes the request still in its socket
node_stopped_after_accepting_lands_the_block_once_after_resume submitted (outcome accepted) the post-offer observation fails, the row reconciles, and the block lands after resume
node_killed_before_submitblock_never_reoffers_the_unsent_block_known_defect orphaned (outcome unknown) known defect #522, pinned rather than desired: the node never had the block, and a reconciliation row is never offered again
node_killed_after_accepting_reconciles_the_lost_block_once orphaned (outcome accepted) an unclean qbitd exit loses the accepted block it had not flushed
node_killed_after_accepting_and_reindexed_lands_the_block_once (#[ignore], nightly) submitted -reindex recovers the block from the block files

Every case asserts:

  • /healthz and /metrics (qbit_prism_health_state, qbit_prism_node_observation_age_seconds) on both servers show the node unavailable, then recovered.
  • Each block is offered exactly once, counted at the proxy.
  • The held offer's outcome is recorded.
  • No row is left in pending, offer_reserved or offered.
  • qbit_prism_accepted_block_unlanded_seconds is raised only for an accepted block and clears afterwards. For the lost block it clears through the peer-orphan collector.
  • Pool credit matches the node.
  • A block mined through the other server after recovery lands.
  • qbit_carry_forward_integrity_report() is clean.

In the crash cases the test flushes the chain state (gettxoutsetinfo) before the fault, so the kill loses at most the held block.

Mutants

Each case fails against at least one deliberately broken build:

mutant failing cases failure
blind submitblock retry after a transport error stopped-before, killed-before each block must be offered exactly once (the held hash is offered twice)
readiness ignores the node poll age all four timed out waiting for server N health unavailable
a reconciliation row never observes the chain again stopped-after-accepting timed out waiting for candidate … submitted
no proven-orphan settlement killed-before, killed-after-accepting timed out waiting for candidate … orphaned

CI runtime

The four gated cases take 87–93 s in total in the live suite, measured on two local runs. Fixed waits dominate: the 15 s health timeout per outage, the reconciliation backoff, and the 10 s metrics collector. The whole live_regtest binary passed locally (47 passed, 1 ignored). The nightly -reindex variant adds about 15 s and does not run in PR CI.

Known defect pinned: #522

A block whose submitblock fails because qbitd is down gets the outcome unknown. It is never offered again, so it ends orphaned even though the restarted node would accept it on the same tip. The killed-before case pins this current behavior as a named known defect, and its doc comment explains it. The #522 fix should flip that case to expect the block to land.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…each block once and lands or reconciles it (#521 scenario 4)

Four gated live_regtest cases put a test-owned JSON-RPC proxy between both
PRISM servers and the real regtest qbitd. The proxy forwards every call
unchanged, records every submitblock, and holds one: before the request is
forwarded, or after the node's accepting reply was read. With the call
held and all proxy traffic paused, the test SIGSTOPs the node (resumed
with SIGCONT) or SIGKILLs it (restarted on the same data directory and RPC
port), then releases the call. A Stratum client in the test mines one
block at a time, so each fault has exactly one block in flight.

Every case asserts that /healthz and /metrics (health_state,
node_observation_age_seconds) on both servers show the node unavailable
and then recovered; that each block is offered exactly once; that the
held block's offer outcome is recorded (unknown or accepted); that no row
is left pending, offer_reserved or offered; that the accepted-unlanded
alarm is raised only for an accepted block and clears; that a new block
mined through the other server after recovery lands; and that the carry
integrity report is clean.

- stopped before submitblock: the node processes the buffered request
  when resumed and the block lands.
- stopped after accepting: the post-offer observation fails, the row
  waits in reconciliation, and the block lands after resume.
- killed before submitblock: the node never had the block; the row stays
  in reconciliation, is never offered again, and settles as a proven
  orphan once a competing block has six confirmations. This pins the
  known defect #522 (the restarted node would accept the block on the
  same tip) rather than desired behaviour; the #522 fix flips the case.
- killed after accepting: an unclean qbitd exit loses the accepted block
  it had not flushed (the test flushes the chain before the fault, so
  only the held block is lost), and the row reconciles to a proven orphan
  as above.

A fifth case, killed after accepting and restarted with -reindex (which
recovers the block, so it lands), is #[ignore] for a nightly run and is
not in the gated list.

Mutants each fail at least one case: a blind submitblock retry on a
transport error (both before-submitblock cases, "offered exactly once"),
readiness that ignores the node poll age (all four), reconciliation rows
that never observe the chain again (stopped after accepting), and no
proven-orphan settlement (both killed cases).

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 28, 2026 15:40
… node's, and release held replies inside the submitblock deadline (#521)

Review fixes to the scenario-4 test fixture:

- The proxy only read from the node after forwarding a request, so a node
  connection that closed while idle (qbitd's idle timeout, or the kill)
  left the server's side open; the server could reuse it and have a
  submitblock recorded as unknown. The relay now closes the server's
  connection as soon as the node's closes, as a direct connection would.
- The Stratum client no longer polls the outbox after submitting, so a
  held accepting reply is released well inside the server's 1-second
  submitblock deadline on a slow runner.
- The -reindex variant is described as opt-in (run with --ignored, for
  the nightly job #521 adds) rather than as already nightly, and the
  proxy's Content-Length-only framing is documented.

Refs #521

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

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Review ledger (head b944153, CI green)

This PR only adds tests, so the review is proportionate: one /code-review medium pass over the test code, three consecutive runs, and the mutant evidence. No production code changed.

Code-review findings (3 found, all fixed in b944153)

# finding disposition
1 The proxy never noticed an idle node connection closing, from qbitd's idle timeout or the kill. A server could then reuse a dead connection and have a submitblock recorded as unknown. fixed: the relay now closes the server's connection when the node's closes
2 The reply-hold cases must release the held reply inside the server's 1 s submitblock deadline, but mine() polled the outbox before the test could release it. fixed: mine() returns right after submitting
3 The -reindex variant was described as nightly, but no job runs it. fixed: now described as opt-in (--ignored), for the nightly job that #521 scenario 6 adds

Mutants. Each gated case fails against at least one:

mutant failing cases failure
blind submitblock retry after a transport error stopped-before, killed-before held hash offered twice
readiness ignores the node poll age all four server health never becomes unavailable
reconciliation rows never observe the chain again stopped-after-accepting held block never submitted
no proven-orphan settlement killed-before, killed-after-accepting held block never orphaned

Flakiness check. Three consecutive local runs of the four cases all passed: 4/4 in 87.3 s, 4/4 in 92.3 s and 4/4 in 87.0 s. The opt-in -reindex variant passed in 16.2 s.

CI runtime added per PR. About 106 s in the live_regtest shard: the four cases ran from 16:14:00 to 16:15:46 in this PR's run.

Known defect pinned. #522: the killed-before case asserts the current loss, and the #522 fix should flip it.

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