Skip to content

Commit 03d2ee9

Browse files
morcosrandom-zebra
authored andcommitted
[mining] Remove -blockprioritysize.
Remove ability of mining code to fill part of a block with transactions sorted by coin age.
1 parent cfaeb97 commit 03d2ee9

File tree

7 files changed

+3
-229
lines changed

7 files changed

+3
-229
lines changed

src/blockassembler.cpp

Lines changed: 0 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ void BlockAssembler::resetBlock()
163163
// These counters do not include coinbase tx
164164
nBlockTx = 0;
165165
nFees = 0;
166-
167-
lastFewTxs = 0;
168-
blockFinished = false;
169166
}
170167

171168
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn,
@@ -204,7 +201,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
204201
if (!fNoMempoolTx) {
205202
// Add transactions from mempool
206203
LOCK2(cs_main,mempool.cs);
207-
//addPriorityTxs(); !TODO: remove
208204
addPackageTxs();
209205
}
210206

@@ -252,16 +248,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
252248
return std::move(pblocktemplate);
253249
}
254250

255-
bool BlockAssembler::isStillDependent(CTxMemPool::txiter iter)
256-
{
257-
for (CTxMemPool::txiter parent : mempool.GetMemPoolParents(iter)) {
258-
if (!inBlock.count(parent)) {
259-
return true;
260-
}
261-
}
262-
return false;
263-
}
264-
265251
void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
266252
{
267253
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
@@ -295,59 +281,6 @@ bool BlockAssembler::TestPackageFinality(const CTxMemPool::setEntries& package)
295281
return true;
296282
}
297283

298-
bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter)
299-
{
300-
// Legacy zerocoin transactions are disabled forever.
301-
assert(!iter->GetSharedTx()->ContainsZerocoins());
302-
303-
// Don't add shielded transactions if Sapling isn't active
304-
const bool isShielded = iter->IsShielded();
305-
if(isShielded && sporkManager.IsSporkActive(SPORK_20_SAPLING_MAINTENANCE)) {
306-
return false;
307-
}
308-
309-
unsigned int nTxSize = iter->GetTxSize();
310-
if (nBlockSize + nTxSize >= nBlockMaxSize) {
311-
// If the block is so close to full that no more txs will fit
312-
// or if we've tried more than 50 times to fill remaining space
313-
// then flag that the block is finished
314-
if (nBlockSize > nBlockMaxSize - 100 || lastFewTxs > 50) {
315-
blockFinished = true;
316-
return false;
317-
}
318-
// Once we're within 1000 bytes of a full block, only look at 50 more txs
319-
// to try to fill the remaining space.
320-
if (nBlockSize > nBlockMaxSize - 1000) {
321-
lastFewTxs++;
322-
}
323-
return false;
324-
}
325-
326-
if (isShielded && nSizeShielded + nTxSize > MAX_BLOCK_SHIELDED_TXES_SIZE) {
327-
return false;
328-
}
329-
330-
if (nBlockSigOps + iter->GetSigOpCount() >= MAX_BLOCK_SIGOPS_CURRENT) {
331-
// If the block has room for no more sig ops then
332-
// flag that the block is finished
333-
if (nBlockSigOps > MAX_BLOCK_SIGOPS_CURRENT - 2) {
334-
blockFinished = true;
335-
return false;
336-
}
337-
// Otherwise attempt to find another tx with fewer sigops
338-
// to put in the block.
339-
return false;
340-
}
341-
342-
// Must check that lock times are still valid
343-
// This can be removed once MTP is always enforced
344-
// as long as reorgs keep the mempool consistent.
345-
if (!IsFinalTx(iter->GetSharedTx(), nHeight))
346-
return false;
347-
348-
return true;
349-
}
350-
351284
void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
352285
{
353286
pblock->vtx.emplace_back(iter->GetSharedTx());
@@ -371,60 +304,6 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
371304
}
372305
}
373306

