diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -28,17 +28,11 @@ struct CBlockTemplateEntry { CTransactionRef tx; - //!< Total real fees paid by the transaction and cached to avoid parent - //!< lookup - Amount txFee; - //!< Cached total size of the transaction to avoid reserializing transaction - size_t txSize; - //!< Cached total number of SigOps - uint64_t txSigOps; - - CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, uint64_t _size, - int64_t _sigOps) - : tx(_tx), txFee(_fees), txSize(_size), txSigOps(_sigOps) {} + Amount fees; + int64_t sigOpCount; + + CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, int64_t _sigOpCount) + : tx(_tx), fees(_fees), sigOpCount(_sigOpCount){}; }; struct CBlockTemplate { diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -128,7 +128,7 @@ pblock = &pblocktemplate->block; // Add dummy coinbase tx as first transaction. It is updated at the end. - pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, 0, -1); + pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1); LOCK2(cs_main, mempool->cs); CBlockIndex *pindexPrev = chainActive.Tip(); @@ -187,11 +187,7 @@ } pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); - // Note: For the Coinbase, the template entry fields aside from the `tx` are - // not used anywhere at the time of writing. The mining rpc throws out the - // entire transaction in fact. The tx itself is only used during regtest - // mode. - pblocktemplate->entries[0].txFee = -1 * nFees; + pblocktemplate->entries[0].fees = -1 * nFees; uint64_t nSerializeSize = GetSerializeSize(*pblock, PROTOCOL_VERSION); @@ -204,7 +200,7 @@ pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); pblock->nNonce = 0; - pblocktemplate->entries[0].txSigOps = GetSigOpCountWithoutP2SH( + pblocktemplate->entries[0].sigOpCount = GetSigOpCountWithoutP2SH( *pblocktemplate->entries[0].tx, STANDARD_SCRIPT_VERIFY_FLAGS); // Copy all the transactions into the block @@ -291,7 +287,6 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) { pblocktemplate->entries.emplace_back(iter->GetSharedTx(), iter->GetFee(), - iter->GetTxSize(), iter->GetSigOpCount()); nBlockSize += iter->GetTxSize(); ++nBlockTx; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -614,9 +614,10 @@ entry.pushKV("data", EncodeHexTx(tx)); entry.pushKV("txid", txId.GetHex()); entry.pushKV("hash", tx.GetHash().GetHex()); - entry.pushKV("fee", pblocktemplate->entries[index_in_template].txFee / - SATOSHI); - int64_t nTxSigOps = pblocktemplate->entries[index_in_template].txSigOps; + entry.pushKV("fee", + pblocktemplate->entries[index_in_template].fees / SATOSHI); + int64_t nTxSigOps = + pblocktemplate->entries[index_in_template].sigOpCount; entry.pushKV("sigops", nTxSigOps); transactions.push_back(entry); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -777,11 +777,10 @@ BOOST_AUTO_TEST_CASE(TestCBlockTemplateEntry) { const CTransaction tx; CTransactionRef txRef = MakeTransactionRef(tx); - CBlockTemplateEntry txEntry(txRef, 1 * SATOSHI, 200, 10); + CBlockTemplateEntry txEntry(txRef, 1 * SATOSHI, 10); BOOST_CHECK_MESSAGE(txEntry.tx == txRef, "Transactions did not match"); - BOOST_CHECK_EQUAL(txEntry.txFee, 1 * SATOSHI); - BOOST_CHECK_EQUAL(txEntry.txSize, 200); - BOOST_CHECK_EQUAL(txEntry.txSigOps, 10); + BOOST_CHECK_EQUAL(txEntry.fees, 1 * SATOSHI); + BOOST_CHECK_EQUAL(txEntry.sigOpCount, 10); } BOOST_AUTO_TEST_SUITE_END()