Skip to content

3.x.x: offer again a won block whose submitblock qbitd answered from its warmup, instead of losing it as unknown (#526) - #566

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b526-warmup-reoffer
Sep 28, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b526-warmup-reoffer

Conversation

@djh58

@djh58 djh58 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Closes #526 (follows #522 / #527)

Problem

A submitblock retry that reaches qbitd while it is still warming up after a restart gets JSON-RPC error -28 (RPC_IN_WARMUP). PRISM recorded that as an unknown outcome, so under the never-offer-twice rule the block was never offered again. The reward was lost, although the warm node would have accepted the block on the same tip. This is #522's failure class, narrowed to a retry that lands inside the warmup window.

Is -28 really "not executed"?

Yes. I checked the source and ran the node:

  • Source (qbit v1.0.0, the version CI pins): CRPCTable::execute checks the warmup flag as its first statement and throws RPC_IN_WARMUP before it looks the method up. The whole src/ tree raises -28 nowhere else. The flag starts true and is cleared once, by SetRPCWarmupFinished() at the end of AppInitMain (step 13). SetRPCWarmupStarting() is called only from test setup, so warmup never comes back after startup. Any exception inside a running command becomes RPC_MISC_ERROR (-1) in ExecuteCommand, never -28. PRISM sends JSON-RPC 1.0, so qbitd answers this -28 with HTTP 500 and the error object. Rpc already surfaces that as RpcReplyError.
  • Behaviour (the v1.0.0 binary): I created a valid block without submitting it, restarted the node held in its warmup, and sent submitblock. The reply was {"code":-28,"message":"Loading banlist…"} with HTTP 500. Once the node was warm, getblockheader for that block returned Block not found and debug.log never mentioned it. The same submitblock was then accepted, and the block became the tip.

Fix

offer_candidate now asks one question before it classifies an outcome: did the node provably never run this call (offer_not_executed)? The answer is yes in two cases:

Both take #527's path unchanged. Ledger::release_unsent_offer returns the reservation to pending in one claim-fenced transaction. The row keeps no outcome, no offered_at_ms and no first-offer sample, and gets the ordinary min(60, attempt_count) s backoff. The next claim runs the pre-offer screen again. last_error keeps the offer not sent prefix and records the node's reply, for example offer not sent: qbit RPC submitblock: {"code":-28,"message":"Loading banlist…"}; the node was still warming up and ran no call; the reservation taken by <instance> was returned to pending for another offer.

Kept exactly as before:

  • Any other error code on submitblock stays unknown, including -1, -9 (shutting down), -22, -25, a non-integer code or no code at all. So does every transport failure after the connection existed, and the timeout.
  • A -28 answer to any other call is not this offer's. A pre-offer probe that gets -28 fails the attempt into the ordinary retry, with the row still pending, as any probe error does. After the call ran, a -28 on an observation settles into reconciliation like any node error, and the block is never offered again.
  • The crash window: a crash between the -28 reply and the release commit leaves offer_reserved, which recovery treats as delivery unknown, as in 3.x.x: offer again a won block whose submitblock never connected, instead of losing it as unknown (#522) #527.
  • No migration, no new metric, no change to any post-offer path.
  • Assumption, now documented on RpcReplyError::in_warmup and in the ledger operations doc: the RPC URL reaches one node (a path-routing reverse proxy is fine). An endpoint that retries a failed POST on another backend is unsupported, because it could submit a block twice by itself.

RpcReplyError gains code() and in_warmup(), and rpc.rs exports RPC_IN_WARMUP. Every caller keeps the same error type and message.

Tests

Test Kind What it pins Per-PR CI time
coordinator::offer_not_executed_tests (5 cases) ungated unit -28 to submitblock → not executed; refused connect still not executed; -28 to another method → not this offer's; every other submitblock error code, a non-integer code or no code → None and Unknown; answers, transport failures and timeouts → None ~0 s
…::offer_not_sent_tests::offer_warmup_tests::a_submitblock_answered_in_warmup_returns_the_row_to_pending_and_lands_the_block_once_when_the_node_is_warm gated PG warmup reply → pending, offer columns empty, reason with -28, backoff, no unknown outcome, no sample; a second warmup reply is also not executed; once the node is warm the block lands with exactly one submitblock the node ran ~1.7 s
…::offer_warmup_tests::a_warmup_answer_after_the_submitblock_ran_keeps_the_offer_and_never_offers_again gated PG the node accepts, then answers everything -28: the offer stays accepted, the row never returns to pending, later claims (warming, then warm) never offer again, the block lands with one submitblock ~1.1 s
live_regtest::node_outage_tests::node_restarted_into_warmup_before_submitblock_lands_the_block_once gated live, sibling of #527's case the block is admitted, qbitd is killed before its submitblock, and the connect is refused (as in #527). qbitd then restarts held in its warmup and the port reopens. The retry reaches the real node, which answers -28; the row is back in pending, and the node is proven still in warmup. The node is released and the block lands. Each block is run by the node exactly once, and only the held block ever got a warmup answer. ~18 s

The gated tests are listed, sorted, in test/prism-gated-tests.txt. Net per-PR CI time: about +21 s, almost all of it the live case in the live shard.

Holding a real qbitd in warmup, deterministically. qbitd opens <datadir>/regtest/fee_estimates.dat with a blocking fopen in startup step 6. That is after its RPC server is up (step 4a) and before its warmup ends (step 13). The test makes that path a FIFO, so startup blocks in that open until the test opens the write end. Until then every call is answered -28. The test checks this directly (a direct probe returns -28 before and after the retry), so it fails loudly rather than passing vacuously if a future qbitd reorders startup. Releasing the FIFO feeds an empty file, which qbitd rejects and ignores ("Continue anyway"). The FIFO is removed only after the warmup has ended, because qbitd still reads the file's time after the open returns. The other outage cases share spawn_node and a wait_unsent that now takes the expected reason. Their behaviour is unchanged, and all five pass.

The proxy now records which submitblock calls the node answered from its warmup. "Offered exactly once" counts only the calls the node ran.

Mutants (each run on the relevant tests, then reverted):

  • A. -28 treated as unknown (the warmup branch removed). The unit case a_warmup_answer_to_submitblock_was_not_executed fails. The gated warmup test fails with state reconciliation, outcome Some("unknown"). The live case fails with recorded with outcome Some("unknown"). That is the lost-block path.
  • B. -28 classified as not executed for any method, not only submitblock. Only the scope pin a_warmup_answer_to_another_call_is_not_this_offers fails. Every state-machine test passes unchanged, including the post-offer warmup test.
  • C. The RPC layer turns every -28 reply, for every method, into "not sent". The post-offer warmup test still passes: a -28 after the call ran never re-offers, because only the one submitblock result is ever classified. Only the reason-text pin of the gated warmup test fails.

Also run on this branch: the full qbit-prism-server lib suite (583 passed, gated tests required), rpc_not_sent, offer_lifecycle, and all five node_outage_tests live cases. cargo fmt --check and cargo clippy --all-targets -D warnings are clean. After the FIFO-removal fix, the live warmup case passed 70 of 70 runs on a shared, heavily loaded host (about 18 s each). Three of those runs took 28 to 67 s. The waits were in the landing of a block after the node recovered, well inside the case's 90 s and 60 s budgets, and did not reproduce in 40 further instrumented runs.

🤖 Generated with Claude Code

…its warmup, instead of losing it as unknown (#526)

A submitblock retry that reached qbitd while it was still warming up
after a restart was answered with JSON-RPC error -28 (RPC_IN_WARMUP)
and recorded as an unknown outcome. Under the never-offer-twice rule
the block was never offered again and the reward was lost, although
the warm node would have accepted it on the same tip.

qbitd, like the Bitcoin Core it derives from, checks its warmup flag
as the first step of CRPCTable::execute, before it looks the method
up; nothing else raises -28, and the flag is cleared once, at the end
of startup, and never set again. Checked in the pinned v1.0.0 source
and against the v1.0.0 binary held in its warmup: a submitblock sent
then is answered -28 (HTTP 500), the node has no record of the block
once warm, and the same block is then accepted.

A -28 reply to submitblock is therefore classified like #522's refused
connection: the call provably never ran, so the reservation returns to
pending through Ledger::release_unsent_offer, with the ordinary backoff
and the pre-offer screen on the next claim. Only a submitblock reply
counts; every other error code, a warmup answer to any other call, and
every answered call keep today's behaviour.

Tests: unit tests for the classification; gated PostgreSQL tests for
the state transition and for a warmup answer after the call ran (never
offered again); and a live regtest sibling of #522's outage case that
restarts qbitd held in its warmup, so the retry is answered -28 by the
real node and the block lands exactly once.

Closes #526

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 28, 2026 20:45
…, and the one-node RPC endpoint assumption

- The test relay keeps its warmup state in one Submit mode (Warming)
  instead of a mode plus a flag.
- The live case releases qbitd's fee-estimates FIFO with a non-blocking
  open polled until the node waits in its open, so a node that never
  gets there fails the wait instead of hanging the test.
- The live case uses RPC_IN_WARMUP instead of a literal -28; the
  coordinator names the classification not_run and logs that the node
  never ran the offer (the stored "offer not sent" prefix is unchanged).
- RpcReplyError::in_warmup and the ledger operations doc state the
  assumption both not-run rules make: the RPC URL reaches one node; an
  endpoint that retries a failed POST on another backend is unsupported.

Refs #526

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

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Deep-review ledger (head ac571d23, CI green)

Stakes: high. The change is on the block-offer path, where one found block is a full block reward.

Lanes: /code-review medium, a thermo-nuclear quality review, and an adversarial review (Claude). The second adversarial model and bugbot were not run in this pass. No bot or reviewer comments had been posted when this ledger was written.

# Lane Finding Disposition
1 code-review A -28 reply is trusted without checking the reply id. A proxy that retries the POST on a second, warming backend could re-offer a block the first backend ran. Fixed (docs), ac571d23. An id check would not catch that scenario: a retrying proxy resends the same body and id. Such a proxy can double-submit on its own, with or without this rule. The assumption both not-run rules make is now stated on RpcReplyError::in_warmup and in the ledger operations doc: the RPC URL reaches one node, and an endpoint that retries a failed POST on another backend is unsupported.
2 thermo Move the not-executed predicate to rpc.rs and drop the submitblock method filter as dead code. Rejected. Scoping the rule to submitblock is a stated requirement, pinned by the mutant that drops it (only the scope pin fails, and no state-machine test changes). The decision belongs next to classify_offer, and the filter keeps the helper safe if it is ever reused for another call.
3 thermo Model Hold::Warmup as a restart mode (Fault::Kill(Restart)) instead of a hold. Rejected. It follows the existing Hold::Reservation pattern from #527, which is also never armed in the proxy. Restructuring Fault would rewrite shared live-test support that other lanes are editing.
4 thermo live_node_outage.rs is over 1k lines; extract the RPC proxy. Rejected. The repo has no such limit (coordinator.rs is over 3k lines). Moving shared support is out of scope, and this change keeps shared support additive.
5 thermo The gated warmup test duplicates #522's refused test; share a scenario helper. Rejected. Two explicit scenario scripts read clearly. A helper would rewrite #527's test for little gain.
6 thermo The test relay keeps its warmup state in two places, a flag and a mode. Fixed, ac571d23. One Submit::Warming mode.
7 thermo The FIFO release (spawn_blocking open behind a timeout) could hang the test instead of failing it. Fixed, ac571d23. It now polls a non-blocking write open, which fails with ENXIO until the node is waiting in its own open. A node that never gets there now fails the wait.
8 thermo Literal -28 in the live test, and "not sent" wording on the warmup path. Fixed, ac571d23. The test uses RPC_IN_WARMUP, the binding is renamed not_run, and the log line is reworded. The stored offer not sent prefix is unchanged. Reusing code() in tools.rs is left out of scope.
9 adversarial No refutation found. It attacked the -28 proof, reply attribution, and the ledger and capture path. No action.
10 adversarial (note) capture_offer_decisions_total{decision="offered"} counts once per reservation, so a warmup retry of a capture block counts again. Rejected. This was known and accepted in #527 and affects the metric only.
11 adversarial (note) A capture block that is re-reserved after a warmup answer, and later abandoned as parent-superseded, keeps offer_decision='offered' in its payout-divergence row. Deferred. It predates this PR (#527's not-sent path has it too), it affects the audit record only, and no funds move. A follow-up issue is left to the maintainers.

Totals: 4 fixed, 6 rejected, 1 deferred.

@djh58
djh58 merged commit 1fb74b7 into 3.x.x Sep 28, 2026
21 checks passed
djh58 added a commit that referenced this pull request Sep 29, 2026
…cenario manifest (#560) (#584)

The manifest check added by #560 fails on 3.x.x
(tests/test_check_e2e_scenarios.py::test_the_checked_in_manifest_passes):
two live_regtest tests in the PR gated list are cited by no running
scenario. Both belong to existing #521 scenarios:

- pg_failover_tests::offer_standby::a_found_block_offered_after_the_standby_flush_survives_a_replication_cut_at_submitblock
  (#570, #529 item c) runs on the #521 scenario 3 failover fixture; its
  criteria gain the standby flush wait's claim.
- node_outage_tests::node_restarted_into_warmup_before_submitblock_lands_the_block_once
  (#566) is a #521 scenario 4 node-outage drill.

scripts/check_e2e_scenarios.py and its tests pass.

Refs #560, #570, #566.

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