Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
// -blockversion=N to test forking scenarios | // -blockversion=N to test forking scenarios | ||||
if (chainparams.MineBlocksOnDemand()) { | if (chainparams.MineBlocksOnDemand()) { | ||||
pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); | pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); | ||||
} | } | ||||
pblock->nTime = GetAdjustedTime(); | pblock->nTime = GetAdjustedTime(); | ||||
nMaxGeneratedBlockSize = ComputeMaxGeneratedBlockSize(*config, pindexPrev); | nMaxGeneratedBlockSize = ComputeMaxGeneratedBlockSize(*config, pindexPrev); | ||||
nMedianTimePast = pindexPrev->GetMedianTimePast(); | |||||
nLockTimeCutoff = | nLockTimeCutoff = | ||||
(STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) | (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) | ||||
? pindexPrev->GetMedianTimePast() | ? nMedianTimePast | ||||
: pblock->GetBlockTime(); | : pblock->GetBlockTime(); | ||||
addPriorityTxs(); | addPriorityTxs(); | ||||
int nPackagesSelected = 0; | int nPackagesSelected = 0; | ||||
int nDescendantsUpdated = 0; | int nDescendantsUpdated = 0; | ||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated); | addPackageTxs(nPackagesSelected, nDescendantsUpdated); | ||||
if (IsMagneticAnomalyEnabled(*config, pindexPrev)) { | if (IsMagneticAnomalyEnabled(*config, pindexPrev)) { | ||||
Show All 15 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
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 = | ||||
nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); | nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); | ||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; | coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; | ||||
// Make sure the coinbase is big enough. | |||||
uint64_t coinbaseSize = | |||||
::GetSerializeSize(coinbaseTx, SER_NETWORK, PROTOCOL_VERSION); | |||||
if (coinbaseSize < MIN_TX_SIZE) { | |||||
coinbaseTx.vin[0].scriptSig | |||||
<< std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | |||||
} | |||||
pblock->vtx[0] = MakeTransactionRef(coinbaseTx); | pblock->vtx[0] = MakeTransactionRef(coinbaseTx); | ||||
pblocktemplate->vTxFees[0] = -1 * nFees; | pblocktemplate->vTxFees[0] = -1 * nFees; | ||||
uint64_t nSerializeSize = | uint64_t nSerializeSize = | ||||
GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); | GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); | ||||
LogPrintf("CreateNewBlock(): total size: %u txs: %u fees: %ld sigops %d\n", | LogPrintf("CreateNewBlock(): total size: %u txs: %u fees: %ld sigops %d\n", | ||||
nSerializeSize, nBlockTx, nFees, nBlockSigOps); | nSerializeSize, nBlockTx, nFees, nBlockSigOps); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
* - Serialized size (in case -blockmaxsize is in use) | * - Serialized size (in case -blockmaxsize is in use) | ||||
*/ | */ | ||||
bool BlockAssembler::TestPackageTransactions( | bool BlockAssembler::TestPackageTransactions( | ||||
const CTxMemPool::setEntries &package) { | const CTxMemPool::setEntries &package) { | ||||
uint64_t nPotentialBlockSize = nBlockSize; | uint64_t nPotentialBlockSize = nBlockSize; | ||||
for (const CTxMemPool::txiter it : package) { | for (const CTxMemPool::txiter it : package) { | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | ||||
nLockTimeCutoff)) { | nLockTimeCutoff, nMedianTimePast)) { | ||||
return false; | return false; | ||||
} | } | ||||
uint64_t nTxSize = | uint64_t nTxSize = | ||||
::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | ::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | ||||
if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 35 Lines | if (nBlockSigOps + it->GetSigOpCount() >= maxBlockSigOps) { | ||||
// block. | // block. | ||||
return TestForBlockResult::TXCantFit; | return TestForBlockResult::TXCantFit; | ||||
} | } | ||||
// Must check that lock times are still valid. This can be removed once MTP | // Must check that lock times are still valid. This can be removed once MTP | ||||
// is always enforced as long as reorgs keep the mempool consistent. | // is always enforced as long as reorgs keep the mempool consistent. | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | ||||
nLockTimeCutoff)) { | nLockTimeCutoff, nMedianTimePast)) { | ||||
return TestForBlockResult::TXCantFit; | return TestForBlockResult::TXCantFit; | ||||
} | } | ||||
return TestForBlockResult::TXFits; | return TestForBlockResult::TXFits; | ||||
} | } | ||||
void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) { | void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) { | ||||
pblock->vtx.emplace_back(iter->GetSharedTx()); | pblock->vtx.emplace_back(iter->GetSharedTx()); | ||||
▲ Show 20 Lines • Show All 348 Lines • Show Last 20 Lines |