From cb6499721632fa1d65066600e34b0d28abfe62b3 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 7 Apr 2022 11:45:55 -0600 Subject: [PATCH] Never consider transactions that pay the default fee to be free. --- src/main.h | 2 +- src/miner.cpp | 29 +++++++++++++++++++++-------- src/txmempool.h | 4 ++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main.h b/src/main.h index 9335ed5ff..62e11a248 100644 --- a/src/main.h +++ b/src/main.h @@ -66,7 +66,7 @@ static const unsigned int MAX_REORG_LENGTH = COINBASE_MATURITY - 1; static const bool DEFAULT_WHITELISTRELAY = true; /** Default for DEFAULT_WHITELISTFORCERELAY. */ static const bool DEFAULT_WHITELISTFORCERELAY = true; -/** Default for -minrelaytxfee, minimum relay fee for transactions */ +/** Default for -minrelaytxfee, minimum relay fee for transactions in zatoshis/kB */ static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 100; //! -maxtxfee default static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN; diff --git a/src/miner.cpp b/src/miner.cpp index a04183577..b17980713 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -64,9 +64,10 @@ public: const CTransaction* ptx; set setDependsOn; CFeeRate feeRate; + CAmount feePaid; double dPriority; - COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0) + COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), feePaid(0), dPriority(0) { } }; @@ -75,7 +76,7 @@ std::optional last_block_num_txs; std::optional last_block_size; // We want to sort transactions by priority and fee rate, so: -typedef boost::tuple TxPriority; +typedef boost::tuple TxPriority; class TxPriorityCompare { bool byFee; @@ -491,15 +492,17 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre uint256 hash = tx.GetHash(); mempool.ApplyDeltas(hash, dPriority, nTotalIn); - CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); + CAmount feePaid = nTotalIn - tx.GetValueOut(); + CFeeRate feeRate(feePaid, nTxSize); if (porphan) { porphan->dPriority = dPriority; porphan->feeRate = feeRate; + porphan->feePaid = feePaid; } else - vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + vecPriority.push_back(TxPriority(dPriority, feeRate, feePaid, &(mi->GetTx()))); } } @@ -546,7 +549,8 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); - const CTransaction& tx = *(vecPriority.front().get<2>()); + CAmount feePaid = vecPriority.front().get<2>(); + const CTransaction& tx = *(vecPriority.front().get<3>()); const uint256& hash = tx.GetHash(); std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); @@ -570,8 +574,17 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre double dPriorityDelta = 0; CAmount nFeeDelta = 0; mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); - if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - LogPrintf("%s: skipping free tx %s; already have minimum block size.", __func__, hash.GetHex()); + if (fSortedByFee && + (dPriorityDelta <= 0) && + (nFeeDelta <= 0) && + (feeRate < ::minRelayTxFee) && + (feePaid < DEFAULT_FEE) && + (nBlockSize + nTxSize >= nBlockMinSize)) + { + LogPrintf( + "%s: skipping free tx %s (fee is %i; %s) with size %u, current block size is %u & already have minimum block size %u.", + __func__, hash.GetHex(), + feePaid, feeRate.ToString(), nTxSize, nBlockSize, nBlockMinSize); continue; } @@ -673,7 +686,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre porphan->setDependsOn.erase(hash); if (porphan->setDependsOn.empty()) { - vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); + vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->feePaid, porphan->ptx)); std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); } } diff --git a/src/txmempool.h b/src/txmempool.h index 4b6962dfe..2337bff4b 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -27,6 +27,10 @@ class CAutoFile; inline double AllowFreeThreshold() { + // 144 is the number of Bitcoin blocks per day. This has not been updated for Zcash, + // as it would make it harder to get shielded transactions into blocks by lowering the + // threshold at which we switch from priority-based selection of transactions into + // blocks to fee-based selection. return COIN * 144 / 250; }