mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-17 21:32:00 +01:00
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.
This commit is contained in:
parent
53ad845fb9
commit
226d81f8b7
@ -34,9 +34,12 @@ public:
|
||||
virtual ~BlockTemplate() = default;
|
||||
|
||||
virtual CBlockHeader getBlockHeader() = 0;
|
||||
// Block contains a dummy coinbase transaction that should not be used.
|
||||
virtual CBlock getBlock() = 0;
|
||||
|
||||
// Fees per transaction, not including coinbase transaction.
|
||||
virtual std::vector<CAmount> getTxFees() = 0;
|
||||
// Sigop cost per transaction, not including coinbase transaction.
|
||||
virtual std::vector<int64_t> getTxSigops() = 0;
|
||||
|
||||
virtual CTransactionRef getCoinbaseTx() = 0;
|
||||
|
@ -124,10 +124,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
||||
pblocktemplate.reset(new CBlockTemplate());
|
||||
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
|
||||
|
||||
// Add dummy coinbase tx as first transaction
|
||||
// Add dummy coinbase tx as first transaction. It is skipped by the
|
||||
// getblocktemplate RPC and mining interface consumers must not use it.
|
||||
pblock->vtx.emplace_back();
|
||||
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
||||
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
|
||||
|
||||
LOCK(::cs_main);
|
||||
CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
|
||||
@ -165,7 +164,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
|
||||
pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
|
||||
LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
|
||||
|
||||
@ -174,7 +172,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
|
||||
pblock->nNonce = 0;
|
||||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
||||
|
||||
BlockValidationState state;
|
||||
if (m_options.test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,
|
||||
|
@ -37,7 +37,9 @@ static const bool DEFAULT_PRINT_MODIFIED_FEE = false;
|
||||
struct CBlockTemplate
|
||||
{
|
||||
CBlock block;
|
||||
// Fees per transaction, not including coinbase transaction (unlike CBlock::vtx).
|
||||
std::vector<CAmount> vTxFees;
|
||||
// Sigops per transaction, not including coinbase transaction (unlike CBlock::vtx).
|
||||
std::vector<int64_t> vTxSigOpsCost;
|
||||
std::vector<unsigned char> vchCoinbaseCommitment;
|
||||
/* A vector of package fee rates, ordered by the sequence in which
|
||||
|
@ -893,7 +893,7 @@ static RPCHelpMan getblocktemplate()
|
||||
}
|
||||
entry.pushKV("depends", std::move(deps));
|
||||
|
||||
int index_in_template = i - 1;
|
||||
int index_in_template = i - 2;
|
||||
entry.pushKV("fee", tx_fees.at(index_in_template));
|
||||
int64_t nTxSigOps{tx_sigops.at(index_in_template)};
|
||||
if (fPreSegWit) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user