Skip to content

fix(client): report an underpriced-replacement answer as possibly broadcast, not re-send - #2571

Merged
thiras merged 2 commits into
mainfrom
fix/2565-underpriced-unconfirmed
Oct 20, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2565-underpriced-unconfirmed

Conversation

@thiras

@thiras thiras commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Closes #2565

send_top_up (crates/client/src/buyer_pool.rs) re-sent a topUp on a fresh nonce when the submit was answered replacement transaction underpriced. That answer speaks for the answering backend only: a load-balancing gateway that lost backend A's response and retried the same signed bytes on B gets it while A's copy can still win nonce N. The re-send at N+1 then escrows twice and the first topUp is untracked.

This is the issue's Option 1. decdn_incentive::tx::send_broadcast_unknown now reads replacement transaction underpriced as uncertain, as it already does nonce too low (#2563) and already known (#2560). So:

  • topUp fails with TopUpUnconfirmed at its nonce and openPool with OpenUnconfirmed, both held in escrows. The node's existing settle_unconfirmed_top_up / settle_unconfirmed_open resolve them against the chain: Pending waits, a spent nonce with no deposit growth ends as "escrowed nothing" and releases the slot, a vacant nonce re-sends at the same nonce.
  • The collision re-send loop, TOPUP_NONCE_RETRIES, TOPUP_NONCE_BACKOFF, the ended select and is_nonce_collision are deleted. refuse_after_end(ended) still gates the one send (fix(client): a drained lane build can still re-send a topUp, or wait on locks, after its fetch ended #2520).
  • send_for_receipt reports MaybeBroadcast for the answer, so pool close / reclaim, publish, key rotation and approve warn that the tx may still mine, as they do for nonce too low.

The classifier change is global rather than local to send_top_up because the gateway-retry argument is the same for openPool, which until now released its entry on this answer and let a later open escrow a second deposit.

Reviewer notes

Read send_broadcast_unknown in crates/incentive/src/tx.rs first, then the shortened send_top_up. Nothing in crates/node changes: the settle paths already handle a hashless entry.

Accepted behaviour changes, the same ones #2563 accepted for nonce too low:

  • Node: a genuine same-key collision (a seller redemption takes N) now holds the top-up slot (decdn_buyer_topup_unresolved = 1) until that redemption mines, about one 5 s settle tick, then funds again on the next low-water refill. Previously a 250 ms re-send. Arbitrum answers most such collisions with nonce too low already, so this path was rarely the one taken there.
  • CLI: TopUpUnconfirmed is Fault::Fatal, so a CLI topUp answered underpriced ends the run naming the nonce instead of re-sending. The CLI has no chain settle; a named fatal beats an untracked double escrow.
  • sponsord keeper: its hold clears once the confirmed nonce passes N, the existing rule for transport failures and nonce too low.

Tests: an_open_pool_submit_answered_underpriced_stays_unconfirmed and a_top_up_submit_answered_underpriced_is_unconfirmed_not_re_sent fail on main. a_top_up_after_the_fetch_ended_is_refused_before_its_send replaces the #2520 coverage the deleted backoff test gave. The incentive side gets a classifier test and a send_for_receipt → MaybeBroadcast test.

Mutation check: with the new is_underpriced_replacement arm disabled, the two buyer_pool tests, the two new incentive tests and a_rejected_send_passes_through_unmarked all fail (5/5).

Second commit (review pass). Every doc site that enumerated the uncertain answers stopped at already known / nonce too low, and some stated the opposite of the code: SendOutcome variant docs, the send_for_receipt comment and its uncertainty text, open_pool, ensure_allowance, send_open_pool, send_top_up_at, the OpenUnconfirmed / TopUpUnconfirmed docs, CLI pool.rs send_failed and TxUnconfirmed, publish.rs MaybeBroadcast variants, the keeper module doc, source.rs, the runbook's openPool paragraph and docs/sponsord/operator.md. Outer layers now point at send_broadcast_unknown instead of re-listing. The runtime/mod.rs comment that said a racing collision "gets a fresh nonce on the next attempt" now says an openPool / topUp is held at its nonce and settled. Added tests: a bare transaction underpriced fee rejection stays a rejection (guards the replacement prefix); the open-pool underpriced test asserts the RpcError reason and exact RPC consumption; the node settle has a composition test for a hashless topUp that waits out the colliding transaction and ends "escrowed nothing" (a_hashless_top_up_waits_out_the_colliding_tx_then_escrowed_nothing).

Follow-ups filed, not in this PR:

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run --workspace --no-fail-fast — 5505 passed, 0 failed (first commit); -p decdn-incentive -p decdn-client -p decdn-cli -p sponsord-core 2367 passed and -p decdn-node buyer_pool 119 passed after the review pass
  • cargo nextest run -p decdn-client --features public-api-test public_api — snapshot unchanged
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • pre-commit run --files <changed> — all hooks pass; cargo deny reports the pre-existing rustls-webpki / webpki-roots emSign advisories (non-blocking, unrelated)
  • contracts/ changed: not applicable
  • User-visible change: CHANGELOG.md — the buyer_pool: a gateway-retried openPool/topUp answered nonce too low is treated as a foreign collision and double-escrows #2562 entry now covers both answers, the fix(client): a drained lane build can still re-send a topUp, or wait on locks, after its fetch ended #2520 entry no longer describes the backoff
  • Design change: adr/appendix-observability.md *_unresolved gauge rows and docs/runbook.md list the new no-hash cause
  • PR title uses fix and a lowercase subject

🤖 Generated with Claude Code

…adcast, not re-send (#2565)

`send_top_up` re-sent a `topUp` on a fresh nonce when the submit was
answered `replacement transaction underpriced`. That answer speaks for one
backend only: a load-balancing gateway that lost backend A's response and
retried the signed bytes on B gets it while A's copy can still win the
nonce, so the re-send at N+1 could escrow twice with the first `topUp`
untracked.

`send_broadcast_unknown` now reads the answer as uncertain, as it does
`nonce too low` and `already known`. `topUp` fails with `TopUpUnconfirmed`
at its nonce and `openPool` with `OpenUnconfirmed`, which the node settles
against the chain; the collision re-send loop, its constants and
`is_nonce_collision` are gone. A node whose seller redemption took the
nonce resolves the settle as "escrowed nothing" and funds again on the
next refill.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 21:36
@thiras thiras self-assigned this Oct 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused change preserves uncertain escrows for settlement, has regression coverage, and has no unresolved findings.

No open issues 🎉

What changed in this PR

Prevents duplicate payment-pool escrow when a gateway answers a submission with replacement transaction underpriced, addressing #2565.

Changes:

  • Classifies underpriced replacements as possibly broadcast.
  • Removes fresh-nonce top-up retries, retaining uncertain submissions for existing settlement.
  • Updates regression tests and operational documentation.
File Description
docs/​runbook.md Documents additional unresolved top-up causes.
crates/​incentive/​src/​tx/​tests.rs Tests uncertain classification and receipt outcomes.
crates/​incentive/​src/​tx/​send_leg/​tests.rs Updates underpriced-send expectations.
crates/​incentive/​src/​tx.rs Classifies underpriced replacements as uncertain.
crates/​client/​src/​source_set.rs Removes obsolete retry documentation.
crates/​client/​src/​scheduler.rs Updates drain documentation.
crates/​client/​src/​funding.rs Updates cancellation documentation.
crates/​client/​src/​buyer_pool/​tests.rs Tests escrow retention, no retry, and cancellation.
crates/​client/​src/​buyer_pool.rs Removes collision retries while preserving escrow tracking.
CHANGELOG.md Describes payment safety and cancellation behavior.
adr/​appendix-observability.md Updates unresolved-escrow gauge descriptions.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main ea31fba fix/2565-underpriced... 3d8d750 +/-
77% 77% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 20, 2026 22:19 UTC

… is described

Every doc site that enumerated the answers `send_broadcast_unknown` reads
as uncertain stopped at `already known` / `nonce too low`; some now stated
the opposite of the code. Outer layers (`publish`, `pool`, the keeper,
`source`) now point at the classifier instead of re-listing, and the
`SendOutcome`, `send_for_receipt`, `open_pool`, `ensure_allowance` and
`*Unconfirmed` docs name all three. The runtime comment that said a racing
collision "gets a fresh nonce on the next attempt" now says an `openPool`
or `topUp` is held at its nonce and settled.

Tests: a bare `transaction underpriced` fee rejection stays a rejection;
the open-pool underpriced test asserts the `RpcError` reason and the
exact RPC consumption; the node settle has a composition test for a
hashless `topUp` that waits out the colliding transaction and ends
"escrowed nothing".

Co-Authored-By: Claude Fable 5.1 <[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.

topUp re-send on replacement transaction underpriced can double-escrow under a gateway retry

2 participants