From 4f61808ffcfe1f2b3e248c30105fe2a48e0205d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 May 2018 16:25:54 +0300 Subject: [PATCH 01/11] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ab27a998f..511a7413c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3766,7 +3766,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 + 5 ) { //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); From eb1ba5a0fe930b05292f0164f53519db05fcbe8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 07:18:05 +0300 Subject: [PATCH 02/11] improve miner to reduce out of order timestamps --- src/dpowassets | 3 --- src/miner.cpp | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/dpowassets b/src/dpowassets index f00ade7f6..a144eab28 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -3,7 +3,6 @@ set -x source pubkey.txt echo $pubkey sleep 3 -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KMD\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}" @@ -33,5 +32,3 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KMD\",\"pubkey\":\"$pubkey\"}" - diff --git a/src/miner.cpp b/src/miner.cpp index 8400e2a17..c46ade13d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -418,7 +418,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - if ( GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) + if ( 0 && GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"need to wait %d seconds to mine:\n",(int32_t)(pblock->nTime - GetAdjustedTime())); while ( GetAdjustedTime()+30 < pblock->nTime ) @@ -834,7 +834,7 @@ void static BitcoinMiner() if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 ) { int32_t dispflag = 0; - if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) &¬aryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 ) + if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) ||notaryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 || notaryid == 62 ) dispflag = 1; komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->nHeight); if ( nonzpkeys > 0 ) @@ -955,9 +955,19 @@ void static BitcoinMiner() for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n");*/ + if ( B.nTime > GetAdjustedTime() ) + { + printf("need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); + while ( GetAdjustedTime() < B.nTime ) + sleep(1); + } if ( ASSETCHAINS_STAKED == 0 ) { - if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) + if ( NOTARY_PUBKEY33[0] != 0 ) + { + MilliSleep((rand() % 2700) + 1000); + } + /*if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) { //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL))); //int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); @@ -968,13 +978,12 @@ void static BitcoinMiner() else if ( ASSETCHAINS_SYMBOL[0] != 0 ) { sleep(rand() % 30); - } + }*/ } else { if ( NOTARY_PUBKEY33[0] != 0 ) { - printf("need to wait %d seconds to submit staked block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime ) sleep(1); } From 97e9d76edcaf99a53897b0208fa0df9c3964d848 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 07:19:10 +0300 Subject: [PATCH 03/11] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c46ade13d..e46756fa9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -418,7 +418,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - if ( 0 && GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) + if ( GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"need to wait %d seconds to mine:\n",(int32_t)(pblock->nTime - GetAdjustedTime())); while ( GetAdjustedTime()+30 < pblock->nTime ) @@ -957,7 +957,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( B.nTime > GetAdjustedTime() ) { - printf("need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); + fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime ) sleep(1); } From 6181f7d5bb090278859d7bc8c12f719828c20cc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 07:22:41 +0300 Subject: [PATCH 04/11] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e46756fa9..dfb12565d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -955,7 +955,7 @@ void static BitcoinMiner() for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n");*/ - if ( B.nTime > GetAdjustedTime() ) + if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() ) { fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime ) From 4cc387ec2c414606e723915990c4591413f50425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 08:44:03 +0300 Subject: [PATCH 05/11] Detect new block during wait --- src/miner.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index dfb12565d..2f7c3b1c9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -959,7 +959,14 @@ void static BitcoinMiner() { fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime ) + { sleep(1); + if ( chainActive.Tip()->nHeight >= Mining_height ) + { + fprintf(stderr,"new block arrived\n"); + return(false); + } + } } if ( ASSETCHAINS_STAKED == 0 ) { From 9bf6c59e33245d27895a04b6160a3b8e000d478b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 09:05:00 +0300 Subject: [PATCH 06/11] PoS mining latency fix --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2f7c3b1c9..99e1dac83 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -421,7 +421,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"need to wait %d seconds to mine:\n",(int32_t)(pblock->nTime - GetAdjustedTime())); - while ( GetAdjustedTime()+30 < pblock->nTime ) + while ( 0 && GetAdjustedTime()+30 < pblock->nTime ) { sleep(30); fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime())); From b92a8cd4bf62c46466b4508bafde3b675b881c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 09:34:51 +0300 Subject: [PATCH 07/11] Block PoS miner, need to cache first timestamp --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 99e1dac83..2f7c3b1c9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -421,7 +421,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( GetAdjustedTime() < pblock->nTime )//|| pblock->GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"need to wait %d seconds to mine:\n",(int32_t)(pblock->nTime - GetAdjustedTime())); - while ( 0 && GetAdjustedTime()+30 < pblock->nTime ) + while ( GetAdjustedTime()+30 < pblock->nTime ) { sleep(30); fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime())); From e7018d1da8dcc3e2b1a0240b0503d6899e283b84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 13:13:47 +0300 Subject: [PATCH 08/11] Exemption for TXSCL* --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 5b2872946..ec1bc8013 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -615,7 +615,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr memset(&MoMoMdata,0,sizeof(MoMoMdata)); if ( matched == 0 && bitweight(signedmask) >= KOMODO_MINRATIFY ) notarized = 1; - if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("SCALE",ccdata.symbol,5) == 0 ) + if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 ) notarized = 1; if ( 0 && opretlen != 149 ) printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",ASSETCHAINS_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); From 98ec2dc219b153e0365a5d1b911ec8b97b510cd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 14:20:34 +0300 Subject: [PATCH 09/11] Add 1 second to timestamp to reduce diff growth --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2f7c3b1c9..ac1116b4e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -480,7 +480,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) 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; + pblock->nTime = pindexPrev->nTime + 61; //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 be381f22ffe1b3748d1e6953a2f8a1e16b713fe0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 3 May 2018 16:18:00 +0300 Subject: [PATCH 10/11] 65 seconds to slow down diff --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ac1116b4e..a62f39846 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -480,7 +480,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) 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 + 61; + pblock->nTime = pindexPrev->nTime + 65; //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 fb38b77469996d6f7e87121f3d96bf3929a309da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 May 2018 17:39:21 +0300 Subject: [PATCH 11/11] Monthly cap --- src/komodo_interest.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 23ed985ca..8fd6becea 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -80,13 +80,15 @@ uint64_t komodo_moneysupply(int32_t height) } #endif -uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +uint64_t _komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t interest = 0; if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; + if ( txheight >= 1000000 && minutes > 31 * 24 * 60 ) + minutes = 31 * 24 * 60; minutes -= 59; interest = ((nValue / 10512000) * minutes); } @@ -97,7 +99,7 @@ uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime, { uint64_t interest = 0; if ( txheight < KOMODO_ENDOFERA && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && - interest = _komodo_interestnew(nValue,nLockTime,tiptime); + interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); return(interest); } @@ -151,21 +153,21 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin else if ( txheight < 1000000 ) { interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) printf("pathA current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } else if ( txheight < 1000000 ) { numerator = (nValue * KOMODO_INTEREST); interest = (numerator / denominator) / COIN; - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) printf("pathB current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } else { @@ -187,11 +189,11 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin numerator = (nValue / 20); // assumes 5%! interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) fprintf(stderr,"pathC current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } if ( 0 && numerator == (nValue * KOMODO_INTEREST) ) fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu) prod.%llu\n",txheight,(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator,(long long)(numerator * minutes));