Skip to content

feat(key-wallet-manager)!: give TransactionsSwept the winner's block - #1507

Merged
xdustinface merged 1 commit into
devfrom
fix/swept-winner-block
Nov 27, 2026
Merged

xdustinface merged 1 commit into
devfrom
fix/swept-winner-block

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

WalletEvent::TransactionsSwept reports a mined winner by height only. A consumer that keeps the sweep as evidence has to check later that the winner's block is still on the active chain, and a height can't say which branch mined it. A header lookup made after the event may already answer for a replacement branch, for example when the consumer misses a ChainTruncated while its event monitor restarts.

winner_mined_height: Option<CoreBlockHeight> becomes winner_block: Option<BlockInfo>. It holds the winner's height, block hash and position as the processed block gives them, and stays None for an InstantSend-locked winner. Display prints height@hash.

Breaking: callers that read winner_mined_height use winner_block.map(|b| b.height()).

Tests: test_block_winner_emits_swept_event_naming_the_released_outpoints now places the winner at index 1 of its block and checks its height, hash and position. transactions_swept_display_reports_the_winners_finality_context covers both display forms. cargo fmt --all --check, contrib/run_clippy.py, cargo doc with -D warnings, and the CI wallet group pass.

🤖 Generated with Claude Code

PR Hygiene · 6939476

  • Bots — coderabbitai skipped after its own rate limit
  • Self-review — posted; again after any push
  • Build green
  • Approvals
    • key-wallet-manager (key-wallet-manager/src/event_tests.rs, key-wallet-manager/src/events.rs, key-wallet-manager/src/process_block.rs) — QuantumExplorer or ZocoLini or xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

`TransactionsSwept` gives a mined winner's height only. A consumer that keeps the sweep as evidence must later check that the winner's block is still on the active chain, and the height alone cannot say which branch mined it: a header lookup made after the event may already answer for a replacement branch, for example when the consumer misses a `ChainTruncated` while its event monitor restarts.

`winner_mined_height: Option<CoreBlockHeight>` becomes `winner_block: Option<BlockInfo>`: the winner's height, block hash and position as the processed block gives them, and `None` for an InstantSend-locked winner as before. `Display` prints `height@hash`.

BREAKING CHANGE: `WalletEvent::TransactionsSwept::winner_mined_height` is replaced by `winner_block`; use `winner_block.map(|b| b.height())` for the height.

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

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fc124a8 and 6939476.

Files selected for processing: 3

  • key-wallet-manager/src/event_tests.rs
  • key-wallet-manager/src/events.rs
  • key-wallet-manager/src/process_block.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PastaPastaPasta

PastaPastaPasta commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Pre-review record for head 693947608ada1846f0052af6b6023f8829fc081f.

An independent automated code review read the first version, then re-read this exact head. Verdict: approved with suggestions.

Fixed before this head:

  • The block test placed the winner alone in its block, so a wrong position of 0 would have passed. The winner now sits at index 1 behind an unrelated transaction, and the test checks its height, hash and position.
  • Renamed the local block in that test, which was shadowed by the event field of the same name.
  • Field doc and test wording now say "block" instead of "height". Dropped a comment that restated the code.

Left as is:

  • The winner_block field doc is longer than three lines. It was already long on dev.
  • The event doesn't say whether the winner's block was chainlocked when it was processed. A consumer still learns that from ChainLockProcessed.

🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.53%. Comparing base (6e15db8) to head (6939476).
⚠️ Report is 16 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1507   +/-   ##
=======================================
  Coverage   87.53%   87.53%           
=======================================
  Files         270      270           
  Lines       71309    71313    +4     
=======================================
+ Hits        62421    62427    +6     
+ Misses       8888     8886    -2     
Flag Coverage Δ
core 83.40% <100.00%> (+0.01%) ⬆️
rpc 83.40% <100.00%> (+0.01%) ⬆️
spv 94.97% <ø> (-0.02%) ⬇️
wallet 83.40% <100.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
key-wallet-manager/src/events.rs 69.10% <100.00%> (+0.51%) ⬆️
key-wallet-manager/src/process_block.rs 95.76% <ø> (ø)

... and 7 files with indirect coverage changes

PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
The two TransactionsSwept events #1520 adds set winner_block, the field
#1507 renamed from winner_mined_height.
PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
…persistence

The events.rs imports combine #1507's BlockInfo with #1522's DismissalChange.
PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
…ture

