Skip to content

Commit b867e40

Browse files
committed
CreateNewBlock: Stick height in coinbase so we pass template sanity check
1 parent 60755db commit b867e40

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/miner.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
124124
{
125125
LOCK2(cs_main, mempool.cs);
126126
CBlockIndex* pindexPrev = chainActive.Tip();
127+
const int nHeight = pindexPrev->nHeight + 1;
127128
CCoinsViewCache view(pcoinsTip);
128129

129130
// Priority order to process transactions
@@ -138,7 +139,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
138139
mi != mempool.mapTx.end(); ++mi)
139140
{
140141
const CTransaction& tx = mi->second.GetTx();
141-
if (tx.IsCoinBase() || !IsFinalTx(tx, pindexPrev->nHeight + 1))
142+
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight))
142143
continue;
143144

144145
COrphan* porphan = NULL;
@@ -181,7 +182,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
181182
CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
182183
nTotalIn += nValueIn;
183184

184-
int nConf = pindexPrev->nHeight - coins->nHeight + 1;
185+
int nConf = nHeight - coins->nHeight;
185186

186187
dPriority += (double)nValueIn * nConf;
187188
}
@@ -269,7 +270,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
269270
continue;
270271

271272
CTxUndo txundo;
272-
UpdateCoins(tx, state, view, txundo, pindexPrev->nHeight+1);
273+
UpdateCoins(tx, state, view, txundo, nHeight);
273274

274275
// Added
275276
pblock->vtx.push_back(tx);
@@ -309,8 +310,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
309310
LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize);
310311

311312
// Compute final coinbase transaction.
312-
txNew.vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
313-
txNew.vin[0].scriptSig = CScript() << OP_0 << OP_0;
313+
txNew.vout[0].nValue = GetBlockValue(nHeight, nFees);
314+
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
314315
pblock->vtx[0] = txNew;
315316
pblocktemplate->vTxFees[0] = -nFees;
316317

0 commit comments

Comments
 (0)