Skip to content

wallet: SetBumpFeeDiscount(const CAmount): Assertion `discount >= 0' failed #34232

Closed

Description

@dergoegge

I hit this assertion in a test running on Antithesis.

Vibe coded functional test to demonstrate: dergoegge@587e42c. Because this is caused by a race condition, the commit also includes a sleep to reliably trigger the issue.

node0 stderr bitcoind: wallet/coinselection.cpp:823: void wallet::SelectionResult::SetBumpFeeDiscount(const CAmount): Assertion `discount >= 0' failed.
Here's an LLM's explanation for the bug:

Bug

Assertion discount >= 0 fails in SelectionResult::SetBumpFeeDiscount (src/wallet/coinselection.cpp:823).

Found during Antithesis testing with concurrent transaction creation.

Root Cause

Race condition between two MiniMiner calculations during coin selection:

  1. Individual bump fees calculated in AvailableCoins (spend.cpp:517) via calculateIndividualBumpFees() - creates MiniMiner, copies mempool state, releases lock
  2. Combined bump fee calculated later in ChooseSelectionResult (spend.cpp:809) via calculateCombinedBumpFee() - creates a new MiniMiner with potentially different mempool state

Each MiniMiner constructor acquires LOCK(mempool.cs) only for the duration of the constructor (mini_miner.cpp:26). The lock is released before the actual fee calculations run.

If mempool state changes between these two calls (e.g., fee deltas modified via prioritisetransaction, new transactions, evictions), the combined calculation can return a higher value than the sum of individual calculations:

// spend.cpp:813-815
CAmount bump_fee_overestimate = summed_bump_fees - combined_bump_fee.value();
if (bump_fee_overestimate) {
    result.SetBumpFeeDiscount(bump_fee_overestimate);  // negative if combined > summed
}

Activity

  1. vamshi567bh commented on Jan 29, 2026

    @vamshi567bh

    @fanquake Can I work on this

  2. added a commit that references this issue on Feb 7, 2026
    c43bd10
  3. added a commit that references this issue on Jul 14, 2026
  4. added a commit that references this issue on Jul 19, 2026
  5. added a commit that references this issue on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions