mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Merge pull request #1816
b867e40CreateNewBlock: Stick height in coinbase so we pass template sanity check (Luke Dashjr)60755dbsubmitblock: Check for duplicate submissions explicitly (Luke Dashjr)bc6cb41QA RPC tests: Add tests block block proposals (Luke Dashjr)9765a50Implement BIP 23 Block Proposal (Luke Dashjr)3dcbb9bAbstract DecodeHexBlk and BIP22ValidationResult functions out of submitblock (Luke Dashjr)132ea9bminer_tests: Disable checkpoints so they don't fail the subsidy-change test (Luke Dashjr)df08a62TestBlockValidity function for CBlock proposals (used by CreateNewBlock) (Luke Dashjr)4ea1be7CreateNewBlock and miner_tests: Also check generated template is valid by CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, and ContextualCheckBlock (Luke Dashjr)a48f2d6Abstract context-dependent block checking from acceptance (Luke Dashjr)
This commit is contained in:
@@ -134,6 +134,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
{
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
const int nHeight = pindexPrev->nHeight + 1;
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
|
||||
// Priority order to process transactions
|
||||
@@ -148,7 +149,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
mi != mempool.mapTx.end(); ++mi)
|
||||
{
|
||||
const CTransaction& tx = mi->second.GetTx();
|
||||
if (tx.IsCoinBase() || !IsFinalTx(tx, pindexPrev->nHeight + 1))
|
||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight))
|
||||
continue;
|
||||
|
||||
COrphan* porphan = NULL;
|
||||
@@ -191,7 +192,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
|
||||
nTotalIn += nValueIn;
|
||||
|
||||
int nConf = pindexPrev->nHeight - coins->nHeight + 1;
|
||||
int nConf = nHeight - coins->nHeight;
|
||||
|
||||
dPriority += (double)nValueIn * nConf;
|
||||
}
|
||||
@@ -279,7 +280,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
continue;
|
||||
|
||||
CTxUndo txundo;
|
||||
UpdateCoins(tx, state, view, txundo, pindexPrev->nHeight+1);
|
||||
UpdateCoins(tx, state, view, txundo, nHeight);
|
||||
|
||||
// Added
|
||||
pblock->vtx.push_back(tx);
|
||||
@@ -319,8 +320,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize);
|
||||
|
||||
// Compute final coinbase transaction.
|
||||
txNew.vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
|
||||
txNew.vin[0].scriptSig = CScript() << OP_0 << OP_0;
|
||||
txNew.vout[0].nValue = GetBlockValue(nHeight, nFees);
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
pblock->vtx[0] = txNew;
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
|
||||
@@ -331,13 +332,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
pblock->nNonce = 0;
|
||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||
|
||||
CBlockIndex indexDummy(*pblock);
|
||||
indexDummy.pprev = pindexPrev;
|
||||
indexDummy.nHeight = pindexPrev->nHeight + 1;
|
||||
CCoinsViewCache viewNew(pcoinsTip);
|
||||
CValidationState state;
|
||||
if (!ConnectBlock(*pblock, state, &indexDummy, viewNew, true))
|
||||
throw std::runtime_error("CreateNewBlock() : ConnectBlock failed");
|
||||
if (!TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
||||
throw std::runtime_error("CreateNewBlock() : TestBlockValidity failed");
|
||||
}
|
||||
|
||||
return pblocktemplate.release();
|
||||
|
||||
Reference in New Issue
Block a user