Browse Source

Allow future block to not trigger severe rejection

pull/4/head
jl777 6 years ago
parent
commit
531b92932a
  1. 2
      src/komodo_bitcoind.h
  2. 32
      src/main.cpp
  3. 6
      src/main.h

2
src/komodo_bitcoind.h

@ -1035,7 +1035,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
cmptime -= 16000;
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);
}

32
src/main.cpp

@ -3762,7 +3762,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60)
{
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 )
{
//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 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;
const CChainParams& chainparams = Params();
AssertLockHeld(cs_main);
int32_t futureblock;
// Check for duplicate
uint256 hash = block.GetHash();
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());
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");
return false;
@ -4046,8 +4046,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
pindexPrev = (*mi).second;
if (pindexPrev == 0 )
{
fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str());
/*if ( komodo_requestedhash == zero )
/*fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str());
if ( komodo_requestedhash == zero )
{
komodo_requestedhash = block.hashPrevBlock;
komodo_requestedcount = 0;
@ -4080,13 +4080,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
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();
AssertLockHeld(cs_main);
CBlockIndex *&pindex = *ppindex;
if (!AcceptBlockHeader(block, state, &pindex))
if (!AcceptBlockHeader(futureblockp,block, state, &pindex))
{
//fprintf(stderr,"AcceptBlockHeader rejected\n");
return false;
@ -4120,9 +4120,8 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
}
// See method docstring for why this is always disabled
int32_t futureblock;
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()) {
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)
{
// Preliminary checks
bool checked; uint256 hash; int32_t futureblock;
bool checked; uint256 hash; int32_t futureblock=0;
auto verifier = libzcash::ProofVerifier::Disabled();
hash = pblock->GetHash();
//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
komodo_ensure(pblock,hash);
}
bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp);
bool ret = AcceptBlock(&futureblock,*pblock, state, &pindex, fRequested, dbp);
if (pindex && pfrom) {
mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId();
}
CheckBlockIndex();
if (!ret)
if (!ret && futureblock == 0)
return error("%s: AcceptBlock FAILED", __func__);
//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 true;
@ -6081,12 +6080,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
Misbehaving(pfrom->GetId(), 20);
return error("non-continuous headers sequence");
}
int32_t futureblock;
//fprintf(stderr,"headers msg nCount.%d\n",(int32_t)nCount);
if (!AcceptBlockHeader(header, state, &pindexLast)) {
if (!AcceptBlockHeader(&futureblock,header, state, &pindexLast)) {
int nDoS;
if (state.IsInvalid(nDoS))
{
if (nDoS > 0)
if (nDoS > 0 && futureblock == 0)
Misbehaving(pfrom->GetId(), nDoS/nDoS);
return error("invalid header received");
}

6
src/main.h

@ -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);
/** 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,
libzcash::ProofVerifier& verifier,
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.
* 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 AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);
bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp);
bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);

Loading…
Cancel
Save