Merge bitcoin/bitcoin#34870: wallet: feebumper, fix crash when combined bump fee is unavailable

6072a2a6a1 wallet: feebumper, fix crash when combined bump fee is unavailable (furszy)

Pull request description:

  When a large cluster of unconfirmed transactions exceeds the limit,
  `calculateCombinedBumpFee()` returns `std::nullopt`.

  Previously, we continued executing and the optional value was
  accessed unconditionally, leading to a `std::bad_optional_access`
  exception (https://en.cppreference.com/w/cpp/utility/optional/value.html).

  Fix this by returning early when the bumped fee is null.

  Note:
  This is a crash for the GUI, and an uncaught exception for the RPC
  `bumpfee` and `psbtbumpfee`.

ACKs for top commit:
  achow101:
    ACK 6072a2a6a1
  luke-jr:
    utACK 6072a2a6a1
  rkrux:
    crACK 6072a2a6a1 based on returning before accessing the null optional.

Tree-SHA512: f863ace1426b2e743e2281e5c624b523de7317c1f305f88f369e77d60005460e4af58b424bc784304fd1ac30a3bfa575137537ec334fa6e449c827daeb262a99
This commit is contained in:
Ava Chow
2026-03-23 17:51:23 -07:00

View File

@@ -80,9 +80,10 @@ static feebumper::Result CheckFeeRate(const CWallet& wallet, const CMutableTrans
reused_inputs.push_back(txin.prevout);
}
std::optional<CAmount> combined_bump_fee = wallet.chain().calculateCombinedBumpFee(reused_inputs, newFeerate);
const std::optional<CAmount> combined_bump_fee = wallet.chain().calculateCombinedBumpFee(reused_inputs, newFeerate);
if (!combined_bump_fee.has_value()) {
errors.push_back(Untranslated(strprintf("Failed to calculate bump fees, because unconfirmed UTXOs depend on an enormous cluster of unconfirmed transactions.")));
return feebumper::Result::WALLET_ERROR;
}
CAmount new_total_fee = newFeerate.GetFee(maxTxSize) + combined_bump_fee.value();