Bitcoin ABC  0.26.3
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 <common/args.h>
15 #include <config.h>
16 #include <consensus/activation.h>
17 #include <consensus/consensus.h>
18 #include <consensus/merkle.h>
19 #include <consensus/tx_verify.h>
20 #include <consensus/validation.h>
21 #include <minerfund.h>
23 #include <policy/policy.h>
24 #include <policy/settings.h>
25 #include <pow/pow.h>
26 #include <primitives/transaction.h>
27 #include <timedata.h>
28 #include <util/moneystr.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,
66  : chainParams(chainstate.m_chainman.GetParams()), m_mempool(mempool),
67  m_chainstate(chainstate), m_avalanche(avalanche),
69  gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY)) {
71  // Limit size to between 1K and options.nExcessiveBlockSize -1K for sanity:
72  nMaxGeneratedBlockSize = std::max<uint64_t>(
73  1000, std::min<uint64_t>(options.nExcessiveBlockSize - 1000,
74  options.nMaxGeneratedBlockSize));
75  // Calculate the max consensus sigchecks for this block.
76  auto nMaxBlockSigChecks = GetMaxBlockSigChecksCount(nMaxGeneratedBlockSize);
77  // Allow the full amount of signature check operations in lieu of a separate
78  // config option. (We are mining relayed transactions with validity cached
79  // by everyone else, and so the block will propagate quickly, regardless of
80  // how many sigchecks it contains.)
81  nMaxGeneratedBlockSigChecks = nMaxBlockSigChecks;
82 }
83 
85  // Block resource limits
86  // If -blockmaxsize is not given, limit to DEFAULT_MAX_GENERATED_BLOCK_SIZE
87  // If only one is given, only restrict the specified resource.
88  // If both are given, restrict both.
90 
91  options.nExcessiveBlockSize = config.GetMaxBlockSize();
92 
93  if (gArgs.IsArgSet("-blockmaxsize")) {
94  options.nMaxGeneratedBlockSize =
96  }
97 
98  Amount n = Amount::zero();
99  if (gArgs.IsArgSet("-blockmintxfee") &&
100  ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) {
101  options.blockMinFeeRate = CFeeRate(n);
102  }
103 
104  return options;
105 }
106 
108  const CTxMemPool *mempool,
110  : BlockAssembler(chainstate, mempool, DefaultOptions(config), avalanche) {}
111 
113  // Reserve space for coinbase tx.
114  nBlockSize = 1000;
115  nBlockSigChecks = 100;
116 
117  // These counters do not include coinbase tx.
118  nBlockTx = 0;
119  nFees = Amount::zero();
120 }
121 
122 std::optional<int64_t> BlockAssembler::m_last_block_num_txs{std::nullopt};
123 std::optional<int64_t> BlockAssembler::m_last_block_size{std::nullopt};
124 
125 std::unique_ptr<CBlockTemplate>
126 BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) {
127  int64_t nTimeStart = GetTimeMicros();
128 
129  resetBlock();
130 
131  pblocktemplate.reset(new CBlockTemplate());
132  if (!pblocktemplate.get()) {
133  return nullptr;
134  }
135 
136  // Pointer for convenience.
137  CBlock *const pblock = &pblocktemplate->block;
138 
139  // Add dummy coinbase tx as first transaction. It is updated at the end.
140  pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1);
141 
142  LOCK(::cs_main);
143  CBlockIndex *pindexPrev = m_chainstate.m_chain.Tip();
144  assert(pindexPrev != nullptr);
145  nHeight = pindexPrev->nHeight + 1;
146 
147  const Consensus::Params &consensusParams = chainParams.GetConsensus();
148 
149  pblock->nVersion = ComputeBlockVersion(pindexPrev, consensusParams);
150  // -regtest only: allow overriding block.nVersion with
151  // -blockversion=N to test forking scenarios
153  pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
154  }
155 
156  pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(GetAdjustedTime());
157  m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
158 
159  if (m_mempool) {
160  LOCK(m_mempool->cs);
161  addTxs(*m_mempool);
162  }
163 
164  if (IsMagneticAnomalyEnabled(consensusParams, pindexPrev)) {
165  // If magnetic anomaly is enabled, we make sure transaction are
166  // canonically ordered.
167  std::sort(std::begin(pblocktemplate->entries) + 1,
168  std::end(pblocktemplate->entries),
169  [](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b)
170  -> bool { return a.tx->GetId() < b.tx->GetId(); });
171  }
172 
173  // Copy all the transactions refs into the block
174  pblock->vtx.reserve(pblocktemplate->entries.size());
175  for (const CBlockTemplateEntry &entry : pblocktemplate->entries) {
176  pblock->vtx.push_back(entry.tx);
177  }
178 
179  int64_t nTime1 = GetTimeMicros();
180 
183 
184  // Create coinbase transaction.
185  CMutableTransaction coinbaseTx;
186  coinbaseTx.vin.resize(1);
187  coinbaseTx.vin[0].prevout = COutPoint();
188  coinbaseTx.vout.resize(1);
189  coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
190  coinbaseTx.vout[0].nValue =
191  nFees + GetBlockSubsidy(nHeight, consensusParams);
192  coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
193 
194  const Amount blockReward = coinbaseTx.vout[0].nValue;
195 
196  const auto whitelisted = GetMinerFundWhitelist(consensusParams);
197  if (!whitelisted.empty()) {
198  const Amount fund =
199  GetMinerFundAmount(consensusParams, blockReward, pindexPrev);
200  coinbaseTx.vout[0].nValue -= fund;
201  coinbaseTx.vout.emplace_back(
202  fund, GetScriptForDestination(*whitelisted.begin()));
203  }
204 
205  std::vector<CScript> stakingRewardsPayoutScripts;
206  if (m_avalanche && IsStakingRewardsActivated(consensusParams, pindexPrev) &&
208  stakingRewardsPayoutScripts)) {
209  const Amount stakingRewards = GetStakingRewardsAmount(blockReward);
210  coinbaseTx.vout[0].nValue -= stakingRewards;
211  coinbaseTx.vout.emplace_back(stakingRewards,
212  stakingRewardsPayoutScripts[0]);
213  }
214 
215  // Make sure the coinbase is big enough.
216  uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION);
217  if (coinbaseSize < MIN_TX_SIZE) {
218  coinbaseTx.vin[0].scriptSig
219  << std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1);
220  }
221 
222  pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx);
223  pblocktemplate->entries[0].fees = -1 * nFees;
224  pblock->vtx[0] = pblocktemplate->entries[0].tx;
225 
226  uint64_t nSerializeSize = GetSerializeSize(*pblock, PROTOCOL_VERSION);
227 
228  LogPrintf(
229  "CreateNewBlock(): total size: %u txs: %u fees: %ld sigChecks %d\n",
230  nSerializeSize, nBlockTx, nFees, nBlockSigChecks);
231 
232  // Fill in header.
233  pblock->hashPrevBlock = pindexPrev->GetBlockHash();
234  UpdateTime(pblock, chainParams, pindexPrev);
235  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainParams);
236  pblock->nNonce = 0;
237  pblocktemplate->entries[0].sigChecks = 0;
238 
239  BlockValidationState state;
240  if (!TestBlockValidity(state, chainParams, m_chainstate, *pblock,
241  pindexPrev, GetAdjustedTime,
243  .withCheckPoW(false)
244  .withCheckMerkleRoot(false))) {
245  throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s",
246  __func__, state.ToString()));
247  }
248  int64_t nTime2 = GetTimeMicros();
249 
250  LogPrint(
251  BCLog::BENCH,
252  "CreateNewBlock() addTxs: %.2fms, validity: %.2fms (total %.2fms)\n",
253  0.001 * (nTime1 - nTimeStart), 0.001 * (nTime2 - nTime1),
254  0.001 * (nTime2 - nTimeStart));
255 
256  return std::move(pblocktemplate);
257 }
258 
259 bool BlockAssembler::TestTxFits(uint64_t txSize, int64_t txSigChecks) const {
260  if (nBlockSize + txSize >= nMaxGeneratedBlockSize) {
261  return false;
262  }
263 
264  if (nBlockSigChecks + txSigChecks >= nMaxGeneratedBlockSigChecks) {
265  return false;
266  }
267 
268  return true;
269 }
270 
272  pblocktemplate->entries.emplace_back(entry->GetSharedTx(), entry->GetFee(),
273  entry->GetSigChecks());
274  nBlockSize += entry->GetTxSize();
275  ++nBlockTx;
276  nBlockSigChecks += entry->GetSigChecks();
277  nFees += entry->GetFee();
278 
279  if (fPrintPriority) {
280  LogPrintf(
281  "fee rate %s txid %s\n",
282  CFeeRate(entry->GetModifiedFee(), entry->GetTxSize()).ToString(),
283  entry->GetTx().GetId().ToString());
284  }
285 }
286 
287 bool BlockAssembler::CheckTx(const CTransaction &tx) const {
288  TxValidationState state;
291 }
292 
298 void BlockAssembler::addTxs(const CTxMemPool &mempool) {
299  // mapped_value is the number of mempool parents that are still needed for
300  // the entry. We decrement this count each time we add a parent of the entry
301  // to the block.
302  std::unordered_map<CTxMemPoolEntryRef, size_t> missingParentCount;
303  missingParentCount.reserve(mempool.size() / 2);
304 
305  // set of children we skipped because we have not yet added their parents
306  std::unordered_set<CTxMemPoolEntryRef> skippedChildren;
307 
308  auto hasMissingParents =
309  [&missingParentCount](const CTxMemPoolEntryRef &entry)
310  EXCLUSIVE_LOCKS_REQUIRED(mempool.cs) {
311  // If we've added any of this tx's parents already, then
312  // missingParentCount will have the current count
313  if (auto pcIt = missingParentCount.find(entry);
314  pcIt != missingParentCount.end()) {
315  // when pcIt->second reaches 0, we have added all of this
316  // tx's parents
317  return pcIt->second != 0;
318  }
319  return !entry->GetMemPoolParentsConst().empty();
320  };
321 
322  // Limit the number of attempts to add transactions to the block when it is
323  // close to full; this is just a simple heuristic to finish quickly if the
324  // mempool has a lot of entries.
325  const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
326  int64_t nConsecutiveFailed = 0;
327 
328  // Transactions where a parent has been added and need to be checked for
329  // inclusion.
330  std::queue<CTxMemPoolEntryRef> backlog;
331  auto mi = mempool.mapTx.get<modified_feerate>().begin();
332 
333  auto nextEntry = [&backlog, &mi](bool &isFromBacklog) {
334  if (backlog.empty()) {
335  return *mi++;
336  }
337 
338  auto &entry = backlog.front();
339  backlog.pop();
340 
341  isFromBacklog = true;
342 
343  return entry;
344  };
345 
346  while (!backlog.empty() ||
347  mi != mempool.mapTx.get<modified_feerate>().end()) {
348  // Get a new or old transaction in mapTx to evaluate.
349  bool isFromBacklog = false;
350  const CTxMemPoolEntryRef &entry = nextEntry(isFromBacklog);
351 
352  if (entry->GetModifiedFeeRate() < blockMinFeeRate) {
353  // Since the txs are sorted by fee, bail early if there is none that
354  // can be included in the block anymore.
355  break;
356  }
357 
358  // Check whether all of this tx's parents are already in the block. If
359  // not, pass on it until later.
360  //
361  // If it's from the backlog, then we know all parents are already in
362  // the block.
363  if (!isFromBacklog && hasMissingParents(entry)) {
364  skippedChildren.insert(entry);
365  continue;
366  }
367 
368  // Check whether the tx will exceed the block limits.
369  if (!TestTxFits(entry->GetTxSize(), entry->GetSigChecks())) {
370  ++nConsecutiveFailed;
371  if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES &&
373  // Give up if we're close to full and haven't succeeded in a
374  // while.
375  break;
376  }
377  continue;
378  }
379 
380  // Test transaction finality (locktime)
381  if (!CheckTx(entry->GetTx())) {
382  continue;
383  }
384 
385  // This transaction will make it in; reset the failed counter.
386  nConsecutiveFailed = 0;
387 
388  // Tx can be added.
389  AddToBlock(entry);
390 
391  // This tx's children may now be candidates for addition if they have
392  // higher scores than the tx at the cursor. We can only process a
393  // child once all of that tx's parents have been added, though. To
394  // avoid O(n^2) checking of dependencies, we store and decrement the
395  // number of mempool parents for each child. Although this code
396  // ends up taking O(n) time to process a single tx with n children,
397  // that's okay because the amount of time taken is proportional to the
398  // tx's byte size and fee paid.
399  for (const auto &child : entry->GetMemPoolChildrenConst()) {
400  // Remember this tx has missing parents.
401  // Create the map entry if it doesn't exist already, and init with
402  // the number of parents.
403  const auto &[parentCount, _] = missingParentCount.try_emplace(
404  child, child.get()->GetMemPoolParentsConst().size());
405  // We just added one parent, so decrement the counter and check if
406  // we have any missing parent remaining.
407  const bool allParentsAdded = --parentCount->second == 0;
408 
409  // If all parents have been added to the block, and if this child
410  // has been previously skipped due to missing parents, enqueue it
411  // (if it hasn't been skipped it will come up in a later iteration)
412  if (allParentsAdded && skippedChildren.count(child) > 0) {
413  backlog.push(child);
414  }
415  }
416  }
417 }
418 } // 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
ArgsManager gArgs
Definition: args.cpp:38
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: args.cpp:381
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:526
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:494
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:25
int64_t GetMedianTimePast() const
Definition: blockindex.h:192
BlockHash GetBlockHash() const
Definition: blockindex.h:146
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:38
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:150
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:80
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:125
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:92
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:505
unsigned long size() const
Definition: txmempool.h:477
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:630
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:739
Definition: config.h:19
virtual uint64_t GetMaxBlockSize() const =0
Definition: rcu.h:85
std::string ToString() const
Definition: validation.h:118
bool getStakingRewardWinners(const BlockHash &prevBlockHash, std::vector< CScript > &winners) const EXCLUSIVE_LOCKS_REQUIRED(!cs_stakingRewards)
Definition: processor.cpp:921
Generate a new block, without valid proof-of-work.
Definition: miner.h:53
Chainstate & m_chainstate
Definition: miner.h:75
uint64_t nMaxGeneratedBlockSize
Definition: miner.h:59
void resetBlock()
Clear the block's state and prepare for assembling a new block.
Definition: miner.cpp:112
const CTxMemPool *const m_mempool
Definition: miner.h:74
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition: miner.cpp:126
CFeeRate blockMinFeeRate
Definition: miner.h:61
const bool fPrintPriority
Definition: miner.h:78
uint64_t nBlockTx
Definition: miner.h:65
const CChainParams & chainParams
Definition: miner.h:72
int64_t m_lock_time_cutoff
Definition: miner.h:71
static std::optional< int64_t > m_last_block_size
Definition: miner.h:102
std::unique_ptr< CBlockTemplate > pblocktemplate
Definition: miner.h:56
bool CheckTx(const CTransaction &tx) const
Check the transaction for finality, etc before adding to block.
Definition: miner.cpp:287
static std::optional< int64_t > m_last_block_num_txs
Definition: miner.h:101
void AddToBlock(const CTxMemPoolEntryRef &entry)
Add a tx to the block.
Definition: miner.cpp:271
void addTxs(const CTxMemPool &mempool) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs)
Add transactions from the mempool based on individual tx feerate.
Definition: miner.cpp:298
uint64_t nBlockSigChecks
Definition: miner.h:66
BlockAssembler(const Config &config, Chainstate &chainstate, const CTxMemPool *mempool, const avalanche::Processor *avalanche=nullptr)
Definition: miner.cpp:107
uint64_t nBlockSize
Definition: miner.h:64
bool TestTxFits(uint64_t txSize, int64_t txSigChecks) const
Test if a new Tx would "fit" in the block.
Definition: miner.cpp:259
uint64_t nMaxGeneratedBlockSigChecks
Definition: miner.h:60
const avalanche::Processor *const m_avalanche
Definition: miner.h:76
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:211
#define LogPrintf(...)
Definition: logging.h:207
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:51
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:35
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:84
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:75
uint64_t nMaxGeneratedBlockSize
Definition: miner.h:84
uint64_t nExcessiveBlockSize
Definition: miner.h:83
Definition: miner.h:37
CTransactionRef tx
Definition: miner.h:38
#define LOCK(cs)
Definition: sync.h:306
#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:35
#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(bool 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:524
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