Skip to content

Commit 13fc83c

Browse files
committed
Move fee policy out of core
1 parent 4b7b1bb commit 13fc83c

16 files changed

+70
-61
lines changed

src/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
8080
nSatoshisPerK = 0;
8181
}
8282

83-
int64_t CFeeRate::GetFee(size_t nSize)
83+
int64_t CFeeRate::GetFee(size_t nSize) const
8484
{
8585
return nSatoshisPerK*nSize / 1000;
8686
}

src/core.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ class CFeeRate
125125
CFeeRate(int64_t nFeePaid, size_t nSize);
126126
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
127127

128-
int64_t GetFee(size_t size); // unit returned is satoshis
129-
int64_t GetFeePerK() { return GetFee(1000); } // satoshis-per-1000-bytes
128+
int64_t GetFee(size_t size) const; // unit returned is satoshis
129+
int64_t GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
130130

131131
friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
132132
friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
@@ -217,8 +217,6 @@ class CTransaction
217217
void UpdateHash() const;
218218

219219
public:
220-
static CFeeRate minTxFee;
221-
static CFeeRate minRelayTxFee;
222220
static const int CURRENT_VERSION=1;
223221

224222
// The local variables are made const to prevent unintended modification

src/init.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,16 @@ std::string HelpMessage(HelpMessageMode mode)
253253
#ifdef ENABLE_WALLET
254254
strUsage += "\n" + _("Wallet options:") + "\n";
255255
strUsage += " -disablewallet " + _("Do not load the wallet and disable wallet RPC calls") + "\n";
256+
strUsage += " -mintxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"), FormatMoney(CWallet::minTxFee.GetFeePerK())) + "\n";
256257
strUsage += " -paytxfee=<amt> " + strprintf(_("Fee (in BTC/kB) to add to transactions you send (default: %s)"), FormatMoney(payTxFee.GetFeePerK())) + "\n";
257-
strUsage += " -txconfirmtarget=<n> " + _("If paytxfee is not set, include enough fee so transactions are confirmed on average within n blocks (default: 1)") + "\n";
258258
strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + " " + _("on startup") + "\n";
259+
strUsage += " -respendnotify=<cmd> " + _("Execute command when a network tx respends wallet tx input (%s=respend TxID, %t=wallet TxID)") + "\n";
259260
strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup") + "\n";
260261
strUsage += " -spendzeroconfchange " + _("Spend unconfirmed change when sending transactions (default: 1)") + "\n";
262+
strUsage += " -txconfirmtarget=<n> " + _("If paytxfee is not set, include enough fee so transactions are confirmed on average within n blocks (default: 1)") + "\n";
261263
strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + " " + _("on startup") + "\n";
262264
strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + " " + _("(default: wallet.dat)") + "\n";
263265
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
264-
strUsage += " -respendnotify=<cmd> " + _("Execute command when a network tx respends wallet tx input (%s=respend TxID, %t=wallet TxID)") + "\n";
265266
strUsage += " -zapwallettxes=<mode> " + _("Delete all wallet transactions and only recover those part of the blockchain through -rescan on startup") + "\n";
266267
strUsage += " " + _("(default: 1, 1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)") + "\n";
267268
#endif
@@ -295,8 +296,7 @@ std::string HelpMessage(HelpMessageMode mode)
295296
strUsage += " -limitfreerelay=<n> " + _("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default:15)") + "\n";
296297
strUsage += " -maxsigcachesize=<n> " + _("Limit size of signature cache to <n> entries (default: 50000)") + "\n";
297298
}
298-
strUsage += " -mintxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"), FormatMoney(CTransaction::minTxFee.GetFeePerK())) + "\n";
299-
strUsage += " -minrelaytxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for relaying (default: %s)"), FormatMoney(CTransaction::minRelayTxFee.GetFeePerK())) + "\n";
299+
strUsage += " -minrelaytxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for relaying (default: %s)"), FormatMoney(::minRelayTxFee.GetFeePerK())) + "\n";
300300
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
301301
if (GetBoolArg("-help-debug", false))
302302
{
@@ -610,24 +610,24 @@ bool AppInit2(boost::thread_group& threadGroup)
610610
// a transaction spammer can cheaply fill blocks using
611611
// 1-satoshi-fee transactions. It should be set above the real
612612
// cost to you of processing a transaction.
613-
if (mapArgs.count("-mintxfee"))
614-
{
615-
int64_t n = 0;
616-
if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0)
617-
CTransaction::minTxFee = CFeeRate(n);
618-
else
619-
return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"]));
620-
}
621613
if (mapArgs.count("-minrelaytxfee"))
622614
{
623615
int64_t n = 0;
624616
if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0)
625-
CTransaction::minRelayTxFee = CFeeRate(n);
617+
::minRelayTxFee = CFeeRate(n);
626618
else
627619
return InitError(strprintf(_("Invalid amount for -minrelaytxfee=<amount>: '%s'"), mapArgs["-minrelaytxfee"]));
628620
}
629621

