Skip to content

Commit 7b1add3

Browse files
committed
Introduce -incrementalrelayfee
1 parent daec955 commit 7b1add3

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/init.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,10 @@ std::string HelpMessage(HelpMessageMode mode)
465465
AppendParamsHelpMessages(strUsage, showDebug);
466466

467467
strUsage += HelpMessageGroup(_("Node relay options:"));
468-
if (showDebug)
468+
if (showDebug) {
469469
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
470+
strUsage += HelpMessageOpt("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)));
471+
}
470472
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
471473
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
472474
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
@@ -923,6 +925,15 @@ bool AppInitParameterInteraction()
923925
int64_t nMempoolSizeMin = GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
924926
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
925927
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
928+
// incremental relay fee sets the minimimum feerate increase necessary for BIP 125 replacement in the mempool
929+
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
930+
if (IsArgSet("-incrementalrelayfee"))
931+
{
932+
CAmount n = 0;
933+
if (!ParseMoney(GetArg("-incrementalrelayfee", ""), n))
934+
return InitError(AmountErrMsg("incrementalrelayfee", GetArg("-incrementalrelayfee", "")));
935+
incrementalRelayFee = CFeeRate(n);
936+
}
926937

927938
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
928939
nScriptCheckThreads = GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
@@ -969,6 +980,10 @@ bool AppInitParameterInteraction()
969980
return InitError(AmountErrMsg("minrelaytxfee", GetArg("-minrelaytxfee", "")));
970981
// High fee check is done afterward in CWallet::ParameterInteraction()
971982
::minRelayTxFee = CFeeRate(n);
983+
} else if (incrementalRelayFee > ::minRelayTxFee) {
984+
// Allow only setting incrementalRelayFee to control both
985+
::minRelayTxFee = incrementalRelayFee;
986+
LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFee.ToString());
972987
}
973988

974989
// Sanity check argument for min fee for including tx in block

src/policy/policy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
206206
return true;
207207
}
208208

209+
CFeeRate incrementalRelayFee = CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE);
209210
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
210211

211212
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)

src/policy/policy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static const unsigned int MAX_P2SH_SIGOPS = 15;
3030
static const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5;
3131
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
3232
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
33+
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement **/
34+
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000;
3335
/** Default for -bytespersigop */
3436
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
3537
/** The maximum number of witness stack items in a standard P2WSH script */
@@ -85,6 +87,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
8587
*/
8688
bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
8789

90+
extern CFeeRate incrementalRelayFee;
8891
extern unsigned int nBytesPerSigOp;
8992

9093
/** Compute the virtual transaction size (weight reinterpreted as bytes). */

src/txmempool.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ CTxMemPool::CTxMemPool(const CFeeRate& _minReasonableRelayFee) :
359359
nCheckFrequency = 0;
360360

361361
minerPolicyEstimator = new CBlockPolicyEstimator(_minReasonableRelayFee);
362-
minReasonableRelayFee = _minReasonableRelayFee;
363362
}
364363

365364
CTxMemPool::~CTxMemPool()
@@ -1077,12 +1076,12 @@ CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
10771076
rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
10781077
lastRollingFeeUpdate = time;
10791078

1080-
if (rollingMinimumFeeRate < (double)minReasonableRelayFee.GetFeePerK() / 2) {
1079+
if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() / 2) {
10811080
rollingMinimumFeeRate = 0;
10821081
return CFeeRate(0);
10831082
}
10841083
}
1085-
return std::max(CFeeRate(rollingMinimumFeeRate), minReasonableRelayFee);
1084+
return std::max(CFeeRate(rollingMinimumFeeRate), incrementalRelayFee);
10861085
}
10871086

10881087
void CTxMemPool::trackPackageRemoved(const CFeeRate& rate) {
@@ -1106,7 +1105,7 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<uint256>* pvNoSpendsRe
11061105
// to have 0 fee). This way, we don't allow txn to enter mempool with feerate
11071106
// equal to txn which were removed with no block in between.
11081107
CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1109-
removed += minReasonableRelayFee;
1108+
removed += incrementalRelayFee;
11101109
trackPackageRemoved(removed);
11111110
maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
11121111

src/txmempool.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,6 @@ class CTxMemPool
425425
uint64_t totalTxSize; //!< sum of all mempool tx' byte sizes
426426
uint64_t cachedInnerUsage; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
427427

428-
CFeeRate minReasonableRelayFee;
429-
430428
mutable int64_t lastRollingFeeUpdate;
431429
mutable bool blockSinceLastRollingFeeBump;
432430
mutable double rollingMinimumFeeRate; //!< minimum fee to get into the pool, decreases exponentially
@@ -505,9 +503,6 @@ class CTxMemPool
505503
std::map<uint256, std::pair<double, CAmount> > mapDeltas;
506504

507505
/** Create a new CTxMemPool.
508-
* minReasonableRelayFee should be a feerate which is, roughly, somewhere
509-
* around what it "costs" to relay a transaction around the network and
510-
* below which we would reasonably say a transaction has 0-effective-fee.
511506
*/
512507
CTxMemPool(const CFeeRate& _minReasonableRelayFee);
513508
~CTxMemPool();
@@ -591,7 +586,7 @@ class CTxMemPool
591586

592587
/** The minimum fee to get into the mempool, which may itself not be enough
593588
* for larger-sized transactions.
594-
* The minReasonableRelayFee constructor arg is used to bound the time it
589+
* The incrementalRelayFee policy variable is used to bound the time it
595590
* takes the fee rate to go back down all the way to 0. When the feerate
596591
* would otherwise be half of this, it is set to 0 instead.
597592
*/

0 commit comments

Comments
 (0)