2013-07-31 15:43:35 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2023-08-16 19:27:31 +02:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2023-12-31 01:00:00 +01:00
|
|
|
// Copyright (c) 2014-2024 The Dash Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-07-31 15:43:35 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <miner.h>
|
|
|
|
|
|
|
|
#include <amount.h>
|
|
|
|
#include <chain.h>
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <consensus/consensus.h>
|
|
|
|
#include <consensus/merkle.h>
|
2019-02-15 14:56:43 +01:00
|
|
|
#include <consensus/tx_verify.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <consensus/validation.h>
|
2021-07-01 19:15:03 +02:00
|
|
|
#include <deploymentstatus.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <policy/feerate.h>
|
|
|
|
#include <policy/policy.h>
|
|
|
|
#include <pow.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <timedata.h>
|
2021-06-27 08:33:13 +02:00
|
|
|
#include <util/moneystr.h>
|
2019-02-15 14:56:43 +01:00
|
|
|
#include <util/system.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
|
|
|
|
#include <evo/specialtx.h>
|
|
|
|
#include <evo/cbtx.h>
|
2023-07-24 18:39:38 +02:00
|
|
|
#include <evo/creditpool.h>
|
2023-09-21 09:20:42 +02:00
|
|
|
#include <evo/mnhftx.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <evo/simplifiedmns.h>
|
2022-08-26 23:52:53 +02:00
|
|
|
#include <governance/governance.h>
|
2021-10-02 19:32:24 +02:00
|
|
|
#include <llmq/blockprocessor.h>
|
|
|
|
#include <llmq/chainlocks.h>
|
2023-07-30 03:23:02 +02:00
|
|
|
#include <llmq/context.h>
|
2022-09-22 13:14:48 +02:00
|
|
|
#include <llmq/instantsend.h>
|
2024-01-18 02:56:41 +01:00
|
|
|
#include <llmq/options.h>
|
2021-10-01 21:19:08 +02:00
|
|
|
#include <masternode/payments.h>
|
2022-08-26 23:52:53 +02:00
|
|
|
#include <spork.h>
|
2023-12-05 09:32:18 +01:00
|
|
|
#include <validation.h>
|
2018-11-23 15:42:09 +01:00
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
#include <algorithm>
|
2016-10-18 21:11:22 +02:00
|
|
|
#include <utility>
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
|
2015-05-22 23:49:50 +02:00
|
|
|
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
|
2014-10-22 01:31:01 +02:00
|
|
|
{
|
2015-05-22 23:49:50 +02:00
|
|
|
int64_t nOldTime = pblock->nTime;
|
|
|
|
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
|
|
|
|
|
|
|
if (nOldTime < nNewTime)
|
|
|
|
pblock->nTime = nNewTime;
|
2014-10-22 01:31:01 +02:00
|
|
|
|
|
|
|
// Updating time can change work required on testnet:
|
2015-04-10 18:42:50 +02:00
|
|
|
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
|
|
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
2015-05-22 23:49:50 +02:00
|
|
|
|
|
|
|
return nNewTime - nOldTime;
|
2014-10-22 01:31:01 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 12:37:42 +01:00
|
|
|
BlockAssembler::Options::Options() {
|
|
|
|
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
|
|
|
nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
|
|
|
|
}
|
|
|
|
|
2022-08-26 23:52:53 +02:00
|
|
|
BlockAssembler::BlockAssembler(const CSporkManager& sporkManager, CGovernanceManager& governanceManager,
|
2023-07-30 03:23:02 +02:00
|
|
|
LLMQContext& llmq_ctx, CEvoDB& evoDb, CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options) :
|
2022-08-26 23:52:53 +02:00
|
|
|
chainparams(params),
|
2022-09-22 13:14:48 +02:00
|
|
|
m_mempool(mempool),
|
2023-06-01 09:32:41 +02:00
|
|
|
m_chainstate(chainstate),
|
2023-02-11 03:25:11 +01:00
|
|
|
spork_manager(sporkManager),
|
|
|
|
governance_manager(governanceManager),
|
2023-07-30 03:23:02 +02:00
|
|
|
quorum_block_processor(*llmq_ctx.quorum_block_processor),
|
|
|
|
m_clhandler(*llmq_ctx.clhandler),
|
|
|
|
m_isman(*llmq_ctx.isman),
|
refactor: remove the g_evoDb global; use NodeContext and locals (#5058)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
globals should be avoided to avoid annoying lifetime / nullptr /
initialization issues
## What was done?
<!--- Describe your changes in detail -->
removed a global, g_evoDB
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
make check
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [ ] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
2022-12-10 18:58:17 +01:00
|
|
|
m_evoDb(evoDb)
|
2013-07-31 15:43:35 +02:00
|
|
|
{
|
2017-03-01 12:37:42 +01:00
|
|
|
blockMinFeeRate = options.blockMinFeeRate;
|
2023-12-05 09:32:18 +01:00
|
|
|
nBlockMaxSize = options.nBlockMaxSize;
|
2017-03-01 12:37:42 +01:00
|
|
|
}
|
2017-01-16 19:32:51 +01:00
|
|
|
|
2018-07-30 16:30:43 +02:00
|
|
|
static BlockAssembler::Options DefaultOptions()
|
2017-03-01 12:37:42 +01:00
|
|
|
{
|
|
|
|
// Block resource limits
|
|
|
|
BlockAssembler::Options options;
|
|
|
|
options.nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
|
2019-06-24 18:44:27 +02:00
|
|
|
if (gArgs.IsArgSet("-blockmaxsize")) {
|
|
|
|
options.nBlockMaxSize = gArgs.GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
2017-03-01 12:37:42 +01:00
|
|
|
}
|
2022-12-20 17:14:58 +01:00
|
|
|
if (gArgs.IsArgSet("-blockmintxfee")) {
|
|
|
|
std::optional<CAmount> parsed = ParseMoney(gArgs.GetArg("-blockmintxfee", ""));
|
|
|
|
options.blockMinFeeRate = CFeeRate{parsed.value_or(DEFAULT_BLOCK_MIN_TX_FEE)};
|
2017-01-16 19:32:51 +01:00
|
|
|
} else {
|
2022-12-20 17:14:58 +01:00
|
|
|
options.blockMinFeeRate = CFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
|
2017-01-16 19:32:51 +01:00
|
|
|
}
|
2017-03-01 12:37:42 +01:00
|
|
|
return options;
|
2016-06-13 11:27:11 +02:00
|
|
|
}
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2022-08-26 23:52:53 +02:00
|
|
|
BlockAssembler::BlockAssembler(const CSporkManager& sporkManager, CGovernanceManager& governanceManager,
|
2023-07-30 03:23:02 +02:00
|
|
|
LLMQContext& llmq_ctx, CEvoDB& evoDb, CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params)
|
|
|
|
: BlockAssembler(sporkManager, governanceManager, llmq_ctx, evoDb, chainstate, mempool, params, DefaultOptions()) {}
|
2017-03-01 12:37:42 +01:00
|
|
|
|
2016-06-13 11:27:11 +02:00
|
|
|
void BlockAssembler::resetBlock()
|
|
|
|
{
|
|
|
|
inBlock.clear();
|
2015-11-03 16:35:39 +01:00
|
|
|
|
2016-06-13 11:27:11 +02:00
|
|
|
// Reserve space for coinbase tx
|
|
|
|
nBlockSize = 1000;
|
|
|
|
nBlockSigOps = 100;
|
2015-11-03 16:35:39 +01:00
|
|
|
|
2016-06-13 11:27:11 +02:00
|
|
|
// These counters do not include coinbase tx
|
|
|
|
nBlockTx = 0;
|
|
|
|
nFees = 0;
|
|
|
|
}
|
|
|
|
|
2023-06-01 09:32:41 +02:00
|
|
|
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
|
2016-06-13 11:27:11 +02:00
|
|
|
{
|
2017-03-30 20:53:31 +02:00
|
|
|
int64_t nTimeStart = GetTimeMicros();
|
|
|
|
|
2016-06-13 11:27:11 +02:00
|
|
|
resetBlock();
|
|
|
|
|
|
|
|
pblocktemplate.reset(new CBlockTemplate());
|
|
|
|
|
|
|
|
if(!pblocktemplate.get())
|
2016-10-18 21:11:22 +02:00
|
|
|
return nullptr;
|
2020-07-09 20:24:13 +02:00
|
|
|
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
|
2016-06-13 11:27:11 +02:00
|
|
|
|
|
|
|
// Add dummy coinbase tx as first transaction
|
2016-11-21 10:51:32 +01:00
|
|
|
pblock->vtx.emplace_back();
|
2016-06-13 11:27:11 +02:00
|
|
|
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
|
|
|
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
|
|
|
|
|
2019-07-03 15:46:43 +02:00
|
|
|
LOCK2(cs_main, m_mempool.cs);
|
2023-06-01 09:32:41 +02:00
|
|
|
assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*m_chainstate.m_chain.Tip()));
|
|
|
|
CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
|
2017-09-06 23:53:55 +02:00
|
|
|
assert(pindexPrev != nullptr);
|
2016-06-13 11:27:11 +02:00
|
|
|
nHeight = pindexPrev->nHeight + 1;
|
|
|
|
|
2023-12-05 09:32:18 +01:00
|
|
|
const bool fDIP0001Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0001)};
|
2023-12-05 08:48:03 +01:00
|
|
|
const bool fDIP0003Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003)};
|
|
|
|
const bool fDIP0008Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008)};
|
2023-12-04 21:06:32 +01:00
|
|
|
const bool fV20Active_context{DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V20)};
|
2019-04-25 17:39:04 +02:00
|
|
|
|
2023-12-05 09:32:18 +01:00
|
|
|
// Limit size to between 1K and MaxBlockSize()-1K for sanity:
|
|
|
|
nBlockMaxSize = std::max<unsigned int>(1000, std::min<unsigned int>(MaxBlockSize(fDIP0001Active_context) - 1000, nBlockMaxSize));
|
|
|
|
nBlockMaxSigOps = MaxBlockSigOps(fDIP0001Active_context);
|
|
|
|
|
2021-07-01 19:15:03 +02:00
|
|
|
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
|
2023-06-19 21:04:48 +02:00
|
|
|
// Non-mainnet only: allow overriding block.nVersion with
|
2016-06-13 11:27:11 +02:00
|
|
|
// -blockversion=N to test forking scenarios
|
2023-06-19 21:04:48 +02:00
|
|
|
if (Params().NetworkIDString() != CBaseChainParams::MAIN)
|
2019-06-24 18:44:27 +02:00
|
|
|
pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion);
|
2016-06-13 11:27:11 +02:00
|
|
|
|
|
|
|
pblock->nTime = GetAdjustedTime();
|
|
|
|
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
|
|
|
|
|
|
|
nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
|
|
|
? nMedianTimePast
|
|
|
|
: pblock->GetBlockTime();
|
|
|
|
|
2018-11-23 15:42:09 +01:00
|
|
|
if (fDIP0003Active_context) {
|
2024-01-18 02:56:41 +01:00
|
|
|
for (const Consensus::LLMQParams& params : llmq::GetEnabledQuorumParams(pindexPrev)) {
|
2022-04-16 16:46:04 +02:00
|
|
|
std::vector<CTransactionRef> vqcTx;
|
2022-09-22 13:14:48 +02:00
|
|
|
if (quorum_block_processor.GetMineableCommitmentsTx(params,
|
|
|
|
nHeight,
|
|
|
|
vqcTx)) {
|
2022-04-16 16:46:04 +02:00
|
|
|
for (const auto& qcTx : vqcTx) {
|
|
|
|
pblock->vtx.emplace_back(qcTx);
|
|
|
|
pblocktemplate->vTxFees.emplace_back(0);
|
|
|
|
pblocktemplate->vTxSigOps.emplace_back(0);
|
|
|
|
nBlockSize += qcTx->GetTotalSize();
|
|
|
|
++nBlockTx;
|
|
|
|
}
|
2018-11-23 15:42:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:53:31 +02:00
|
|
|
int nPackagesSelected = 0;
|
|
|
|
int nDescendantsUpdated = 0;
|
2023-07-24 18:39:38 +02:00
|
|
|
|
2023-10-30 15:57:20 +01:00
|
|
|
addPackageTxs(nPackagesSelected, nDescendantsUpdated, pindexPrev);
|
2017-03-30 20:53:31 +02:00
|
|
|
|
|
|
|
int64_t nTime1 = GetTimeMicros();
|
2016-06-13 11:27:11 +02:00
|
|
|
|
2019-02-15 14:56:43 +01:00
|
|
|
m_last_block_num_txs = nBlockTx;
|
|
|
|
m_last_block_size = nBlockSize;
|
2016-06-13 11:27:11 +02:00
|
|
|
LogPrintf("CreateNewBlock(): total size %u txs: %u fees: %ld sigops %d\n", nBlockSize, nBlockTx, nFees, nBlockSigOps);
|
|
|
|
|
|
|
|
// Create coinbase transaction.
|
|
|
|
CMutableTransaction coinbaseTx;
|
|
|
|
coinbaseTx.vin.resize(1);
|
|
|
|
coinbaseTx.vin[0].prevout.SetNull();
|
|
|
|
coinbaseTx.vout.resize(1);
|
|
|
|
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
|
|
|
|
|
|
|
|
// NOTE: unlike in bitcoin, we need to pass PREVIOUS block height here
|
2023-10-23 18:57:32 +02:00
|
|
|
CAmount blockSubsidy = GetBlockSubsidyInner(pindexPrev->nBits, pindexPrev->nHeight, Params().GetConsensus(), fV20Active_context);
|
2023-10-18 05:07:37 +02:00
|
|
|
CAmount blockReward = blockSubsidy + nFees;
|
2016-06-13 11:27:11 +02:00
|
|
|
|
|
|
|
// Compute regular coinbase transaction.
|
|
|
|
coinbaseTx.vout[0].nValue = blockReward;
|
2018-04-06 11:00:10 +02:00
|
|
|
|
|
|
|
if (!fDIP0003Active_context) {
|
|
|
|
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
|
|
|
} else {
|
|
|
|
coinbaseTx.vin[0].scriptSig = CScript() << OP_RETURN;
|
|
|
|
|
|
|
|
coinbaseTx.nVersion = 3;
|
|
|
|
coinbaseTx.nType = TRANSACTION_COINBASE;
|
|
|
|
|
|
|
|
CCbTx cbTx;
|
2019-04-04 10:25:50 +02:00
|
|
|
|
2023-07-24 18:39:38 +02:00
|
|
|
if (fV20Active_context) {
|
2023-11-24 18:25:30 +01:00
|
|
|
cbTx.nVersion = CCbTx::Version::CLSIG_AND_BALANCE;
|
2023-05-09 05:34:26 +02:00
|
|
|
} else if (fDIP0008Active_context) {
|
2023-11-24 18:25:30 +01:00
|
|
|
cbTx.nVersion = CCbTx::Version::MERKLE_ROOT_QUORUMS;
|
2019-04-04 10:25:50 +02:00
|
|
|
} else {
|
2023-11-24 18:25:30 +01:00
|
|
|
cbTx.nVersion = CCbTx::Version::MERKLE_ROOT_MNLIST;
|
2019-04-04 10:25:50 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 11:00:10 +02:00
|
|
|
cbTx.nHeight = nHeight;
|
2018-04-09 10:35:43 +02:00
|
|
|
|
2019-10-30 15:27:22 +01:00
|
|
|
BlockValidationState state;
|
2019-07-24 17:45:04 +02:00
|
|
|
if (!CalcCbTxMerkleRootMNList(*pblock, pindexPrev, cbTx.merkleRootMNList, state, ::ChainstateActive().CoinsTip())) {
|
2020-03-01 21:33:52 +01:00
|
|
|
throw std::runtime_error(strprintf("%s: CalcCbTxMerkleRootMNList failed: %s", __func__, state.ToString()));
|
2018-04-09 10:35:43 +02:00
|
|
|
}
|
2019-04-04 10:25:50 +02:00
|
|
|
if (fDIP0008Active_context) {
|
2022-09-22 13:14:48 +02:00
|
|
|
if (!CalcCbTxMerkleRootQuorums(*pblock, pindexPrev, quorum_block_processor, cbTx.merkleRootQuorums, state)) {
|
2020-03-01 21:33:52 +01:00
|
|
|
throw std::runtime_error(strprintf("%s: CalcCbTxMerkleRootQuorums failed: %s", __func__, state.ToString()));
|
2019-04-04 10:25:50 +02:00
|
|
|
}
|
2023-07-24 18:39:38 +02:00
|
|
|
if (fV20Active_context) {
|
2023-05-09 05:34:26 +02:00
|
|
|
if (CalcCbTxBestChainlock(m_clhandler, pindexPrev, cbTx.bestCLHeightDiff, cbTx.bestCLSignature)) {
|
|
|
|
LogPrintf("CreateNewBlock() h[%d] CbTx bestCLHeightDiff[%d] CLSig[%s]\n", nHeight, cbTx.bestCLHeightDiff, cbTx.bestCLSignature.ToString());
|
2023-07-24 18:39:38 +02:00
|
|
|
} else {
|
2023-05-09 05:34:26 +02:00
|
|
|
// not an error
|
|
|
|
LogPrintf("CreateNewBlock() h[%d] CbTx failed to find best CL. Inserting null CL\n", nHeight);
|
|
|
|
}
|
2023-10-30 15:57:20 +01:00
|
|
|
BlockValidationState state;
|
|
|
|
const auto creditPoolDiff = GetCreditPoolDiffForBlock(*pblock, pindexPrev, chainparams.GetConsensus(), blockSubsidy, state);
|
|
|
|
if (creditPoolDiff == std::nullopt) {
|
|
|
|
throw std::runtime_error(strprintf("%s: GetCreditPoolDiffForBlock failed: %s", __func__, state.ToString()));
|
2022-12-08 10:10:26 +01:00
|
|
|
}
|
2023-10-30 15:57:20 +01:00
|
|
|
|
2023-08-08 12:49:31 +02:00
|
|
|
cbTx.creditPoolBalance = creditPoolDiff->GetTotalLocked();
|
2023-05-09 05:34:26 +02:00
|
|
|
}
|
2019-04-04 10:25:50 +02:00
|
|
|
}
|
2018-04-09 10:35:43 +02:00
|
|
|
|
2018-04-06 11:00:10 +02:00
|
|
|
SetTxPayload(coinbaseTx, cbTx);
|
|
|
|
}
|
2016-06-13 11:27:11 +02:00
|
|
|
|
|
|
|
// Update coinbase transaction with additional info about masternode and governance payments,
|
|
|
|
// get some info back to pass to getblocktemplate
|
2023-10-18 05:07:37 +02:00
|
|
|
MasternodePayments::FillBlockPayments(spork_manager, governance_manager, coinbaseTx, pindexPrev, blockSubsidy, nFees, pblocktemplate->voutMasternodePayments, pblocktemplate->voutSuperblockPayments);
|
2016-06-13 11:27:11 +02:00
|
|
|
|
2016-11-21 10:51:32 +01:00
|
|
|
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
|
2016-06-13 11:27:11 +02:00
|
|
|
pblocktemplate->vTxFees[0] = -nFees;
|
|
|
|
|
|
|
|
// Fill in header
|
|
|
|
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
|
|
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
|
|
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
|
|
|
|
pblock->nNonce = 0;
|
2018-08-11 00:28:30 +02:00
|
|
|
pblocktemplate->nPrevBits = pindexPrev->nBits;
|
2016-11-21 10:51:32 +01:00
|
|
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(*pblock->vtx[0]);
|
2016-06-13 11:27:11 +02:00
|
|
|
|
2019-10-30 15:27:22 +01:00
|
|
|
BlockValidationState state;
|
2023-06-01 09:32:41 +02:00
|
|
|
assert(std::addressof(::ChainstateActive()) == std::addressof(m_chainstate));
|
|
|
|
if (!TestBlockValidity(state, m_clhandler, m_evoDb, chainparams, m_chainstate, *pblock, pindexPrev, false, false)) {
|
2020-03-01 21:33:52 +01:00
|
|
|
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
|
2016-06-13 11:27:11 +02:00
|
|
|
}
|
2017-03-30 20:53:31 +02:00
|
|
|
int64_t nTime2 = GetTimeMicros();
|
|
|
|
|
2019-05-22 23:51:39 +02:00
|
|
|
LogPrint(BCLog::BENCHMARK, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
|
2014-05-10 14:47:16 +02:00
|
|
|
|
2016-10-18 21:11:22 +02:00
|
|
|
return std::move(pblocktemplate);
|
2016-06-13 11:27:11 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
|
|
|
{
|
|
|
|
for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
|
|
|
|
// Only test txs not already in the block
|
|
|
|
if (inBlock.count(*iit)) {
|
|
|
|
testSet.erase(iit++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 02:09:10 +02:00
|
|
|
bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOps) const
|
2016-06-16 18:42:45 +02:00
|
|
|
{
|
|
|
|
if (nBlockSize + packageSize >= nBlockMaxSize)
|
|
|
|
return false;
|
2023-12-05 09:32:18 +01:00
|
|
|
if (nBlockSigOps + packageSigOps >= nBlockMaxSigOps)
|
2016-06-16 18:42:45 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2016-07-18 08:23:38 +02:00
|
|
|
// Perform transaction-level checks before adding to block:
|
|
|
|
// - transaction finality (locktime)
|
2019-03-06 07:58:27 +01:00
|
|
|
// - safe TXs in regard to ChainLocks
|
2021-01-07 09:03:35 +01:00
|
|
|
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
|
2016-06-16 18:42:45 +02:00
|
|
|
{
|
2018-06-24 16:34:56 +02:00
|
|
|
for (CTxMemPool::txiter it : package) {
|
2016-06-16 18:42:45 +02:00
|
|
|
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
|
|
|
return false;
|
2023-07-10 17:13:42 +02:00
|
|
|
|
|
|
|
const auto& txid = it->GetTx().GetHash();
|
|
|
|
if (!m_isman.RejectConflictingBlocks() || !m_isman.IsInstantSendEnabled() || m_isman.IsLocked(txid)) continue;
|
|
|
|
|
2023-10-18 05:31:40 +02:00
|
|
|
if (!it->GetTx().vin.empty() && !m_clhandler.IsTxSafeForMining(txid)) {
|
2019-03-06 07:58:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-16 18:42:45 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2016-06-13 11:27:11 +02:00
|
|
|
void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
|
|
|
|
{
|
2020-07-09 20:24:13 +02:00
|
|
|
pblocktemplate->block.vtx.emplace_back(iter->GetSharedTx());
|
2016-06-13 11:27:11 +02:00
|
|
|
pblocktemplate->vTxFees.push_back(iter->GetFee());
|
|
|
|
pblocktemplate->vTxSigOps.push_back(iter->GetSigOpCount());
|
|
|
|
nBlockSize += iter->GetTxSize();
|
|
|
|
++nBlockTx;
|
|
|
|
nBlockSigOps += iter->GetSigOpCount();
|
|
|
|
nFees += iter->GetFee();
|
|
|
|
inBlock.insert(iter);
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2019-06-24 18:44:27 +02:00
|
|
|
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
|
2016-06-13 11:27:11 +02:00
|
|
|
if (fPrintPriority) {
|
2019-03-14 15:44:42 +01:00
|
|
|
LogPrintf("fee %s txid %s\n",
|
2016-06-13 11:27:11 +02:00
|
|
|
CFeeRate(iter->GetModifiedFee(), iter->GetTxSize()).ToString(),
|
|
|
|
iter->GetTx().GetHash().ToString());
|
|
|
|
}
|
|
|
|
}
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2017-03-30 20:53:31 +02:00
|
|
|
int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
|
2016-06-16 18:42:45 +02:00
|
|
|
indexed_modified_transaction_set &mapModifiedTx)
|
|
|
|
{
|
2021-12-07 18:48:14 +01:00
|
|
|
AssertLockHeld(m_mempool.cs);
|
|
|
|
|
2017-03-30 20:53:31 +02:00
|
|
|
int nDescendantsUpdated = 0;
|
2018-06-24 16:34:56 +02:00
|
|
|
for (CTxMemPool::txiter it : alreadyAdded) {
|
2016-06-16 18:42:45 +02:00
|
|
|
CTxMemPool::setEntries descendants;
|
2019-07-03 15:46:43 +02:00
|
|
|
m_mempool.CalculateDescendants(it, descendants);
|
2016-06-16 18:42:45 +02:00
|
|
|
// Insert all descendants (not yet in block) into the modified set
|
2019-07-05 09:06:28 +02:00
|
|
|
for (CTxMemPool::txiter desc : descendants) {
|
2016-06-16 18:42:45 +02:00
|
|
|
if (alreadyAdded.count(desc))
|
|
|
|
continue;
|
2017-03-30 20:53:31 +02:00
|
|
|
++nDescendantsUpdated;
|
2016-06-16 18:42:45 +02:00
|
|
|
modtxiter mit = mapModifiedTx.find(desc);
|
|
|
|
if (mit == mapModifiedTx.end()) {
|
|
|
|
CTxMemPoolModifiedEntry modEntry(desc);
|
|
|
|
modEntry.nSizeWithAncestors -= it->GetTxSize();
|
|
|
|
modEntry.nModFeesWithAncestors -= it->GetModifiedFee();
|
|
|
|
modEntry.nSigOpCountWithAncestors -= it->GetSigOpCount();
|
|
|
|
mapModifiedTx.insert(modEntry);
|
|
|
|
} else {
|
|
|
|
mapModifiedTx.modify(mit, update_for_parent_inclusion(it));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-30 20:53:31 +02:00
|
|
|
return nDescendantsUpdated;
|
2016-06-16 18:42:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip entries in mapTx that are already in a block or are present
|
|
|
|
// in mapModifiedTx (which implies that the mapTx ancestor state is
|
|
|
|
// stale due to ancestor inclusion in the block)
|
|
|
|
// Also skip transactions that we've already failed to add. This can happen if
|
|
|
|
// we consider a transaction in mapModifiedTx and it fails: we can then
|
|
|
|
// potentially consider it again while walking mapTx. It's currently
|
|
|
|
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
|
|
|
|
// failedTx and avoid re-evaluation, since the re-evaluation would be using
|
|
|
|
// cached size/sigops/fee values that are not actually correct.
|
|
|
|
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx)
|
|
|
|
{
|
2021-12-07 18:48:14 +01:00
|
|
|
AssertLockHeld(m_mempool.cs);
|
|
|
|
|
2019-07-03 15:46:43 +02:00
|
|
|
assert(it != m_mempool.mapTx.end());
|
2017-05-02 14:50:25 +02:00
|
|
|
return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
|
2016-06-16 18:42:45 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 00:12:47 +01:00
|
|
|
void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries)
|
2016-06-16 18:42:45 +02:00
|
|
|
{
|
|
|
|
// Sort package by ancestor count
|
|
|
|
// If a transaction A depends on transaction B, then A's ancestor count
|
|
|
|
// must be greater than B's. So this is sufficient to validly order the
|
|
|
|
// transactions for block inclusion.
|
|
|
|
sortedEntries.clear();
|
|
|
|
sortedEntries.insert(sortedEntries.begin(), package.begin(), package.end());
|
|
|
|
std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByAncestorCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
// This transaction selection algorithm orders the mempool based
|
|
|
|
// on feerate of a transaction including all unconfirmed ancestors.
|
|
|
|
// Since we don't remove transactions from the mempool as we select them
|
|
|
|
// for block inclusion, we need an alternate method of updating the feerate
|
|
|
|
// of a transaction with its not-yet-selected ancestors as we go.
|
|
|
|
// This is accomplished by walking the in-mempool descendants of selected
|
|
|
|
// transactions and storing a temporary modified state in mapModifiedTxs.
|
|
|
|
// Each time through the loop, we compare the best transaction in
|
|
|
|
// mapModifiedTxs with the next transaction in the mempool to decide what
|
|
|
|
// transaction package to work on next.
|
2023-10-30 15:57:20 +01:00
|
|
|
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, const CBlockIndex* const pindexPrev)
|
2016-06-16 18:42:45 +02:00
|
|
|
{
|
2021-12-07 18:48:14 +01:00
|
|
|
AssertLockHeld(m_mempool.cs);
|
|
|
|
|
2023-10-30 15:57:20 +01:00
|
|
|
// This credit pool is used only to check withdrawal limits and to find
|
|
|
|
// duplicates of indexes. There's used `BlockSubsidy` equaled to 0
|
|
|
|
std::optional<CCreditPoolDiff> creditPoolDiff;
|
2023-12-04 21:06:32 +01:00
|
|
|
if (DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V20)) {
|
2023-10-30 15:57:20 +01:00
|
|
|
CCreditPool creditPool = creditPoolManager->GetCreditPool(pindexPrev, chainparams.GetConsensus());
|
|
|
|
creditPoolDiff.emplace(std::move(creditPool), pindexPrev, chainparams.GetConsensus(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This map with signals is used only to find duplicates
|
|
|
|
std::unordered_map<uint8_t, int> signals = m_chainstate.GetMNHFSignalsStage(pindexPrev);
|
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
// mapModifiedTx will store sorted packages after they are modified
|
|
|
|
// because some of their txs are already in the block
|
|
|
|
indexed_modified_transaction_set mapModifiedTx;
|
|
|
|
// Keep track of entries that failed inclusion, to avoid duplicate work
|
|
|
|
CTxMemPool::setEntries failedTx;
|
|
|
|
|
2019-07-03 15:46:43 +02:00
|
|
|
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = m_mempool.mapTx.get<ancestor_score>().begin();
|
2016-06-16 18:42:45 +02:00
|
|
|
CTxMemPool::txiter iter;
|
2017-03-30 20:53:31 +02:00
|
|
|
|
|
|
|
// Limit the number of attempts to add transactions to the block when it is
|
|
|
|
// close to full; this is just a simple heuristic to finish quickly if the
|
|
|
|
// mempool has a lot of entries.
|
|
|
|
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
|
|
|
|
int64_t nConsecutiveFailed = 0;
|
|
|
|
|
2019-07-03 15:46:43 +02:00
|
|
|
while (mi != m_mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) {
|
2016-06-16 18:42:45 +02:00
|
|
|
// First try to find a new transaction in mapTx to evaluate.
|
2019-07-03 15:46:43 +02:00
|
|
|
if (mi != m_mempool.mapTx.get<ancestor_score>().end() &&
|
|
|
|
SkipMapTxEntry(m_mempool.mapTx.project<0>(mi), mapModifiedTx, failedTx)) {
|
2016-06-16 18:42:45 +02:00
|
|
|
++mi;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that mi is not stale, determine which transaction to evaluate:
|
|
|
|
// the next entry from mapTx, or the best from mapModifiedTx?
|
|
|
|
bool fUsingModified = false;
|
|
|
|
|
|
|
|
modtxscoreiter modit = mapModifiedTx.get<ancestor_score>().begin();
|
2019-07-03 15:46:43 +02:00
|
|
|
if (mi == m_mempool.mapTx.get<ancestor_score>().end()) {
|
2016-06-16 18:42:45 +02:00
|
|
|
// We're out of entries in mapTx; use the entry from mapModifiedTx
|
|
|
|
iter = modit->iter;
|
|
|
|
fUsingModified = true;
|
|
|
|
} else {
|
|
|
|
// Try to compare the mapTx entry to the mapModifiedTx entry
|
2019-07-03 15:46:43 +02:00
|
|
|
iter = m_mempool.mapTx.project<0>(mi);
|
2016-06-16 18:42:45 +02:00
|
|
|
if (modit != mapModifiedTx.get<ancestor_score>().end() &&
|
2018-01-15 15:36:25 +01:00
|
|
|
CompareTxMemPoolEntryByAncestorFee()(*modit, CTxMemPoolModifiedEntry(iter))) {
|
2016-06-16 18:42:45 +02:00
|
|
|
// The best entry in mapModifiedTx has higher score
|
|
|
|
// than the one from mapTx.
|
|
|
|
// Switch which transaction (package) to consider
|
|
|
|
iter = modit->iter;
|
|
|
|
fUsingModified = true;
|
|
|
|
} else {
|
|
|
|
// Either no entry in mapModifiedTx, or it's worse than mapTx.
|
|
|
|
// Increment mi for the next loop iteration.
|
|
|
|
++mi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-24 18:39:38 +02:00
|
|
|
if (creditPoolDiff != std::nullopt) {
|
|
|
|
// If one transaction is skipped due to limits, it is not a reason to interrupt
|
|
|
|
// whole process of adding transactions.
|
2023-09-21 09:20:42 +02:00
|
|
|
// `state` is local here because used only to log info about this specific tx
|
2023-07-24 18:39:38 +02:00
|
|
|
TxValidationState state;
|
|
|
|
|
2023-10-04 19:47:21 +02:00
|
|
|
if (!creditPoolDiff->ProcessLockUnlockTransaction(iter->GetTx(), state)) {
|
2023-07-24 18:39:38 +02:00
|
|
|
if (fUsingModified) {
|
|
|
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
|
|
|
failedTx.insert(iter);
|
|
|
|
}
|
|
|
|
LogPrintf("%s: asset-locks tx %s skipped due %s\n",
|
|
|
|
__func__, iter->GetTx().GetHash().ToString(), state.ToString());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 09:20:42 +02:00
|
|
|
if (std::optional<uint8_t> signal = extractEHFSignal(iter->GetTx()); signal != std::nullopt) {
|
|
|
|
if (signals.find(*signal) != signals.end()) {
|
2023-09-23 20:33:30 +02:00
|
|
|
if (fUsingModified) {
|
|
|
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
|
|
|
failedTx.insert(iter);
|
|
|
|
}
|
2023-09-21 09:20:42 +02:00
|
|
|
LogPrintf("%s: ehf signal tx %s skipped due to duplicate %d\n",
|
|
|
|
__func__, iter->GetTx().GetHash().ToString(), *signal);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
signals.insert({*signal, 0});
|
|
|
|
}
|
2023-07-24 18:39:38 +02:00
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
|
|
|
|
// contain anything that is inBlock.
|
|
|
|
assert(!inBlock.count(iter));
|
|
|
|
|
|
|
|
uint64_t packageSize = iter->GetSizeWithAncestors();
|
|
|
|
CAmount packageFees = iter->GetModFeesWithAncestors();
|
|
|
|
unsigned int packageSigOps = iter->GetSigOpCountWithAncestors();
|
|
|
|
if (fUsingModified) {
|
|
|
|
packageSize = modit->nSizeWithAncestors;
|
|
|
|
packageFees = modit->nModFeesWithAncestors;
|
|
|
|
packageSigOps = modit->nSigOpCountWithAncestors;
|
|
|
|
}
|
|
|
|
|
2017-01-16 19:32:51 +01:00
|
|
|
if (packageFees < blockMinFeeRate.GetFee(packageSize)) {
|
2016-06-16 18:42:45 +02:00
|
|
|
// Everything else we might consider has a lower fee rate
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TestPackage(packageSize, packageSigOps)) {
|
|
|
|
if (fUsingModified) {
|
|
|
|
// Since we always look at the best entry in mapModifiedTx,
|
|
|
|
// we must erase failed entries so that we can consider the
|
|
|
|
// next best entry on the next loop iteration
|
|
|
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
|
|
|
failedTx.insert(iter);
|
|
|
|
}
|
2017-03-30 20:53:31 +02:00
|
|
|
|
|
|
|
++nConsecutiveFailed;
|
|
|
|
|
2018-01-26 17:31:20 +01:00
|
|
|
if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockSize > nBlockMaxSize - 1000) {
|
2017-03-30 20:53:31 +02:00
|
|
|
// Give up if we're close to full and haven't succeeded in a while
|
|
|
|
break;
|
|
|
|
}
|
2016-06-16 18:42:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTxMemPool::setEntries ancestors;
|
|
|
|
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
|
|
|
|
std::string dummy;
|
2019-07-03 15:46:43 +02:00
|
|
|
m_mempool.CalculateMemPoolAncestors(*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
|
2016-06-16 18:42:45 +02:00
|
|
|
|
|
|
|
onlyUnconfirmed(ancestors);
|
|
|
|
ancestors.insert(iter);
|
|
|
|
|
2019-03-06 07:58:27 +01:00
|
|
|
// Test if all tx's are Final and safe
|
2016-07-18 08:23:38 +02:00
|
|
|
if (!TestPackageTransactions(ancestors)) {
|
2016-06-16 18:42:45 +02:00
|
|
|
if (fUsingModified) {
|
|
|
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
|
|
|
failedTx.insert(iter);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:53:31 +02:00
|
|
|
// This transaction will make it in; reset the failed counter.
|
|
|
|
nConsecutiveFailed = 0;
|
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
// Package can be added. Sort the entries in a valid order.
|
2017-01-30 13:13:07 +01:00
|
|
|
std::vector<CTxMemPool::txiter> sortedEntries;
|
2018-03-16 00:12:47 +01:00
|
|
|
SortForBlock(ancestors, sortedEntries);
|
2016-06-16 18:42:45 +02:00
|
|
|
|
|
|
|
for (size_t i=0; i<sortedEntries.size(); ++i) {
|
|
|
|
AddToBlock(sortedEntries[i]);
|
|
|
|
// Erase from the modified set, if present
|
|
|
|
mapModifiedTx.erase(sortedEntries[i]);
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:53:31 +02:00
|
|
|
++nPackagesSelected;
|
|
|
|
|
2016-06-16 18:42:45 +02:00
|
|
|
// Update transactions that depend on each of these
|
2017-03-30 20:53:31 +02:00
|
|
|
nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
|
2016-06-16 18:42:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-08 18:18:41 +02:00
|
|
|
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
2013-07-31 15:43:35 +02:00
|
|
|
{
|
|
|
|
// Update nExtraNonce
|
|
|
|
static uint256 hashPrevBlock;
|
|
|
|
if (hashPrevBlock != pblock->hashPrevBlock)
|
|
|
|
{
|
|
|
|
nExtraNonce = 0;
|
|
|
|
hashPrevBlock = pblock->hashPrevBlock;
|
|
|
|
}
|
|
|
|
++nExtraNonce;
|
|
|
|
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
|
2016-11-21 10:51:32 +01:00
|
|
|
CMutableTransaction txCoinbase(*pblock->vtx[0]);
|
2021-08-31 18:51:34 +02:00
|
|
|
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
|
2014-06-07 13:53:27 +02:00
|
|
|
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
2013-07-31 15:43:35 +02:00
|
|
|
|
2016-11-21 10:51:32 +01:00
|
|
|
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
|
2015-11-17 17:35:44 +01:00
|
|
|
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
|
2013-07-31 15:43:35 +02:00
|
|
|
}
|