630622
#ifdef ENABLE_WALLET
623+
if (mapArgs.count("-mintxfee"))
624+
{
625+
int64_t n = 0;
626+
if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0)
627+
CWallet::minTxFee = CFeeRate(n);
628+
else
629+
return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"]));
630+
}
631631
if (mapArgs.count("-paytxfee"))
632632
{
633633
int64_t nFeePerK = 0;
@@ -636,10 +636,10 @@ bool AppInit2(boost::thread_group& threadGroup)
636636
if (nFeePerK > nHighTransactionFeeWarning)
637637
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
638638
payTxFee = CFeeRate(nFeePerK, 1000);
639-
if (payTxFee < CTransaction::minRelayTxFee)
639+
if (payTxFee < ::minRelayTxFee)
640640
{
641641
return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
642-
mapArgs["-paytxfee"], CTransaction::minRelayTxFee.ToString()));
642+
mapArgs["-paytxfee"], ::minRelayTxFee.ToString()));
643643
}
644644
}
645645
nTxConfirmTarget = GetArg("-txconfirmtarget", 1);

src/main.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ using namespace boost;
3838

3939
CCriticalSection cs_main;
4040

41-
CTxMemPool mempool;
42-
4341
map<uint256, CBlockIndex*> mapBlockIndex;
4442
CChain chainActive;
4543
int64_t nTimeBestReceived = 0;
@@ -50,10 +48,10 @@ bool fBenchmark = false;
5048
bool fTxIndex = false;
5149
unsigned int nCoinCacheSize = 5000;
5250

53-
/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
54-
CFeeRate CTransaction::minTxFee = CFeeRate(10000); // Override with -mintxfee
5551
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */
56-
CFeeRate CTransaction::minRelayTxFee = CFeeRate(1000);
52+
CFeeRate minRelayTxFee = CFeeRate(1000);
53+
54+
CTxMemPool mempool(::minRelayTxFee);
5755

5856
struct COrphanBlock {
5957
uint256 hashBlock;
@@ -617,7 +615,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
617615
}
618616
if (whichType == TX_NULL_DATA)
619617
nDataOut++;
620-
else if (txout.IsDust(CTransaction::minRelayTxFee)) {
618+
else if (txout.IsDust(::minRelayTxFee)) {
621619
reason = "dust";
622620
return false;
623621
}
@@ -870,7 +868,7 @@ int64_t GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
870868
return 0;
871869
}
872870

873-
int64_t nMinFee = tx.minRelayTxFee.GetFee(nBytes);
871+
int64_t nMinFee = ::minRelayTxFee.GetFee(nBytes);
874872

875873
if (fAllowFree)
876874
{
@@ -1009,7 +1007,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
10091007
// Continuously rate-limit free (really, very-low-fee)transactions
10101008
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
10111009
// be annoying or make others' transactions take longer to confirm.
1012-
if (fLimitFree && nFees < CTransaction::minRelayTxFee.GetFee(nSize))
1010+
if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize))
10131011
{
10141012
static double dFreeCount;
10151013
static int64_t nLastFreeTime;
@@ -1022,10 +1020,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
10221020
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
10231021
}
10241022

