Repository navigation
3.x.x: offer again a won block whose submitblock never connected, instead of losing it as unknown (#522) - #527
Conversation
…tead of losing it as unknown (#522) A submitblock that fails before its connection is established (the node refuses the connection, a name or route failure, the connect timeout) provably never reached the node. Rpc::call_timeout now returns a typed RpcNotSentError for exactly reqwest's is_connect() errors. hyper raises that kind only while obtaining a connection, before any request is handed to one. The offer path returns such an attempt's own reservation to pending in one claim-fenced transaction: the offer columns are cleared, the attempt is recorded in last_error, and the row is offered again after the ordinary pending backoff. Every failure after the connection existed (a reset or close after the write, a lost reply, the request timeout, any HTTP or JSON-RPC error) stays unknown and is never offered again. A crash between the refused connect and the row update leaves offer_reserved, which recovery still treats as delivery unknown. Tests: rpc_not_sent (classification against real sockets), three gated PostgreSQL cases (refused lands once, reset after write stays unknown, crash window recovers unknown), and #521 scenario 4's kill-before-submit live case flipped to land the block exactly once after qbitd restarts. Closes #522 Refs #521 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 15595b8. Configure here.
…candidate wording, outage fault helpers - Classify release_unsent_offer's ledger transaction in the pool-acquire census like its sibling offer transitions (the guard failed CI). - Say what the next claim's pre-offer phase does for a leased candidate: it is offered without the supersession screen, as every leased candidate is (#350), in the ledger doc comment and the operations doc. - Move the two held-block fault paths of the scenario-4 live test into held_offer and unsent_offer, so outage_steps no longer branches on the hold in four places. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deep-review ledger (head 9a7ddcf, CI green: 20 passed, 1 skipped)Stakes: high, because this is the block-submission path (reward capture, chain state). Bugbot was summoned.
Adversarial pass: no refutation found. The three riskiest areas I attacked, and why they held:
Review-lane gaps: the review battery ran inline in the authoring session. The worker contract forbade nested workers and non-Claude providers, so there was no independent cross-agent adversarial lane (Fable worker or Codex). Follow-up (the coordinator is filing it): a retry that reaches qbitd during its warmup gets a JSON-RPC |
Closes #522 (Refs #521)
Problem
If
submitblockfails because qbitd refuses the connection (a node or RPC restart, a network blip), the offer is recorded as an unknown outcome. Under the never-offer-twice rule the block is then never offered again. The restarted node would still accept it on the same tip, so a full block reward is lost. #521 scenario 4 pinned this as a known defect innode_killed_before_submitblock_never_reoffers_the_unsent_block_known_defect.Fix
A
submitblockwhose connection was never established did not reach the node. That attempt now returns its own reservation topending, and the block is offered again after the ordinary pending backoff. Every other failure stays unknown, exactly as today.Where the boundary is (
rpc.rs)Rpc::call_timeoutnow returns a typedRpcNotSentErrorexactly when reqwest'sis_connect()holds. Every other transport failure keeps today's untyped error.is_connect()is true when hyper-util's legacy client reports itsConnecterror kind somewhere in the chain. I checked this in the locked versions (reqwest 0.12.28, hyper-util 0.1.20, hyper 1.11.1):Connectonly insideconnection_for: the connector (DNS, TCP connect, reqwest's 5 s connect timeout, TLS or proxy handshake) or the pool checkout. A request is handed to a connection (try_send_request) only afterconnection_forhas returned one.take_message()isSomeonly if the message was never serialized). So if an attempt after such a retry fails to connect, still no attempt wrote the request.Not treated as "not sent", because the request may have reached the node:
The classifier checks the error kind, not the OS error code. The error message keeps the
qbit RPC <method> transport failedwording that callers and tests match on, and never includes the URL. No pre-flight probe is needed: the client distinguishes the case reliably, andtests/rpc_not_sent.rspins that against real sockets, so a dependency upgrade that changed these kinds would fail CI.State machine (
coordinator.rs,ledger/candidates.rs)offer_candidatechecks thesubmitblockresult forRpcNotSentErrorbefore it classifies an outcome. When it finds one,Ledger::release_unsent_offerdoes the following in one transaction:offer_reserved→pending, fenced on the live claim token and on a reservation with no recorded call (offered_at_ms IS NULL AND offer_outcome IS NULL).pending, which still means "never offered".last_errorunder the newOFFER_NOT_SENT_REASON_PREFIX(offer not sent: … connection refused …; the reservation taken by <instance> was returned to pending).min(60, attempt_count)s pending backoff.After that:
unknown-joband never reached the node #478 ceiling again. A 3.x.x: Reference the window from candidates and move the found-block write off the ordering lock #350 leased candidate is offered without that screen, as every leased candidate is. The node decides everything else.offer_reservedwith no recorded call. Nothing durable proves the call was not made, so recovery keeps treating that row as delivery unknown and never offers it. No recovery path was changed.offered_at_msand no first-offer sample. It never counts as an unknown outcome. While the node refuses, the row ispendingand counts towardblock_candidate_oldest_unacknowledged_seconds, like any block the node has not accepted, so a long outage still pages. When the offer finally goes through, its first-offer sample covers the whole outage.No migration, no new metric, and no change to any post-write path.
Known, accepted: a block whose payout revision was superseded (#478) is re-reserved on each attempt, so
capture_offer_decisions_total{decision="offered"}counts once per reservation.Tests
rpc_not_sent(6 cases)candidate_lease_tests::offer_not_sent_tests::a_refused_submitblock_returns_the_row_to_pending_and_lands_the_block_once_when_the_node_is_backpendingwith empty offer columns, reason recorded, backoff, no unknown outcome, no sample; a second refused attempt is also not sent; once the node is reachable the block lands with exactly onesubmitblock…::a_reset_after_the_submitblock_was_written_stays_unknown_and_is_never_offered_againpending, later claims never offer again (onesubmitblock)…::a_crash_between_the_refused_connect_and_the_row_update_recovers_as_delivery_unknownoffer_reserved; recovery settles it unknown and never offers it, even with the node backlive_regtest::node_outage_tests::node_killed_before_submitblock_lands_the_block_once_after_restartsubmitblock→ refused,pending, retried (≥2 attempts, none reaches the node) → qbitd restarts → the block lands; exactly onesubmitblockper blockThe live case. The #521 case held the request inside the test's proxy after the server had written it, then killed the node. For the server that is a request that may have reached the node, so it correctly stays unknown after this fix; flipping that assertion as written would break never-offer-twice. The flipped case therefore faults where "before submit" really is before the write:
The other scenario-4 cases are unchanged and pass.
Mutants (each run on the relevant tests, then reverted):
a_reset_after_the_request_was_read_may_have_been_sent,a_connection_closed_right_after_it_was_accepted_may_have_been_sent, and the gated reset test withstate pending(the double-offer path).rpc_not_sentcases, the gated refused test and the gated crash test, and the flipped live case withrecorded with outcome Some("unknown") (reconciliation)(the lost-block path).Follow-up (not in this PR)
A retry that reaches qbitd during its warmup gets a JSON-RPC
-28(RPC_IN_WARMUP) reply. Today that reply is still recorded as unknown, which loses the block. It is an answered call, so this PR keeps it unknown as scoped. In Bitcoin Core, from which qbitd derives, the warmup check runs before any method is dispatched. This deserves its own issue.🤖 Generated with Claude Code