From 4ea1be7fb84a397222754473c2bc315e3665ff18 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 16 Oct 2014 03:50:33 +0000 Subject: CreateNewBlock and miner_tests: Also check generated template is valid by CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, and ContextualCheckBlock --- src/miner.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/miner.cpp') diff --git a/src/miner.cpp b/src/miner.cpp index b5bfa9c7be..d7ecd5e40e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -326,8 +326,17 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) indexDummy.nHeight = pindexPrev->nHeight + 1; CCoinsViewCache viewNew(pcoinsTip); CValidationState state; + // NOTE: CheckBlockHeader is called by CheckBlock + if (!ContextualCheckBlockHeader(*pblock, state, pindexPrev)) + throw std::runtime_error("CreateNewBlock() : ContextualCheckBlockHeader failed"); + if (!CheckBlock(*pblock, state, false, false)) + throw std::runtime_error("CreateNewBlock() : CheckBlock failed"); + if (!ContextualCheckBlock(*pblock, state, pindexPrev)) + throw std::runtime_error("CreateNewBlock() : ContextualCheckBlock failed"); if (!ConnectBlock(*pblock, state, &indexDummy, viewNew, true)) throw std::runtime_error("CreateNewBlock() : ConnectBlock failed"); + if (!state.IsValid()) + throw std::runtime_error("CreateNewBlock() : State is not valid"); } return pblocktemplate.release(); -- cgit v1.2.3 From df08a626e0440457ae0d1966439fd956c27ae2fe Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 20 Oct 2014 02:10:03 +0000 Subject: TestBlockValidity function for CBlock proposals (used by CreateNewBlock) --- src/miner.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'src/miner.cpp') diff --git a/src/miner.cpp b/src/miner.cpp index d7ecd5e40e..200498d109 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -321,22 +321,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; - // NOTE: CheckBlockHeader is called by CheckBlock - if (!ContextualCheckBlockHeader(*pblock, state, pindexPrev)) - throw std::runtime_error("CreateNewBlock() : ContextualCheckBlockHeader failed"); - if (!CheckBlock(*pblock, state, false, false)) - throw std::runtime_error("CreateNewBlock() : CheckBlock failed"); - if (!ContextualCheckBlock(*pblock, state, pindexPrev)) - throw std::runtime_error("CreateNewBlock() : ContextualCheckBlock failed"); - if (!ConnectBlock(*pblock, state, &indexDummy, viewNew, true)) - throw std::runtime_error("CreateNewBlock() : ConnectBlock failed"); - if (!state.IsValid()) - throw std::runtime_error("CreateNewBlock() : State is not valid"); + if (!TestBlockValidity(state, *pblock, pindexPrev, false, false)) + throw std::runtime_error("CreateNewBlock() : TestBlockValidity failed"); } return pblocktemplate.release(); -- cgit v1.2.3 From b867e409e5dd34b84eb9d6d0d8f257dbb19b986d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 20 Nov 2014 02:23:20 +0000 Subject: CreateNewBlock: Stick height in coinbase so we pass template sanity check --- src/miner.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/miner.cpp') diff --git a/src/miner.cpp b/src/miner.cpp index 200498d109..5ac4b05af8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -124,6 +124,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 @@ -138,7 +139,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; @@ -181,7 +182,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; } @@ -269,7 +270,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); @@ -309,8 +310,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; -- cgit v1.2.3