Merge pull request #585 from jl777/dev

Dev
This commit is contained in:
jl777
2018-04-16 05:34:21 +03:00
committed by GitHub
3 changed files with 22 additions and 17 deletions

View File

@@ -2429,7 +2429,7 @@ static int64_t nTimeIndex = 0;
static int64_t nTimeCallbacks = 0; static int64_t nTimeCallbacks = 0;
static int64_t nTimeTotal = 0; static int64_t nTimeTotal = 0;
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW)
{ {
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
@@ -2447,7 +2447,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
auto disabledVerifier = libzcash::ProofVerifier::Disabled(); auto disabledVerifier = libzcash::ProofVerifier::Disabled();
// Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in
if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, 1, !fJustCheck)) //!fJustCheck, !fJustCheck)) if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) //!fJustCheck, !fJustCheck))
return false; return false;
// verify that the view's current state corresponds to the previous block // verify that the view's current state corresponds to the previous block
@@ -2923,7 +2923,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001); LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
{ {
CCoinsViewCache view(pcoinsTip); CCoinsViewCache view(pcoinsTip);
bool rv = ConnectBlock(*pblock, state, pindexNew, view); bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true);
GetMainSignals().BlockChecked(*pblock, state); GetMainSignals().BlockChecked(*pblock, state);
if (!rv) { if (!rv) {
if (state.IsInvalid()) if (state.IsInvalid())
@@ -3564,12 +3564,14 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
// Check that the header is valid (particularly PoW). This is mostly // Check that the header is valid (particularly PoW). This is mostly
// redundant with the call in AcceptBlockHeader. // redundant with the call in AcceptBlockHeader.
if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW))
{
fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW);
return false; return false;
//komodo_index2pubkey33(pubkey33,pindex,height); }
komodo_block2pubkey33(pubkey33,(CBlock *)&block); komodo_block2pubkey33(pubkey33,(CBlock *)&block);
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) ) if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) )
{ {
komodo_reverify_blockcheck(state,height,pindex); //komodo_reverify_blockcheck(state,height,pindex);
return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash"); return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash");
} }
// Check the merkle root. // Check the merkle root.
@@ -3626,7 +3628,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
//if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 ) //if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 )
{ {
static uint32_t counter; static uint32_t counter;
if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
fprintf(stderr,"check deposit rejection\n"); fprintf(stderr,"check deposit rejection\n");
return(false); return(false);
} }
@@ -3968,7 +3970,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
} }
if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot))
{ {
//fprintf(stderr,"TestBlockValidity failure B\n"); fprintf(stderr,"TestBlockValidity failure B\n");
return false; return false;
} }
if (!ContextualCheckBlock(block, state, pindexPrev)) if (!ContextualCheckBlock(block, state, pindexPrev))
@@ -3976,7 +3978,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
fprintf(stderr,"TestBlockValidity failure C\n"); fprintf(stderr,"TestBlockValidity failure C\n");
return false; return false;
} }
if (!ConnectBlock(block, state, &indexDummy, viewNew, true)) if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
{ {
fprintf(stderr,"TestBlockValidity failure D\n"); fprintf(stderr,"TestBlockValidity failure D\n");
return false; return false;
@@ -4414,7 +4416,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, pindex)) if (!ReadBlockFromDisk(block, pindex))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!ConnectBlock(block, state, pindex, coins)) if (!ConnectBlock(block, state, pindex, coins,false, true))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
} }
} }

View File

@@ -447,7 +447,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL); bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL);
/** Apply the effects of this block (with given index) on the UTXO set represented by coins */ /** Apply the effects of this block (with given index) on the UTXO set represented by coins */
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = false);
/** Context-independent validity checks */ /** Context-independent validity checks */
bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);

View File

@@ -386,7 +386,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
nLastBlockTx = nBlockTx; nLastBlockTx = nBlockTx;
nLastBlockSize = nBlockSize; nLastBlockSize = nBlockSize;
blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
pblock->nTime = blocktime + 1; //pblock->nTime = blocktime + 1;
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
//LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits);
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 )
@@ -480,8 +480,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// Fill in header // Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashPrevBlock = pindexPrev->GetBlockHash();
pblock->hashReserved = uint256(); pblock->hashReserved = uint256();
//UpdateTime(pblock, Params().GetConsensus(), pindexPrev); if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
//pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); {
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
}
pblock->nSolution.clear(); pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
@@ -489,8 +492,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
{ {
static uint32_t counter; static uint32_t counter;
if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
fprintf(stderr,"warning: testblockvalidity failed\n"); fprintf(stderr,"warning: miner testblockvalidity failed\n");
return(0); return(0);
} }
} }
@@ -933,9 +936,9 @@ void static BitcoinMiner()
else else
{ {
CValidationState state; CValidationState state;
if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false))
{ {
//fprintf(stderr,"Invalid block mined, try again\n"); fprintf(stderr,"Invalid block mined, try again\n");
return(false); return(false);
} }
if ( NOTARY_PUBKEY33[0] != 0 ) if ( NOTARY_PUBKEY33[0] != 0 )