diff --git a/src/chain.h b/src/chain.h index 66ae025b7599ef..732fe6826a2a57 100644 --- a/src/chain.h +++ b/src/chain.h @@ -275,7 +275,7 @@ class CBlockIndex SetNull(); } - CBlockIndex(const CBlock& block) + explicit CBlockIndex(const CBlock& block) { SetNull(); diff --git a/src/kernel.cpp b/src/kernel.cpp index 9106860994faf3..5846c8276f11fd 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -288,10 +288,6 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned bnTargetPerCoinDay.SetCompact(nBits); CAmount nValueIn = txPrev->vout[prevout.n].nValue; - // discard stakes generated from inputs of less than 10000 PAC - if (nValueIn < Params().GetConsensus().nMinimumStakeValue) - return error("CheckStakeKernelHash() : min amount violation"); - // v0.3 protocol kernel hash weight starts from 0 at the 30-day min age // this change increases active coins participating the hash and helps // to secure the network when proof-of-stake difficulty is low @@ -366,11 +362,6 @@ bool CheckProofOfStake(const CBlock &block, uint256& hashProofOfStake) CTxOut prevTxOut = txPrev->vout[txin.prevout.n]; - // Enforce minimum amount for stake input - if (prevTxOut.nValue < Params().GetConsensus().nMinimumStakeValue) - return error("CheckProofOfStake() : INFO: stakeinput value less than minimum required (%llu < %llu), blockhash %s\n", - prevTxOut.nValue, Params().GetConsensus().nMinimumStakeValue, hashBlock.ToString().c_str()); - CBlockIndex* pindex = NULL; BlockMap::iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) @@ -386,10 +377,6 @@ bool CheckProofOfStake(const CBlock &block, uint256& hashProofOfStake) if(!CheckKernelScript(prevTxOut.scriptPubKey, tx->vout[1].scriptPubKey)) return error("CheckProofOfStake() : INFO: check kernel script failed on coinstake %s, hashProof=%s \n", tx->GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str()); - unsigned int nTime = block.nTime; - if (!CheckStakeKernelHash(block.nBits, blockprev, sizeof(CBlock), txPrev, txin.prevout, nTime, hashProofOfStake, false, true)) - return error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s \n", tx->GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str()); // may occur during initial download or if behind on block chain sync - return true; } diff --git a/src/validation.cpp b/src/validation.cpp index 3dab739cb590b2..a91dd70015bcfe 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1095,8 +1095,10 @@ bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHea return true; } -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, const char* str) { + LogPrintf("ReadBlockFromDisk(CDiskBlockPos)::called by %s\n", str); + LOCK(cs_main); block.SetNull(); @@ -1120,8 +1122,10 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus: return true; } -bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams) +bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, const char* str) { + LogPrintf("ReadBlockFromDisk(CBlockIndex)::called by %s\n", str); + CDiskBlockPos blockPos; { LOCK(cs_main); @@ -3681,6 +3685,7 @@ static bool AcceptBlock(const std::shared_ptr& pblock, CValidation CBlockIndex *pindexDummy = NULL; CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy; + if (!AcceptBlockHeader(block, state, chainparams, &pindex)) return false; @@ -3725,11 +3730,10 @@ static bool AcceptBlock(const std::shared_ptr& pblock, CValidation if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) GetMainSignals().NewPoWValidBlock(pindex, pblock); - int nHeight = pindex->nHeight; + if (block.IsProofOfStake() || + !IsInitialBlockDownload()) { - if (block.IsProofOfStake()) { LOCK(cs_main); - CCoinsViewCache coins(pcoinsTip); const CTransaction& tx = *block.vtx[1]; @@ -3781,12 +3785,12 @@ static bool AcceptBlock(const std::shared_ptr& pblock, CValidation } } - // test if hashproofofstake matches + //// hashproof test uint256 hashProofOfStake = uint256(); if (block.IsProofOfStake()) { - if(block.GetHash() == hashProofOfStake) - return state.DoS(100, error("CheckBlock(): invalid proof of stake block\n")); + if(block.GetHash() == hashProofOfStake) + return state.DoS(100, error("CheckBlock(): invalid proof of stake block\n")); if(!CheckProofOfStake(block, hashProofOfStake)) return state.DoS(100, error("CheckBlock(): check proof-of-stake failed for block %s\n", hashProofOfStake.ToString().c_str())); @@ -3805,7 +3809,7 @@ static bool AcceptBlock(const std::shared_ptr& pblock, CValidation CDiskBlockPos blockPos; if (dbp != NULL) blockPos = *dbp; - if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) + if (!FindBlockPos(state, blockPos, nBlockSize+8, pindex->nHeight, block.GetBlockTime(), dbp != NULL)) return error("AcceptBlock(): FindBlockPos failed"); if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) diff --git a/src/validation.h b/src/validation.h index 86b0e03ab0224a..83437ec07258ff 100644 --- a/src/validation.h +++ b/src/validation.h @@ -486,8 +486,8 @@ bool GetAddressUnspent(uint160 addressHash, int type, /** Functions for disk access for blocks */ bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart); -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams); -bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams); +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, const char* str = __builtin_FUNCTION()); +bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, const char* str = __builtin_FUNCTION()); /** Functions for validating blocks and updating the block tree */