Skip to content

Commit 4fe2823

Browse files
committed
Change wallet and GUI code to use new smart fee estimation calls.
1 parent 22eca7d commit 4fe2823

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
538538
nBytes = nBytesInputs + ((CoinControlDialog::payAmounts.size() > 0 ? CoinControlDialog::payAmounts.size() + 1 : 2) * 34) + 10; // always assume +1 output for change here
539539

540540
// Priority
541-
double mempoolEstimatePriority = mempool.estimatePriority(nTxConfirmTarget);
541+
double mempoolEstimatePriority = mempool.estimateSmartPriority(nTxConfirmTarget);
542542
dPriority = dPriorityInputs / (nBytes - nBytesInputs + (nQuantityUncompressed * 29)); // 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 bytes of the input are ignored for priority)
543543
sPriorityLabel = CoinControlDialog::getPriorityLabel(dPriority, mempoolEstimatePriority);
544544

@@ -550,10 +550,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
550550
// Fee
551551
nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
552552

553-
// Allow free?
554-
double dPriorityNeeded = mempoolEstimatePriority;
555-
if (dPriorityNeeded <= 0)
556-
dPriorityNeeded = AllowFreeThreshold(); // not enough data, back to hard-coded
553+
// Allow free? (require at least hard-coded threshold and default to that if no estimate)
554+
double dPriorityNeeded = std::max(mempoolEstimatePriority, AllowFreeThreshold());
557555
fAllowFree = (dPriority >= dPriorityNeeded);
558556

559557
if (fSendFreeTransactions)
@@ -649,8 +647,9 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
649647
double dFeeVary;
650648
if (payTxFee.GetFeePerK() > 0)
651649
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), payTxFee.GetFeePerK()) / 1000;
652-
else
653-
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), mempool.estimateFee(nTxConfirmTarget).GetFeePerK()) / 1000;
650+
else {
651+
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), mempool.estimateSmartFee(nTxConfirmTarget).GetFeePerK()) / 1000;
652+
}
654653
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
655654

656655
l3->setToolTip(toolTip4);
@@ -686,7 +685,7 @@ void CoinControlDialog::updateView()
686685
QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
687686

688687
int nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
689-
double mempoolEstimatePriority = mempool.estimatePriority(nTxConfirmTarget);
688+
double mempoolEstimatePriority = mempool.estimateSmartPriority(nTxConfirmTarget);
690689

691690
std::map<QString, std::vector<COutput> > mapCoins;
692691
model->listCoins(mapCoins);

src/qt/sendcoinsdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ void SendCoinsDialog::updateSmartFeeLabel()
633633
return;
634634

635635
int nBlocksToConfirm = defaultConfirmTarget - ui->sliderSmartFee->value();
636-
CFeeRate feeRate = mempool.estimateFee(nBlocksToConfirm);
636+
int estimateFoundAtBlocks = nBlocksToConfirm;
637+
CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks);
637638
if (feeRate <= CFeeRate(0)) // not enough data => minfee
638639
{
639640
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB");
@@ -644,7 +645,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
644645
{
645646
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB");
646647
ui->labelSmartFee2->hide();
647-
ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", nBlocksToConfirm));
648+
ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks));
648649
}
649650

650651
updateFeeMinimizedLabel();

src/wallet/wallet.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,14 +2033,10 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
20332033
if (fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
20342034
{
20352035
// Not enough fee: enough priority?
2036-
double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
2037-
// Not enough mempool history to estimate: use hard-coded AllowFree.
2038-
if (dPriorityNeeded <= 0 && AllowFree(dPriority))
2039-
break;
2040-
2041-
// Small enough, and priority high enough, to send for free
2042-
if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded)
2043-
break;
2036+
double dPriorityNeeded = mempool.estimateSmartPriority(nTxConfirmTarget);
2037+
// Require at least hard-coded AllowFree.
2038+
if (dPriority >= dPriorityNeeded && AllowFree(dPriority))
2039+
break;
20442040
}
20452041

20462042
CAmount nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
@@ -2131,12 +2127,14 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
21312127
if (fPayAtLeastCustomFee && nFeeNeeded > 0 && nFeeNeeded < payTxFee.GetFeePerK())
21322128
nFeeNeeded = payTxFee.GetFeePerK();
21332129
// User didn't set: use -txconfirmtarget to estimate...
2134-
if (nFeeNeeded == 0)
2135-
nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
2136-
// ... unless we don't have enough mempool data, in which case fall
2137-
// back to the required fee
2138-
if (nFeeNeeded == 0)
2139-
nFeeNeeded = GetRequiredFee(nTxBytes);
2130+
if (nFeeNeeded == 0) {
2131+
int estimateFoundTarget = nConfirmTarget;
2132+
nFeeNeeded = pool.estimateSmartFee(nConfirmTarget, &estimateFoundTarget).GetFee(nTxBytes);
2133+
// ... unless we don't have enough mempool data for our desired target
2134+
// so we make sure we're paying at least minTxFee
2135+
if (nFeeNeeded == 0 || (unsigned int)estimateFoundTarget > nConfirmTarget)
2136+
nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));
2137+
}
21402138
// prevent user from paying a non-sense fee (like 1 satoshi): 0 < fee < minRelayFee
21412139
if (nFeeNeeded < ::minRelayTxFee.GetFee(nTxBytes))
21422140
nFeeNeeded = ::minRelayTxFee.GetFee(nTxBytes);

0 commit comments

Comments
 (0)