Test
This commit is contained in:
@@ -1272,7 +1272,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
|||||||
{
|
{
|
||||||
if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
|
if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 )
|
||||||
height = pprev->nHeight + 1;
|
height = pprev->nHeight + 1;
|
||||||
fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d zeroheight\n",slowflag,height);
|
//fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d zeroheight\n",slowflag,height);
|
||||||
//if ( height == 0 )
|
//if ( height == 0 )
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
@@ -1337,9 +1337,23 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d notaryid.%d failed.%d\n",slowflag,height,notaryid,failed);
|
//fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d notaryid.%d failed.%d\n",slowflag,height,notaryid,failed);
|
||||||
if ( failed != 0 && notaryid < 0 )
|
if ( failed != 0 && notaryid < 0 )
|
||||||
return(-1);
|
return(-1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash)
|
||||||
|
{
|
||||||
|
CBlockIndex *pindex;
|
||||||
|
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
|
||||||
|
if ( miSelf != mapBlockIndex.end() )
|
||||||
|
{
|
||||||
|
if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail
|
||||||
|
{
|
||||||
|
pindex = AddToBlockIndex(*pblock);
|
||||||
|
fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),pindex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
55
src/main.cpp
55
src/main.cpp
@@ -3543,7 +3543,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
BlockMap::iterator it = mapBlockIndex.find(hash);
|
BlockMap::iterator it = mapBlockIndex.find(hash);
|
||||||
if (it != mapBlockIndex.end())
|
if (it != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
fprintf(stderr,"addtoblockindex already there %p\n",it->second);
|
//fprintf(stderr,"addtoblockindex already there %p\n",it->second);
|
||||||
if ( ASSETCHAINS_STAKED == 0 || it->second != 0 )
|
if ( ASSETCHAINS_STAKED == 0 || it->second != 0 )
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
@@ -3559,8 +3559,8 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
|
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
|
||||||
if (miPrev != mapBlockIndex.end())
|
if (miPrev != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
pindexNew->pprev = (*miPrev).second;
|
if ( (pindexNew->pprev= (*miPrev).second) != 0 )
|
||||||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
||||||
pindexNew->BuildSkip();
|
pindexNew->BuildSkip();
|
||||||
}
|
}
|
||||||
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
|
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
|
||||||
@@ -3569,7 +3569,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
pindexBestHeader = pindexNew;
|
pindexBestHeader = pindexNew;
|
||||||
|
|
||||||
setDirtyBlockIndex.insert(pindexNew);
|
setDirtyBlockIndex.insert(pindexNew);
|
||||||
fprintf(stderr,"added to block index %s\n",hash.ToString().c_str());
|
//fprintf(stderr,"added to block index %s\n",hash.ToString().c_str());
|
||||||
return pindexNew;
|
return pindexNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3782,7 +3782,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
|
|||||||
// 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);
|
//fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( fCheckPOW )
|
if ( fCheckPOW )
|
||||||
@@ -3854,7 +3854,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
|
|||||||
{
|
{
|
||||||
//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);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -3975,13 +3975,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
|
|||||||
*ppindex = pindex;
|
*ppindex = pindex;
|
||||||
if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK )
|
if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK )
|
||||||
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
|
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
|
||||||
if ( pindex == 0 )
|
//if ( pindex == 0 )
|
||||||
fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str());
|
// fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
|
if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"CheckBlockHeader failed\n");
|
//fprintf(stderr,"CheckBlockHeader failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get prev block index
|
// Get prev block index
|
||||||
@@ -3998,14 +3998,14 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
|
|||||||
}
|
}
|
||||||
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"ContextualCheckBlockHeader failed\n");
|
//fprintf(stderr,"ContextualCheckBlockHeader failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pindex == NULL)
|
if (pindex == NULL)
|
||||||
{
|
{
|
||||||
if ( (pindex= AddToBlockIndex(block)) == 0 )
|
if ( (pindex= AddToBlockIndex(block)) == 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"couldnt add to block index\n");
|
//fprintf(stderr,"couldnt add to block index\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ppindex)
|
if (ppindex)
|
||||||
@@ -4021,12 +4021,12 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||||||
CBlockIndex *&pindex = *ppindex;
|
CBlockIndex *&pindex = *ppindex;
|
||||||
if (!AcceptBlockHeader(block, state, &pindex))
|
if (!AcceptBlockHeader(block, state, &pindex))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"AcceptBlockHeader rejected\n");
|
//fprintf(stderr,"AcceptBlockHeader rejected\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( pindex == 0 )
|
if ( pindex == 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"AcceptBlock error null pindex\n");
|
//fprintf(stderr,"AcceptBlock error null pindex\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//fprintf(stderr,"acceptblockheader passed\n");
|
//fprintf(stderr,"acceptblockheader passed\n");
|
||||||
@@ -4044,7 +4044,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||||||
|
|
||||||
// TODO: deal better with return value and error conditions for duplicate
|
// TODO: deal better with return value and error conditions for duplicate
|
||||||
// and unrequested blocks.
|
// and unrequested blocks.
|
||||||
fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead);
|
//fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead);
|
||||||
if (fAlreadyHave) return true;
|
if (fAlreadyHave) return true;
|
||||||
if (!fRequested) { // If we didn't ask for it:
|
if (!fRequested) { // If we didn't ask for it:
|
||||||
if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned
|
if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned
|
||||||
@@ -4060,7 +4060,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
setDirtyBlockIndex.insert(pindex);
|
setDirtyBlockIndex.insert(pindex);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"CheckBlock or ContextualCheckBlock failed\n");
|
//fprintf(stderr,"CheckBlock or ContextualCheckBlock failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4109,7 +4109,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
|
|||||||
bool checked; uint256 hash;
|
bool checked; uint256 hash;
|
||||||
auto verifier = libzcash::ProofVerifier::Disabled();
|
auto verifier = libzcash::ProofVerifier::Disabled();
|
||||||
hash = pblock->GetHash();
|
hash = pblock->GetHash();
|
||||||
fprintf(stderr,"process newblock %s\n",hash.ToString().c_str());
|
//fprintf(stderr,"process newblock %s\n",hash.ToString().c_str());
|
||||||
if ( chainActive.Tip() != 0 )
|
if ( chainActive.Tip() != 0 )
|
||||||
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
||||||
checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
|
checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
|
||||||
@@ -4120,7 +4120,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
|
|||||||
if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 )
|
if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 )
|
||||||
{
|
{
|
||||||
checked = 0;
|
checked = 0;
|
||||||
fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0);
|
//fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0);
|
||||||
}
|
}
|
||||||
if (!checked)
|
if (!checked)
|
||||||
{
|
{
|
||||||
@@ -4134,15 +4134,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
|
|||||||
CBlockIndex *pindex = NULL;
|
CBlockIndex *pindex = NULL;
|
||||||
if ( ASSETCHAINS_STAKED != 0 ) // or other low node count networks
|
if ( ASSETCHAINS_STAKED != 0 ) // or other low node count networks
|
||||||
{
|
{
|
||||||
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
|
//komodo_ensure(pblock->hashPrevBlock);
|
||||||
if ( miSelf != mapBlockIndex.end() )
|
komodo_ensure(pblock,hash);
|
||||||
{
|
|
||||||
if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail
|
|
||||||
{
|
|
||||||
pindex = AddToBlockIndex(*pblock);
|
|
||||||
fprintf(stderr,"Block header %s is already known, but without pindex -> %p\n",hash.ToString().c_str(),pindex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp);
|
bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp);
|
||||||
if (pindex && pfrom) {
|
if (pindex && pfrom) {
|
||||||
@@ -4151,7 +4144,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
|
|||||||
CheckBlockIndex();
|
CheckBlockIndex();
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return error("%s: AcceptBlock FAILED", __func__);
|
return error("%s: AcceptBlock FAILED", __func__);
|
||||||
else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev);
|
//else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ActivateBestChain(state, pblock))
|
if (!ActivateBestChain(state, pblock))
|
||||||
@@ -4174,22 +4167,22 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
|
|||||||
// NOTE: CheckBlockHeader is called by CheckBlock
|
// NOTE: CheckBlockHeader is called by CheckBlock
|
||||||
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW);
|
//fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
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 checkPOW.%d\n",fCheckPOW);
|
//fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ContextualCheckBlock(block, state, pindexPrev))
|
if (!ContextualCheckBlock(block, state, pindexPrev))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW);
|
//fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
|
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW);
|
//fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert(state.IsValid());
|
assert(state.IsValid());
|
||||||
|
|||||||
Reference in New Issue
Block a user