Chainparams: Explicit CChainParams arg for main (pre miner):
-ProcessNewBlock -TestBlockValidity
This commit is contained in:
parent
3ac7060934
commit
598e494587
12
src/main.cpp
12
src/main.cpp
@ -2915,9 +2915,8 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
|
||||
}
|
||||
|
||||
|
||||
bool ProcessNewBlock(CValidationState &state, const CNode* pfrom, const CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp)
|
||||
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, const CNode* pfrom, const CBlock* pblock, bool fForceProcessing, CDiskBlockPos* dbp)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
// Preliminary checks
|
||||
bool checked = CheckBlock(*pblock, state);
|
||||
|
||||
@ -2946,9 +2945,8 @@ bool ProcessNewBlock(CValidationState &state, const CNode* pfrom, const CBlock*
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex * const pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
|
||||
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
AssertLockHeld(cs_main);
|
||||
assert(pindexPrev && pindexPrev == chainActive.Tip());
|
||||
if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, block.GetHash()))
|
||||
@ -3488,7 +3486,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
|
||||
// process in case the block isn't known yet
|
||||
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
|
||||
CValidationState state;
|
||||
if (ProcessNewBlock(state, NULL, &block, true, dbp))
|
||||
if (ProcessNewBlock(state, chainparams, NULL, &block, true, dbp))
|
||||
nLoaded++;
|
||||
if (state.IsError())
|
||||
break;
|
||||
@ -3510,7 +3508,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
|
||||
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
|
||||
head.ToString());
|
||||
CValidationState dummy;
|
||||
if (ProcessNewBlock(dummy, NULL, &block, true, &it->second))
|
||||
if (ProcessNewBlock(dummy, chainparams, NULL, &block, true, &it->second))
|
||||
{
|
||||
nLoaded++;
|
||||
queue.push_back(block.GetHash());
|
||||
@ -4547,7 +4545,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// Such an unrequested block may still be processed, subject to the
|
||||
// conditions in AcceptBlock().
|
||||
bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload();
|
||||
ProcessNewBlock(state, pfrom, &block, forceProcessing, NULL);
|
||||
ProcessNewBlock(state, chainparams, pfrom, &block, forceProcessing, NULL);
|
||||
int nDoS;
|
||||
if (state.IsInvalid(nDoS)) {
|
||||
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
|
||||
|
@ -31,6 +31,7 @@
|
||||
class CBlockIndex;
|
||||
class CBlockTreeDB;
|
||||
class CBloomFilter;
|
||||
class CChainParams;
|
||||
class CInv;
|
||||
class CScriptCheck;
|
||||
class CTxMemPool;
|
||||
@ -159,7 +160,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals);
|
||||
* @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location.
|
||||
* @return True if state.IsValid()
|
||||
*/
|
||||
bool ProcessNewBlock(CValidationState &state, const CNode* pfrom, const CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp);
|
||||
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, const CNode* pfrom, const CBlock* pblock, bool fForceProcessing, CDiskBlockPos* dbp);
|
||||
/** Check whether enough disk space is available for an incoming block */
|
||||
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
|
||||
/** Open a block file (blk?????.dat) */
|
||||
@ -378,7 +379,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
|
||||
bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex *pindexPrev);
|
||||
|
||||
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
|
||||
bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex *pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
|
||||
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
|
||||
|
||||
/** Store block on disk. If dbp is non-NULL, the file is known to already reside on disk */
|
||||
bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp);
|
||||
|
@ -351,7 +351,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||
|
||||
CValidationState state;
|
||||
if (!TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
||||
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false))
|
||||
throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
|
||||
}
|
||||
|
||||
@ -432,7 +432,7 @@ static bool ProcessBlockFound(const CBlock* pblock, const CChainParams& chainpar
|
||||
|
||||
// Process this block the same as if we had received it from another node
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
||||
if (!ProcessNewBlock(state, chainparams, NULL, pblock, true, NULL))
|
||||
return error("BitcoinMiner: ProcessNewBlock, block not accepted");
|
||||
|
||||
return true;
|
||||
|
@ -171,7 +171,7 @@ UniValue generate(const UniValue& params, bool fHelp)
|
||||
++pblock->nNonce;
|
||||
}
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
|
||||
if (!ProcessNewBlock(state, Params(), NULL, pblock, true, NULL))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||
++nHeight;
|
||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||
@ -426,7 +426,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
|
||||
return "inconclusive-not-best-prevblk";
|
||||
CValidationState state;
|
||||
TestBlockValidity(state, block, pindexPrev, false, true);
|
||||
TestBlockValidity(state, Params(), block, pindexPrev, false, true);
|
||||
return BIP22ValidationResult(state);
|
||||
}
|
||||
}
|
||||
@ -652,7 +652,7 @@ UniValue submitblock(const UniValue& params, bool fHelp)
|
||||
CValidationState state;
|
||||
submitblock_StateCatcher sc(block.GetHash());
|
||||
RegisterValidationInterface(&sc);
|
||||
bool fAccepted = ProcessNewBlock(state, NULL, &block, true, NULL);
|
||||
bool fAccepted = ProcessNewBlock(state, Params(), NULL, &block, true, NULL);
|
||||
UnregisterValidationInterface(&sc);
|
||||
if (fBlockPresent)
|
||||
{
|
||||
|
@ -59,6 +59,7 @@ struct {
|
||||
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
{
|
||||
const CChainParams& chainparams = Params(CBaseChainParams::MAIN);
|
||||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
CBlockTemplate *pblocktemplate;
|
||||
CMutableTransaction tx,tx2;
|
||||
@ -91,7 +92,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
pblock->hashMerkleRoot = pblock->ComputeMerkleRoot();
|
||||
pblock->nNonce = blockinfo[i].nonce;
|
||||
CValidationState state;
|
||||
BOOST_CHECK(ProcessNewBlock(state, NULL, pblock, true, NULL));
|
||||
BOOST_CHECK(ProcessNewBlock(state, chainparams, NULL, pblock, true, NULL));
|
||||
BOOST_CHECK(state.IsValid());
|
||||
pblock->hashPrevBlock = pblock->GetHash();
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
|
||||
CBlock
|
||||
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
CBlockTemplate *pblocktemplate = CreateNewBlock(scriptPubKey);
|
||||
CBlock& block = pblocktemplate->block;
|
||||
|
||||
@ -125,10 +126,10 @@ TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>&
|
||||
unsigned int extraNonce = 0;
|
||||
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
|
||||
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, Params(CBaseChainParams::REGTEST).GetConsensus())) ++block.nNonce;
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
|
||||
|
||||
CValidationState state;
|
||||
ProcessNewBlock(state, NULL, &block, true, NULL);
|
||||
ProcessNewBlock(state, chainparams, NULL, &block, true, NULL);
|
||||
|
||||
CBlock result = block;
|
||||
delete pblocktemplate;
|
||||
|
Loading…
Reference in New Issue
Block a user