Skip to content

Commit

Permalink
[wallet]: warn user if 1kvb tx with -maxtxfee base fee has fee rate…
Browse files Browse the repository at this point in the history
… less than `minrelaytxfee`

- Wallet prevents creating transactions with fee rates lower than `-minrelaytxfee`.
  Also prevents creating a transaction with a base fee above `-maxtxfee`.

- Warn user if a 1kvb transaction, with a base fee set to `-maxtxfee`, has a fee rate less than
  `-minrelaytxfee`. It is likely that some transactions with fee rates greater than or equal
  to the `-minrelaytxfee` will also likely exceed `-maxtxfee`, the wallet won't be able to create
  transactions.
  • Loading branch information
ismaelsadeeq committed Feb 20, 2025
1 parent 16eedb9 commit 15e82f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,15 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
return nullptr;
} else if (max_tx_fee.value() > HIGH_MAX_TX_FEE) {
warnings.push_back(strprintf(_("%s is set very high! Fees this large could be paid on a single transaction."), "-maxtxfee"));

// Wallet prevents creating transactions with fee rates lower than minrelaytxfee.
// Also the wallet prevents creating transaction with base fee above maxtxfee.
// Warn when a 1kvb transaction, with a base fee set to maxtxfee, has a fee rate less than minrelaytxfee.
// It is likely that some transactions with fee rates greater than or equal to the minrelaytxfee will exceed maxtxfee.
// In such cases, the wallet won't be able to create transactions. Therefore, warn the user.
} else if (chain && CFeeRate(max_tx_fee.value(), 1000) < chain->relayMinFee()) {
warnings.push_back(strprintf(_("Invalid amount for %s=<amount>: '%s' conflicts with the minimum relay transaction feerate %s. Please set a higher %s or lower %s"),
"-maxtxfee", args.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString(), "-maxtxfee", "-minrelaytxfee"));
}

walletInstance->m_max_tx_fee = max_tx_fee.value();
Expand Down
14 changes: 14 additions & 0 deletions test/functional/wallet_bumpfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,20 @@ def test_maxtxfee_fails(self, rbf_node, dest_address):

# When user passed fee rate causes base fee to be above maxtxfee we fail early
assert_raises_rpc_error(-4, "Specified or calculated fee 0.0000282 is too high (cannot be higher than -maxtxfee 0.000025)", rbf_node.bumpfee, rbfid, fee_rate=20)

self.log.info("Test that a low -maxtxfee, which may prevent tx fee rate from reaching -minrelaytxfee triggers a warning.")
low_max_tx_fee = '0.000001'
high_max_tx_fee = '0.001'
high_min_relay_fee = '0.0002'
msg = f"Invalid amount for -maxtxfee=<amount>: '{low_max_tx_fee}' conflicts with the minimum relay transaction feerate {format(float(high_min_relay_fee), '.8f')} BTC/kvB. Please set a higher -maxtxfee or lower -minrelaytxfee"
self.restart_node(1, extra_args=[f'-minrelaytxfee={high_min_relay_fee}', f'-maxtxfee={low_max_tx_fee}'])
warnings = self.nodes[1].createwallet("test-wallet")["warnings"]
assert msg in warnings

self.log.info("Test that a -maxtxfee high enough to allow tx fee rate to meet or exceed -minrelaytxfee should start normally.")
msg = "Warning: " + msg
self.stop_node(1, expected_stderr=msg)
self.start_node(1, extra_args=[f'-minrelaytxfee={high_min_relay_fee}', f'-maxtxfee={high_max_tx_fee}'])
self.restart_node(1, self.extra_args[1])
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
self.connect_nodes(1, 0)
Expand Down

0 comments on commit 15e82f0

Please sign in to comment.