374-
void BlockAssembler::addScoreTxs()
375-
{
376-
std::priority_queue<CTxMemPool::txiter, std::vector<CTxMemPool::txiter>, ScoreCompare> clearedTxs;
377-
CTxMemPool::setEntries waitSet;
378-
CTxMemPool::indexed_transaction_set::index<mining_score>::type::iterator mi = mempool.mapTx.get<mining_score>().begin();
379-
CTxMemPool::txiter iter;
380-
while (!blockFinished && (mi != mempool.mapTx.get<mining_score>().end() || !clearedTxs.empty())) {
381-
// If no txs that were previously postponed are available to try
382-
// again, then try the next highest score tx
383-
if (clearedTxs.empty()) {
384-
iter = mempool.mapTx.project<0>(mi);
385-
mi++;
386-
}
387-
// If a previously postponed tx is available to try again, then it
388-
// has higher score than all untried so far txs
389-
else {
390-
iter = clearedTxs.top();
391-
clearedTxs.pop();
392-
}
393-
394-
// If tx already in block, skip (added by addPriorityTxs)
395-
if (inBlock.count(iter)) {
396-
continue;
397-
}
398-
399-
// If tx is dependent on other mempool txs which haven't yet been included
400-
// then put it in the waitSet
401-
if (isStillDependent(iter)) {
402-
waitSet.insert(iter);
403-
continue;
404-
}
405-
406-
// If the fee rate is below the min fee rate for mining, then we're done
407-
// adding txs based on score (fee rate)
408-
if (iter->GetModifiedFee() < ::minRelayTxFee.GetFee(iter->GetTxSize()) && nBlockSize >= nBlockMinSize) {
409-
return;
410-
}
411-
412-
// If this tx fits in the block add it, otherwise keep looping
413-
if (TestForBlock(iter)) {
414-
AddToBlock(iter);
415-
416-
// This tx was successfully added, so
417-
// add transactions that depend on this one to the priority queue to try again
418-
for (CTxMemPool::txiter child : mempool.GetMemPoolChildren(iter)) {
419-
if (waitSet.count(child)) {
420-
clearedTxs.push(child);
421-
waitSet.erase(child);
422-
}
423-
}
424-
}
425-
}
426-
}
427-
428307
void BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
429308
indexed_modified_transaction_set& mapModifiedTx)
430309
{
@@ -610,78 +489,6 @@ void BlockAssembler::addPackageTxs()
610489
}
611490
}
612491

613-
void BlockAssembler::addPriorityTxs()
614-
{
615-
// How much of the block should be dedicated to high-priority transactions,
616-
// included regardless of the fees they pay
617-
unsigned int nBlockPrioritySize = gArgs.GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
618-
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
619-
620-
if (nBlockPrioritySize == 0) {
621-
return;
622-
}
623-
624-
// This vector will be sorted into a priority queue:
625-
std::vector<TxCoinAgePriority> vecPriority;
626-
TxCoinAgePriorityCompare pricomparer;
627-
std::map<CTxMemPool::txiter, double, CTxMemPool::CompareIteratorByHash> waitPriMap;
628-
typedef std::map<CTxMemPool::txiter, double, CTxMemPool::CompareIteratorByHash>::iterator waitPriIter;
629-
double actualPriority = -1;
630-
631-
vecPriority.reserve(mempool.mapTx.size());
632-
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
633-
mi != mempool.mapTx.end(); ++mi) {
634-
double dPriority = mi->GetPriority(nHeight);
635-
CAmount dummy{0};
636-
mempool.ApplyDeltas(mi->GetSharedTx()->GetHash(), dPriority, dummy);
637-
vecPriority.emplace_back(TxCoinAgePriority(dPriority, mi));
638-
}
639-
std::make_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
640-
641-
CTxMemPool::txiter iter;
642-
while (!vecPriority.empty() && !blockFinished) { // add a tx from priority queue to fill the blockprioritysize
643-
iter = vecPriority.front().second;
644-
actualPriority = vecPriority.front().first;
645-
std::pop_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
646-
vecPriority.pop_back();
647-
648-
// If tx already in block, skip
649-
if (inBlock.count(iter)) {
650-
assert(false); // shouldn't happen for priority txs
651-
continue;
652-
}
653-
654-
// If tx is dependent on other mempool txs which haven't yet been included
655-
// then put it in the waitSet
656-
if (isStillDependent(iter)) {
657-
waitPriMap.insert(std::make_pair(iter, actualPriority));
658-
continue;
659-
}
660-
661-
// If this tx fits in the block add it, otherwise keep looping
662-
if (TestForBlock(iter)) {
663-
AddToBlock(iter);
664-
665-
// If now that this txs is added we've surpassed our desired priority size
666-
// or have dropped below the AllowFreeThreshold, then we're done adding priority txs
667-
if (nBlockSize >= nBlockPrioritySize || !AllowFree(actualPriority)) {
668-
return;
669-
}
670-
671-
// This tx was successfully added, so
672-
// add transactions that depend on this one to the priority queue to try again
673-
for (CTxMemPool::txiter child : mempool.GetMemPoolChildren(iter)) {
674-
waitPriIter wpiter = waitPriMap.find(child);
675-
if (wpiter != waitPriMap.end()) {
676-
vecPriority.emplace_back(TxCoinAgePriority(wpiter->second,child));
677-
std::push_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
678-
waitPriMap.erase(wpiter);
679-
}
680-
}
681-
}
682-
}
683-
}
684-
685492
void BlockAssembler::appendSaplingTreeRoot()
686493
{
687494
// Update header

src/blockassembler.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ class BlockAssembler
153153
int nHeight{0};
154154
const CChainParams& chainparams;
155155

156-
// Variables used for addScoreTxs and addPriorityTxs
157-
int lastFewTxs{0};
158-
bool blockFinished{false};
159-
160156
// Keep track of block space used for shield txes
161157
unsigned int nSizeShielded{0};
162158

@@ -180,21 +176,11 @@ class BlockAssembler
180176
void AddToBlock(CTxMemPool::txiter iter);
181177

182178
// Methods for how to add transactions to a block.
183-
/** Add transactions based on modified feerate */
184-
void addScoreTxs();
185-
/** Add transactions based on tx "priority" */
186-
void addPriorityTxs();
187179
/** Add transactions based on feerate including unconfirmed ancestors */
188180
void addPackageTxs();
189181
/** Add the tip updated incremental merkle tree to the header */
190182
void appendSaplingTreeRoot();
191183

192-
// helper function for addScoreTxs and addPriorityTxs
193-
/** Test if tx will still "fit" in the block */
194-
bool TestForBlock(CTxMemPool::txiter iter);
195-
/** Test if tx still has unconfirmed parents not yet in block */
196-
bool isStillDependent(CTxMemPool::txiter iter);
197-
198184
// helper functions for addPackageTxs()
199185
/** Remove confirmed (inBlock) entries from given set */
200186
void onlyUnconfirmed(CTxMemPool::setEntries& testSet);

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ std::string HelpMessage(HelpMessageMode mode)
599599
strUsage += HelpMessageGroup(_("Block creation options:"));
600600
strUsage += HelpMessageOpt("-blockminsize=<n>", strprintf(_("Set minimum block size in bytes (default: %u)"), DEFAULT_BLOCK_MIN_SIZE));
601601
strUsage += HelpMessageOpt("-blockmaxsize=<n>", strprintf(_("Set maximum block size in bytes (default: %d)"), DEFAULT_BLOCK_MAX_SIZE));
602-
strUsage += HelpMessageOpt("-blockprioritysize=<n>", strprintf(_("Set maximum size of high-priority/low-fee transactions in bytes (default: %d)"), DEFAULT_BLOCK_PRIORITY_SIZE));
602+
if (showDebug)
603+
strUsage += HelpMessageOpt("-blockversion=<n>", "Override block version to test forking scenarios");
603604

604605
strUsage += HelpMessageGroup(_("RPC server options:"));
605606
strUsage += HelpMessageOpt("-server", _("Accept command line and JSON-RPC commands"));

src/policy/policy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class CTxOut;
2020
/** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
2121
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
2222
static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
23-
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
24-
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
2523
/** Maximum number of signature check operations in an IsStandard() P2SH script */
2624
static const unsigned int MAX_P2SH_SIGOPS = 15;
2725
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
@@ -54,7 +52,6 @@ static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCR
5452

5553
// Sanity check the magic numbers when we change them
5654
BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE_CURRENT);
57-
BOOST_STATIC_ASSERT(DEFAULT_BLOCK_PRIORITY_SIZE <= DEFAULT_BLOCK_MAX_SIZE);
5855

