Bitcoin ABC  0.29.2
P2P Digital Currency
miner.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 The Bitcoin Core developers
3 // Copyright (c) 2020-2021 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include <node/miner.h>
8 
9 #include <avalanche/avalanche.h>
10 #include <avalanche/processor.h>
11 #include <chain.h>
12 #include <chainparams.h>
13 #include <coins.h>
14 #include <config.h>
15 #include <consensus/activation.h>
16 #include <consensus/consensus.h>
17 #include <consensus/merkle.h>
18 #include <consensus/tx_verify.h>
19 #include <consensus/validation.h>
20 #include <minerfund.h>
22 #include <policy/policy.h>
23 #include <policy/settings.h>
24 #include <pow/pow.h>
25 #include <primitives/transaction.h>
26 #include <timedata.h>
27 #include <util/moneystr.h>
28 #include <util/system.h>
29 #include <validation.h>
30 #include <versionbits.h>
31 
32 #include <algorithm>
33 #include <queue>
34 #include <unordered_map>
35 #include <utility>
36 
37 namespace node {
38 int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams,
39  const CBlockIndex *pindexPrev) {
40  int64_t nOldTime = pblock->nTime;
41  int64_t nNewTime{std::max<int64_t>(
42  pindexPrev->GetMedianTimePast() + 1,
43  TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime()))};
44 
45  if (nOldTime < nNewTime) {
46  pblock->nTime = nNewTime;
47  }
48 
49  // Updating time can change work required on testnet:
50  if (chainParams.GetConsensus().fPowAllowMinDifficultyBlocks) {
51  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainParams);
52  }
53 
54  return nNewTime - nOldTime;
55 }
56 
58  : nExcessiveBlockSize(DEFAULT_MAX_BLOCK_SIZE),
59  nMaxGeneratedBlockSize(DEFAULT_MAX_GENERATED_BLOCK_SIZE),
60  blockMinFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) {}
61 
63  const CTxMemPool *mempool,
64  const Options &options)
65  : chainParams(chainstate.m_chainman.GetParams()), m_mempool(mempool),
66  m_chainstate(chainstate), fPrintPriority(gArgs.GetBoolArg(
67  "-printpriority", DEFAULT_PRINTPRIORITY)) {
69  // Limit size to between 1K and options.nExcessiveBlockSize -1K for sanity:
70  nMaxGeneratedBlockSize = std::max<uint64_t>(
71  1000, std::min<uint64_t>(options.nExcessiveBlockSize - 1000,
72  options.nMaxGeneratedBlockSize));
73  // Calculate the max consensus sigchecks for this block.
74  auto nMaxBlockSigChecks = GetMaxBlockSigChecksCount(nMaxGeneratedBlockSize);
75  // Allow the full amount of signature check operations in lieu of a separate
76  // config option. (We are mining relayed transactions with validity cached
77  // by everyone else, and so the block will propagate quickly, regardless of
78  // how many sigchecks it contains.)
79  nMaxGeneratedBlockSigChecks = nMaxBlockSigChecks;
80 }
81 
83  // Block resource limits
84  // If -blockmaxsize is not given, limit to DEFAULT_MAX_GENERATED_BLOCK_SIZE
85  // If only one is given, only restrict the specified resource.
86  // If both are given, restrict both.
88 
89  options.nExcessiveBlockSize = config.GetMaxBlockSize();
90 
91  if (gArgs.IsArgSet("-blockmaxsize")) {
92  options.nMaxGeneratedBlockSize =
94  }
95 
96  Amount n = Amount::zero();
97  if (gArgs.IsArgSet("-blockmintxfee") &&
98  ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) {
99  options.blockMinFeeRate = CFeeRate(n);
100  }
101 
102  return options;
103 }
104 
106  const CTxMemPool *mempool)
107  : BlockAssembler(chainstate, mempool, DefaultOptions(config)) {}
108 
110  // Reserve space for coinbase tx.
111  nBlockSize = 1000;
112  nBlockSigChecks = 100;
113 
114  // These counters do not include coinbase tx.
115  nBlockTx = 0;
116  nFees = Amount::zero();
117 }
118 
119 std::optional<int64_t> BlockAssembler::m_last_block_num_txs{std::nullopt};
120 std::optional<int64_t> BlockAssembler::m_last_block_size{std::nullopt};
121 
122 std::unique_ptr<CBlockTemplate>
123 BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) {
124  int64_t nTimeStart = GetTimeMicros();
125 
126  resetBlock();
127 
128  pblocktemplate.reset(new CBlockTemplate());
129  if (!pblocktemplate.get()) {
130  return nullptr;
131  }
132 
133  // Pointer for convenience.
134  CBlock *const pblock = &pblocktemplate->block;
135 
136  // Add dummy coinbase tx as first transaction. It is updated at the end.
137  pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1);
138 
139  LOCK(::cs_main);
140  CBlockIndex *pindexPrev = m_chainstate.m_chain.Tip();
141  assert(pindexPrev != nullptr);
142  nHeight = pindexPrev->nHeight + 1;
143 
144  const Consensus::Params &consensusParams = chainParams.GetConsensus();
145 
146  pblock->nVersion = ComputeBlockVersion(pindexPrev, consensusParams);
147  // -regtest only: allow overriding block.nVersion with
148  // -blockversion=N to test forking scenarios
150  pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
151  }
152 
153  pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
154  m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
155 
156  if (m_mempool) {
157  LOCK(m_mempool->cs);
158  addTxs(*m_mempool);
159  }
160 
161  if (IsMagneticAnomalyEnabled(consensusParams, pindexPrev)) {
162  // If magnetic anomaly is enabled, we make sure transaction are
163  // canonically ordered.
164  std::sort(std::begin(pblocktemplate->entries) + 1,
165  std::end(pblocktemplate->entries),
166  [](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b)
167  -> bool { return a.tx->GetId() < b.tx->GetId(); });
168  }
169 
170  // Copy all the transactions refs into the block
171  pblock->vtx.reserve(pblocktemplate->entries.size());
172  for (const CBlockTemplateEntry &entry : pblocktemplate->entries) {
173  pblock->vtx.push_back(entry.tx);
174  }
175 
176  int64_t nTime1 = GetTimeMicros();
177 
180 
181  // Create coinbase transaction.
182  CMutableTransaction coinbaseTx;
183  coinbaseTx.vin.resize(1);
184  coinbaseTx.vin[0].prevout = COutPoint();
185  coinbaseTx.vout.resize(1);
186  coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
187  coinbaseTx.vout[0].nValue =
188  nFees + GetBlockSubsidy(nHeight, consensusParams);
189  coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
190 
191  const Amount blockReward = coinbaseTx.vout[0].nValue;
192 
193  const auto whitelisted = GetMinerFundWhitelist(consensusParams);
194  if (!whitelisted.empty()) {
195  const Amount fund =
196  GetMinerFundAmount(consensusParams, blockReward, pindexPrev);
197  coinbaseTx.vout[0].nValue -= fund;
198  coinbaseTx.vout.emplace_back(
199  fund, GetScriptForDestination(*whitelisted.begin()));
200  }
201 
202  std::vector<CScript> stakingRewardsPayoutScripts;
203  if (IsStakingRewardsActivated(consensusParams, pindexPrev) &&
204  g_avalanche->getStakingRewardWinners(pindexPrev->GetBlockHash(),
205  stakingRewardsPayoutScripts)) {
206  const Amount stakingRewards = GetStakingRewardsAmount(blockReward);
207  coinbaseTx.vout[0].nValue -= stakingRewards;
208  coinbaseTx.vout.emplace_back(stakingRewards,
209  stakingRewardsPayoutScripts[0]);
210  }
211 
212  // Make sure the coinbase is big enough.
213  uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION);
214  if (coinbaseSize < MIN_TX_SIZE) {
215  coinbaseTx.vin[0].scriptSig
216  << std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1);
217  }
218 
219  pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx);
220  pblocktemplate->entries[0].fees = -1 * nFees;
221  pblock->vtx[0] = pblocktemplate->entries[0].tx;
222 
223  uint64_t nSerializeSize = GetSerializeSize(*pblock, PROTOCOL_VERSION);
224 
225  LogPrintf(
226  "CreateNewBlock(): total size: %u txs: %u fees: %ld sigChecks %d\n",
227  nSerializeSize, nBlockTx, nFees, nBlockSigChecks);
228 
229  // Fill in header.
230  pblock->hashPrevBlock = pindexPrev->GetBlockHash();
231  UpdateTime(pblock, chainParams, pindexPrev);
232  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainParams);
233  pblock->nNonce = 0;
234  pblocktemplate->entries[0].sigChecks = 0;
235 
236  BlockValidationState state;
237  if (!TestBlockValidity(state, chainParams, m_chainstate, *pblock,
238  pindexPrev, GetAdjustedTime,
240  .withCheckPoW(false)
241  .withCheckMerkleRoot(false))) {
242  throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s",
243  __func__, state.ToString()));
244  }
245  int64_t nTime2 = GetTimeMicros();
246 
247  LogPrint(
248  BCLog::BENCH,
249  "CreateNewBlock() addTxs: %.2fms, validity: %.2fms (total %.2fms)\n",
250  0.001 * (nTime1 - nTimeStart), 0.001 * (nTime2 - nTime1),
251  0.001 * (nTime2 - nTimeStart));
252 
253  return std::move(pblocktemplate);
254 }
255 
256 bool BlockAssembler::TestTxFits(uint64_t txSize, int64_t txSigChecks) const {
257  if (nBlockSize + txSize >= nMaxGeneratedBlockSize) {
258  return false;
259  }
260 
261  if (nBlockSigChecks + txSigChecks >= nMaxGeneratedBlockSigChecks) {
262  return false;
263  }
264 
265  return true;
266 }
267 
269  pblocktemplate->entries.emplace_back(entry->GetSharedTx(), entry->GetFee(),
270  entry->GetSigChecks());
271  nBlockSize += entry->GetTxSize();
272  ++nBlockTx;
273  nBlockSigChecks += entry->GetSigChecks();
274  nFees += entry->GetFee();
275 
276  if (fPrintPriority) {
277  LogPrintf(
278  "fee rate %s txid %s\n",
279  CFeeRate(entry->GetModifiedFee(), entry->GetTxSize()).ToString(),
280  entry->GetTx().GetId().ToString());
281  }
282 }
283 
284 bool BlockAssembler::CheckTx(const CTransaction &tx) const {
285  TxValidationState state;
288 }
289 
295 void BlockAssembler::addTxs(const CTxMemPool &mempool) {
296  // mapped_value is the number of mempool parents that are still needed for
297  // the entry. We decrement this count each time we add a parent of the entry
298  // to the block.
299  std::unordered_map<CTxMemPoolEntryRef, size_t> missingParentCount;
300  missingParentCount.reserve(mempool.size() / 2);
301 
302  // set of children we skipped because we have not yet added their parents
303  std::unordered_set<CTxMemPoolEntryRef> skippedChildren;
304 
305  auto hasMissingParents =
306  [&missingParentCount](const CTxMemPoolEntryRef &entry)
307  EXCLUSIVE_LOCKS_REQUIRED(mempool.cs) {
308  // If we've added any of this tx's parents already, then
309  // missingParentCount will have the current count
310  if (auto pcIt = missingParentCount.find(entry);
311  pcIt != missingParentCount.end()) {
312  // when pcIt->second reaches 0, we have added all of this
313  // tx's parents
314  return pcIt->second != 0;
315  }
316  return !entry->GetMemPoolParentsConst().empty();
317  };
318 
319  // Limit the number of attempts to add transactions to the block when it is
320  // close to full; this is just a simple heuristic to finish quickly if the
321  // mempool has a lot of entries.
322  const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
323  int64_t nConsecutiveFailed = 0;
324 
325  // Transactions where a parent has been added and need to be checked for
326  // inclusion.
327  std::queue<CTxMemPoolEntryRef> backlog;
328  auto mi = mempool.mapTx.get<modified_feerate>().begin();
329 
330  auto nextEntry = [&backlog, &mi](bool &isFromBacklog) {
331  if (backlog.empty()) {
332  return *mi++;
333  }
334 
335  auto &entry = backlog.front();
336  backlog.pop();
337 
338  isFromBacklog = true;
339 
340  return entry;
341  };
342 
343  while (!backlog.empty() ||
344  mi != mempool.mapTx.get<modified_feerate>().end()) {
345  // Get a new or old transaction in mapTx to evaluate.
346  bool isFromBacklog = false;
347  const CTxMemPoolEntryRef &entry = nextEntry(isFromBacklog);
348 
349  if (entry->GetModifiedFeeRate() < blockMinFeeRate) {
350  // Since the txs are sorted by fee, bail early if there is none that
351  // can be included in the block anymore.
352  break;
353  }
354 
355  // Check whether all of this tx's parents are already in the block. If
356  // not, pass on it until later.
357  //
358  // If it's from the backlog, then we know all parents are already in
359  // the block.
360  if (!isFromBacklog && hasMissingParents(entry)) {
361  skippedChildren.insert(entry);
362  continue;
363  }
364 
365  // Check whether the tx will exceed the block limits.
366  if (!TestTxFits(entry->GetTxSize(), entry->GetSigChecks())) {
367  ++nConsecutiveFailed;
368  if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES &&
370  // Give up if we're close to full and haven't succeeded in a
371  // while.
372  break;
373  }
374  continue;
375  }
376 
377  // Test transaction finality (locktime)
378  if (!CheckTx(entry->GetTx())) {
379  continue;
380  }
381 
382  // This transaction will make it in; reset the failed counter.
383  nConsecutiveFailed = 0;
384 
385  // Tx can be added.
386  AddToBlock(entry);
387 
388  // This tx's children may now be candidates for addition if they have
389  // higher scores than the tx at the cursor. We can only process a
390  // child once all of that tx's parents have been added, though. To
391  // avoid O(n^2) checking of dependencies, we store and decrement the
392  // number of mempool parents for each child. Although this code
393  // ends up taking O(n) time to process a single tx with n children,
394  // that's okay because the amount of time taken is proportional to the
395  // tx's byte size and fee paid.
396  for (const auto &child : entry->GetMemPoolChildrenConst()) {
397  // Remember this tx has missing parents.
398  // Create the map entry if it doesn't exist already, and init with
399  // the number of parents.
400  const auto &[parentCount, _] = missingParentCount.try_emplace(
401  child, child.get()->GetMemPoolParentsConst().size());
402  // We just added one parent, so decrement the counter and check if
403  // we have any missing parent remaining.
404  const bool allParentsAdded = --parentCount->second == 0;
405 
406  // If all parents have been added to the block, and if this child
407  // has been previously skipped due to missing parents, enqueue it
408  // (if it hasn't been skipped it will come up in a later iteration)
409  if (allParentsAdded && skippedChildren.count(child) > 0) {
410  backlog.push(child);
411  }
412  }
413  }
414 }
415 } // namespace node
bool IsMagneticAnomalyEnabled(const Consensus::Params &params, int32_t nHeight)
Check if Nov 15, 2018 HF has activated using block height.
Definition: activation.cpp:37
static constexpr Amount SATOSHI
Definition: amount.h:143
std::unique_ptr< avalanche::Processor > g_avalanche
Global avalanche instance.
Definition: processor.cpp:38
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:490
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: system.cpp:635
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:603
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:23
uint32_t nNonce
Definition: block.h:31
uint32_t nBits
Definition: block.h:30
uint32_t nTime
Definition: block.h:29
BlockHash hashPrevBlock
Definition: block.h:27
int32_t nVersion
Definition: block.h:26
Definition: block.h:60
std::vector< CTransactionRef > vtx
Definition: block.h:63
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:26
int64_t GetMedianTimePast() const
Definition: blockindex.h:190
BlockHash GetBlockHash() const
Definition: blockindex.h:147
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:39
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:156
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:119
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:86
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
std::string ToString() const
Definition: feerate.cpp:57
A mutable version of CTransaction.
Definition: transaction.h:274
std::vector< CTxOut > vout
Definition: transaction.h:277
std::vector< CTxIn > vin
Definition: transaction.h:276
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:20
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:209
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:296
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:490
unsigned long size() const
Definition: txmempool.h:475
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:628
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:737
Definition: config.h:17
virtual uint64_t GetMaxBlockSize() const =0
Definition: rcu.h:85
std::string ToString() const
Definition: validation.h:118
Generate a new block, without valid proof-of-work.
Definition: miner.h:49
Chainstate & m_chainstate
Definition: miner.h:71
uint64_t nMaxGeneratedBlockSize
Definition: miner.h:55
void resetBlock()
Clear the block's state and prepare for assembling a new block.
Definition: miner.cpp:109
const CTxMemPool *const m_mempool
Definition: miner.h:70
BlockAssembler(const Config &config, Chainstate &chainstate, const CTxMemPool *mempool)
Definition: miner.cpp:105
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition: miner.cpp:123
CFeeRate blockMinFeeRate
Definition: miner.h:57
const bool fPrintPriority
Definition: miner.h:73
uint64_t nBlockTx
Definition: miner.h:61
const CChainParams & chainParams
Definition: miner.h:68
int64_t m_lock_time_cutoff
Definition: miner.h:67
static std::optional< int64_t > m_last_block_size
Definition: miner.h:95
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition: miner.h:52
bool CheckTx(const CTransaction &tx) const
Check the transaction for finality, etc before adding to block.
Definition: miner.cpp:284
static std::optional< int64_t > m_last_block_num_txs
Definition: miner.h:94
void AddToBlock(const CTxMemPoolEntryRef &entry)
Add a tx to the block.
Definition: miner.cpp:268
void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add transactions from the mempool based on individual tx feerate.
Definition: miner.cpp:295
uint64_t nBlockSigChecks
Definition: miner.h:62
uint64_t nBlockSize
Definition: miner.h:60
bool TestTxFits(uint64_t txSize, int64_t txSigChecks) const
Test if a new Tx would "fit" in the block.
Definition: miner.cpp:256
uint64_t nMaxGeneratedBlockSigChecks
Definition: miner.h:56
static const uint64_t MIN_TX_SIZE
The minimum allowed size for a transaction, in bytes.
Definition: consensus.h:16
static const uint64_t DEFAULT_MAX_BLOCK_SIZE
Default setting for maximum allowed size for a block, in bytes.
Definition: consensus.h:20
uint64_t GetMaxBlockSigChecksCount(uint64_t maxBlockSize)
Compute the maximum number of sigchecks that can be contained in a block given the MAXIMUM block size...
Definition: consensus.h:47
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
#define LogPrint(category,...)
Definition: logging.h:210
#define LogPrintf(...)
Definition: logging.h:206
Amount GetMinerFundAmount(const Consensus::Params &params, const Amount &coinbaseValue, const CBlockIndex *pprev)
Definition: minerfund.cpp:22
std::unordered_set< CTxDestination, TxDestinationHasher > GetMinerFundWhitelist(const Consensus::Params &params)
Definition: minerfund.cpp:49
bool ParseMoney(const std::string &money_string, Amount &nRet)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:37
@ BENCH
Definition: logging.h:44
Definition: init.h:28
static const bool DEFAULT_PRINTPRIORITY
Definition: miner.h:31
int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, const CBlockIndex *pindexPrev)
Definition: miner.cpp:38
static BlockAssembler::Options DefaultOptions(const Config &config)
Definition: miner.cpp:82
static constexpr uint64_t DEFAULT_MAX_GENERATED_BLOCK_SIZE
Default for -blockmaxsize, which controls the maximum size of block the mining code will create.
Definition: policy.h:25
static constexpr Amount DEFAULT_BLOCK_MIN_TX_FEE_PER_KB(1000 *SATOSHI)
Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by min...
uint32_t GetNextWorkRequired(const CBlockIndex *pindexPrev, const CBlockHeader *pblock, const CChainParams &chainParams)
Definition: pow.cpp:21
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:316
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
@ OP_0
Definition: script.h:49
size_t GetSerializeSize(const T &t, int nVersion=0)
Definition: serialize.h:1258
bool IsStakingRewardsActivated(const Consensus::Params &params, const CBlockIndex *pprev)
Amount GetStakingRewardsAmount(const Amount &coinbaseValue)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:240
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
Parameters that influence chain consensus.
Definition: params.h:34
bool fPowAllowMinDifficultyBlocks
Definition: params.h:77
uint64_t nMaxGeneratedBlockSize
Definition: miner.h:79
uint64_t nExcessiveBlockSize
Definition: miner.h:78
Definition: miner.h:33
CTransactionRef tx
Definition: miner.h:34
#define LOCK(cs)
Definition: sync.h:306
ArgsManager gArgs
Definition: system.cpp:80
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: time.cpp:105
NodeClock::time_point GetAdjustedTime()
Definition: timedata.cpp:34
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:68
bool ContextualCheckTransaction(const Consensus::Params &params, const CTransaction &tx, TxValidationState &state, int nHeight, int64_t nMedianTimePast)
Context dependent validity checks for non coinbase transactions.
Definition: tx_verify.cpp:41
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
assert(!tx.IsCoinBase())
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex *active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(boo TestBlockValidity)(BlockValidationState &state, const CChainParams &params, Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev, const std::function< NodeClock::time_point()> &adjusted_time_callback, BlockValidationOptions validationOptions) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction...
Definition: validation.h:526
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
Definition: versionbits.cpp:8