Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
// Pointer for convenience. | // Pointer for convenience. | ||||
CBlock *const pblock = &pblocktemplate->block; | CBlock *const pblock = &pblocktemplate->block; | ||||
// Add dummy coinbase tx as first transaction. It is updated at the end. | // Add dummy coinbase tx as first transaction. It is updated at the end. | ||||
pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1); | pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1); | ||||
LOCK2(cs_main, m_mempool.cs); | LOCK2(cs_main, m_mempool.cs); | ||||
assert(std::addressof(*::ChainActive().Tip()) == | |||||
std::addressof(*m_chainstate.m_chain.Tip())); | |||||
CBlockIndex *pindexPrev = m_chainstate.m_chain.Tip(); | CBlockIndex *pindexPrev = m_chainstate.m_chain.Tip(); | ||||
assert(pindexPrev != nullptr); | assert(pindexPrev != nullptr); | ||||
nHeight = pindexPrev->nHeight + 1; | nHeight = pindexPrev->nHeight + 1; | ||||
const Consensus::Params &consensusParams = chainParams.GetConsensus(); | const Consensus::Params &consensusParams = chainParams.GetConsensus(); | ||||
pblock->nVersion = ComputeBlockVersion(pindexPrev, consensusParams); | pblock->nVersion = ComputeBlockVersion(pindexPrev, consensusParams); | ||||
// -regtest only: allow overriding block.nVersion with | // -regtest only: allow overriding block.nVersion with | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
// Fill in header. | // Fill in header. | ||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||||
UpdateTime(pblock, chainParams, pindexPrev); | UpdateTime(pblock, chainParams, pindexPrev); | ||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainParams); | pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainParams); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
pblocktemplate->entries[0].sigOpCount = 0; | pblocktemplate->entries[0].sigOpCount = 0; | ||||
BlockValidationState state; | BlockValidationState state; | ||||
assert(std::addressof(::ChainstateActive()) == | |||||
std::addressof(m_chainstate)); | |||||
if (!TestBlockValidity(state, chainParams, m_chainstate, *pblock, | if (!TestBlockValidity(state, chainParams, m_chainstate, *pblock, | ||||
pindexPrev, | pindexPrev, | ||||
BlockValidationOptions(nMaxGeneratedBlockSize) | BlockValidationOptions(nMaxGeneratedBlockSize) | ||||
.withCheckPoW(false) | .withCheckPoW(false) | ||||
.withCheckMerkleRoot(false))) { | .withCheckMerkleRoot(false))) { | ||||
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", | throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", | ||||
__func__, state.ToString())); | __func__, state.ToString())); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 345 Lines • Show Last 20 Lines |