From f65a34b970a4509a67e147d222c31cd51abdb2a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:32:35 +0300 Subject: [PATCH 1/7] Test --- src/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 23d8d65c4..acf898246 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4009,7 +4009,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - //fprintf(stderr,"CheckBlockHeader failed\n"); + fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; } // Get prev block index @@ -4025,26 +4025,33 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; } - // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 ) + { + fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); + if ( komodo_requestedhash == zero ) + { + komodo_requestedhash = block.hashPrevBlock; + komodo_requestedcount = 0; + } return(false); + } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"ContextualCheckBlockHeader failed\n"); + fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL) { if ( (pindex= AddToBlockIndex(block)) == 0 ) { - //fprintf(stderr,"couldnt add to block index\n"); + fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); } } if (ppindex) From 5d9f111967b5d06beb44c03914f24fe8fc67aac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:52:16 +0300 Subject: [PATCH 2/7] Test --- src/main.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index acf898246..47f6e2485 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,9 +3761,19 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + if ( (tipindex= chainActive().Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) + { + fprintf(stderr,"it is the next block, let's wait a bit\n"); + while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) + sleep(1); + fprintf(stderr,"now its valid\n"); + } + else + { + return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + } } - else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) + if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); From 82b4714bee6f6211d9d5329fb13d91c4a8cf96c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:55:27 +0300 Subject: [PATCH 3/7] Test --- src/main.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 47f6e2485..6b15ea775 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3760,6 +3760,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { + CBlockIndex *tipindex; fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive().Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { @@ -4072,11 +4073,6 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; } - /*else //if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) - { - fprintf(stderr,"random komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); - komodo_requestedhash = hash; - }*/ return true; } From d1cd2af5f4a690f989dcd160a71f2d9da0604c4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:56:28 +0300 Subject: [PATCH 4/7] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6b15ea775..951558e52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3762,7 +3762,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl { CBlockIndex *tipindex; fprintf(stderr,"future block %u vs time.%u + 60\n",(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 a bit\n"); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) From 8d725ab46ff31e50d34dbc6714b833715ff68b06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:59:51 +0300 Subject: [PATCH 5/7] -komodo_requesthash --- src/main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 951558e52..b2962565d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3988,8 +3988,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return true; } -static uint256 komodo_requestedhash; -static int32_t komodo_requestedcount; +//static uint256 komodo_requestedhash; +//static int32_t komodo_requestedcount; bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { @@ -4008,12 +4008,12 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - if ( pindex != 0 && hash == komodo_requestedhash ) + /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; - } + }*/ //if ( pindex == 0 ) // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; @@ -4030,24 +4030,24 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); - if ( komodo_requestedhash == zero ) + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); + /*if ( komodo_requestedhash == zero ) { komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; - } + }*/ return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 ) { - fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.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; - } + }*/ return(false); } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) @@ -4067,12 +4067,12 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (ppindex) *ppindex = pindex; - if ( pindex != 0 && hash == komodo_requestedhash ) + /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; - } + }*/ return true; } @@ -6729,7 +6729,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } } - CBlockIndex *pindex; + /*CBlockIndex *pindex; if ( komodo_requestedhash != zero && komodo_requestedcount < 16 && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { LogPrint("net","komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId()); @@ -6742,7 +6742,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; } - } + }*/ // // Message: getdata (non-blocks) From 43ef3068d139d449c198f7a8598288a1dd8bbc8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 23:47:48 +0300 Subject: [PATCH 6/7] 10 second window for notary mining --- src/main.cpp | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b2962565d..2ac1e416c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,10 +3761,10 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; - fprintf(stderr,"future block %u vs time.%u + 60\n",(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 a bit\n"); + fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) sleep(1); fprintf(stderr,"now its valid\n"); diff --git a/src/miner.cpp b/src/miner.cpp index 02327522a..d9da98f3c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -463,7 +463,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) { pblock->nTime = pindexPrev->nTime + 60; - while ( pblock->GetBlockTime() > GetAdjustedTime() + 30 ) + while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 ) sleep(1); //fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); } From 2fea1c97239ac17f65346aa8790ef98685437580 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 00:00:45 +0300 Subject: [PATCH 7/7] -print --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ac1e416c..87e14bbaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,13 +3761,13 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl 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()); + //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) sleep(1); - fprintf(stderr,"now its valid\n"); + //fprintf(stderr,"now its valid\n"); } else { @@ -4020,7 +4020,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); + //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; } // Get prev block index @@ -4055,7 +4055,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); + //fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL)