Skip to content

Commit 1a6a0b0

Browse files
committed
wallet: Use existing feerate instead of getting a new one
During each loop of CreateTransaction, instead of constantly getting a new feerate, use the feerate that we have already fetched for all fee calculations. Thix fixes a race condition where the feerate required changes during each iteration of the loop. This commit changes behavior as the "Fee estimation failed" error will now take priority over "Signing transaction failed".
1 parent ea5a50f commit 1a6a0b0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,11 @@ bool CWallet::CreateTransactionInternal(
28142814
error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(FeeEstimateMode::SAT_VB), nFeeRateNeeded.ToString(FeeEstimateMode::SAT_VB));
28152815
return false;
28162816
}
2817+
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
2818+
// eventually allow a fallback fee
2819+
error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
2820+
return false;
2821+
}
28172822

28182823
nFeeRet = 0;
28192824
bool pick_new_inputs = true;
@@ -2951,13 +2956,7 @@ bool CWallet::CreateTransactionInternal(
29512956
return false;
29522957
}
29532958

2954-
nFeeNeeded = GetMinimumFee(*this, nBytes, coin_control, &feeCalc);
2955-
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
2956-
// eventually allow a fallback fee
2957-
error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
2958-
return false;
2959-
}
2960-
2959+
nFeeNeeded = coin_selection_params.effective_fee.GetFee(nBytes);
29612960
if (nFeeRet >= nFeeNeeded) {
29622961
// Reduce fee to only the needed amount if possible. This
29632962
// prevents potential overpayment in fees if the coins
@@ -2971,7 +2970,7 @@ bool CWallet::CreateTransactionInternal(
29712970
// change output. Only try this once.
29722971
if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && pick_new_inputs) {
29732972
unsigned int tx_size_with_change = nBytes + coin_selection_params.change_output_size + 2; // Add 2 as a buffer in case increasing # of outputs changes compact size
2974-
CAmount fee_needed_with_change = GetMinimumFee(*this, tx_size_with_change, coin_control, nullptr);
2973+
CAmount fee_needed_with_change = coin_selection_params.effective_fee.GetFee(tx_size_with_change);
29752974
CAmount minimum_value_for_change = GetDustThreshold(change_prototype_txout, discard_rate);
29762975
if (nFeeRet >= fee_needed_with_change + minimum_value_for_change) {
29772976
pick_new_inputs = false;

0 commit comments

Comments
 (0)