Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
Show All 17 Lines | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <queue> | #include <queue> | ||||
#include <utility> | #include <utility> | ||||
// Unconfirmed transactions in the memory pool often depend on other | |||||
// transactions in the memory pool. When we select transactions from the | |||||
// pool, we select by highest fee rate of a transaction combined with all | |||||
// its ancestors. | |||||
uint64_t nLastBlockTx = 0; | |||||
uint64_t nLastBlockSize = 0; | |||||
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params ¶ms, | int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params ¶ms, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
int64_t nOldTime = pblock->nTime; | int64_t nOldTime = pblock->nTime; | ||||
int64_t nNewTime = | int64_t nNewTime = | ||||
std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); | std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); | ||||
if (nOldTime < nNewTime) { | if (nOldTime < nNewTime) { | ||||
pblock->nTime = nNewTime; | pblock->nTime = nNewTime; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | void BlockAssembler::resetBlock() { | ||||
nBlockSize = 1000; | nBlockSize = 1000; | ||||
nBlockSigOps = 100; | nBlockSigOps = 100; | ||||
// These counters do not include coinbase tx. | // These counters do not include coinbase tx. | ||||
nBlockTx = 0; | nBlockTx = 0; | ||||
nFees = Amount::zero(); | nFees = Amount::zero(); | ||||
} | } | ||||
Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt}; | |||||
Optional<int64_t> BlockAssembler::m_last_block_size{nullopt}; | |||||
std::unique_ptr<CBlockTemplate> | std::unique_ptr<CBlockTemplate> | ||||
BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
int64_t nTimeStart = GetTimeMicros(); | int64_t nTimeStart = GetTimeMicros(); | ||||
resetBlock(); | resetBlock(); | ||||
pblocktemplate.reset(new CBlockTemplate()); | pblocktemplate.reset(new CBlockTemplate()); | ||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
// Copy all the transactions refs into the block | // Copy all the transactions refs into the block | ||||
pblock->vtx.reserve(pblocktemplate->entries.size()); | pblock->vtx.reserve(pblocktemplate->entries.size()); | ||||
for (const CBlockTemplateEntry &entry : pblocktemplate->entries) { | for (const CBlockTemplateEntry &entry : pblocktemplate->entries) { | ||||
pblock->vtx.push_back(entry.tx); | pblock->vtx.push_back(entry.tx); | ||||
} | } | ||||
int64_t nTime1 = GetTimeMicros(); | int64_t nTime1 = GetTimeMicros(); | ||||
nLastBlockTx = nBlockTx; | m_last_block_num_txs = nBlockTx; | ||||
nLastBlockSize = nBlockSize; | m_last_block_size = nBlockSize; | ||||
// Create coinbase transaction. | // Create coinbase transaction. | ||||
CMutableTransaction coinbaseTx; | CMutableTransaction coinbaseTx; | ||||
coinbaseTx.vin.resize(1); | coinbaseTx.vin.resize(1); | ||||
coinbaseTx.vin[0].prevout = COutPoint(); | coinbaseTx.vin[0].prevout = COutPoint(); | ||||
coinbaseTx.vout.resize(1); | coinbaseTx.vout.resize(1); | ||||
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; | coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; | ||||
coinbaseTx.vout[0].nValue = | coinbaseTx.vout[0].nValue = | ||||
▲ Show 20 Lines • Show All 396 Lines • Show Last 20 Lines |