0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

[wallet]: warn user if 1kvb tx with -maxtxfee base fee has fee rate 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.
This commit is contained in:
ismaelsadeeq 2025-01-23 14:16:27 -05:00
parent 02cb132dbe
commit ce0f154689
No known key found for this signature in database
GPG key ID: 0E3908F364989888
2 changed files with 23 additions and 0 deletions

View file

@ -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();

View file

@ -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)