Bitcoin Core 29.99.0
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages Concepts
miner.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2022 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include <node/miner.h>
7
8#include <chain.h>
9#include <chainparams.h>
10#include <coins.h>
11#include <common/args.h>
12#include <consensus/amount.h>
13#include <consensus/consensus.h>
14#include <consensus/merkle.h>
15#include <consensus/tx_verify.h>
17#include <deploymentstatus.h>
18#include <logging.h>
19#include <policy/feerate.h>
20#include <policy/policy.h>
21#include <pow.h>
23#include <util/moneystr.h>
24#include <util/time.h>
25#include <validation.h>
26
27#include <algorithm>
28#include <utility>
29
30namespace node {
31
32int64_t GetMinimumTime(const CBlockIndex* pindexPrev, const int64_t difficulty_adjustment_interval)
33{
34 int64_t min_time{pindexPrev->GetMedianTimePast() + 1};
35 // Height of block to be mined.
36 const int height{pindexPrev->nHeight + 1};
37 // Account for BIP94 timewarp rule on all networks. This makes future
38 // activation safer.
39 if (height % difficulty_adjustment_interval == 0) {
40 min_time = std::max<int64_t>(min_time, pindexPrev->GetBlockTime() - MAX_TIMEWARP);
41 }
42 return min_time;
43}
44
45int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
46{
47 int64_t nOldTime = pblock->nTime;
48 int64_t nNewTime{std::max<int64_t>(GetMinimumTime(pindexPrev, consensusParams.DifficultyAdjustmentInterval()),
49 TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()))};
50
51 if (nOldTime < nNewTime) {
52 pblock->nTime = nNewTime;
53 }
54
55 // Updating time can change work required on testnet:
56 if (consensusParams.fPowAllowMinDifficultyBlocks) {
57 pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
58 }
59
60 return nNewTime - nOldTime;
61}
62
64{
65 CMutableTransaction tx{*block.vtx.at(0)};
66 tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
67 block.vtx.at(0) = MakeTransactionRef(tx);
68
69 const CBlockIndex* prev_block = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
70 chainman.GenerateCoinbaseCommitment(block, prev_block);
71
72 block.hashMerkleRoot = BlockMerkleRoot(block);
73}
74
76{
80 // Limit weight to between block_reserved_weight and MAX_BLOCK_WEIGHT for sanity:
81 // block_reserved_weight can safely exceed -blockmaxweight, but the rest of the block template will be empty.
82 options.nBlockMaxWeight = std::clamp<size_t>(options.nBlockMaxWeight, options.block_reserved_weight, MAX_BLOCK_WEIGHT);
83 return options;
84}
85
86BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
87 : chainparams{chainstate.m_chainman.GetParams()},
88 m_mempool{options.use_mempool ? mempool : nullptr},
89 m_chainstate{chainstate},
90 m_options{ClampOptions(options)}
91{
92}
93
95{
96 // Block resource limits
97 options.nBlockMaxWeight = args.GetIntArg("-blockmaxweight", options.nBlockMaxWeight);
98 if (const auto blockmintxfee{args.GetArg("-blockmintxfee")}) {
99 if (const auto parsed{ParseMoney(*blockmintxfee)}) options.blockMinFeeRate = CFeeRate{*parsed};
100 }
101 options.print_modified_fee = args.GetBoolArg("-printpriority", options.print_modified_fee);
102 options.block_reserved_weight = args.GetIntArg("-blockreservedweight", options.block_reserved_weight);
103}
104
105void BlockAssembler::resetBlock()
106{
107 inBlock.clear();
108
109 // Reserve space for fixed-size block header, txs count, and coinbase tx.
110 nBlockWeight = m_options.block_reserved_weight;
111 nBlockSigOpsCost = m_options.coinbase_output_max_additional_sigops;
112
113 // These counters do not include coinbase tx
114 nBlockTx = 0;
115 nFees = 0;
116}
117
118std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
119{
120 const auto time_start{SteadyClock::now()};
121
122 resetBlock();
123
124 pblocktemplate.reset(new CBlockTemplate());
125 CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
126
127 // Add dummy coinbase tx as first transaction. It is skipped by the
128 // getblocktemplate RPC and mining interface consumers must not use it.
129 pblock->vtx.emplace_back();
130
132 CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
133 assert(pindexPrev != nullptr);
134 nHeight = pindexPrev->nHeight + 1;
135
136 pblock->nVersion = m_chainstate.m_chainman.m_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
137 // -regtest only: allow overriding block.nVersion with
138 // -blockversion=N to test forking scenarios
139 if (chainparams.MineBlocksOnDemand()) {
140 pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
141 }
142
143 pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(NodeClock::now());
144 m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
145
146 int nPackagesSelected = 0;
147 int nDescendantsUpdated = 0;
148 if (m_mempool) {
149 addPackageTxs(nPackagesSelected, nDescendantsUpdated);
150 }
151
152 const auto time_1{SteadyClock::now()};
153
154 m_last_block_num_txs = nBlockTx;
155 m_last_block_weight = nBlockWeight;
156
157 // Create coinbase transaction.
158 CMutableTransaction coinbaseTx;
159 coinbaseTx.vin.resize(1);
160 coinbaseTx.vin[0].prevout.SetNull();
161 coinbaseTx.vout.resize(1);
162 coinbaseTx.vout[0].scriptPubKey = m_options.coinbase_output_script;
163 coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
164 coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
165 pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
166 pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
167
168 LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
169
170 // Fill in header
171 pblock->hashPrevBlock = pindexPrev->GetBlockHash();
172 UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
173 pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
174 pblock->nNonce = 0;
175
177 if (m_options.test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,
178 /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
179 throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
180 }
181 const auto time_2{SteadyClock::now()};
182
183 LogDebug(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n",
184 Ticks<MillisecondsDouble>(time_1 - time_start), nPackagesSelected, nDescendantsUpdated,
185 Ticks<MillisecondsDouble>(time_2 - time_1),
186 Ticks<MillisecondsDouble>(time_2 - time_start));
187
188 return std::move(pblocktemplate);
189}
190
191void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
192{
193 for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
194 // Only test txs not already in the block
195 if (inBlock.count((*iit)->GetSharedTx()->GetHash())) {
196 testSet.erase(iit++);
197 } else {
198 iit++;
199 }
200 }
201}
202
203bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
204{
205 // TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
206 if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= m_options.nBlockMaxWeight) {
207 return false;
208 }
209 if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
210 return false;
211 }
212 return true;
213}
214
215// Perform transaction-level checks before adding to block:
216// - transaction finality (locktime)
217bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
218{
219 for (CTxMemPool::txiter it : package) {
220 if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
221 return false;
222 }
223 }
224 return true;
225}
226
227void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
228{
229 pblocktemplate->block.vtx.emplace_back(iter->GetSharedTx());
230 pblocktemplate->vTxFees.push_back(iter->GetFee());
231 pblocktemplate->vTxSigOpsCost.push_back(iter->GetSigOpCost());
232 nBlockWeight += iter->GetTxWeight();
233 ++nBlockTx;
234 nBlockSigOpsCost += iter->GetSigOpCost();
235 nFees += iter->GetFee();
236 inBlock.insert(iter->GetSharedTx()->GetHash());
237
238 if (m_options.print_modified_fee) {
239 LogPrintf("fee rate %s txid %s\n",
240 CFeeRate(iter->GetModifiedFee(), iter->GetTxSize()).ToString(),
241 iter->GetTx().GetHash().ToString());
242 }
243}
244
248static int UpdatePackagesForAdded(const CTxMemPool& mempool,
249 const CTxMemPool::setEntries& alreadyAdded,
251{
252 AssertLockHeld(mempool.cs);
253
254 int nDescendantsUpdated = 0;
255 for (CTxMemPool::txiter it : alreadyAdded) {
256 CTxMemPool::setEntries descendants;
257 mempool.CalculateDescendants(it, descendants);
258 // Insert all descendants (not yet in block) into the modified set
259 for (CTxMemPool::txiter desc : descendants) {
260 if (alreadyAdded.count(desc)) {
261 continue;
262 }
263 ++nDescendantsUpdated;
264 modtxiter mit = mapModifiedTx.find(desc);
265 if (mit == mapModifiedTx.end()) {
266 CTxMemPoolModifiedEntry modEntry(desc);
267 mit = mapModifiedTx.insert(modEntry).first;
268 }
269 mapModifiedTx.modify(mit, update_for_parent_inclusion(it));
270 }
271 }
272 return nDescendantsUpdated;
273}
274
275void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries)
276{
277 // Sort package by ancestor count
278 // If a transaction A depends on transaction B, then A's ancestor count
279 // must be greater than B's. So this is sufficient to validly order the
280 // transactions for block inclusion.
281 sortedEntries.clear();
282 sortedEntries.insert(sortedEntries.begin(), package.begin(), package.end());
283 std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByAncestorCount());
284}
285
286// This transaction selection algorithm orders the mempool based
287// on feerate of a transaction including all unconfirmed ancestors.
288// Since we don't remove transactions from the mempool as we select them
289// for block inclusion, we need an alternate method of updating the feerate
290// of a transaction with its not-yet-selected ancestors as we go.
291// This is accomplished by walking the in-mempool descendants of selected
292// transactions and storing a temporary modified state in mapModifiedTxs.
293// Each time through the loop, we compare the best transaction in
294// mapModifiedTxs with the next transaction in the mempool to decide what
295// transaction package to work on next.
296void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
297{
298 const auto& mempool{*Assert(m_mempool)};
299 LOCK(mempool.cs);
300
301 // mapModifiedTx will store sorted packages after they are modified
302 // because some of their txs are already in the block
304 // Keep track of entries that failed inclusion, to avoid duplicate work
305 std::set<Txid> failedTx;
306
307 CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
309
310 // Limit the number of attempts to add transactions to the block when it is
311 // close to full; this is just a simple heuristic to finish quickly if the
312 // mempool has a lot of entries.
313 const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
314 int64_t nConsecutiveFailed = 0;
315
316 while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) {
317 // First try to find a new transaction in mapTx to evaluate.
318 //
319 // Skip entries in mapTx that are already in a block or are present
320 // in mapModifiedTx (which implies that the mapTx ancestor state is
321 // stale due to ancestor inclusion in the block)
322 // Also skip transactions that we've already failed to add. This can happen if
323 // we consider a transaction in mapModifiedTx and it fails: we can then
324 // potentially consider it again while walking mapTx. It's currently
325 // guaranteed to fail again, but as a belt-and-suspenders check we put it in
326 // failedTx and avoid re-evaluation, since the re-evaluation would be using
327 // cached size/sigops/fee values that are not actually correct.
330 if (mi != mempool.mapTx.get<ancestor_score>().end()) {
331 auto it = mempool.mapTx.project<0>(mi);
332 assert(it != mempool.mapTx.end());
333 if (mapModifiedTx.count(it) || inBlock.count(it->GetSharedTx()->GetHash()) || failedTx.count(it->GetSharedTx()->GetHash())) {
334 ++mi;
335 continue;
336 }
337 }
338
339 // Now that mi is not stale, determine which transaction to evaluate:
340 // the next entry from mapTx, or the best from mapModifiedTx?
341 bool fUsingModified = false;
342
343 modtxscoreiter modit = mapModifiedTx.get<ancestor_score>().begin();
344 if (mi == mempool.mapTx.get<ancestor_score>().end()) {
345 // We're out of entries in mapTx; use the entry from mapModifiedTx
346 iter = modit->iter;
347 fUsingModified = true;
348 } else {
349 // Try to compare the mapTx entry to the mapModifiedTx entry
350 iter = mempool.mapTx.project<0>(mi);
351 if (modit != mapModifiedTx.get<ancestor_score>().end() &&
353 // The best entry in mapModifiedTx has higher score
354 // than the one from mapTx.
355 // Switch which transaction (package) to consider
356 iter = modit->iter;
357 fUsingModified = true;
358 } else {
359 // Either no entry in mapModifiedTx, or it's worse than mapTx.
360 // Increment mi for the next loop iteration.
361 ++mi;
362 }
363 }
364
365 // We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
366 // contain anything that is inBlock.
367 assert(!inBlock.count(iter->GetSharedTx()->GetHash()));
368
369 uint64_t packageSize = iter->GetSizeWithAncestors();
370 CAmount packageFees = iter->GetModFeesWithAncestors();
371 int64_t packageSigOpsCost = iter->GetSigOpCostWithAncestors();
372 if (fUsingModified) {
373 packageSize = modit->nSizeWithAncestors;
374 packageFees = modit->nModFeesWithAncestors;
375 packageSigOpsCost = modit->nSigOpCostWithAncestors;
376 }
377
378 if (packageFees < m_options.blockMinFeeRate.GetFee(packageSize)) {
379 // Everything else we might consider has a lower fee rate
380 return;
381 }
382
383 if (!TestPackage(packageSize, packageSigOpsCost)) {
384 if (fUsingModified) {
385 // Since we always look at the best entry in mapModifiedTx,
386 // we must erase failed entries so that we can consider the
387 // next best entry on the next loop iteration
388 mapModifiedTx.get<ancestor_score>().erase(modit);
389 failedTx.insert(iter->GetSharedTx()->GetHash());
390 }
391
392 ++nConsecutiveFailed;
393
394 if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
395 m_options.nBlockMaxWeight - m_options.block_reserved_weight) {
396 // Give up if we're close to full and haven't succeeded in a while
397 break;
398 }
399 continue;
400 }
401
402 auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *iter, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
403
404 onlyUnconfirmed(ancestors);
405 ancestors.insert(iter);
406
407 // Test if all tx's are Final
408 if (!TestPackageTransactions(ancestors)) {
409 if (fUsingModified) {
410 mapModifiedTx.get<ancestor_score>().erase(modit);
411 failedTx.insert(iter->GetSharedTx()->GetHash());
412 }
413 continue;
414 }
415
416 // This transaction will make it in; reset the failed counter.
417 nConsecutiveFailed = 0;
418
419 // Package can be added. Sort the entries in a valid order.
420 std::vector<CTxMemPool::txiter> sortedEntries;
421 SortForBlock(ancestors, sortedEntries);
422
423 for (size_t i = 0; i < sortedEntries.size(); ++i) {
424 AddToBlock(sortedEntries[i]);
425 // Erase from the modified set, if present
426 mapModifiedTx.erase(sortedEntries[i]);
427 }
428
429 ++nPackagesSelected;
430 pblocktemplate->m_package_feerates.emplace_back(packageFees, static_cast<int32_t>(packageSize));
431
432 // Update transactions that depend on each of these
433 nDescendantsUpdated += UpdatePackagesForAdded(mempool, ancestors, mapModifiedTx);
434 }
435}
436} // namespace node
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
ArgsManager gArgs
Definition: args.cpp:42
ArgsManager & args
Definition: bitcoind.cpp:277
#define Assert(val)
Identity function.
Definition: check.h:85
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:482
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:457
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:507
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
uint32_t nNonce
Definition: block.h:30
uint32_t nBits
Definition: block.h:29
uint32_t nTime
Definition: block.h:28
int32_t nVersion
Definition: block.h:25
uint256 hashPrevBlock
Definition: block.h:26
uint256 hashMerkleRoot
Definition: block.h:27
Definition: block.h:69
std::vector< CTransactionRef > vtx
Definition: block.h:72
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:141
uint256 GetBlockHash() const
Definition: chain.h:243
int64_t GetBlockTime() const
Definition: chain.h:266
int64_t GetMedianTimePast() const
Definition: chain.h:278
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:153
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:304
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:396
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:393
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:505
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:866
std::vector< unsigned char > GenerateCoinbaseCommitment(CBlock &block, const CBlockIndex *pindexPrev) const
Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks...
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1007
Definition: txmempool.h:164
std::string ToString() const
Definition: validation.h:111
BlockAssembler(Chainstate &chainstate, const CTxMemPool *mempool, const Options &options)
Definition: miner.cpp:86
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static int64_t GetBlockWeight(const CBlock &block)
Definition: validation.h:136
int GetWitnessCommitmentIndex(const CBlock &block)
Compute at which vout of the block's coinbase transaction the witness commitment occurs,...
Definition: validation.h:147
static constexpr int64_t MAX_TIMEWARP
Maximum number of seconds that the timestamp of the first block of a difficulty adjustment period is ...
Definition: consensus.h:35
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
static const int64_t MAX_BLOCK_SIGOPS_COST
The maximum allowed number of signature check operations in a block (network rule)
Definition: consensus.h:17
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
#define LogDebug(category,...)
Definition: logging.h:280
#define LogPrintf(...)
Definition: logging.h:266
unsigned int nHeight
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
Definition: merkle.cpp:66
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:45
@ BENCH
Definition: logging.h:47
Definition: messages.h:20
static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
Definition: miner.cpp:75
boost::multi_index_container< CTxMemPoolModifiedEntry, CTxMemPoolModifiedEntry_Indices > indexed_modified_transaction_set
Definition: miner.h:125
indexed_modified_transaction_set::nth_index< 0 >::type::iterator modtxiter
Definition: miner.h:127
void RegenerateCommitments(CBlock &block, ChainstateManager &chainman)
Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed.
Definition: miner.cpp:63
int64_t GetMinimumTime(const CBlockIndex *pindexPrev, const int64_t difficulty_adjustment_interval)
Get the minimum time a miner should use in the next block.
Definition: miner.cpp:32
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
Definition: miner.cpp:45
indexed_modified_transaction_set::index< ancestor_score >::type::iterator modtxscoreiter
Definition: miner.h:128
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
static int UpdatePackagesForAdded(const CTxMemPool &mempool, const CTxMemPool::setEntries &alreadyAdded, indexed_modified_transaction_set &mapModifiedTx) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add descendants of given transactions to mapModifiedTx with ancestor state updated assuming given tra...
Definition: miner.cpp:248
static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT
This accounts for the block header, var_int encoding of the transaction count and a minimally viable ...
Definition: policy.h:30
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock, const Consensus::Params &params)
Definition: pow.cpp:14
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:424
@ OP_0
Definition: script.h:76
A mutable version of CTransaction.
Definition: transaction.h:378
std::vector< CTxOut > vout
Definition: transaction.h:380
std::vector< CTxIn > vin
Definition: transaction.h:379
Parameters that influence chain consensus.
Definition: params.h:74
int64_t DifficultyAdjustmentInterval() const
Definition: params.h:123
bool fPowAllowMinDifficultyBlocks
Definition: params.h:110
static time_point now() noexcept
Return current system time or mocked time, if set.
Definition: time.cpp:26
static constexpr MemPoolLimits NoLimits()
size_t block_reserved_weight
The default reserved weight for the fixed-size block header, transaction count and coinbase transacti...
Definition: types.h:43
size_t coinbase_output_max_additional_sigops
The maximum additional sigops which the pool will add in coinbase transaction outputs.
Definition: types.h:48
Definition: miner.h:52
#define LOCK(cs)
Definition: sync.h:257
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.
Definition: tx_verify.cpp:17
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
bool TestBlockValidity(BlockValidationState &state, const CChainParams &chainparams, Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
Check a block is completely valid from start to finish (only works on top of our current best block)
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())