diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 72cc4889768..04895fca6f5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3192,6 +3192,15 @@ std::shared_ptr 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=: '%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(); diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index ff7a57cbc6d..849ba56e5a8 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -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=: '{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)