1025-
if (fRejectInsaneFee && nFees > CTransaction::minRelayTxFee.GetFee(nSize) * 10000)
1023+
if (fRejectInsaneFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
10261024
return error("AcceptToMemoryPool: : insane fees %s, %d > %d",
10271025
hash.ToString(),
1028-
nFees, CTransaction::minRelayTxFee.GetFee(nSize) * 10000);
1026+
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
10291027

10301028
// Check against previous transactions
10311029
// This is done last to help prevent CPU exhaustion denial-of-service attacks.

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern bool fBenchmark;
9393
extern int nScriptCheckThreads;
9494
extern bool fTxIndex;
9595
extern unsigned int nCoinCacheSize;
96+
extern CFeeRate minRelayTxFee;
9697

9798
// Minimum disk space required - used in CheckDiskSpace()
9899
static const uint64_t nMinDiskSpace = 52428800;

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
236236
double dPriorityDelta = 0;
237237
int64_t nFeeDelta = 0;
238238
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
239-
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < CTransaction::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
239+
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
240240
continue;
241241

242242
// Prioritise by fee once past the priority size or we run out of high-priority

src/qt/coincontroldialog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ QString CoinControlDialog::getPriorityLabel(const CTxMemPool& pool, double dPrio
406406
{
407407
// confirmations -> textual description
408408
typedef std::map<unsigned int, QString> PriorityDescription;
409-
static PriorityDescription priorityDescriptions = boost::assign::map_list_of
409+
const static PriorityDescription priorityDescriptions = boost::assign::map_list_of
410410
(1, tr("highest"))(2, tr("higher"))(3, tr("high"))
411411
(5, tr("medium-high"))(6, tr("medium"))
412412
(10, tr("low-medium"))(15, tr("low"))
@@ -452,7 +452,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
452452
{
453453
CTxOut txout(amount, (CScript)vector<unsigned char>(24, 0));
454454
txDummy.vout.push_back(txout);
455-
if (txout.IsDust(CTransaction::minRelayTxFee))
455+
if (txout.IsDust(::minRelayTxFee))
456456
fDust = true;
457457
}
458458
}
@@ -544,7 +544,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
544544
if (nChange > 0 && nChange < CENT)
545545
{
546546
CTxOut txout(nChange, (CScript)vector<unsigned char>(24, 0));
547-
if (txout.IsDust(CTransaction::minRelayTxFee))
547+
if (txout.IsDust(::minRelayTxFee))
548548
{
549549
nPayFee += nChange;
550550
nChange = 0;
@@ -605,17 +605,17 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
605605

606606
// tool tips
607607
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
608-
toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK())) + "<br /><br />";
608+
toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CWallet::minTxFee.GetFeePerK())) + "<br /><br />";
609609
toolTip1 += tr("Can vary +/- 1 byte per input.");
610610

611611
QString toolTip2 = tr("Transactions with higher priority are more likely to get included into a block.") + "<br /><br />";
612612
toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\".") + "<br /><br />";
613-
toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK()));
613+
toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CWallet::minTxFee.GetFeePerK()));
614614

615-
QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minRelayTxFee.GetFee(546)));
615+
QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, ::minRelayTxFee.GetFee(546)));
616616

617617
// how many satoshis the estimated fee can vary per byte we guess wrong
618-
double dFeeVary = (double)std::max(CTransaction::minTxFee.GetFeePerK(), payTxFee.GetFeePerK()) / 1000;
618+
double dFeeVary = (double)std::max(CWallet::minTxFee.GetFeePerK(), payTxFee.GetFeePerK()) / 1000;
619619
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
620620

621621
l3->setToolTip(toolTip4);

src/qt/guiutil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "core.h"
1313
#include "init.h"
14+
#include "main.h"
1415
#include "protocol.h"
1516
#include "util.h"
1617

@@ -212,7 +213,7 @@ bool isDust(const QString& address, qint64 amount)
212213
CTxDestination dest = CBitcoinAddress(address.toStdString()).Get();
213214
CScript script; script.SetDestination(dest);
214215
CTxOut txOut(amount, script);
215-
return txOut.IsDust(CTransaction::minRelayTxFee);
216+
return txOut.IsDust(::minRelayTxFee);
216217
}
217218

218219
QString HtmlEscape(const QString& str, bool fMultiLine)

src/qt/optionsdialog.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
#include "monitoreddatamapper.h"
1515
#include "optionsmodel.h"
1616

17-
#include "main.h" // for CTransaction::minTxFee and MAX_SCRIPTCHECK_THREADS
17+
#include "main.h" // for MAX_SCRIPTCHECK_THREADS
18+
#ifdef ENABLE_WALLET
19+
#include "wallet.h" // for CWallet::minTxFee
20+
#endif
1821
#include "netbase.h"
1922
#include "txdb.h" // for -dbcache defaults
2023

@@ -101,7 +104,9 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
101104
#endif
102105

103106
ui->unit->setModel(new BitcoinUnits(this));
104-
ui->transactionFee->setSingleStep(CTransaction::minTxFee.GetFeePerK());
107+
#ifdef ENABLE_WALLET
108+
ui->transactionFee->setSingleStep(CWallet::minTxFee.GetFeePerK());
109+
#endif
105110

106111
/* Widget-to-option mapper */
107112
mapper = new MonitoredDataMapper(this);

src/qt/paymentserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
551551

552552
// Extract and check amounts
553553
CTxOut txOut(sendingTo.second, sendingTo.first);
554-
if (txOut.IsDust(CTransaction::minRelayTxFee)) {
554+
if (txOut.IsDust(::minRelayTxFee)) {
555555
emit message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).")
556556
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)),
557557
CClientUIInterface::MSG_ERROR);

0 commit comments

Comments
 (0)