Skip to content

Commit

Permalink
Readblockfromdisk error (#28)
Browse files Browse the repository at this point in the history
* Remove doubleup of checks in kernel.cpp
* Resolve readblockfromdisk error; left tracing enabled just in case
  • Loading branch information
barrystyle authored Nov 14, 2019
1 parent bfed33b commit 353444b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class CBlockIndex
SetNull();
}

CBlockIndex(const CBlock& block)
explicit CBlockIndex(const CBlock& block)
{
SetNull();

Expand Down
13 changes: 0 additions & 13 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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;
}

Expand Down
22 changes: 13 additions & 9 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -3681,6 +3685,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation

CBlockIndex *pindexDummy = NULL;
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;

if (!AcceptBlockHeader(block, state, chainparams, &pindex))
return false;

Expand Down Expand Up @@ -3725,11 +3730,10 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& 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];
Expand Down Expand Up @@ -3781,12 +3785,12 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& 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()));
Expand All @@ -3805,7 +3809,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& 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()))
Expand Down
4 changes: 2 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit 353444b

Please sign in to comment.