Allow future block to not trigger severe rejection

This commit is contained in:
jl777
2018-04-24 14:47:21 +03:00
parent 2a5ffc0486
commit 531b92932a
3 changed files with 20 additions and 20 deletions

View File

@@ -1035,7 +1035,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
cmptime -= 16000; cmptime -= 16000;
if ( (int64_t)tx.nLockTime < cmptime-3600 ) if ( (int64_t)tx.nLockTime < cmptime-3600 )
{ {
if ( tx.nLockTime != 1477258935 || dispflag != 0 ) if ( tx.nLockTime != 1477258935 && dispflag != 0 )
{ {
fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime);
} }

View File

@@ -3762,7 +3762,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60)
{ {
CBlockIndex *tipindex; CBlockIndex *tipindex;
//fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime());
if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 )
{ {
//fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime());
@@ -3994,12 +3994,12 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
//static uint256 komodo_requestedhash; //static uint256 komodo_requestedhash;
//static int32_t komodo_requestedcount; //static int32_t komodo_requestedcount;
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex)
{ {
static uint256 zero; static uint256 zero;
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
int32_t futureblock;
// Check for duplicate // Check for duplicate
uint256 hash = block.GetHash(); uint256 hash = block.GetHash();
BlockMap::iterator miSelf = mapBlockIndex.find(hash); BlockMap::iterator miSelf = mapBlockIndex.find(hash);
@@ -4022,7 +4022,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
// 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(&futureblock,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
{ {
//fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n");
return false; return false;
@@ -4046,8 +4046,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
pindexPrev = (*mi).second; pindexPrev = (*mi).second;
if (pindexPrev == 0 ) if (pindexPrev == 0 )
{ {
fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); /*fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str());
/*if ( komodo_requestedhash == zero ) if ( komodo_requestedhash == zero )
{ {
komodo_requestedhash = block.hashPrevBlock; komodo_requestedhash = block.hashPrevBlock;
komodo_requestedcount = 0; komodo_requestedcount = 0;
@@ -4080,13 +4080,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
return true; return true;
} }
bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp)
{ {
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
CBlockIndex *&pindex = *ppindex; CBlockIndex *&pindex = *ppindex;
if (!AcceptBlockHeader(block, state, &pindex)) if (!AcceptBlockHeader(futureblockp,block, state, &pindex))
{ {
//fprintf(stderr,"AcceptBlockHeader rejected\n"); //fprintf(stderr,"AcceptBlockHeader rejected\n");
return false; return false;
@@ -4120,9 +4120,8 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
} }
// See method docstring for why this is always disabled // See method docstring for why this is always disabled
int32_t futureblock;
auto verifier = libzcash::ProofVerifier::Disabled(); auto verifier = libzcash::ProofVerifier::Disabled();
if ((!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev))
{ {
if (futureblock == 0 && state.IsInvalid() && !state.CorruptionPossible()) { if (futureblock == 0 && state.IsInvalid() && !state.CorruptionPossible()) {
pindex->nStatus |= BLOCK_FAILED_VALID; pindex->nStatus |= BLOCK_FAILED_VALID;
@@ -4197,7 +4196,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash)
bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp)
{ {
// Preliminary checks // Preliminary checks
bool checked; uint256 hash; int32_t futureblock; bool checked; uint256 hash; int32_t futureblock=0;
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());
@@ -4227,17 +4226,17 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
// without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync
komodo_ensure(pblock,hash); komodo_ensure(pblock,hash);
} }
bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp); bool ret = AcceptBlock(&futureblock,*pblock, state, &pindex, fRequested, dbp);
if (pindex && pfrom) { if (pindex && pfrom) {
mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId(); mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId();
} }
CheckBlockIndex(); CheckBlockIndex();
if (!ret) if (!ret && futureblock == 0)
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 (futureblock == 0 && !ActivateBestChain(state, pblock))
return error("%s: ActivateBestChain failed", __func__); return error("%s: ActivateBestChain failed", __func__);
return true; return true;
@@ -6081,12 +6080,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
Misbehaving(pfrom->GetId(), 20); Misbehaving(pfrom->GetId(), 20);
return error("non-continuous headers sequence"); return error("non-continuous headers sequence");
} }
int32_t futureblock;
//fprintf(stderr,"headers msg nCount.%d\n",(int32_t)nCount); //fprintf(stderr,"headers msg nCount.%d\n",(int32_t)nCount);
if (!AcceptBlockHeader(header, state, &pindexLast)) { if (!AcceptBlockHeader(&futureblock,header, state, &pindexLast)) {
int nDoS; int nDoS;
if (state.IsInvalid(nDoS)) if (state.IsInvalid(nDoS))
{ {
if (nDoS > 0) if (nDoS > 0 && futureblock == 0)
Misbehaving(pfrom->GetId(), nDoS/nDoS); Misbehaving(pfrom->GetId(), nDoS/nDoS);
return error("invalid header received"); return error("invalid header received");
} }

View File

@@ -796,7 +796,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = 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 *futureblockp,int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state,
libzcash::ProofVerifier& verifier, libzcash::ProofVerifier& verifier,
bool fCheckPOW = true, bool fCheckMerkleRoot = true); bool fCheckPOW = true, bool fCheckMerkleRoot = true);
@@ -815,8 +815,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
* - The only caller of AcceptBlock verifies JoinSplit proofs elsewhere. * - The only caller of AcceptBlock verifies JoinSplit proofs elsewhere.
* If dbp is non-NULL, the file is known to already reside on disk * If dbp is non-NULL, the file is known to already reside on disk
*/ */
bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp); bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp);
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL); bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);