Skip to content

Commit e420a1b

Browse files
committed
Add sane fallback for fee estimation
Add new commandline option "-fallbackfee" to use when fee estimation does not have sufficient data.
1 parent 995b9f3 commit e420a1b

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/init.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ std::string HelpMessage(HelpMessageMode mode)
393393
strUsage += HelpMessageGroup(_("Wallet options:"));
394394
strUsage += HelpMessageOpt("-disablewallet", _("Do not load the wallet and disable wallet RPC calls"));
395395
strUsage += HelpMessageOpt("-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), DEFAULT_KEYPOOL_SIZE));
396+
strUsage += HelpMessageOpt("-fallbackfee=<amt>", strprintf(_("A fee rate (in %s/kB) that will be used when fee estimation has insufficient data (default: %s)"),
397+
CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE)));
396398
strUsage += HelpMessageOpt("-mintxfee=<amt>", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)"),
397399
CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE)));
398400
strUsage += HelpMessageOpt("-paytxfee=<amt>", strprintf(_("Fee (in %s/kB) to add to transactions you send (default: %s)"),
@@ -947,6 +949,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
947949
else
948950
return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"]));
949951
}
952+
if (mapArgs.count("-fallbackfee"))
953+
{
954+
CAmount nFeePerK = 0;
955+
if (!ParseMoney(mapArgs["-fallbackfee"], nFeePerK))
956+
return InitError(strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), mapArgs["-fallbackfee"]));
957+
if (nFeePerK > nHighTransactionFeeWarning)
958+
InitWarning(_("-fallbackfee is set very high! This is the transaction fee you may pay when fee estimates are not available."));
959+
CWallet::fallbackFee = CFeeRate(nFeePerK);
960+
}
950961
if (mapArgs.count("-paytxfee"))
951962
{
952963
CAmount nFeePerK = 0;

src/qt/sendcoinsdialog.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,15 @@ void SendCoinsDialog::updateSmartFeeLabel()
640640
CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks);
641641
if (feeRate <= CFeeRate(0)) // not enough data => minfee
642642
{
643-
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB");
643+
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(),
644+
std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB");
644645
ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...)
645646
ui->labelFeeEstimation->setText("");
646647
}
647648
else
648649
{
649-
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB");
650+
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(),
651+
std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB");
650652
ui->labelSmartFee2->hide();
651653
ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks));
652654
}

src/wallet/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
4747
* Override with -mintxfee
4848
*/
4949
CFeeRate CWallet::minTxFee = CFeeRate(DEFAULT_TRANSACTION_MINFEE);
50+
/**
51+
* If fee estimation does not have enough data to provide estimates, use this fee instead.
52+
* Has no effect if not using fee estimation
53+
* Override with -fallbackfee
54+
*/
55+
CFeeRate CWallet::fallbackFee = CFeeRate(DEFAULT_FALLBACK_FEE);
5056

5157
/** @defgroup mapWallet
5258
*
@@ -2223,6 +2229,9 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
22232229
if (nFeeNeeded == 0) {
22242230
int estimateFoundTarget = nConfirmTarget;
22252231
nFeeNeeded = pool.estimateSmartFee(nConfirmTarget, &estimateFoundTarget).GetFee(nTxBytes);
2232+
// ... unless we don't have enough mempool data for estimatefee, then use fallbackFee
2233+
if (nFeeNeeded == 0)
2234+
nFeeNeeded = fallbackFee.GetFee(nTxBytes);
22262235
}
22272236
// prevent user from paying a fee below minRelayTxFee or minTxFee
22282237
nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
4141
static const CAmount DEFAULT_TRANSACTION_FEE = 0;
4242
//! -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
4343
static const CAmount nHighTransactionFeeWarning = 0.01 * COIN;
44+
//! -fallbackfee default
45+
static const CAmount DEFAULT_FALLBACK_FEE = 20000;
4446
//! -mintxfee default
4547
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
4648
//! -maxtxfee default
@@ -666,6 +668,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
666668
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
667669

668670
static CFeeRate minTxFee;
671+
static CFeeRate fallbackFee;
669672
/**
670673
* Estimate the minimum fee considering user set parameters
671674
* and the required fee

0 commit comments

Comments
 (0)