From 78fa6faa82f5b998dc118311bd791d1be040e2de Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 19:11:06 +0300 Subject: [PATCH 1/8] -60 test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7b746c3d2..15f3f92db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3759,7 +3759,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, } } *futureblockp = 0; - if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) + 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()); From 48f12344d29ff1315094b7b38147c24ce7e760e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 19:11:44 +0300 Subject: [PATCH 2/8] revert --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 15f3f92db..7b746c3d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3759,7 +3759,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, } } *futureblockp = 0; - if (blockhdr.GetBlockTime() > GetAdjustedTime() - 60) + 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()); From 06ce10a9a7d9bce8c071ce6ed231583a898b8d4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 19:24:14 +0300 Subject: [PATCH 3/8] Test --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7b746c3d2..c4c3e29db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4012,7 +4012,11 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) - return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + { + if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) + return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + else pindex->nStatus &= ~BLOCK_FAILED_MASK; + } /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); From 85f1853e3553203c3483af406efbf4cbd117cd26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 19:28:42 +0300 Subject: [PATCH 4/8] Revert --- src/main.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c4c3e29db..7b746c3d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4012,11 +4012,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) - { - if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) - return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - else pindex->nStatus &= ~BLOCK_FAILED_MASK; - } + return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); From 42c2e91bbfdecec09709b765d46869fe045346ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 19:32:48 +0300 Subject: [PATCH 5/8] Test --- src/main.cpp | 2 +- src/main.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7b746c3d2..31a95a43a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4110,7 +4110,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // blocks which are too close in height to the tip. Apply this test // regardless of whether pruning is enabled; it should generally be safe to // not process unrequested blocks. - bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); + bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP)); // TODO: deal better with return value and error conditions for duplicate // and unrequested blocks. diff --git a/src/main.h b/src/main.h index ef46cd83d..956d8351e 100644 --- a/src/main.h +++ b/src/main.h @@ -94,7 +94,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 160; * Larger windows tolerate larger download speed differences between peer, but increase the potential * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning * harder). We'll probably want to make this a per-peer adaptive value at some point. */ -static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; +static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024 * 2; /** Time to wait (in seconds) between writing blocks/block index to disk. */ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; /** Time to wait (in seconds) between flushing chainstate to disk. */ From e8314e82f50412bf8c244fdd0752a1caba0e920f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 20:23:29 +0300 Subject: [PATCH 6/8] +logprints --- src/main.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 31a95a43a..af10d91be 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3774,6 +3774,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, { if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600) *futureblockp = 1; + LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime()); return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } } @@ -3815,8 +3816,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW)) { if ( *futureblockp == 0 ) + { + LogPrintf("CheckBlock header error"); return false; - //else fprintf(stderr,"checkblockheader PoW.%d got futureblock\n",fCheckPOW); + } } if ( fCheckPOW ) { @@ -3888,6 +3891,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) // fprintf(stderr,"check deposit rejection\n"); + LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } return true; @@ -4026,8 +4030,10 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { if ( *futureblockp == 0 ) + { + LogPrintf("AcceptBlockHeader CheckBlockHeader error"); return false; - //else fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader got future block\n"); + } } // Get prev block index CBlockIndex* pindexPrev = NULL; @@ -4042,6 +4048,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; }*/ + LogPrintf("AcceptBlockHeader hashPrevBlock %s not found",block.hashPrevBlock.ToString().c_str()); return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } @@ -4054,6 +4061,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; }*/ + LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev",block.hashPrevBlock.ToString().c_str()); return(false); } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) @@ -4062,13 +4070,14 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { //fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); + LogPrintf("AcceptBlockHeader ContextualCheckBlockHeader failed"); return false; } if (pindex == NULL) { if ( (pindex= AddToBlockIndex(block)) == 0 ) { - fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); + //fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); } } if (ppindex) @@ -4091,12 +4100,14 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (!AcceptBlockHeader(futureblockp,block, state, &pindex)) { if ( *futureblockp == 0 ) + { + LogPrintf("AcceptBlock AcceptBlockHeader error"); return false; - //else fprintf(stderr,"AcceptBlock AcceptBlockHeader got future block\n"); + } } if ( pindex == 0 ) { - //fprintf(stderr,"AcceptBlock error null pindex\n"); + LogPrintf("AcceptBlock null pindex error"); return false; } //fprintf(stderr,"acceptblockheader passed\n"); @@ -4132,8 +4143,9 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); } + LogPrintf("AcceptBlock CheckBlock or ContextualCheckBlock error"); return false; - } else fprintf(stderr,"CheckBlock or ContextualCheckBlock got futureblock\n"); + } } int nHeight = pindex->nHeight; @@ -4159,7 +4171,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files if ( *futureblockp == 0 ) return true; - else return false; + LogPrintf("AcceptBlock block from future error"); + return false; } static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams) From 395f10cf91a0e08e6e4f8dbec64a5f08f82972cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 21:09:51 +0300 Subject: [PATCH 7/8] Test --- src/main.cpp | 3 +++ src/main.h | 2 +- src/miner.cpp | 41 +++++++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index af10d91be..c1ca3f9a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,7 @@ extern uint8_t NOTARY_PUBKEY33[33]; extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN; int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); +void komodo_broadcast(CBlock *pblock,int32_t limit); BlockMap mapBlockIndex; CChain chainActive; @@ -3218,6 +3219,8 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); + if ( ASSETHCHAINS_SYMBOL[0] == 0 ) + komodo_broadcast(pblock,8); return true; } diff --git a/src/main.h b/src/main.h index 956d8351e..ef46cd83d 100644 --- a/src/main.h +++ b/src/main.h @@ -94,7 +94,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 160; * Larger windows tolerate larger download speed differences between peer, but increase the potential * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning * harder). We'll probably want to make this a per-peer adaptive value at some point. */ -static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024 * 2; +static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; /** Time to wait (in seconds) between writing blocks/block index to disk. */ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; /** Time to wait (in seconds) between flushing chainstate to disk. */ diff --git a/src/miner.cpp b/src/miner.cpp index d9da98f3c..25c71918d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -584,6 +584,26 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) return CreateNewBlock(scriptPubKey); } +void komodo_broadcast(CBlock *pblock,int32_t limit) +{ + int32_t n = 1; + //fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); + { + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + if ( (rand() % n) == 0 ) + { + pnode->PushMessage("block", *pblock); + if ( n++ > limit ) + break; + } + } + } + //fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL)); +} static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) #else @@ -635,26 +655,7 @@ static bool ProcessBlockFound(CBlock* pblock) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); - //if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE*2 ) - { - int32_t n = 1; - //fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); - { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - if ( pnode->hSocket == INVALID_SOCKET ) - continue; - if ( (rand() % n) == 0 ) - { - pnode->PushMessage("block", *pblock); - if ( n++ > 8 ) - break; - } - } - } - //fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL)); - } + komodo_broadcast(pblock,16); return true; } From c4318f427bce4c72365c4476802bd72babdd4552 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 21:11:32 +0300 Subject: [PATCH 8/8] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c1ca3f9a8..6ba882d2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3219,7 +3219,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); - if ( ASSETHCHAINS_SYMBOL[0] == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) komodo_broadcast(pblock,8); return true; }