v29.4-roots.4 · Commit 3: [PATCH 03/37] policy: restore conservative relay and network controls
src/node/miner.cpp
Before: src/node/miner.cpp · After: src/node/miner.cpp
File metadata
index b9ecd855f0a60fce28f8395c94a4eae8ee6458b6..aabe3fef4d97e3fb612f1a37d4e40ef3b3be6ea9 100644
Download original patch · Release notes
Diff rows 1–107 of 107. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/node/miner.cpp
CHANGED
|
@@ -77,6 +77,7 @@ static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
|
|
|
77
77
|
Assert(options.block_reserved_weight <= MAX_BLOCK_WEIGHT);
|
|
78
78
|
Assert(options.block_reserved_weight >= MINIMUM_BLOCK_RESERVED_WEIGHT);
|
|
79
79
|
Assert(options.coinbase_output_max_additional_sigops <= MAX_BLOCK_SIGOPS_COST);
|
|
80
|
+
options.nBlockMaxSize = std::clamp<size_t>(options.nBlockMaxSize, DEFAULT_BLOCK_RESERVED_SIZE, MAX_BLOCK_SERIALIZED_SIZE);
|
|
80
81
|
// Limit weight to between block_reserved_weight and MAX_BLOCK_WEIGHT for sanity:
|
|
81
82
|
// block_reserved_weight can safely exceed -blockmaxweight, but the rest of the block template will be empty.
|
|
82
83
|
options.nBlockMaxWeight = std::clamp<size_t>(options.nBlockMaxWeight, options.block_reserved_weight, MAX_BLOCK_WEIGHT);
|
|
@@ -89,12 +90,26 @@ BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool
|
|
|
89
90
|
m_chainstate{chainstate},
|
|
90
91
|
m_options{ClampOptions(options)}
|
|
91
92
|
{
|
|
93
|
+
fNeedSizeAccounting = m_options.nBlockMaxSize < MAX_BLOCK_SERIALIZED_SIZE;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& options)
|
|
95
97
|
{
|
|
96
98
|
// Block resource limits
|
|
97
|
-
options.nBlockMaxWeight = args.GetIntArg("-blockmaxweight", options.nBlockMaxWeight);
|
|
99
|
+
// If only one resource limit is set, leave the other unrestricted. If
|
|
100
|
+
// neither is set, retain the conservative default weight limit.
|
|
101
|
+
bool weight_set{false};
|
|
102
|
+
if (args.IsArgSet("-blockmaxweight")) {
|
|
103
|
+
options.nBlockMaxWeight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
|
|
104
|
+
options.nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
|
|
105
|
+
weight_set = true;
|
|
106
|
+
}
|
|
107
|
+
if (args.IsArgSet("-blockmaxsize")) {
|
|
108
|
+
options.nBlockMaxSize = args.GetIntArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
|
109
|
+
if (!weight_set) {
|
|
110
|
+
options.nBlockMaxWeight = MAX_BLOCK_WEIGHT;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
98
113
|
if (const auto blockmintxfee{args.GetArg("-blockmintxfee")}) {
|
|
99
114
|
if (const auto parsed{ParseMoney(*blockmintxfee)}) options.blockMinFeeRate = CFeeRate{*parsed};
|
|
100
115
|
}
|
|
@@ -107,6 +122,7 @@ void BlockAssembler::resetBlock()
|
|
|
107
122
|
inBlock.clear();
|
|
108
123
|
|
|
109
124
|
// Reserve space for fixed-size block header, txs count, and coinbase tx.
|
|
125
|
+
nBlockSize = 1000;
|
|
110
126
|
nBlockWeight = m_options.block_reserved_weight;
|
|
111
127
|
nBlockSigOpsCost = m_options.coinbase_output_max_additional_sigops;
|
|
112
128
|
|
|
@@ -147,6 +163,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
|
|
147
163
|
int nPackagesSelected = 0;
|
|
148
164
|
int nDescendantsUpdated = 0;
|
|
149
165
|
if (m_mempool) {
|
|
166
|
+
LOCK(m_mempool->cs);
|
|
167
|
+
addPriorityTxs(*m_mempool, nPackagesSelected);
|
|
168
|
+
// addPackageTxs acquires the same recursive mempool lock.
|
|
150
169
|
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
|
|
151
170
|
}
|
|
152
171
|
|
|
@@ -195,7 +214,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
|
|
195
214
|
{
|
|
196
215
|
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
|
|
197
216
|
// Only test txs not already in the block
|
|
198
|
-
if (inBlock.count((*iit)->GetSharedTx()->GetHash())) {
|
|
217
|
+
if (inBlock.count(*iit)) {
|
|
199
218
|
testSet.erase(iit++);
|
|
200
219
|
} else {
|
|
201
220
|
iit++;
|
|
@@ -217,12 +236,21 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
|
|
|
217
236
|
|
|
218
237
|
// Perform transaction-level checks before adding to block:
|
|
219
238
|
// - transaction finality (locktime)
|
|
239
|
+
// - serialized size when -blockmaxsize is in use
|
|
220
240
|
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
|
|
221
241
|
{
|
|
242
|
+
uint64_t potential_block_size{nBlockSize};
|
|
222
243
|
for (CTxMemPool::txiter it : package) {
|
|
223
244
|
if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
|
|
224
245
|
return false;
|
|
225
246
|
}
|
|
247
|
+
if (fNeedSizeAccounting) {
|
|
248
|
+
const uint64_t tx_size{::GetSerializeSize(TX_WITH_WITNESS(it->GetTx()))};
|
|
249
|
+
if (potential_block_size + tx_size >= m_options.nBlockMaxSize) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
potential_block_size += tx_size;
|
|
253
|
+
}
|
|
226
254
|
}
|
|
227
255
|
return true;
|
|
228
256
|
}
|
|
@@ -233,10 +261,11 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
|
|
|
233
261
|
pblocktemplate->vTxFees.push_back(iter->GetFee());
|
|
234
262
|
pblocktemplate->vTxSigOpsCost.push_back(iter->GetSigOpCost());
|
|
235
263
|
nBlockWeight += iter->GetTxWeight();
|
|
264
|
+
nBlockSize += GetSerializeSize(TX_WITH_WITNESS(iter->GetTx()));
|
|
236
265
|
++nBlockTx;
|
|
237
266
|
nBlockSigOpsCost += iter->GetSigOpCost();
|
|
238
267
|
nFees += iter->GetFee();
|
|
239
|
-
inBlock.insert(iter->GetSharedTx()->GetHash());
|
|
268
|
+
inBlock.insert(iter);
|
|
240
269
|
|
|
241
270
|
if (m_options.print_modified_fee) {
|
|
242
271
|
LogPrintf("fee rate %s txid %s\n",
|
|
@@ -333,7 +362,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
|
|
|
333
362
|
if (mi != mempool.mapTx.get<ancestor_score>().end()) {
|
|
334
363
|
auto it = mempool.mapTx.project<0>(mi);
|
|
335
364
|
assert(it != mempool.mapTx.end());
|
|
336
|
-
if (mapModifiedTx.count(it) || inBlock.count(it->GetSharedTx()->GetHash()) || failedTx.count(it->GetSharedTx()->GetHash())) {
|
|
365
|
+
if (mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it->GetSharedTx()->GetHash())) {
|
|
337
366
|
++mi;
|
|
338
367
|
continue;
|
|
339
368
|
}
|
|
@@ -367,7 +396,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
|
|
|
367
396
|
|
|
368
397
|
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
|
|
369
398
|
// contain anything that is inBlock.
|
|
370
|
-
assert(!inBlock.count(iter->GetSharedTx()->GetHash()));
|
|
399
|
+
assert(!inBlock.count(iter));
|
|
371
400
|
|
|
372
401
|
uint64_t packageSize = iter->GetSizeWithAncestors();
|
|
373
402
|
CAmount packageFees = iter->GetModFeesWithAncestors();
|