From 8fc79ac9fb8808bbd3b88d70979a351983006733 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 May 2018 13:18:19 +0300 Subject: [PATCH 1/2] Reduce miner created latency --- src/komodo.h | 3 ++- src/miner.cpp | 44 +++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 74c6e2010..5b2872946 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -680,7 +680,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr else { komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); - printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth); + if ( matched != 0 ) + printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth); } if ( MoMoMdata.pairs != 0 ) free(MoMoMdata.pairs); diff --git a/src/miner.cpp b/src/miner.cpp index 445ea2dad..8400e2a17 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -476,23 +476,25 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); } + pblock->nSolution.clear(); + pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) { pblock->nTime = pindexPrev->nTime + 60; - while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 ) - sleep(1); + //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)); } - pblock->nSolution.clear(); - pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - - CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + else { - //static uint32_t counter; - //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - // fprintf(stderr,"warning: miner testblockvalidity failed\n"); - return(0); + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + { + //static uint32_t counter; + //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) + // fprintf(stderr,"warning: miner testblockvalidity failed\n"); + return(0); + } } } @@ -788,7 +790,7 @@ void static BitcoinMiner() static uint32_t counter; if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"created illegal block, retry\n"); - sleep(3); + sleep(1); continue; } unique_ptr pblocktemplate(ptr); @@ -953,15 +955,6 @@ void static BitcoinMiner() for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n");*/ - CValidationState state; - if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) - { - h = UintToArith256(B.GetHash()); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," Invalid block mined, try again\n"); - return(false); - } if ( ASSETCHAINS_STAKED == 0 ) { if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) @@ -993,6 +986,15 @@ void static BitcoinMiner() fprintf(stderr," mined block!\n"); } } + CValidationState state; + if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) + { + h = UintToArith256(B.GetHash()); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," Invalid block mined, try again\n"); + return(false); + } KOMODO_CHOSEN_ONE = 1; // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); From 82f1287731de001fc7807444291c81a2188e35c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 May 2018 13:53:11 +0300 Subject: [PATCH 2/2] -prints --- src/komodo_events.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index c7e17ed54..53e72ae95 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -41,9 +41,9 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { static uint32_t counter; int32_t verified=0; char *coin; struct komodo_event_notarized N; coin = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - if ( (ASSETCHAINS_SYMBOL[0] == 0 && height > 800000) && NOTARY_PUBKEY33[0] != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) + if ( (ASSETCHAINS_SYMBOL[0] == 0 && height > 814000) && NOTARY_PUBKEY33[0] != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) { - if ( ASSETCHAINS_SYMBOL[0] == 0 && height > 800000 && counter++ < 10 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && height > 814000 && counter++ < 10 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } else if ( strcmp(symbol,coin) == 0 )