Merges fix/pending-spend-authorization at 920f103 (built on #1416 at f134961).

Conflict resolutions:
- key-wallet-manager events.rs and process_block.rs: R9's wording for the drop trigger combined with #1507's `winner_block` field; R9's event test reads `winner_block: None`.
- key-wallet helpers.rs: #1518/#1519's dismissal and give-back helpers and R9's authorization helpers are kept side by side; imports are merged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PastaPastaPasta
PastaPastaPasta marked this pull request as ready for review November 27, 2026 03:06
@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@manki-review

manki-review Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Review complete in 6m 55s

Planner (5s)
    refactor · 97 lines · 2 agents
    judge effort: medium

Review (security · full): 10 findings
    ✅ Claude Opus 5.5 · high: 1 finding (1m 19s)
    ✅ GPT 6.2 Sol · high: 4 findings (2m 26s)
    ✅ Related checks and claim checks: 12 of 12 done, 5 findings (1m 54s)
    ✅ Second reads: 1 of 1 done (18s)

Judge (2m 26s)
    graded 10 findings: 1 kept · 3 dropped · 6 merged
    dropped, as the finders filed them: 1 blocker · 2 warnings
    refuter: 1 checked · 1 unsettled
    origin checks: 1 checked
    verdict reader: read the diff (20s)

Posted: 1 finding
    1 warning

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 31% (resets 2026-12-02 17:00 UTC)
  • ChatGPT subscription: weekly 4% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "dashpay/platform stops compiling against this version: it still reads and builds winner_mined_height" (warning): "warning. The rename at key-wallet-manager/src/events.rs:266 removes winner_mined_height. The consumer still binds it in dashpay/platform:packages/rs-platform-wallet/src/changeset/core_bridge.rs:1833, copies it at :1872 and builds the variant with it at payment_handler.rs:486. All three are compile errors after the upgrade. The PR description calls the change breaking and gives a migration (winner_block.map(|b| b.height())). Under the rule for consumer breaks, that makes this a warning, not a blocker. The consumer's SweepBatch stores only a height, so it also needs widening to keep the new block hash.", trigger 7 and harm 4 of 10: "Any downstream consumer that upgrades to this version and uses the renamed field fails to compile at once."
  • Dropped: "A sweep can name a different block from the one that contained the winner" (ignore): "ignore. The event carries tx_info, which is the same BlockInfo that stamps every record of this block (key-wallet-manager/src/process_block.rs:44 and :80). A caller that passes a hash that does not match its block therefore already mislabels every stored record before this PR. Passing a mismatched hash breaks the documented parameter contract and is not a defect this change introduces. The dash-spv caller passes the hash of its HashedBlock.
    Refutation disproved: The only non-test caller is dash-spv's apply_block. It passes block.block() and *block.hash() from the same HashedBlock. That type's fields are private, and it is made only through From or From<&Block>, which compute block.block_hash(), or through Decodable, which reads back the hash Encodable wrote next to its own block. Every in-repo test and consumer call passes x.block_hash() for the same block x, so normal use never produces a mismatched pair. Even a caller that broke this contract w... Rule checked: A block and the hash passed beside it can disagree only if some caller builds them separately; a HashedBlock whose fields are private and which is only made by hashing its block, or by decoding what it encoded itself, always pairs a block with its own hash.
  • Premise "every caller of process_block_for_wallets passes the hash of the block it passes" confirmed. The production caller passes the hash cached in the same HashedBlock, and that cache is set from block.block_hash() or decoded from its own encoding. Every other caller found, in tests and in dashpay/platform, passes block.block_hash() for the block it passes.
    Pair refutation confirmed: A mismatched pair would put the supplied hash and the winner’s actual transaction position into the emitted sweep event. Storage replay can forward that pair unchecked, but the normal network path computes the hash before saving the block, and I found no caller or stored example that supplies a mismatch. Rule checked: Decoding a block and its cached hash separately does not establish that the hash belongs to the block.
  • Premise "every caller of process_block_for_wallets passes the hash of the block it passes" disproved. The storage replay caller does not guarantee a matching hash: it loads a block whose cached hash was decoded independently, then forwards both values without recomputing or comparing the hash."
  • Dropped: "Sweep events omit account balances changed by removing the loser" (ignore): "ignore. account_balances: BTreeMap::new() at process_block.rs:155 and the mempool snapshot logic are unchanged context lines. The PR only replaces the winner field, so it neither causes nor exposes this behaviour."
  • Dropped: "A late InstantSend delivery may report a mined winner as unmined" (ignore): "ignore. Line 316 only renames winner_mined_height: None to winner_block: None. The mempool path emitted None the same way before this PR, and the ordering in wallet_checker.rs is untouched. The PR does not affect whether a late IS delivery can sweep."

Timing:

  • Parse: 6.4s
  • Review agents: 263.0s
  • Judge: 145.9s
  • Total: 415.2s

Last reviewed 6939476 · head 6939476 · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review

@manki-review manki-review Bot 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.

⚠️ 1 warning to address. Fix it, reply in its thread with a reason Manki accepts, or tick Create an issue for this to track it for later. Manki approves once every warning is handled.

About this review
  • Reviewed 6939476, round 1
  • 97 changed lines read in 6m 55s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 4.4M in (3.5M from cache) · 48k out · about $5.11 at API prices
  • Runner: self-hosted · started after 7m 37s · peak memory 2.7 GiB of 30.0 GiB
  • How Manki reviews

Comment thread key-wallet-manager/src/events.rs Resolved

@manki-review manki-review Bot 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.

✅ Approved. All blocking threads are resolved, and no warning thread holds the approval.

What this does: A sweep event used to report only the height of the block whose transaction beat the removed spends. It now reports that block's hash, height and the winner's position in it.

What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: A wallet manager with a funded wallet holding two coins from one funding transaction, and a subscriber on subscribe_events.

  1. Record a mempool spend of both coins, then process a block whose second transaction spends only the first coin. Expect one TransactionsSwept with winner_block set to that block's hash and height and position() equal to Some(1).
  2. In the same scenario, check released_outpoints. Expect only the second coin.
  3. Format that event with Display. Expect the text winner_block=<height>@<hash>.
  4. Instead of a block, deliver the winning spend from the mempool with an InstantSend lock. Expect TransactionsSwept with winner_block equal to None and Display showing winner_block=None.
  5. Process the same winner in two blocks with different hashes at the same height. Expect each sweep to carry its own block hash.

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

/self-reviewed 6939476

@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — key-wallet-manager: QuantumExplorer or ZocoLini or xdustinface.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 27, 2026
@xdustinface
xdustinface merged commit 9f62a5e into dev Nov 27, 2026
36 of 37 checks passed
@xdustinface
xdustinface deleted the fix/swept-winner-block branch November 27, 2026 23:10
manki-review Bot added a commit to manki-review/review-memory that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants