Skip to content

Commit 226d81f

Browse files
committed
mining: drop unused -nFees and sigops from CBlockTemplate
For the coinbase vTxFees used a dummy value of -nFees. This value was never returned by the RPC or used in a test. Similarly the fist vTxSigOpsCost entry was calculated from the dummy coinbase transaction. Drop both and add code comments to prevent confusion.
1 parent 53ad845 commit 226d81f

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/interfaces/mining.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ class BlockTemplate
3434
virtual ~BlockTemplate() = default;
3535

3636
virtual CBlockHeader getBlockHeader() = 0;
37+
// Block contains a dummy coinbase transaction that should not be used.
3738
virtual CBlock getBlock() = 0;
3839

40+
// Fees per transaction, not including coinbase transaction.
3941
virtual std::vector<CAmount> getTxFees() = 0;
42+
// Sigop cost per transaction, not including coinbase transaction.
4043
virtual std::vector<int64_t> getTxSigops() = 0;
4144

4245
virtual CTransactionRef getCoinbaseTx() = 0;

src/node/miner.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
124124
pblocktemplate.reset(new CBlockTemplate());
125125
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
126126

127-
// Add dummy coinbase tx as first transaction
127+
// Add dummy coinbase tx as first transaction. It is skipped by the
128+
// getblocktemplate RPC and mining interface consumers must not use it.
128129
pblock->vtx.emplace_back();
129-
pblocktemplate->vTxFees.push_back(-1); // updated at end
130-
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
131130

132131
LOCK(::cs_main);
133132
CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
@@ -165,7 +164,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
165164
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
166165
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
167166
pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
168-
pblocktemplate->vTxFees[0] = -nFees;
169167

170168
LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
171169

@@ -174,7 +172,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
174172
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
175173
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
176174
pblock->nNonce = 0;
177-
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
178175

179176
BlockValidationState state;
180177
if (m_options.test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,

src/node/miner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static const bool DEFAULT_PRINT_MODIFIED_FEE = false;
3737
struct CBlockTemplate
3838
{
3939
CBlock block;
40+
// Fees per transaction, not including coinbase transaction (unlike CBlock::vtx).
4041
std::vector<CAmount> vTxFees;
42+
// Sigops per transaction, not including coinbase transaction (unlike CBlock::vtx).
4143
std::vector<int64_t> vTxSigOpsCost;
4244
std::vector<unsigned char> vchCoinbaseCommitment;
4345
/* A vector of package fee rates, ordered by the sequence in which

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static RPCHelpMan getblocktemplate()
893893
}
894894
entry.pushKV("depends", std::move(deps));
895895

896-
int index_in_template = i - 1;
896+
int index_in_template = i - 2;
897897
entry.pushKV("fee", tx_fees.at(index_in_template));
898898
int64_t nTxSigOps{tx_sigops.at(index_in_template)};
899899
if (fPreSegWit) {

0 commit comments

Comments
 (0)