diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -132,7 +132,8 @@ // Pointer for convenience. pblock = &pblocktemplate->block; - // Add dummy coinbase tx as first transaction. It is updated at the end. + // Add dummy coinbase tx as first transaction. Its fees/sigops are updated + // at the end. pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1); LOCK2(cs_main, mempool->cs); @@ -169,6 +170,13 @@ -> 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(); nLastBlockTx = nBlockTx; @@ -191,7 +199,8 @@ << std::vector(MIN_TX_SIZE - coinbaseSize - 1); } - pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); + pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); + pblocktemplate->entries[0].fees = -1 * nFees; uint64_t nSerializeSize = GetSerializeSize(*pblock, PROTOCOL_VERSION); @@ -205,15 +214,8 @@ pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); pblock->nNonce = 0; - pblocktemplate->entries[0].sigOpCount = GetSigOpCountWithoutP2SH( - *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); - } + pblocktemplate->entries[0].sigOpCount = + GetSigOpCountWithoutP2SH(*pblock->vtx[0], STANDARD_SCRIPT_VERIFY_FLAGS); CValidationState state; if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev,