Skip to content

Commit

Permalink
Checkblock optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed May 22, 2014
1 parent 1cb4871 commit 7b662d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,8 @@ bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex)

bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
{
// Check it again in case a previous version let a bad block in
if (!CheckBlock(!fJustCheck, !fJustCheck))
// Check it again in case a previous version let a bad block in, but skip BlockSig checking
if (!CheckBlock(!fJustCheck, !fJustCheck, false))
return false;

// Do not allow blocks that contain transactions which 'overwrite' older transactions,
Expand Down Expand Up @@ -2019,7 +2019,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)



bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const
bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) const
{
// These are checks that are independent of context
// that can be verified before saving an orphan block.
Expand Down Expand Up @@ -2063,6 +2063,10 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const
// Check coinstake timestamp
if (!CheckCoinStakeTimestamp(GetBlockTime(), (int64)vtx[1].nTime))
return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%"PRI64d" nTimeTx=%u", GetBlockTime(), vtx[1].nTime));

// Check proof-of-stake block signature
if (fCheckSig && !CheckBlockSignature(true))
return DoS(100, error("CheckBlock() : bad proof-of-stake block signature"));
}
else
{
Expand Down Expand Up @@ -2118,10 +2122,6 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const
if (fCheckMerkleRoot && hashMerkleRoot != BuildMerkleTree())
return DoS(100, error("CheckBlock() : hashMerkleRoot mismatch"));

// ppcoin: check block signature
if (!CheckBlockSignature())
return DoS(100, error("CheckBlock() : bad block signature"));

return true;
}

Expand Down Expand Up @@ -2411,16 +2411,16 @@ bool CBlock::SignBlock(const CKeyStore& keystore)
return false;
}

// ppcoin: check block signature
bool CBlock::CheckBlockSignature() const
// check block signature
bool CBlock::CheckBlockSignature(bool fProofOfStake) const
{
if (GetHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
return vchBlockSig.empty();

vector<valtype> vSolutions;
txnouttype whichType;

if(IsProofOfStake())
if(fProofOfStake)
{
const CTxOut& txout = vtx[1].vout[1];

Expand Down
4 changes: 2 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,11 @@ class CBlock
bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
bool SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew);
bool AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos);
bool CheckBlock(bool fCheckPOW=true, bool fCheckMerkleRoot=true) const;
bool CheckBlock(bool fCheckPOW=true, bool fCheckMerkleRoot=true, bool fCheckSig=true) const;
bool AcceptBlock();
bool GetCoinAge(uint64& nCoinAge) const; // ppcoin: calculate total coin age spent in block
bool SignBlock(const CKeyStore& keystore);
bool CheckBlockSignature() const;
bool CheckBlockSignature(bool fProofOfStake) const;

private:
bool SetBestChainInner(CTxDB& txdb, CBlockIndex *pindexNew);
Expand Down

0 comments on commit 7b662d4

Please sign in to comment.