Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | |||||
getExcessiveBlockSizeSig(const Config &config) { | getExcessiveBlockSizeSig(const Config &config) { | ||||
std::string cbmsg = "/EB" + getSubVersionEB(config.GetMaxBlockSize()) + "/"; | std::string cbmsg = "/EB" + getSubVersionEB(config.GetMaxBlockSize()) + "/"; | ||||
const char *cbcstr = cbmsg.c_str(); | const char *cbcstr = cbmsg.c_str(); | ||||
std::vector<uint8_t> vec(cbcstr, cbcstr + cbmsg.size()); | std::vector<uint8_t> vec(cbcstr, cbcstr + cbmsg.size()); | ||||
return vec; | return vec; | ||||
} | } | ||||
std::unique_ptr<CBlockTemplate> | std::unique_ptr<CBlockTemplate> | ||||
BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn, | ||||
const BlockAssemblerFlags &flags) { | |||||
int64_t nTimeStart = GetTimeMicros(); | int64_t nTimeStart = GetTimeMicros(); | ||||
resetBlock(); | resetBlock(); | ||||
pblocktemplate.reset(new CBlockTemplate()); | pblocktemplate.reset(new CBlockTemplate()); | ||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn, | ||||
for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | ||||
pblock->vtx.push_back(tx.tx); | pblock->vtx.push_back(tx.tx); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
BlockValidationOptions validationOptions(false, false); | BlockValidationOptions validationOptions(false, false); | ||||
if (!TestBlockValidity(*config, state, *pblock, pindexPrev, | if (!TestBlockValidity(*config, state, *pblock, pindexPrev, | ||||
validationOptions)) { | validationOptions)) { | ||||
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", | if (flags & BlockAssemblerFlags::EMPTY_BLOCK_ON_FAILURE) { | ||||
__func__, | LogPrintf("%s: WARNING: TestBlockValidity failed: %s\nUsing empty " | ||||
"block as a fallback.\n", | |||||
__func__, FormatStateMessage(state)); | |||||
// To prevent mining on useless hashes, generate an empty block. | |||||
coinbaseTx.vout[0].nValue = | |||||
GetBlockSubsidy(nHeight, chainparams.GetConsensus()); | |||||
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); | |||||
} | |||||
pblocktemplate->entries.resize(1, pblocktemplate->entries[0]); | |||||
pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); | |||||
pblocktemplate->entries[0].txFee = Amount::zero(); | |||||
pblock->vtx.resize(0); | |||||
pblock->vtx.push_back(pblocktemplate->entries[0].tx); | |||||
// Only fail if the empty block also fails validity checks. | |||||
CValidationState fallbackState; | |||||
if (!TestBlockValidity(*config, fallbackState, *pblock, pindexPrev, | |||||
validationOptions)) { | |||||
throw std::runtime_error(strprintf( | |||||
"%s: TestBlockValidity failed: %s\nTestBlockValidity also " | |||||
"failed for fallback empty block: %s", | |||||
__func__, FormatStateMessage(state), | |||||
FormatStateMessage(fallbackState))); | |||||
} | |||||
} else { | |||||
throw std::runtime_error( | |||||
strprintf("%s: TestBlockValidity failed: %s", __func__, | |||||
FormatStateMessage(state))); | FormatStateMessage(state))); | ||||
} | } | ||||
} | |||||
int64_t nTime2 = GetTimeMicros(); | int64_t nTime2 = GetTimeMicros(); | ||||
LogPrint(BCLog::BENCH, | LogPrint(BCLog::BENCH, | ||||
"CreateNewBlock() packages: %.2fms (%d packages, %d updated " | "CreateNewBlock() packages: %.2fms (%d packages, %d updated " | ||||
"descendants), validity: %.2fms (total %.2fms)\n", | "descendants), validity: %.2fms (total %.2fms)\n", | ||||
0.001 * (nTime1 - nTimeStart), nPackagesSelected, | 0.001 * (nTime1 - nTimeStart), nPackagesSelected, | ||||
nDescendantsUpdated, 0.001 * (nTime2 - nTime1), | nDescendantsUpdated, 0.001 * (nTime2 - nTime1), | ||||
0.001 * (nTime2 - nTimeStart)); | 0.001 * (nTime2 - nTimeStart)); | ||||
▲ Show 20 Lines • Show All 472 Lines • Show Last 20 Lines |