Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | if (IsMagneticAnomalyEnabled(chainparams.GetConsensus(), pindexPrev)) { | ||||
// canonically ordered. | // canonically ordered. | ||||
// FIXME: Use a zipped list. See T479 | // FIXME: Use a zipped list. See T479 | ||||
std::sort(std::begin(pblocktemplate->entries) + 1, | std::sort(std::begin(pblocktemplate->entries) + 1, | ||||
std::end(pblocktemplate->entries), | std::end(pblocktemplate->entries), | ||||
[](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b) | [](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b) | ||||
-> bool { return a.tx->GetId() < b.tx->GetId(); }); | -> bool { return a.tx->GetId() < b.tx->GetId(); }); | ||||
} | } | ||||
// Copy all the transactions into the block | |||||
// FIXME: This should be removed as it is significant overhead. | |||||
// See T479 | |||||
for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | |||||
pblock->vtx.push_back(tx.tx); | |||||
} | |||||
int64_t nTime1 = GetTimeMicros(); | int64_t nTime1 = GetTimeMicros(); | ||||
nLastBlockTx = nBlockTx; | nLastBlockTx = nBlockTx; | ||||
nLastBlockSize = nBlockSize; | nLastBlockSize = 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 = | ||||
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. | // Make sure the coinbase is big enough. | ||||
uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION); | uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION); | ||||
if (coinbaseSize < MIN_TX_SIZE) { | if (coinbaseSize < MIN_TX_SIZE) { | ||||
coinbaseTx.vin[0].scriptSig | coinbaseTx.vin[0].scriptSig | ||||
<< std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | << std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | ||||
} | } | ||||
pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); | pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); | ||||
pblocktemplate->entries[0].fees = -1 * nFees; | pblocktemplate->entries[0].fees = -1 * nFees; | ||||
pblock->vtx[0] = pblocktemplate->entries[0].tx; | |||||
uint64_t nSerializeSize = GetSerializeSize(*pblock, PROTOCOL_VERSION); | uint64_t nSerializeSize = GetSerializeSize(*pblock, 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); | ||||
// Fill in header. | // Fill in header. | ||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | ||||
pblock->nBits = | pblock->nBits = | ||||
GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); | GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
pblocktemplate->entries[0].sigOpCount = GetSigOpCountWithoutP2SH( | pblocktemplate->entries[0].sigOpCount = GetSigOpCountWithoutP2SH( | ||||
*pblocktemplate->entries[0].tx, STANDARD_SCRIPT_VERIFY_FLAGS); | *pblocktemplate->entries[0].tx, STANDARD_SCRIPT_VERIFY_FLAGS); | ||||
// Copy all the transactions into the block | |||||
// FIXME: This should be removed as it is significant overhead. | |||||
// See T479 | |||||
for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | |||||
pblock->vtx.push_back(tx.tx); | |||||
} | |||||
CValidationState state; | CValidationState state; | ||||
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, | if (!TestBlockValidity(state, chainparams, *pblock, 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__, | __func__, | ||||
FormatStateMessage(state))); | FormatStateMessage(state))); | ||||
▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines |