Make QT fee displays use GetMinimumFee instead of estimateSmartFee

Remove helper function (CalculateEstimateType) for determining whether
estimates should be conservative or not, now that this is only called
once from GetMinimumFee and incorporate the logic directly there.
pull/384/head
Alex Morcos 7 years ago
parent 1983ca6cb3
commit 2fffaa9738

@ -490,8 +490,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
else nBytesInputs += 148; else nBytesInputs += 148;
} }
bool conservative_estimate = CalculateEstimateType(FeeEstimateMode::UNSET, coinControl->signalRbf);
// calculation // calculation
if (nQuantity > 0) if (nQuantity > 0)
{ {
@ -583,12 +581,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold."); QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold.");
// how many satoshis the estimated fee can vary per byte we guess wrong // how many satoshis the estimated fee can vary per byte we guess wrong
double dFeeVary; double dFeeVary = (double)nPayFee / nBytes;
if (payTxFee.GetFeePerK() > 0)
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), payTxFee.GetFeePerK()) / 1000;
else {
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), ::feeEstimator.estimateSmartFee(*coinControl->m_confirm_target, NULL, ::mempool, conservative_estimate).GetFeePerK()) / 1000;
}
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary); QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
l3->setToolTip(toolTip4); l3->setToolTip(toolTip4);

@ -652,7 +652,7 @@ void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)
if (ui->radioCustomFee->isChecked()) { if (ui->radioCustomFee->isChecked()) {
ctrl.m_feerate = CFeeRate(ui->customFee->value()); ctrl.m_feerate = CFeeRate(ui->customFee->value());
} else { } else {
ctrl.m_feerate = boost::none; ctrl.m_feerate.reset();
} }
// Avoid using global defaults when sending money from the GUI // Avoid using global defaults when sending money from the GUI
// Either custom fee will be used or if not selected, the confirmation target from dropdown box // Either custom fee will be used or if not selected, the confirmation target from dropdown box
@ -666,15 +666,13 @@ void SendCoinsDialog::updateSmartFeeLabel()
return; return;
CCoinControl coin_control; CCoinControl coin_control;
updateCoinControlState(coin_control); updateCoinControlState(coin_control);
coin_control.m_feerate = boost::none; // Explicitly use only fee estimation rate for smart fee labels coin_control.m_feerate.reset(); // Explicitly use only fee estimation rate for smart fee labels
FeeCalculation feeCalc; FeeCalculation feeCalc;
bool conservative_estimate = CalculateEstimateType(FeeEstimateMode::UNSET, coin_control.signalRbf); CFeeRate feeRate = CFeeRate(CWallet::GetMinimumFee(1000, coin_control, ::mempool, ::feeEstimator, &feeCalc));
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(*coin_control.m_confirm_target, &feeCalc, ::mempool, conservative_estimate);
if (feeRate <= CFeeRate(0)) // not enough data => minfee ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB");
{
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), if (feeCalc.reason == FeeReason::FALLBACK) {
std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB");
ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...)
ui->labelFeeEstimation->setText(""); ui->labelFeeEstimation->setText("");
ui->fallbackFeeWarningLabel->setVisible(true); ui->fallbackFeeWarningLabel->setVisible(true);
@ -685,8 +683,6 @@ void SendCoinsDialog::updateSmartFeeLabel()
} }
else else
{ {
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(),
std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB");
ui->labelSmartFee2->hide(); ui->labelSmartFee2->hide();
ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", feeCalc.returnedTarget)); ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", feeCalc.returnedTarget));
ui->fallbackFeeWarningLabel->setVisible(false); ui->fallbackFeeWarningLabel->setVisible(false);

@ -43,9 +43,9 @@ public:
fAllowOtherInputs = false; fAllowOtherInputs = false;
fAllowWatchOnly = false; fAllowWatchOnly = false;
setSelected.clear(); setSelected.clear();
m_feerate = boost::none; m_feerate.reset();
fOverrideFeeRate = false; fOverrideFeeRate = false;
m_confirm_target = boost::none; m_confirm_target.reset();
signalRbf = fWalletRbf; signalRbf = fWalletRbf;
m_fee_mode = FeeEstimateMode::UNSET; m_fee_mode = FeeEstimateMode::UNSET;
} }

@ -2945,8 +2945,11 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_c
else { // 2. or 4. else { // 2. or 4.
// We will use smart fee estimation // We will use smart fee estimation
unsigned int target = coin_control.m_confirm_target ? *coin_control.m_confirm_target : ::nTxConfirmTarget; unsigned int target = coin_control.m_confirm_target ? *coin_control.m_confirm_target : ::nTxConfirmTarget;
// By default estimates are economical iff we are signaling opt-in-RBF
bool conservative_estimate = !coin_control.signalRbf;
// Allow to override the default fee estimate mode over the CoinControl instance // Allow to override the default fee estimate mode over the CoinControl instance
bool conservative_estimate = CalculateEstimateType(coin_control.m_fee_mode, coin_control.signalRbf); if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true;
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false;
fee_needed = estimator.estimateSmartFee(target, feeCalc, pool, conservative_estimate).GetFee(nTxBytes); fee_needed = estimator.estimateSmartFee(target, feeCalc, pool, conservative_estimate).GetFee(nTxBytes);
if (fee_needed == 0) { if (fee_needed == 0) {
@ -4194,15 +4197,3 @@ bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState&
{ {
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee); return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee);
} }
bool CalculateEstimateType(FeeEstimateMode mode, bool opt_in_rbf) {
switch (mode) {
case FeeEstimateMode::UNSET:
return !opt_in_rbf; // Allow for lower fees if RBF is an option
case FeeEstimateMode::CONSERVATIVE:
return true;
case FeeEstimateMode::ECONOMICAL:
return false;
}
return true;
}

@ -1213,6 +1213,4 @@ bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins
return true; return true;
} }
bool CalculateEstimateType(FeeEstimateMode mode, bool opt_in_rbf);
#endif // BITCOIN_WALLET_WALLET_H #endif // BITCOIN_WALLET_WALLET_H

Loading…
Cancel
Save