5956
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn);
6057

src/test/miner_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ struct {
7474
// Test suite for ancestor feerate transaction selection.
7575
// Implemented as an additional function, rather than a separate test case,
7676
// to allow reusing the blockchain created in CreateNewBlock_validity.
77-
// Note that this test assumes blockprioritysize is 0.
7877
void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey, std::vector<CTransactionRef>& txFirst)
7978
{
8079
// Test the ancestor feerate transaction selection.

src/txmempool.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -760,19 +760,6 @@ class CCoinsViewMemPool : public CCoinsViewBacked
760760
bool GetNullifier(const uint256& nullifier) const;
761761
};
762762

763-
// We want to sort transactions by coin age priority
764-
typedef std::pair<double, CTxMemPool::txiter> TxCoinAgePriority;
765-
766-
struct TxCoinAgePriorityCompare
767-
{
768-
bool operator()(const TxCoinAgePriority& a, const TxCoinAgePriority& b)
769-
{
770-
if (a.first == b.first)
771-
return CompareTxMemPoolEntryByScore()(*(b.second), *(a.second)); //Reverse order to make sort less than
772-
return a.first < b.first;
773-
}
774-
};
775-
776763
/**
777764
* DisconnectedBlockTransactions
778765
* During the reorg, it's desirable to re-add previously confirmed transactions

src/validation.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ CAmount GetMinRelayFee(unsigned int nBytes, bool fAllowFree)
302302

303303
if (fAllowFree) {
304304
// There is a free transaction area in blocks created by most miners,
305-
// * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
306-
// to be considered to fall into this category. We don't want to encourage sending
307-
// multiple transactions instead of one big transaction to avoid fees.
308-
if (nBytes < (DEFAULT_BLOCK_PRIORITY_SIZE - 1000))
305+
// !TODO: remove
309306
nMinFee = 0;
310307
}
311308

0 commit comments

Comments
 (0)