From 6b7c6804aca69b61a1b34e504c5a7796c6392582 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 09:49:05 -1100 Subject: [PATCH 001/120] Zawy13 special booster --- src/pow.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index a84db0015..fb249ed34 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -101,10 +101,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; - uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; + uint32_t nbits,blocktime; int32_t diff,mult = 0,block3diff=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { - mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; + tipdiff = (pblock->nTime - pindexFirst->nTime); + mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; bnPrev.SetCompact(pindexFirst->nBits); //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); } @@ -119,7 +120,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead //fprintf(stderr,"%d ",diff); if ( i < 12 ) { - if ( i == 3 ) + if ( i == 2 ) + block3diff = diff; + else if ( i == 3 ) { block4diff = diff; bnSum4 = bnTot; @@ -167,6 +170,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + if ( block3diff != 0 && block3diff < ASSETCHAINS_BLOCKTIME/5 && 1000*tipdiff/180 < 1000 ) + { + fprintf(stderr,"special booster tipdiff.%d -> %d\n",tipdiff,1000*tipdiff/180); + bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); + } flag = 1; } else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? From 6d063fd1a7abda3ec369943066126b69dce1392b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 10:25:25 -1100 Subject: [PATCH 002/120] Zawy14 --- src/pow.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index fb249ed34..ef6756335 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -120,9 +120,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead //fprintf(stderr,"%d ",diff); if ( i < 12 ) { - if ( i == 2 ) - block3diff = diff; - else if ( i == 3 ) + if ( i == 3 ) { block4diff = diff; bnSum4 = bnTot; @@ -170,9 +168,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - if ( block3diff != 0 && block3diff < ASSETCHAINS_BLOCKTIME/5 && 1000*tipdiff/180 < 1000 ) + block3diff = (block4diff - tipdiff); + if ( block3diff > 0 && block3diff < ASSETCHAINS_BLOCKTIME/5 && 1000*tipdiff/180 < 1000 ) { - fprintf(stderr,"special booster tipdiff.%d -> %d\n",tipdiff,1000*tipdiff/180); + fprintf(stderr,"special booster block3diff.%d block4diff.%d tipdiff.%d -> %d\n",block3diff,block4diff,tipdiff,1000*tipdiff/180); bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); } flag = 1; From 6a1291ad880c8a66192ddb7fd3739daa1dbfc764 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 10:55:12 -1100 Subject: [PATCH 003/120] 14b --- src/pow.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ef6756335..b17024e00 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -101,7 +101,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; - uint32_t nbits,blocktime; int32_t diff,mult = 0,block3diff=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; + uint32_t nbits,blocktime; int32_t diff,mult = 0,block3sum=0,block6sum=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { tipdiff = (pblock->nTime - pindexFirst->nTime); @@ -168,10 +168,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - block3diff = (block4diff - tipdiff); - if ( block3diff > 0 && block3diff < ASSETCHAINS_BLOCKTIME/5 && 1000*tipdiff/180 < 1000 ) + block3sum = (block4diff - tipdiff); + block6sum = (block7diff - tipdiff); + if ( 1000*tipdiff/180 < 1000 && ((block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5) || (block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2)) ) { - fprintf(stderr,"special booster block3diff.%d block4diff.%d tipdiff.%d -> %d\n",block3diff,block4diff,tipdiff,1000*tipdiff/180); + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); } flag = 1; From 700ba476422b84e31a3a047d144865a55c5a5f60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 20:43:04 -1100 Subject: [PATCH 004/120] Hard booster --- src/pow.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index b17024e00..3cc3c1b32 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -150,7 +150,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; int32_t divisor=0,flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) { @@ -167,14 +167,22 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTmp < bnTarget ) { fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); block3sum = (block4diff - tipdiff); block6sum = (block7diff - tipdiff); - if ( 1000*tipdiff/180 < 1000 && ((block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5) || (block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2)) ) + if ( block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5 ) + divisor += 5; + if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) + divisor += 2; + if ( divisor != 0 ) { - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); - bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); + bnTmp /= arith_uint256(divisor); + if ( 1000*tipdiff/60 < 1000 ) + { + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60); + bnTmp = bnTmp * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); + } } + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); flag = 1; } else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? From ea85a08e91accfb7bedc7ff84f46f591ee86bba2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 20:57:00 -1100 Subject: [PATCH 005/120] Tweak --- src/pow.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3cc3c1b32..935252936 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -101,7 +101,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; - uint32_t nbits,blocktime; int32_t diff,mult = 0,block3sum=0,block6sum=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; + uint32_t nbits,blocktime; int32_t diff,mult = 0,block3sum=0,block6sum=0,block11sum=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { tipdiff = (pblock->nTime - pindexFirst->nTime); @@ -166,23 +166,27 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTmp = bnSum12; if ( bnTmp < bnTarget ) { + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); block3sum = (block4diff - tipdiff); block6sum = (block7diff - tipdiff); + block11sum = (block12diff - tipdiff); if ( block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5 ) - divisor += 5; - if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) - divisor += 2; + divisor = 15; + else if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) + divisor = 3; + else if ( block11sum > 0 && block11sum < ASSETCHAINS_BLOCKTIME*5 ) + divisor = 2; if ( divisor != 0 ) { - bnTmp /= arith_uint256(divisor); - if ( 1000*tipdiff/60 < 1000 ) + bnTarget /= arith_uint256(divisor); + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60,divisor); + if ( 0 && 1000*tipdiff/60 < 1000 ) { fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60); - bnTmp = bnTmp * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); + bnTarget = bnTarget * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); } } - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); flag = 1; } else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? From f2780d9b26096306d02bedb35074f79268249f31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 21:37:55 -1100 Subject: [PATCH 006/120] 100x booster, let e^x find real hash rate --- src/pow.cpp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 935252936..d88947f36 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -154,8 +154,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) { + block3sum = (block4diff - tipdiff); + block6sum = (block7diff - tipdiff); + block11sum = (block12diff - tipdiff); origtarget = bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) + { + bnTarget /= arith_uint256(100); + fprintf(stderr,"booster triggered 100x\n"); + nbits = bnTarget.GetCompact(); + return(nbits); + } bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); @@ -164,27 +174,28 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else bnTmp = bnSum7; if ( bnSum12 < bnTmp ) bnTmp = bnSum12; - if ( bnTmp < bnTarget ) + if ( flag == 0 && bnTmp < bnTarget ) { bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - block3sum = (block4diff - tipdiff); - block6sum = (block7diff - tipdiff); - block11sum = (block12diff - tipdiff); - if ( block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5 ) - divisor = 15; - else if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) - divisor = 3; - else if ( block11sum > 0 && block11sum < ASSETCHAINS_BLOCKTIME*5 ) - divisor = 2; - if ( divisor != 0 ) + if ( 0 ) { - bnTarget /= arith_uint256(divisor); - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60,divisor); - if ( 0 && 1000*tipdiff/60 < 1000 ) + + if ( block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5 ) + divisor = 15; + else if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) + divisor = 3; + else if ( block11sum > 0 && block11sum < ASSETCHAINS_BLOCKTIME*5 ) + divisor = 2; + if ( divisor != 0 ) { - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60); - bnTarget = bnTarget * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); + bnTarget /= arith_uint256(divisor); + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60,divisor); + if ( 0 && 1000*tipdiff/60 < 1000 ) + { + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60); + bnTarget = bnTarget * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); + } } } flag = 1; From a69d7073b0eb5168180b19735337a74044914f17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 21:46:05 -1100 Subject: [PATCH 007/120] Test --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index d88947f36..b91bc23e1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -162,9 +162,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) { bnTarget /= arith_uint256(100); - fprintf(stderr,"booster triggered 100x\n"); + fprintf(stderr,"ht.%d booster triggered 100x\n",(int32_t)pindexLast->GetHeight()+1); nbits = bnTarget.GetCompact(); - return(nbits); + //return(nbits); } bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); From 0fe9a014251af6b042d41ffa8dac1070b07c543a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 21:50:57 -1100 Subject: [PATCH 008/120] Reorder precedence --- src/pow.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index b91bc23e1..3d1a4f6e0 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -159,13 +159,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block11sum = (block12diff - tipdiff); origtarget = bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) - { - bnTarget /= arith_uint256(100); - fprintf(stderr,"ht.%d booster triggered 100x\n",(int32_t)pindexLast->GetHeight()+1); - nbits = bnTarget.GetCompact(); - //return(nbits); - } bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); @@ -176,8 +169,15 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTmp = bnSum12; if ( flag == 0 && bnTmp < bnTarget ) { + flag = 1; bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) + { + bnTarget /= arith_uint256(100); + fprintf(stderr,"ht.%d booster triggered 100x\n",(int32_t)pindexLast->GetHeight()+1); + flag = 0; + } if ( 0 ) { @@ -198,9 +198,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } } - flag = 1; } - else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? + if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { flag = 1; bnTarget = zawy_exponential(bnTarget,mult); From 07112fe397ffed7d49827a971e3c6d4e9d0ab57a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 21:57:01 -1100 Subject: [PATCH 009/120] Prevent max after min, even if booster --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3d1a4f6e0..28462a815 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -176,7 +176,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget /= arith_uint256(100); fprintf(stderr,"ht.%d booster triggered 100x\n",(int32_t)pindexLast->GetHeight()+1); - flag = 0; + flag = -1; } if ( 0 ) { @@ -199,7 +199,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } } - if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? + if ( flag <= 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { flag = 1; bnTarget = zawy_exponential(bnTarget,mult); From 83ade337e14384f47e3e6c2dffa22441c580ea98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 22:12:09 -1100 Subject: [PATCH 010/120] Increase to 777x --- src/pow.cpp | 56 +++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 28462a815..564ab9be8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -159,42 +159,34 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block11sum = (block12diff - tipdiff); origtarget = bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); - if ( bnSum4 < bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 < bnTmp ) - bnTmp = bnSum12; - if ( flag == 0 && bnTmp < bnTarget ) + if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME ) { - flag = 1; - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) + bnTarget /= arith_uint256(777); + fprintf(stderr,"ht.%d booster triggered 777x\n",(int32_t)pindexLast->GetHeight()+1); + flag = -1; + } + if ( flag == 0 ) + { + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); + if ( bnSum4 < bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 < bnTmp ) + bnTmp = bnSum12; + if ( bnTmp < bnTarget ) { - bnTarget /= arith_uint256(100); - fprintf(stderr,"ht.%d booster triggered 100x\n",(int32_t)pindexLast->GetHeight()+1); - flag = -1; - } - if ( 0 ) - { - - if ( block3sum > 0 && block3sum < ASSETCHAINS_BLOCKTIME/5 ) - divisor = 15; - else if ( block6sum > 0 && block6sum < ASSETCHAINS_BLOCKTIME*2 ) - divisor = 3; - else if ( block11sum > 0 && block11sum < ASSETCHAINS_BLOCKTIME*5 ) - divisor = 2; - if ( divisor != 0 ) + flag = 1; + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + if ( 0 ) { - bnTarget /= arith_uint256(divisor); - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60,divisor); - if ( 0 && 1000*tipdiff/60 < 1000 ) + fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180,divisor); + if ( 0 && 1000*tipdiff/180 < 1000 ) { - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/60); - bnTarget = bnTarget * arith_uint256(1000*tipdiff/60) / arith_uint256(1000); + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); + bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); } } } From a4b552eb8383232ce9969cc7b1118adb79a122c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 22:24:54 -1100 Subject: [PATCH 011/120] Fix origtarget --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 564ab9be8..0d82fa246 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -157,7 +157,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block3sum = (block4diff - tipdiff); block6sum = (block7diff - tipdiff); block11sum = (block12diff - tipdiff); - origtarget = bnTarget = arith_uint256().SetCompact(nbits); + bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME ) { @@ -194,6 +194,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( flag <= 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { flag = 1; + origtarget = bnTarget; bnTarget = zawy_exponential(bnTarget,mult); if ( bnTarget < origtarget || bnTarget > easy ) { From 48395e681f9431b05960d503b2c6cbf4726436a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 22:36:19 -1100 Subject: [PATCH 012/120] Extreme range --- src/pow.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0d82fa246..1f43785a9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -150,7 +150,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t divisor=0,flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) { @@ -159,10 +159,15 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block11sum = (block12diff - tipdiff); bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME ) + if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) { - bnTarget /= arith_uint256(777); - fprintf(stderr,"ht.%d booster triggered 777x\n",(int32_t)pindexLast->GetHeight()+1); + bnTarget /= arith_uint256(77777); + { + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d booster triggered 77777x\n",(int32_t)pindexLast->GetHeight()+1); flag = -1; } if ( flag == 0 ) @@ -182,7 +187,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); if ( 0 ) { - fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d, divisor.%d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180,divisor); + fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); if ( 0 && 1000*tipdiff/180 < 1000 ) { fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); @@ -201,7 +206,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = easy; fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); return(KOMODO_MINDIFF_NBITS); - } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); + } + { + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); } if ( flag == 0 ) { From d6ee3301d94a1658ddcb81af15a28b8fff0806d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 22:55:45 -1100 Subject: [PATCH 013/120] Smaller booster 7x --- src/pow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1f43785a9..7d0823242 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -161,13 +161,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) { - bnTarget /= arith_uint256(77777); + bnTarget /= arith_uint256(7); { int32_t z; - for (z=0; z<32; z++) + for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d booster triggered 77777x\n",(int32_t)pindexLast->GetHeight()+1); + fprintf(stderr," ht.%d booster triggered 7x\n",(int32_t)pindexLast->GetHeight()+1); flag = -1; } if ( flag == 0 ) @@ -209,10 +209,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } { int32_t z; - for (z=0; z<32; z++) + for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); + fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()+1); } if ( flag == 0 ) { From 9400118aadce15284ebd9066d56bc412a8bcddd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 23:19:09 -1100 Subject: [PATCH 014/120] Less is more --- src/miner.cpp | 2 +- src/pow.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 54af1d021..e4eb84e8e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1922,7 +1922,7 @@ void static BitcoinMiner() 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"); + //fprintf(stderr," Invalid block mined, try again\n"); gotinvalid = 1; return(false); } diff --git a/src/pow.cpp b/src/pow.cpp index 7d0823242..7cf13fb10 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -161,14 +161,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) { - bnTarget /= arith_uint256(7); + bnTarget /= arith_uint256(2); { int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d booster triggered 7x\n",(int32_t)pindexLast->GetHeight()+1); - flag = -1; + fprintf(stderr," ht.%d booster triggered 2x\n",(int32_t)pindexLast->GetHeight()+1); } if ( flag == 0 ) { From cee26803b11305ff81a8181acd827a2b803e0c69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 23:31:29 -1100 Subject: [PATCH 015/120] Tipdiff decay --- src/miner.cpp | 4 ++-- src/pow.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e4eb84e8e..5b0d2658f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1920,8 +1920,8 @@ void static BitcoinMiner() if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + //for (z=31; z>=0; z--) + // fprintf(stderr,"%02x",((uint8_t *)&h)[z]); //fprintf(stderr," Invalid block mined, try again\n"); gotinvalid = 1; return(false); diff --git a/src/pow.cpp b/src/pow.cpp index 7cf13fb10..63a396ec8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -168,8 +168,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } fprintf(stderr," ht.%d booster triggered 2x\n",(int32_t)pindexLast->GetHeight()+1); + flag = -1; } - if ( flag == 0 ) + if ( flag <= 0 ) { bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); @@ -184,13 +185,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead flag = 1; bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - if ( 0 ) + if ( flag < 0 ) { - fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); - if ( 0 && 1000*tipdiff/180 < 1000 ) + //fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/120); + if ( 1000*tipdiff/120 < 1000 ) { - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/180); - bnTarget = bnTarget * arith_uint256(1000*tipdiff/180) / arith_uint256(1000); + fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %.3f\n",block3sum,block6sum,tipdiff,(double)tipdiff/120); + bnTarget = bnTarget * arith_uint256(1000*tipdiff/120) / arith_uint256(1000); } } } From 6c6699ef2b3498f47532192b4d25e818012c1aa2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 23:41:36 -1100 Subject: [PATCH 016/120] Fix flag order --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 63a396ec8..5a7f5b5c2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -182,7 +182,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTmp = bnSum12; if ( bnTmp < bnTarget ) { - flag = 1; bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); if ( flag < 0 ) @@ -194,6 +193,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTarget * arith_uint256(1000*tipdiff/120) / arith_uint256(1000); } } + flag = 1; } } if ( flag <= 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? From 66d8745194ef5af03c29b87140bf6d02773a2e71 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 4 Aug 2019 00:50:11 -1100 Subject: [PATCH 017/120] Disable boosters --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5a7f5b5c2..37ad8a163 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -159,7 +159,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block11sum = (block12diff - tipdiff); bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) + /*if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) { bnTarget /= arith_uint256(2); { @@ -169,7 +169,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," ht.%d booster triggered 2x\n",(int32_t)pindexLast->GetHeight()+1); flag = -1; - } + }*/ if ( flag <= 0 ) { bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); @@ -184,7 +184,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget = (bnTmp + bnPrev) / arith_uint256(2); fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - if ( flag < 0 ) + if ( 0 && flag < 0 ) { //fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/120); if ( 1000*tipdiff/120 < 1000 ) From ea0f7dd6d34be0c12b7569a9c5f911cef57e5cdd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 04:50:48 -1100 Subject: [PATCH 018/120] Initial RT_CST_RST --- src/pow.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index 37ad8a163..e00fa5778 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,6 +42,109 @@ uint32_t komodo_chainactive_timestamp(); unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); +/* from zawy repo + Preliminary code for super-fast increases in difficulty. + Requires the ability to change the difficulty during the current block, + based on the timestamp the miner selects. See my github issue #36 and KMD. + Needs intr-block exponential decay function because + this can make difficulty jump very high. + Miners need to caclulate new difficulty with each second, or + maybe 3 seconds. FTL, MTP, and revert to local times must be small. + MTP=1 if using Digishield. Out-of-sequence timestamps must be forbidden. + 1) bnTarget = Digishield() or other baseline DA + 2) bnTarget = RT_CST_RST() + 3) bnTarget = max(bnTarget,expdecay()) + RT_CST_RST() multiplies Recent Target(s), Current Solvetimes, & + Recent SolveTime if RST had an unlikely 1/200 block chance of + being too fast on accident. This estimates and adjusts for recent + hashrate aggressively (lots of random error) but corrects the error by + CST adjusting the difficulty during the block. + It checks to see if there was an "active trigger" still in play which + occurs when recent block emission rate has been too fast. Triggers + are supposed to be active if emission rate has not slowed up enough + to get back on track. It checks the longest range first because it's + the least aggressive. + T = target blocktime + ts = timestamp vector, 62 elements, 62 is oldest (elements needed are 50+W) + ct = cumulative targets, 62 elements, 62 is oldest + W = window size of recent solvetimes and targets to use that estimates hashrate + numerator & deonominator needed for 1/200 possion estimator + past = how far back in past to look for beginning of a trigger + */ + +/* create ts and cw vectors +// Get bnTarget = Digishield(); + +arith_uint256 past = 50; + +arith_uint256 W = 12; +arith_uint256 numerator = 12; +arith_uint256 denominator = 7; + +// bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); + +W = 6; top = 7; denominator = 3; + +// bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); + +W = 3; top = 1; denominator = 2; + +bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); +*/ + +#define T ASSETCHAINS_BLOCKTIME + +arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +{ + //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small + //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust + int32_t K = 1000000,i,j,ii=0; // K is a scaling factor for integer divisions + + if ( ts[1]-ts[W] < T*numerator/denominator ) + { + bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); + } + /* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy + because the blockchain does not allow us to store a variable to know + if we are currently in a triggered state that is making a sequence of + adjustments to prevTargets, so we have to look for them. + Nested loops do this: if block emission has not slowed to be back on track at + any time since most recent trigger and we are at current block, aggressively + adust prevTarget. */ + + for (j=past-1; j>=1; j--) + { + if ( ts[j]-ts[j+W] < T*numerator/denominator ) + { + ii = 0; + for (i=j-1; i>=0; i-- ) + { + ii++; + // Check if emission caught up. If yes, "trigger stopped at i". + // Break loop to try more recent j's to see if trigger activates again. + if ( ts[i-1]-ts[j+W] > (ii+W)*T ) + break; + + // We're here, so there was a TS[j]-TS[j-3] < T/2 trigger in the past and emission rate has not yet slowed up to be back on track so the "trigger is still active", aggressively adjusting target here at block "i" + if ( i == 0 ) + { + + /* We made it all the way to current block. Emission rate since + last trigger never slowed enough to get back on track, so adjust again. + If avg last 3 STs = T, this increases target to prevTarget as ST increases to T. + This biases it towards ST=~1.75*T to get emission back on track. + If avg last 3 STs = T/2, target increases to prevTarget at 2*T. + Rarely, last 3 STs can be 1/2 speed => target = prevTarget at T/2, & 1/2 at T.*/ + + bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; + j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. + } + } + } + } + return bnTarget; +} + arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor) { bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num * num * divisor); From 0226b07af757b9afdea2e5f5a89098fa220738ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:05:21 -1100 Subject: [PATCH 019/120] Calculate bnTargets --- src/pow.cpp | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e00fa5778..90a999775 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -98,11 +98,16 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust - int32_t K = 1000000,i,j,ii=0; // K is a scaling factor for integer divisions + int32_t altK,K = 1000000,i,j,ii=0; // K is a scaling factor for integer divisions if ( ts[1]-ts[W] < T*numerator/denominator ) { - bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); + //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); + bnTarget = (ct[0] - ct[1]) / arith_uint256(K); + altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); + if ( altK < K ) + altK = K; + bnTarget *= arith_uint256(altK); } /* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy because the blockchain does not allow us to store a variable to know @@ -122,7 +127,7 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit ii++; // Check if emission caught up. If yes, "trigger stopped at i". // Break loop to try more recent j's to see if trigger activates again. - if ( ts[i-1]-ts[j+W] > (ii+W)*T ) + if ( ts[i]-ts[j+W] > (ii+W)*T ) break; // We're here, so there was a TS[j]-TS[j-3] < T/2 trigger in the past and emission rate has not yet slowed up to be back on track so the "trigger is still active", aggressively adjusting target here at block "i" @@ -136,7 +141,10 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit If avg last 3 STs = T/2, target increases to prevTarget at 2*T. Rarely, last 3 STs can be 1/2 speed => target = prevTarget at T/2, & 1/2 at T.*/ - bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; + //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; + bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); + altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T); + bnTarget *= arith_uint256(altK); j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. } } @@ -203,13 +211,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; - uint32_t nbits,blocktime; int32_t diff,mult = 0,block3sum=0,block6sum=0,block11sum=0,tipdiff = 0,block4diff=0,block7diff=0,block12diff=0; + arith_uint256 bnTmp,bnTarget,bnTot {0};//,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0}; + uint32_t nbits,blocktime; int32_t diff,mult = 0,tipdiff = 0; //block3sum=0,block6sum=0,block11sum=0,block4diff=0,block7diff=0,block12diff=0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { tipdiff = (pblock->nTime - pindexFirst->nTime); mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; - bnPrev.SetCompact(pindexFirst->nBits); + //bnPrev.SetCompact(pindexFirst->nBits); //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); } for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -223,7 +231,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead //fprintf(stderr,"%d ",diff); if ( i < 12 ) { - if ( i == 3 ) + /*if ( i == 3 ) { block4diff = diff; bnSum4 = bnTot; @@ -237,7 +245,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { block12diff = diff; bnSum12 = bnTot; - } + }*/ diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) { @@ -262,18 +270,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead block11sum = (block12diff - tipdiff); bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - /*if ( block3sum < ASSETCHAINS_BLOCKTIME/5 || block6sum < ASSETCHAINS_BLOCKTIME || block11sum < ASSETCHAINS_BLOCKTIME*5 ) - { - bnTarget /= arith_uint256(2); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d booster triggered 2x\n",(int32_t)pindexLast->GetHeight()+1); - flag = -1; - }*/ - if ( flag <= 0 ) + /*if ( flag <= 0 ) { bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); @@ -298,7 +295,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } flag = 1; } - } + }*/ if ( flag <= 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { flag = 1; @@ -317,7 +314,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()+1); } - if ( flag == 0 ) + /*if ( flag == 0 ) { bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); @@ -333,7 +330,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (bnTmp + bnPrev) / arith_uint256(2); flag = 1; } - } + }*/ nbits = bnTarget.GetCompact(); } return(nbits); From dba0d713ab8a51258cf9d10c92bdcdf7da992abf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:06:44 -1100 Subject: [PATCH 020/120] Syntax --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 90a999775..7aa8e7767 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -263,11 +263,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - block3sum = (block4diff - tipdiff); - block6sum = (block7diff - tipdiff); - block11sum = (block12diff - tipdiff); + //block3sum = (block4diff - tipdiff); + //block6sum = (block7diff - tipdiff); + //block11sum = (block12diff - tipdiff); bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); /*if ( flag <= 0 ) From 7869032ed46aef5a553f531ae7dae00f2c1f44b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:27:45 -1100 Subject: [PATCH 021/120] Call RT_CST_RST --- src/pow.cpp | 101 ++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 70 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 7aa8e7767..a5744cb30 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -99,7 +99,8 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust int32_t altK,K = 1000000,i,j,ii=0; // K is a scaling factor for integer divisions - + if ( ts[W+past] == 0 ) + return(bnTarget); if ( ts[1]-ts[W] < T*numerator/denominator ) { //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); @@ -150,7 +151,7 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit } } } - return bnTarget; + return(bnTarget); } arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor) @@ -211,16 +212,26 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTmp,bnTarget,bnTot {0};//,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0}; - uint32_t nbits,blocktime; int32_t diff,mult = 0,tipdiff = 0; //block3sum=0,block6sum=0,block11sum=0,block4diff=0,block7diff=0,block12diff=0; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) + arith_uint256 ct[64],bnTmp,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t i,diff,height=0,mult = 0,tipdiff = 0; + memset(ts,0,sizeof(ts)); + memset(ct,0,sizeof(ct)); + if ( pindexLast != 0 ) + height = (int32_t)pindexLast->GetHeight() + 1; + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) { tipdiff = (pblock->nTime - pindexFirst->nTime); mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; + for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) + { + ct[i].SetCompact(pindexFirst->nBits); + ts[i] = pindexFirst->nTime; + pindexFirst = pindexFirst->pprev; + } //bnPrev.SetCompact(pindexFirst->nBits); - //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); } - for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) + pindexFirst = pindexLast; + for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { bnTmp.SetCompact(pindexFirst->nBits); bnTot += bnTmp; @@ -231,21 +242,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead //fprintf(stderr,"%d ",diff); if ( i < 12 ) { - /*if ( i == 3 ) - { - block4diff = diff; - bnSum4 = bnTot; - } - else if ( i == 6 ) - { - block7diff = diff; - bnSum7 = bnTot; - } - else if ( i == 11 ) - { - block12diff = diff; - bnSum12 = bnTot; - }*/ diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) { @@ -261,44 +257,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - //block3sum = (block4diff - tipdiff); - //block6sum = (block7diff - tipdiff); - //block11sum = (block12diff - tipdiff); bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - /*if ( flag <= 0 ) + if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1); - if ( bnSum4 < bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 < bnTmp ) - bnTmp = bnSum12; - if ( bnTmp < bnTarget ) - { - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - if ( 0 && flag < 0 ) - { - //fprintf(stderr,"booster block3sum.%d block6sum.%d tipdiff.%d -> %d\n",block3sum,block6sum,tipdiff,1000*tipdiff/120); - if ( 1000*tipdiff/120 < 1000 ) - { - fprintf(stderr,"special booster block3sum.%d block6sum.%d tipdiff.%d -> %.3f\n",block3sum,block6sum,tipdiff,(double)tipdiff/120); - bnTarget = bnTarget * arith_uint256(1000*tipdiff/120) / arith_uint256(1000); - } - } - flag = 1; - } - }*/ - if ( flag <= 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? - { - flag = 1; origtarget = bnTarget; bnTarget = zawy_exponential(bnTarget,mult); if ( bnTarget < origtarget || bnTarget > easy ) @@ -314,23 +280,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()+1); } - /*if ( flag == 0 ) + else { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10); - if ( bnSum4 > bnSum7 ) - bnTmp = bnSum4; - else bnTmp = bnSum7; - if ( bnSum12 > bnTmp ) - bnTmp = bnSum12; - if ( bnTmp > bnTarget ) - { - fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - flag = 1; - } - }*/ + // bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); + bnTarget = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,1,2,3,50); + bnTarget6 = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,7,3,6,50); + bnTarget12 = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,12,7,12,50); + if ( bnTarget6 < bnTarget12 ) + bnTmp = bnTarget6; + else bnTmp = bnTarget12; + if ( 0 && bnTmp < bnTarget ) + bnTarget = bnTmp; + } nbits = bnTarget.GetCompact(); } return(nbits); From 62ec3eb4797ee0ef5667a8323f6733656e31c7ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:34:41 -1100 Subject: [PATCH 022/120] #define K --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index a5744cb30..628d7627c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -93,12 +93,13 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); */ #define T ASSETCHAINS_BLOCKTIME +#define K 1000000 arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust - int32_t altK,K = 1000000,i,j,ii=0; // K is a scaling factor for integer divisions + int32_t altK,i,j,ii=0; // K is a scaling factor for integer divisions if ( ts[W+past] == 0 ) return(bnTarget); if ( ts[1]-ts[W] < T*numerator/denominator ) From 49383efcd1beae9cc6d08a89640d3be33059b825 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:42:03 -1100 Subject: [PATCH 023/120] +prints and fix max -> min for altK --- src/pow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 628d7627c..0dabfb11e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -107,7 +107,8 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = (ct[0] - ct[1]) / arith_uint256(K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); - if ( altK < K ) + fprintf(stderr,"initial altK.%d\n",altK); + if ( altK > K ) altK = K; bnTarget *= arith_uint256(altK); } @@ -135,7 +136,6 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit // We're here, so there was a TS[j]-TS[j-3] < T/2 trigger in the past and emission rate has not yet slowed up to be back on track so the "trigger is still active", aggressively adjusting target here at block "i" if ( i == 0 ) { - /* We made it all the way to current block. Emission rate since last trigger never slowed enough to get back on track, so adjust again. If avg last 3 STs = T, this increases target to prevTarget as ST increases to T. @@ -146,6 +146,7 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T); + fprintf(stderr,"made it to i == 0, j.%d ii.%d altK %d\n",j,ii,altK); bnTarget *= arith_uint256(altK); j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. } From cf94e03ac65854c34aaacd5ec17c6c357454f917 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 05:46:15 -1100 Subject: [PATCH 024/120] Fix null block access --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0dabfb11e..ba7c1d91e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -282,7 +282,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()+1); } - else + else if ( pblock != 0 ) { // bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); bnTarget = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,1,2,3,50); From e9cdff1a28e88a0d9da950d41c6c7a30a595979c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:00:28 -1100 Subject: [PATCH 025/120] genminingCSV --- src/rpc/mining.cpp | 32 +++++++++++++++++++++++++++++++- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d70f198f1..862b13f9f 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -403,7 +403,37 @@ UniValue setgenerate(const UniValue& params, bool fHelp) } #endif - +UniValue genminingCSV(const UniValue& params, bool fHelp) +{ + int32_t i,z,height; FILE *fp; char str[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + if (fHelp || params.size() > 2 || params.size() < 1) + throw runtime_error("genminingCSV\n"); + LOCK(cs_main); + if ( (fp= fopen("mining.csv","wb")) != 0 ) + { + fprintf(fp,"height,nTime,nBits,bnTarget,diff,netdiff\n"); + height = komodo_nextheight(); + for (i=0; inBits,&fNegative,&fOverflow); + for (z=31; z>=0; z--) + sprintf(str,"%02x",((uint8_t *)&bnTarget)[z]); + fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)) + } + } + fclose(fp); + result.push_back(Pair("result", "success")); + result.push_back(Pair("created", "mining.csv")); + } + else + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("error", "couldnt create mining.csv")); + } +} + UniValue getmininginfo(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 6baa8a67d..24f6344ef 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -384,6 +384,7 @@ static const CRPCCommand vRPCCommands[] = { "mining", "prioritisetransaction", &prioritisetransaction, true }, { "mining", "submitblock", &submitblock, true }, { "mining", "getblocksubsidy", &getblocksubsidy, true }, + { "mining", "genminingCSV", &genminingCSV, true }, #ifdef ENABLE_MINING /* Coin generation */ diff --git a/src/rpc/server.h b/src/rpc/server.h index 6338989a5..f594b0fb5 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -463,6 +463,7 @@ extern UniValue importgatewaycompletesigning(const UniValue& params, bool fHelp) extern UniValue importgatewaymarkdone(const UniValue& params, bool fHelp); extern UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp); extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp); +extern UniValue genminingCSV(const UniValue& params, bool fHelp); extern UniValue nspv_getinfo(const UniValue& params, bool fHelp); extern UniValue nspv_login(const UniValue& params, bool fHelp); From 3ff34c97ccf8ac1418ecdf24c51fcab6feb000e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:03:47 -1100 Subject: [PATCH 026/120] CBlockIndex *komodo_chainactive(int32_t height); --- src/rpc/mining.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 862b13f9f..accdccb38 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -403,6 +403,8 @@ UniValue setgenerate(const UniValue& params, bool fHelp) } #endif +CBlockIndex *komodo_chainactive(int32_t height); + UniValue genminingCSV(const UniValue& params, bool fHelp) { int32_t i,z,height; FILE *fp; char str[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); From 69f87c00ad266d7123f84cc5a788782f933c70d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:04:30 -1100 Subject: [PATCH 027/120] ; --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index accdccb38..2b01bbb6c 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -422,7 +422,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); for (z=31; z>=0; z--) sprintf(str,"%02x",((uint8_t *)&bnTarget)[z]); - fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)) + fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); } } fclose(fp); From 8e2fc1c6d9e35cc2ab6ce00326c4e63aa1edacb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:10:50 -1100 Subject: [PATCH 028/120] /tmp/mining.csv --- src/rpc/mining.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 2b01bbb6c..21621f51a 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -411,7 +411,8 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) if (fHelp || params.size() > 2 || params.size() < 1) throw runtime_error("genminingCSV\n"); LOCK(cs_main); - if ( (fp= fopen("mining.csv","wb")) != 0 ) + sprintf(str,"/tmp/%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); + if ( (fp= fopen(str,"wb")) != 0 ) { fprintf(fp,"height,nTime,nBits,bnTarget,diff,netdiff\n"); height = komodo_nextheight(); @@ -433,6 +434,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("error", "couldnt create mining.csv")); + result.push_back(Pair("filename", str)); } } From 4a09f0d13ed4b98a2d11a36a58a432e3a4d43c39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:13:34 -1100 Subject: [PATCH 029/120] No args --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 21621f51a..a0e89b4a8 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -408,7 +408,7 @@ CBlockIndex *komodo_chainactive(int32_t height); UniValue genminingCSV(const UniValue& params, bool fHelp) { int32_t i,z,height; FILE *fp; char str[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); - if (fHelp || params.size() > 2 || params.size() < 1) + if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); sprintf(str,"/tmp/%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); From fd28ee9c660e214936bf4da5a1385f6afc7b44bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:15:49 -1100 Subject: [PATCH 030/120] Return result --- src/rpc/mining.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index a0e89b4a8..9f80d0603 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -436,6 +436,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) result.push_back(Pair("error", "couldnt create mining.csv")); result.push_back(Pair("filename", str)); } + return(result); } UniValue getmininginfo(const UniValue& params, bool fHelp) From caeb613e0b446bb4e1a5e3aa96a12dbeebd6155e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:17:04 -1100 Subject: [PATCH 031/120] Print target --- src/rpc/mining.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 9f80d0603..abbeae528 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -411,7 +411,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); - sprintf(str,"/tmp/%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); + sprintf(str,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); if ( (fp= fopen(str,"wb")) != 0 ) { fprintf(fp,"height,nTime,nBits,bnTarget,diff,netdiff\n"); @@ -422,8 +422,8 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); for (z=31; z>=0; z--) - sprintf(str,"%02x",((uint8_t *)&bnTarget)[z]); - fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); + sprintf(&str[z],"%02x",((uint8_t *)&bnTarget)[z]); + str[32] = 0; fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); } } fclose(fp); From 5e980a8c262ed4880a084b8e96ed42fbff98e947 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:18:50 -1100 Subject: [PATCH 032/120] fname --- src/rpc/mining.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index abbeae528..2b9795d81 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -407,12 +407,12 @@ CBlockIndex *komodo_chainactive(int32_t height); UniValue genminingCSV(const UniValue& params, bool fHelp) { - int32_t i,z,height; FILE *fp; char str[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + int32_t i,z,height; FILE *fp; char str[64],fname[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); - sprintf(str,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); - if ( (fp= fopen(str,"wb")) != 0 ) + sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); + if ( (fp= fopen(fname,"wb")) != 0 ) { fprintf(fp,"height,nTime,nBits,bnTarget,diff,netdiff\n"); height = komodo_nextheight(); @@ -434,7 +434,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("error", "couldnt create mining.csv")); - result.push_back(Pair("filename", str)); + result.push_back(Pair("filename", fname)); } return(result); } From 1ee818c98cd95b765682b458be85de555c959931 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:19:17 -1100 Subject: [PATCH 033/120] fname --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 2b9795d81..e166ffe8d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -428,7 +428,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) } fclose(fp); result.push_back(Pair("result", "success")); - result.push_back(Pair("created", "mining.csv")); + result.push_back(Pair("created", fname)); } else { From 7bedc90a8b1373c7a07cb745a7bb713267f3135c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:20:19 -1100 Subject: [PATCH 034/120] Str fix --- src/rpc/mining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e166ffe8d..e507a2e70 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -421,8 +421,8 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) if ( (pindex= komodo_chainactive(i)) != 0 ) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); - for (z=31; z>=0; z--) - sprintf(&str[z],"%02x",((uint8_t *)&bnTarget)[z]); + for (z=0; z<32; z++) + sprintf(&str[z<<1],"%02x",((uint8_t *)&bnTarget)[31-z]); str[32] = 0; fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); } } From 314c06007c0322026964ed1df735e2766de9d435 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:23:45 -1100 Subject: [PATCH 035/120] fname[] --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e507a2e70..a2c66c464 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -407,7 +407,7 @@ CBlockIndex *komodo_chainactive(int32_t height); UniValue genminingCSV(const UniValue& params, bool fHelp) { - int32_t i,z,height; FILE *fp; char str[64],fname[64]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + int32_t i,z,height; FILE *fp; char str[64],fname[256]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); From 4dbac8fea06023a23cfa8464a6af7dfbb1711084 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 07:25:53 -1100 Subject: [PATCH 036/120] Strange --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index a2c66c464..0dd1fba36 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -428,7 +428,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) } fclose(fp); result.push_back(Pair("result", "success")); - result.push_back(Pair("created", fname)); + result.push_back(Pair("created", "COIN_mining.csv")); } else { From 4d7f11ccf8b4e924455a2b098e27c1a5b26321f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 08:40:21 -1100 Subject: [PATCH 037/120] Test averaging --- src/pow.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ba7c1d91e..16db74f05 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -214,7 +214,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 ct[64],bnTmp,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t i,diff,height=0,mult = 0,tipdiff = 0; memset(ts,0,sizeof(ts)); memset(ct,0,sizeof(ct)); @@ -224,13 +224,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { tipdiff = (pblock->nTime - pindexFirst->nTime); mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; + bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } - //bnPrev.SetCompact(pindexFirst->nBits); } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -265,9 +265,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + origtarget = bnTarget; if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { - origtarget = bnTarget; bnTarget = zawy_exponential(bnTarget,mult); if ( bnTarget < origtarget || bnTarget > easy ) { @@ -293,6 +293,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else bnTmp = bnTarget12; if ( 0 && bnTmp < bnTarget ) bnTarget = bnTmp; + if ( pindexLast->GetHeight()+1 >= 230 ) + { + if ( bnTarget < origtarget ) + bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); + else bnTarget = origtarget; + } } nbits = bnTarget.GetCompact(); } From ebd1595279f485e2856ebfc2ef785d0817fe4983 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 08:54:05 -1100 Subject: [PATCH 038/120] Easily the diff adjust --- src/pow.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 16db74f05..da7c8595c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -214,10 +214,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 ct[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],ct0[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t i,diff,height=0,mult = 0,tipdiff = 0; memset(ts,0,sizeof(ts)); memset(ct,0,sizeof(ct)); + memset(ct0,0,sizeof(ct0)); if ( pindexLast != 0 ) height = (int32_t)pindexLast->GetHeight() + 1; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) @@ -295,10 +296,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTmp; if ( pindexLast->GetHeight()+1 >= 230 ) { - if ( bnTarget < origtarget ) - bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); - else bnTarget = origtarget; + if ( pindexLast->GetHeight()+1 < 270 ) + { + if ( bnTarget < origtarget ) + bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); + else bnTarget = origtarget; + } + else + { + if ( bnTarget < origtarget ) + bnTarget = bnTarget * arith_uint256(2); + } } + } nbits = bnTarget.GetCompact(); } From f036bb7e90a229a7f5bc6491299f7e30befd424d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 09:11:25 -1100 Subject: [PATCH 039/120] *= 2 and average --- src/pow.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index da7c8595c..a0352c807 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -302,13 +302,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } - else + else if ( pindexLast->GetHeight()+1 < 290 ) { if ( bnTarget < origtarget ) bnTarget = bnTarget * arith_uint256(2); } + else + { + bnTarget *= arith_uint256(2); + if ( bnTarget < origtarget ) + bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); + else bnTarget = origtarget; + } } - } nbits = bnTarget.GetCompact(); } From f77173b2d91c6dabf8d8d7b5d4e94e5f1562f29f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 09:16:53 -1100 Subject: [PATCH 040/120] Test --- src/pow.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index a0352c807..c9ab3e726 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -307,13 +307,20 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTarget < origtarget ) bnTarget = bnTarget * arith_uint256(2); } - else + else if ( pindexLast->GetHeight()+1 < 310 ) { bnTarget *= arith_uint256(2); if ( bnTarget < origtarget ) bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } + else + { + bnTarget /= arith_uint256(2); + if ( bnTarget < origtarget ) + bnTarget = (bnTarget + bnPrev) / arith_uint256(2); + else bnTarget = origtarget; + } } } nbits = bnTarget.GetCompact(); From 53bf8107c0d183a1182c6b5ee4afca5b48b0973f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 09:31:58 -1100 Subject: [PATCH 041/120] Change ct[] to double diff --- src/pow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index c9ab3e726..9bb1c3ffc 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -229,6 +229,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); + if ( pindexLast->GetHeight()+1 >= 310 ) + ct[i] /= arith_uint256(2); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } @@ -314,7 +316,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } - else + else if ( pindexLast->GetHeight()+1 < 310 ) { bnTarget /= arith_uint256(2); if ( bnTarget < origtarget ) From 5c6d671f1ca912e875ea1af3753fbedff5518763 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 09:34:29 -1100 Subject: [PATCH 042/120] Double digishield diff --- src/pow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index 9bb1c3ffc..86e3b6223 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -263,6 +263,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return nProofOfWorkLimit; bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + bnTot /= arith_uint256(2); nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) { From dba368306bddd78f08a0ebc027ac179b3aea7ddc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 09:37:48 -1100 Subject: [PATCH 043/120] 330 hardfork --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 86e3b6223..3de3fd574 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -229,7 +229,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( pindexLast->GetHeight()+1 >= 310 ) + if ( pindexLast->GetHeight()+1 >= 330 ) ct[i] /= arith_uint256(2); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; @@ -263,7 +263,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return nProofOfWorkLimit; bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 330 ) bnTot /= arith_uint256(2); nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) From e94370e3f06a295ecd14d616318e4b6987c02926 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 10:07:48 -1100 Subject: [PATCH 044/120] 350 hf --- src/pow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3de3fd574..fbd0d68b1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -325,7 +325,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (bnTarget + bnPrev) / arith_uint256(2); else bnTarget = origtarget; } - } + else if ( pindexLast->GetHeight()+1 >= 350 ) + { + if ( bnTarget < origtarget ) + bnTarget = (bnTarget + bnPrev) / arith_uint256(2); + else bnTarget = origtarget; + } + } } nbits = bnTarget.GetCompact(); } From fb0c1cdafae319f5884dd6d60d5f90dfb1dae17c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 10:16:10 -1100 Subject: [PATCH 045/120] 380hf --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index fbd0d68b1..c42c7f17e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -318,7 +318,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } - else if ( pindexLast->GetHeight()+1 < 310 ) + else if ( pindexLast->GetHeight()+1 < 310 || pindexLast->GetHeight()+1 >= 380 ) { bnTarget /= arith_uint256(2); if ( bnTarget < origtarget ) From 5f017849fd8f122e390aa9a45fcce8bd47fa0267 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 11:13:07 -1100 Subject: [PATCH 046/120] Encode bits --- src/pow.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index c42c7f17e..aa9c8060a 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -229,7 +229,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( pindexLast->GetHeight()+1 >= 330 ) + if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 450 || (pindexFirst->nBits&1) != 0) ) ct[i] /= arith_uint256(2); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; @@ -239,7 +239,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { bnTmp.SetCompact(pindexFirst->nBits); - bnTot += bnTmp; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 ) { blocktime = pindexFirst->nTime; @@ -254,7 +253,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } + if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 450 || (pindexFirst->nBits&1) != 0) ) + bnTmp /= arith_uint256(2); // check against ct[i] } + bnTot += bnTmp; pindexFirst = pindexFirst->pprev; } //fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight()); @@ -262,9 +264,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 330 ) - bnTot /= arith_uint256(2); + bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) { @@ -318,7 +318,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } - else if ( pindexLast->GetHeight()+1 < 310 || pindexLast->GetHeight()+1 >= 380 ) + else if ( pindexLast->GetHeight()+1 < 310 || (pindexLast->GetHeight()+1 >= 380 && pindexLast->GetHeight()+1 < 450) ) { bnTarget /= arith_uint256(2); if ( bnTarget < origtarget ) @@ -328,13 +328,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else if ( pindexLast->GetHeight()+1 >= 350 ) { if ( bnTarget < origtarget ) + { bnTarget = (bnTarget + bnPrev) / arith_uint256(2); + zawyflag = 1; + } else bnTarget = origtarget; } } } nbits = bnTarget.GetCompact(); } + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 450 ) + nbits = (nbits & 0xfffffffe) | zawyflag; return(nbits); } From 73bf43cf9925ece3ff9b6760cc5e2161415a4ac1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 11:20:44 -1100 Subject: [PATCH 047/120] 430hf --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index aa9c8060a..8513d0864 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -229,7 +229,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 450 || (pindexFirst->nBits&1) != 0) ) + if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 430 || (pindexFirst->nBits&1) != 0) ) ct[i] /= arith_uint256(2); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; @@ -253,7 +253,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 450 || (pindexFirst->nBits&1) != 0) ) + if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 430 || (pindexFirst->nBits&1) != 0) ) bnTmp /= arith_uint256(2); // check against ct[i] } bnTot += bnTmp; @@ -318,7 +318,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); else bnTarget = origtarget; } - else if ( pindexLast->GetHeight()+1 < 310 || (pindexLast->GetHeight()+1 >= 380 && pindexLast->GetHeight()+1 < 450) ) + else if ( pindexLast->GetHeight()+1 < 310 || (pindexLast->GetHeight()+1 >= 380 && pindexLast->GetHeight()+1 < 430) ) { bnTarget /= arith_uint256(2); if ( bnTarget < origtarget ) @@ -338,7 +338,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } nbits = bnTarget.GetCompact(); } - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 450 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 430 ) nbits = (nbits & 0xfffffffe) | zawyflag; return(nbits); } From f5cbe88600d59b7c9a5eea71bc73b286ce743a62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 20:48:27 -1100 Subject: [PATCH 048/120] Zawy17 --- src/pow.cpp | 82 +++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 53 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8513d0864..b4fa31dd9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -95,19 +95,19 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); #define T ASSETCHAINS_BLOCKTIME #define K 1000000 -arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust int32_t altK,i,j,ii=0; // K is a scaling factor for integer divisions if ( ts[W+past] == 0 ) return(bnTarget); - if ( ts[1]-ts[W] < T*numerator/denominator ) + if ( ts[0]-ts[W] < T*numerator/denominator ) { //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = (ct[0] - ct[1]) / arith_uint256(K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); - fprintf(stderr,"initial altK.%d\n",altK); + fprintf(stderr,"ht.%d initial altK.%d\n",height,altK); if ( altK > K ) altK = K; bnTarget *= arith_uint256(altK); @@ -146,7 +146,7 @@ arith_uint256 RT_CST_RST(uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arit //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T); - fprintf(stderr,"made it to i == 0, j.%d ii.%d altK %d\n",j,ii,altK); + fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %d\n",height,j,ii,altK); bnTarget *= arith_uint256(altK); j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. } @@ -229,8 +229,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 430 || (pindexFirst->nBits&1) != 0) ) - ct[i] /= arith_uint256(2); + if ( (pindexFirst->nBits&3) != 0 ) + ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } @@ -253,13 +253,17 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( pindexLast->GetHeight()+1 >= 330 && (pindexLast->GetHeight()+1 < 430 || (pindexFirst->nBits&1) != 0) ) - bnTmp /= arith_uint256(2); // check against ct[i] + if ( (pindexFirst->nBits&3) != 0 ) + { + bnTmp /= arith_uint256((pindexFirst->nBits&3) + 1); // check against ct[i] + if ( ct[i] != bnTmp ) + fprintf(stderr,"ht.%d i.%d ct[] != bnTmp boost X%d\n",height,i,(int32_t)(pindexFirst->nBits&3) + 1); + } } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; } - //fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight()); + //fprintf(stderr,"diffs %d\n",height); // Check we have enough blocks if (pindexFirst == NULL) return nProofOfWorkLimit; @@ -277,7 +281,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTarget < origtarget || bnTarget > easy ) { bnTarget = easy; - fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); + fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); return(KOMODO_MINDIFF_NBITS); } { @@ -285,61 +289,33 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()+1); + fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } else if ( pblock != 0 ) { - // bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); - bnTarget = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,1,2,3,50); - bnTarget6 = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,7,3,6,50); - bnTarget12 = RT_CST_RST(pblock->nTime,bnTarget,ts,ct,12,7,12,50); + // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); + bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,50); + bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); + bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); if ( bnTarget6 < bnTarget12 ) bnTmp = bnTarget6; else bnTmp = bnTarget12; if ( 0 && bnTmp < bnTarget ) bnTarget = bnTmp; - if ( pindexLast->GetHeight()+1 >= 230 ) + if ( bnTarget < origtarget ) { - if ( pindexLast->GetHeight()+1 < 270 ) - { - if ( bnTarget < origtarget ) - bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); - else bnTarget = origtarget; - } - else if ( pindexLast->GetHeight()+1 < 290 ) - { - if ( bnTarget < origtarget ) - bnTarget = bnTarget * arith_uint256(2); - } - else if ( pindexLast->GetHeight()+1 < 310 ) - { - bnTarget *= arith_uint256(2); - if ( bnTarget < origtarget ) - bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); - else bnTarget = origtarget; - } - else if ( pindexLast->GetHeight()+1 < 310 || (pindexLast->GetHeight()+1 >= 380 && pindexLast->GetHeight()+1 < 430) ) - { - bnTarget /= arith_uint256(2); - if ( bnTarget < origtarget ) - bnTarget = (bnTarget + bnPrev) / arith_uint256(2); - else bnTarget = origtarget; - } - else if ( pindexLast->GetHeight()+1 >= 350 ) - { - if ( bnTarget < origtarget ) - { - bnTarget = (bnTarget + bnPrev) / arith_uint256(2); - zawyflag = 1; - } - else bnTarget = origtarget; - } - } + if ( bnTarget < origtarget/arith_uint256(3) ) + zawyflag = 1; + else if ( bnTarget < origtarget / arith_uint256(2) ) + zawyflag = 2; + else zawyflag = 3; + fprintf(stderr,"ht.%d -> zawy.%d\n",height,zawyflag); + } } nbits = bnTarget.GetCompact(); } - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexLast->GetHeight()+1 >= 430 ) - nbits = (nbits & 0xfffffffe) | zawyflag; + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + nbits = (nbits & 0xfffffffc) | zawyflag; return(nbits); } From c296c5fdd8470f3c00733ad2eb59f63a72e8c369 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 20:55:25 -1100 Subject: [PATCH 049/120] Height check --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index b4fa31dd9..9c2c0e4bc 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -100,7 +100,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust int32_t altK,i,j,ii=0; // K is a scaling factor for integer divisions - if ( ts[W+past] == 0 ) + if ( height < 64 ) return(bnTarget); if ( ts[0]-ts[W] < T*numerator/denominator ) { @@ -229,7 +229,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( (pindexFirst->nBits&3) != 0 ) + if ( pindexFirst->GetHeight() >= 64 && (pindexFirst->nBits&3) != 0 ) ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; @@ -253,7 +253,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( (pindexFirst->nBits&3) != 0 ) + if ( pindexFirst->GetHeight() >= 64 && (pindexFirst->nBits&3) != 0 ) { bnTmp /= arith_uint256((pindexFirst->nBits&3) + 1); // check against ct[i] if ( ct[i] != bnTmp ) From 488093279218243efc344774507c5b94f135d74a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 21:06:33 -1100 Subject: [PATCH 050/120] +print --- src/pow.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 9c2c0e4bc..8fb2cc189 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -107,9 +107,9 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = (ct[0] - ct[1]) / arith_uint256(K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); - fprintf(stderr,"ht.%d initial altK.%d\n",height,altK); if ( altK > K ) altK = K; + else fprintf(stderr,"ht.%d initial altK.%d %d * %d * %d / %d\n",height,altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); bnTarget *= arith_uint256(altK); } /* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy @@ -183,6 +183,8 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } +// 9:53 launch for ZAWY17 + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) @@ -221,7 +223,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead memset(ct0,0,sizeof(ct0)); if ( pindexLast != 0 ) height = (int32_t)pindexLast->GetHeight() + 1; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) { tipdiff = (pblock->nTime - pindexFirst->nTime); mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; @@ -229,7 +231,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); - if ( pindexFirst->GetHeight() >= 64 && (pindexFirst->nBits&3) != 0 ) + if ( (pindexFirst->nBits&3) != 0 ) ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; @@ -253,7 +255,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( pindexFirst->GetHeight() >= 64 && (pindexFirst->nBits&3) != 0 ) + if ( pindexFirst->GetHeight() >= (int32_t)(sizeof(ct)/sizeof(*ct)) && (pindexFirst->nBits&3) != 0 ) { bnTmp /= arith_uint256((pindexFirst->nBits&3) + 1); // check against ct[i] if ( ct[i] != bnTmp ) @@ -270,7 +272,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 )//&& block12diff != 0 && block7diff != 0 && block4diff != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) { bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); From 138e569388c172cc03a83e96abb95a53997ff4bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 21:45:41 -1100 Subject: [PATCH 051/120] Use actual target met --- src/pow.cpp | 10 ++++------ src/rpc/mining.cpp | 14 +++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8fb2cc189..3d6762304 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -230,9 +230,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { - ct[i].SetCompact(pindexFirst->nBits); if ( (pindexFirst->nBits&3) != 0 ) + { + ct[i] = UintToArith256(pindexFirst->GetBlockHash()); ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); + } else ct[i].SetCompact(pindexFirst->nBits); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } @@ -256,11 +258,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } if ( pindexFirst->GetHeight() >= (int32_t)(sizeof(ct)/sizeof(*ct)) && (pindexFirst->nBits&3) != 0 ) - { - bnTmp /= arith_uint256((pindexFirst->nBits&3) + 1); // check against ct[i] - if ( ct[i] != bnTmp ) - fprintf(stderr,"ht.%d i.%d ct[] != bnTmp boost X%d\n",height,i,(int32_t)(pindexFirst->nBits&3) + 1); - } + bnTmp = ct[i]; } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 0dd1fba36..d0917fafd 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -407,28 +407,32 @@ CBlockIndex *komodo_chainactive(int32_t height); UniValue genminingCSV(const UniValue& params, bool fHelp) { - int32_t i,z,height; FILE *fp; char str[64],fname[256]; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + int32_t i,z,height; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"height,nTime,nBits,bnTarget,diff,netdiff\n"); + fprintf(fp,"height,nTime,nBits,bnTarget,blockhash,diff,netdiff\n"); height = komodo_nextheight(); for (i=0; inBits,&fNegative,&fOverflow); - for (z=0; z<32; z++) + for (z=0; z<16; z++) sprintf(&str[z<<1],"%02x",((uint8_t *)&bnTarget)[31-z]); - str[32] = 0; fprintf(fp,"%d,%u,%u,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); + str[32] = 0; + hash = pindex->GetBlockHash(); + for (z=0; z<16; z++) + sprintf(&strw[z<<1],"%02x",((uint8_t *)&hash)[31-z]); + strw[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); } } fclose(fp); result.push_back(Pair("result", "success")); - result.push_back(Pair("created", "COIN_mining.csv")); + result.push_back(Pair("created", fname)); } else { From bfb2e128f71b3407a8dcb7ddc534b77c32c83dea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 21:47:27 -1100 Subject: [PATCH 052/120] Str2 --- src/rpc/mining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d0917fafd..d9db188c5 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -426,8 +426,8 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) str[32] = 0; hash = pindex->GetBlockHash(); for (z=0; z<16; z++) - sprintf(&strw[z<<1],"%02x",((uint8_t *)&hash)[31-z]); - strw[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); + sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); + str2[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); } } fclose(fp); From 7e5cca6029524182d87a56479e6816c4af3f20ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 22:11:54 -1100 Subject: [PATCH 053/120] Test --- src/pow.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3d6762304..64d082b2e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -183,7 +183,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 9:53 launch for ZAWY17 +// 10:49 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -309,8 +309,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else if ( bnTarget < origtarget / arith_uint256(2) ) zawyflag = 2; else zawyflag = 3; - fprintf(stderr,"ht.%d -> zawy.%d\n",height,zawyflag); - } + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d -> zawy.%d\n",height,zawyflag); + } else bnTarget = origtarget; } nbits = bnTarget.GetCompact(); } From 47fcb0f0672836dec31b82ce0fe9a1944dd98db6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 22:20:15 -1100 Subject: [PATCH 054/120] Tip-off based factor --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 64d082b2e..0b708cb3d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -183,7 +183,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 10:49 launch for ZAWY17 +// 11:15 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -304,9 +304,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTmp; if ( bnTarget < origtarget ) { - if ( bnTarget < origtarget/arith_uint256(3) ) + if ( tipdiff < T ) zawyflag = 1; - else if ( bnTarget < origtarget / arith_uint256(2) ) + else if ( tipdiff > 2*T && tipdiff < 3*T ) zawyflag = 2; else zawyflag = 3; { @@ -314,7 +314,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d -> zawy.%d\n",height,zawyflag); + fprintf(stderr," ht.%d -> zawy.%d tipdiff.%d\n",height,zawyflag,tipdiff); } else bnTarget = origtarget; } nbits = bnTarget.GetCompact(); From 579336f96e9953fda20ee19fa59cee7bcbc4e59b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 22:30:59 -1100 Subject: [PATCH 055/120] Exp after RST --- src/pow.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0b708cb3d..84433f578 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -274,25 +274,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - origtarget = bnTarget; - if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? - { - bnTarget = zawy_exponential(bnTarget,mult); - if ( bnTarget < origtarget || bnTarget > easy ) - { - bnTarget = easy; - fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); - return(KOMODO_MINDIFF_NBITS); - } - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); - } - else if ( pblock != 0 ) + if ( pblock != 0 ) { + origtarget = bnTarget; // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,50); bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); @@ -317,6 +301,23 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," ht.%d -> zawy.%d tipdiff.%d\n",height,zawyflag,tipdiff); } else bnTarget = origtarget; } + if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? + { + origtarget = bnTarget; + bnTarget = zawy_exponential(bnTarget,mult); + if ( bnTarget < origtarget || bnTarget > easy ) + { + bnTarget = easy; + fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); + return(KOMODO_MINDIFF_NBITS); + } + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); + } nbits = bnTarget.GetCompact(); } if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) From 489f089ebf19abfe22464e3b986f1d25015112a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 22:40:31 -1100 Subject: [PATCH 056/120] Fix off by 1 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 84433f578..67c090aaf 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -290,7 +290,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { if ( tipdiff < T ) zawyflag = 1; - else if ( tipdiff > 2*T && tipdiff < 3*T ) + else if ( tipdiff > T && tipdiff < 2*T ) zawyflag = 2; else zawyflag = 3; { From ee058b33aec227e8d95de62aa95a949fb3f5f81a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 22:42:41 -1100 Subject: [PATCH 057/120] Limit bits encoding --- src/pow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 67c090aaf..5ad7d0134 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -319,9 +319,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } nbits = bnTarget.GetCompact(); - } - if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) nbits = (nbits & 0xfffffffc) | zawyflag; + } return(nbits); } From 7aedfe619c23991e61701df1a21230335ca58127 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 23:06:59 -1100 Subject: [PATCH 058/120] One shot exp --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5ad7d0134..8bdc65e3c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -183,7 +183,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 11:15 launch for ZAWY17 +// 11:45 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -248,7 +248,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead blocktime = pindexFirst->nTime; diff = (pblock->nTime - blocktime); //fprintf(stderr,"%d ",diff); - if ( i < 12 ) + if ( 0 && i < 12 ) { diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) From e782d8a1f9fb49f4ee626500180221e9b0648688 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 23:41:50 -1100 Subject: [PATCH 059/120] +print --- src/pow.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8bdc65e3c..805744cd2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -99,7 +99,8 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust - int32_t altK,i,j,ii=0; // K is a scaling factor for integer divisions + int64_t altK; + int32_t i,j,ii=0; // K is a scaling factor for integer divisions if ( height < 64 ) return(bnTarget); if ( ts[0]-ts[W] < T*numerator/denominator ) @@ -109,7 +110,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); if ( altK > K ) altK = K; - else fprintf(stderr,"ht.%d initial altK.%d %d * %d * %d / %d\n",height,altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); + else fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); bnTarget *= arith_uint256(altK); } /* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy @@ -146,7 +147,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T); - fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %d\n",height,j,ii,altK); + fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %lld (%d * %d)\n",height,j,ii,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W])); bnTarget *= arith_uint256(altK); j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. } @@ -183,7 +184,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 11:45 launch for ZAWY17 +// 12:09 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { From da318a8bee456f2d56ceff6654cdfa01006eaf0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Aug 2019 23:46:22 -1100 Subject: [PATCH 060/120] +prints --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 805744cd2..7f33d3f8d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -147,7 +147,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T); - fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %lld (%d * %d)\n",height,j,ii,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W])); + fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %lld (%d * %d) %u - %u W.%d\n",height,j,ii,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),ts[0],ts[W],W); bnTarget *= arith_uint256(altK); j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop. } From f704978f1cb84b5d017688ceb91c79fad5de9cfa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Aug 2019 00:00:18 -1100 Subject: [PATCH 061/120] Size of K --- src/pow.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 7f33d3f8d..8fdfd273c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -93,7 +93,7 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); */ #define T ASSETCHAINS_BLOCKTIME -#define K 1000000 +#define K ((int64_t)1000000) arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { @@ -280,13 +280,16 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead origtarget = bnTarget; // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,50); - bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); - bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); - if ( bnTarget6 < bnTarget12 ) - bnTmp = bnTarget6; - else bnTmp = bnTarget12; - if ( 0 && bnTmp < bnTarget ) - bnTarget = bnTmp; + if ( 0 ) + { + bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); + bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); + if ( bnTarget6 < bnTarget12 ) + bnTmp = bnTarget6; + else bnTmp = bnTarget12; + if ( 0 && bnTmp < bnTarget ) + bnTarget = bnTmp; + } if ( bnTarget < origtarget ) { if ( tipdiff < T ) From 0bcd42542491c15bf4146872b35ae1c4e2e48752 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Aug 2019 00:32:04 -1100 Subject: [PATCH 062/120] Solvetime in csv --- src/pow.cpp | 2 +- src/rpc/mining.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8fdfd273c..c19b2514f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -184,7 +184,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 12:09 launch for ZAWY17 +// 13:04 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d9db188c5..9b64a7d32 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -407,14 +407,14 @@ CBlockIndex *komodo_chainactive(int32_t height); UniValue genminingCSV(const UniValue& params, bool fHelp) { - int32_t i,z,height; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + int32_t i,z,height; uint32_t prevtime=0; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"height,nTime,nBits,bnTarget,blockhash,diff,netdiff\n"); + fprintf(fp,"height,nTime,nBits,bnTarget,blockhash,diff,netdiff,solvetime\n"); height = komodo_nextheight(); for (i=0; iGetBlockHash(); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); - str2[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.8f,%.8f\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex)); + str2[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); + prevtime = pindex->nTime; } } fclose(fp); From fde3a1bd5278ae043d4b7b2678d55d16c20d9e6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Aug 2019 01:05:05 -1100 Subject: [PATCH 063/120] Hex print nBits --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 9b64a7d32..58226f719 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -427,7 +427,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) hash = pindex->GetBlockHash(); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); - str2[32] = 0; fprintf(fp,"%d,%u,%u,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); + str2[32] = 0; fprintf(fp,"%d,%08x,%u,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); prevtime = pindex->nTime; } } From c9326196b257d8f3f8c09ee98ea41057360e56f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Aug 2019 01:08:24 -1100 Subject: [PATCH 064/120] Bits not timestamp! --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 58226f719..91c94893d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -427,7 +427,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) hash = pindex->GetBlockHash(); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); - str2[32] = 0; fprintf(fp,"%d,%08x,%u,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); + str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); prevtime = pindex->nTime; } } From e9ccc56e87a8f67dcc63ce4aa24c8bd16a561e7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Aug 2019 23:40:36 -1100 Subject: [PATCH 065/120] Zawy18 --- src/pow.cpp | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index c19b2514f..de1a7904b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -99,8 +99,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust - int64_t altK; - int32_t i,j,ii=0; // K is a scaling factor for integer divisions + int64_t altK; int32_t i,j,ii=0; // K is a scaling factor for integer divisions if ( height < 64 ) return(bnTarget); if ( ts[0]-ts[W] < T*numerator/denominator ) @@ -108,10 +107,12 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = (ct[0] - ct[1]) / arith_uint256(K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); + fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); if ( altK > K ) altK = K; - else fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); bnTarget *= arith_uint256(altK); + if ( altK < K ) + return(bnTarget); } /* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy because the blockchain does not allow us to store a variable to know @@ -121,17 +122,17 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui any time since most recent trigger and we are at current block, aggressively adust prevTarget. */ - for (j=past-1; j>=1; j--) + for (j=past-1; j>=2; j--) { if ( ts[j]-ts[j+W] < T*numerator/denominator ) { ii = 0; - for (i=j-1; i>=0; i-- ) + for (i=j-2; i>=0; i-- ) { ii++; // Check if emission caught up. If yes, "trigger stopped at i". // Break loop to try more recent j's to see if trigger activates again. - if ( ts[i]-ts[j+W] > (ii+W)*T ) + if ( (ts[i] - ts[j+W]) > (ii+W)*T ) break; // We're here, so there was a TS[j]-TS[j-3] < T/2 trigger in the past and emission rate has not yet slowed up to be back on track so the "trigger is still active", aggressively adjusting target here at block "i" @@ -184,7 +185,7 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 13:04 launch for ZAWY17 +// 17:03 6x at ht.255 launch for ZAWY17 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -217,11 +218,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 ct[64],ct0[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; - uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t i,diff,height=0,mult = 0,tipdiff = 0; + arith_uint256 ct[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t zflags[sizeof(ct)/sizeof(*ct)],i,diff,height=0,mult = 0,tipdiff = 0; memset(ts,0,sizeof(ts)); memset(ct,0,sizeof(ct)); - memset(ct0,0,sizeof(ct0)); + memset(zflags,0,sizeof(zflags)); if ( pindexLast != 0 ) height = (int32_t)pindexLast->GetHeight() + 1; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) @@ -231,14 +232,26 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { - if ( (pindexFirst->nBits&3) != 0 ) + zflags[i] = (pindexFirst->nBits & 3); + /*if ( (pindexFirst->nBits&3) != 0 ) { ct[i] = UintToArith256(pindexFirst->GetBlockHash()); ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); - } else ct[i].SetCompact(pindexFirst->nBits); + } else*/ + ct[i].SetCompact(pindexFirst->nBits); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } + for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) + { + if ( zflags[i] != 0 ) + { + ct[i] /= arith_uint256(K); + ct[i] *= arith_uint256((int64_t)(ts[i] - ts[i+1]) * (ts[i] - ts[i+1]) * 1000); + ct[i] /= arith_uint256(T * T * 784); + ct[i] *= arith_uint256(K); + } + } } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -249,7 +262,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead blocktime = pindexFirst->nTime; diff = (pblock->nTime - blocktime); //fprintf(stderr,"%d ",diff); - if ( 0 && i < 12 ) + if ( i < 3 ) { diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) @@ -258,7 +271,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( pindexFirst->GetHeight() >= (int32_t)(sizeof(ct)/sizeof(*ct)) && (pindexFirst->nBits&3) != 0 ) + if ( zflags[i] != 0 ) bnTmp = ct[i]; } bnTot += bnTmp; @@ -287,10 +300,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTarget6 < bnTarget12 ) bnTmp = bnTarget6; else bnTmp = bnTarget12; - if ( 0 && bnTmp < bnTarget ) + if ( bnTmp < bnTarget ) bnTarget = bnTmp; } - if ( bnTarget < origtarget ) + /*if ( bnTarget < origtarget ) { if ( tipdiff < T ) zawyflag = 1; @@ -303,7 +316,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } fprintf(stderr," ht.%d -> zawy.%d tipdiff.%d\n",height,zawyflag,tipdiff); - } else bnTarget = origtarget; + } else bnTarget = origtarget;*/ + if ( bnTarget > origtarget ) + bnTarget = origtarget; + else zawyflag = 1; } if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { From e0a9862c9d179612663462327d7859afa86230e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:10:20 -1100 Subject: [PATCH 066/120] New initial altK calc and trigger for zawy18 --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index de1a7904b..f8c09556e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -102,11 +102,11 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui int64_t altK; int32_t i,j,ii=0; // K is a scaling factor for integer divisions if ( height < 64 ) return(bnTarget); - if ( ts[0]-ts[W] < T*numerator/denominator ) + if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator ) { //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = (ct[0] - ct[1]) / arith_uint256(K); - altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator / numerator) / (T * T); + altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator * W) / (numerator * (W-1) * (T * T)); fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); if ( altK > K ) altK = K; @@ -292,7 +292,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { origtarget = bnTarget; // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); - bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,50); + bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20); if ( 0 ) { bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); From 1afc2f2569cd024d0d0f2586888d70edab0ac425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:24:00 -1100 Subject: [PATCH 067/120] bnTargetB in CSV --- src/pow.cpp | 12 ++++++++++++ src/rpc/mining.cpp | 13 +++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index f8c09556e..14b5ddbb8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -187,6 +187,16 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) // 17:03 6x at ht.255 launch for ZAWY17 +arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) +{ + bnTarget /= arith_uint256(K); + bnTarget *= arith_uint256((int64_t)solvetime * solvetime * 1000); + bnTarget /= arith_uint256(T * T * 784); + bnTarget *= arith_uint256(K); + return(bnTarget); +} + + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) @@ -245,6 +255,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { if ( zflags[i] != 0 ) + ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); + { ct[i] /= arith_uint256(K); ct[i] *= arith_uint256((int64_t)(ts[i] - ts[i+1]) * (ts[i] - ts[i+1]) * 1000); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 91c94893d..e14a1cd05 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -404,30 +404,35 @@ UniValue setgenerate(const UniValue& params, bool fHelp) #endif CBlockIndex *komodo_chainactive(int32_t height); +arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime); UniValue genminingCSV(const UniValue& params, bool fHelp) { - int32_t i,z,height; uint32_t prevtime=0; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); + int32_t i,z,height; uint32_t solvetime,prevtime=0; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ); if (fHelp || params.size() != 0 ) throw runtime_error("genminingCSV\n"); LOCK(cs_main); sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"height,nTime,nBits,bnTarget,blockhash,diff,netdiff,solvetime\n"); + fprintf(fp,"height,nTime,nBits,bnTarget,bnTargetB,diff,netdiff,solvetime\n"); height = komodo_nextheight(); for (i=0; inBits,&fNegative,&fOverflow); + solvetime = (prevtime==0) ? 0 : (int32_t)(pindex->nTime - prevtime); for (z=0; z<16; z++) sprintf(&str[z<<1],"%02x",((uint8_t *)&bnTarget)[31-z]); str[32] = 0; - hash = pindex->GetBlockHash(); + //hash = pindex->GetBlockHash(); + memset(&hash,0,sizeof(hash)); + if ( (pindex->nBits & 3) != 0 ) + hash = zawy_ctB(bnTarget,solvetime); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); - str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),prevtime==0?0:(int32_t)(pindex->nTime-prevtime)); + str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),solvetime); prevtime = pindex->nTime; } } From ac6e144233a7d6e0114d0d0dc3a56e92f36326bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:27:35 -1100 Subject: [PATCH 068/120] Delete duplicated code --- src/pow.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 14b5ddbb8..3f0219ee8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -256,13 +256,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); - - { - ct[i] /= arith_uint256(K); - ct[i] *= arith_uint256((int64_t)(ts[i] - ts[i+1]) * (ts[i] - ts[i+1]) * 1000); - ct[i] /= arith_uint256(T * T * 784); - ct[i] *= arith_uint256(K); - } } } pindexFirst = pindexLast; From f38c46bbad059bc1ed8fd34d5e87a236a7edd2ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:44:11 -1100 Subject: [PATCH 069/120] Fix ctB calc --- src/pow.cpp | 11 +++++++---- src/rpc/mining.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3f0219ee8..81c0df76b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -189,10 +189,13 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) { - bnTarget /= arith_uint256(K); - bnTarget *= arith_uint256((int64_t)solvetime * solvetime * 1000); - bnTarget /= arith_uint256(T * T * 784); - bnTarget *= arith_uint256(K); + int64_t num; + num = (K * (int64_t)solvetime * solvetime * 1000) / (T * T * 784); + if ( num > 1 ) + { + bnTarget /= arith_uint256(K); + bnTarget *= arith_uint256(num); + } return(bnTarget); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e14a1cd05..00af7fd4b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -428,7 +428,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) str[32] = 0; //hash = pindex->GetBlockHash(); memset(&hash,0,sizeof(hash)); - if ( (pindex->nBits & 3) != 0 ) + if ( i > 64 && (pindex->nBits & 3) != 0 ) hash = zawy_ctB(bnTarget,solvetime); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); From bf44de39a711f438cb78d053ff76623088ee718a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:48:17 -1100 Subject: [PATCH 070/120] Print --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 00af7fd4b..1d44a791a 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -429,7 +429,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) //hash = pindex->GetBlockHash(); memset(&hash,0,sizeof(hash)); if ( i > 64 && (pindex->nBits & 3) != 0 ) - hash = zawy_ctB(bnTarget,solvetime); + hash = ArithToUint256(zawy_ctB(bnTarget,solvetime)); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),solvetime); From 752870e9f273bb038158add7314c5bef9ea68a70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:52:41 -1100 Subject: [PATCH 071/120] Reverse ctB --- src/pow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 81c0df76b..8c498f320 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,11 +190,10 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) { int64_t num; - num = (K * (int64_t)solvetime * solvetime * 1000) / (T * T * 784); + num = ((int64_t)solvetime * solvetime * 1000) / (T * T * 784); if ( num > 1 ) { - bnTarget /= arith_uint256(K); - bnTarget *= arith_uint256(num); + bnTarget /= arith_uint256(num); } return(bnTarget); } From dc7178dbe44ce99fda6c9ddeac05d452191e8af8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 00:55:55 -1100 Subject: [PATCH 072/120] Add 0.001 precision to cab --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8c498f320..ff64b58e1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,10 +190,11 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) { int64_t num; - num = ((int64_t)solvetime * solvetime * 1000) / (T * T * 784); + num = ((int64_t)1000 * solvetime * solvetime * 1000) / (T * T * 784); if ( num > 1 ) { bnTarget /= arith_uint256(num); + bnTarget *= arith_uint256(1000); } return(bnTarget); } From e22c71715efcd306b2c3806be662f293f35a3985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 01:32:31 -1100 Subject: [PATCH 073/120] Invert cab --- src/pow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ff64b58e1..78053398a 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -185,16 +185,14 @@ arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) return(bnTarget); } -// 17:03 6x at ht.255 launch for ZAWY17 - arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) { int64_t num; num = ((int64_t)1000 * solvetime * solvetime * 1000) / (T * T * 784); if ( num > 1 ) { - bnTarget /= arith_uint256(num); - bnTarget *= arith_uint256(1000); + bnTarget /= arith_uint256(1000); + bnTarget *= arith_uint256(num); } return(bnTarget); } From 1076f8fe3514bf833c8fac8862531ca30c90065e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 01:52:17 -1100 Subject: [PATCH 074/120] Make ct[] diffs correct --- src/pow.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 78053398a..e4a4e4e41 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -105,7 +105,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator ) { //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); - bnTarget = (ct[0] - ct[1]) / arith_uint256(K); + bnTarget = ct[0] / arith_uint256(K); altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator * W) / (numerator * (W-1) * (T * T)); fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); if ( altK > K ) @@ -146,7 +146,10 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui Rarely, last 3 STs can be 1/2 speed => target = prevTarget at T/2, & 1/2 at T.*/ //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; - bnTarget = (ct[0]-ct[W]) / arith_uint256(W * K); + bnTarget = ct[0]; + for (i=1; i Date: Wed, 7 Aug 2019 02:03:25 -1100 Subject: [PATCH 075/120] Undo W-1 --- src/pow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e4a4e4e41..8400c9926 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -102,11 +102,13 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui int64_t altK; int32_t i,j,ii=0; // K is a scaling factor for integer divisions if ( height < 64 ) return(bnTarget); - if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator ) + //if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator ) + if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) { //bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T); bnTarget = ct[0] / arith_uint256(K); - altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator * W) / (numerator * (W-1) * (T * T)); + //altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator * W) / (numerator * (W-1) * (T * T)); + altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); if ( altK > K ) altK = K; From df86b2df71f159cf88b2823ccaf5996218b5d02a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 02:15:41 -1100 Subject: [PATCH 076/120] Fix loop --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8400c9926..bf062f27a 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -99,7 +99,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust - int64_t altK; int32_t i,j,ii=0; // K is a scaling factor for integer divisions + int64_t altK; int32_t i,j,k,ii=0; // K is a scaling factor for integer divisions if ( height < 64 ) return(bnTarget); //if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator ) @@ -129,7 +129,7 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui if ( ts[j]-ts[j+W] < T*numerator/denominator ) { ii = 0; - for (i=j-2; i>=0; i-- ) + for (i=j-2; i>=0; i--) { ii++; // Check if emission caught up. If yes, "trigger stopped at i". @@ -149,8 +149,8 @@ arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,ui //bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T; bnTarget = ct[0]; - for (i=1; i Date: Wed, 7 Aug 2019 02:26:06 -1100 Subject: [PATCH 077/120] >= 64 display --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 1d44a791a..c3317da41 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -428,7 +428,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) str[32] = 0; //hash = pindex->GetBlockHash(); memset(&hash,0,sizeof(hash)); - if ( i > 64 && (pindex->nBits & 3) != 0 ) + if ( i >= 64 && (pindex->nBits & 3) != 0 ) hash = ArithToUint256(zawy_ctB(bnTarget,solvetime)); for (z=0; z<16; z++) sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]); From 772cb5ceae7f5f2fb9ce1dd153ab2fffe1292003 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 03:41:28 -1100 Subject: [PATCH 078/120] States for flags --- src/pow.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index bf062f27a..1a4e82a21 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -95,7 +95,12 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); #define T ASSETCHAINS_BLOCKTIME #define K ((int64_t)1000000) -arith_uint256 RT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +{ + +} + +arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small //if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust @@ -293,7 +298,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) { @@ -302,6 +307,26 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( pblock != 0 ) { origtarget = bnTarget; + past = 20; + if ( zflags[0] == 0 ) + { + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); + if ( bnTarget < origtarget ) + zawyflag = 2; + } + else + { + for (i=1; inTime,bnTarget,ts,ct,1,2,3,past,i); + if ( bnTarget != origtarget ) + zawyflag = 1; + } + } + /* // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20); if ( 0 ) @@ -313,24 +338,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else bnTmp = bnTarget12; if ( bnTmp < bnTarget ) bnTarget = bnTmp; - } - /*if ( bnTarget < origtarget ) - { - if ( tipdiff < T ) - zawyflag = 1; - else if ( tipdiff > T && tipdiff < 2*T ) - zawyflag = 2; - else zawyflag = 3; - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d -> zawy.%d tipdiff.%d\n",height,zawyflag,tipdiff); - } else bnTarget = origtarget;*/ + }*/ if ( bnTarget > origtarget ) bnTarget = origtarget; - else zawyflag = 1; } if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { From 8804ae4096b68c956f1a4eddae7461124118851e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 04:00:19 -1100 Subject: [PATCH 079/120] RST outer and inner --- src/pow.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1a4e82a21..d2d71e1f4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -95,9 +95,36 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); #define T ASSETCHAINS_BLOCKTIME #define K ((int64_t)1000000) -arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { - + int64_t outerK; + if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) + { + outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); + fprintf(stderr,"ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); + if ( outerK < K ) + { + bnTarget = ct[0] / arith_uint256(K); + bnTarget *= arith_uint256(outerK); + } + } + return(bnTarget); +} + +arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) +{ + int64_t innerK; int32_t i; + if ( (ts[0] - ts[outeri+W]) < (outeri+W)*T ) + { + bnTarget = ct[0]; + for (i=1; i Date: Wed, 7 Aug 2019 04:10:15 -1100 Subject: [PATCH 080/120] Fix initial flags --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index d2d71e1f4..f925a7b30 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -280,7 +280,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { - zflags[i] = (pindexFirst->nBits & 3); + if ( height-i-1 >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) + zflags[i] = (pindexFirst->nBits & 3); /*if ( (pindexFirst->nBits&3) != 0 ) { ct[i] = UintToArith256(pindexFirst->GetBlockHash()); From 8c37d63a0f083ae66b753a9e3c4781f4d8ec2a9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 04:27:47 -1100 Subject: [PATCH 081/120] min() --- src/pow.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index f925a7b30..60818ec64 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -111,18 +111,31 @@ arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTar return(bnTarget); } +arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t width) +{ + int32_t i; int64_t innerK; + bnTarget = ct[0]; + for (i=1; i Date: Wed, 7 Aug 2019 04:46:37 -1100 Subject: [PATCH 082/120] Always set nBits --- src/pow.cpp | 116 ++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 60818ec64..401b6c692 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -107,7 +107,7 @@ arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTar bnTarget = ct[0] / arith_uint256(K); bnTarget *= arith_uint256(outerK); } - } + } else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator); return(bnTarget); } @@ -127,6 +127,7 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) { arith_uint256 bnTargetW,bnTargetwidth,bnTmp; int32_t width = outeri+W; + fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d\n",outeri,width,(ts[0] - ts[width]),width*T); if ( (ts[0] - ts[width]) < width*T ) { bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); @@ -293,20 +294,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { - if ( height-i-1 >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) - zflags[i] = (pindexFirst->nBits & 3); - /*if ( (pindexFirst->nBits&3) != 0 ) - { - ct[i] = UintToArith256(pindexFirst->GetBlockHash()); - ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1); - } else*/ - ct[i].SetCompact(pindexFirst->nBits); + zflags[i] = (pindexFirst->nBits & 3); + ct[i].SetCompact(pindexFirst->nBits); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { - if ( zflags[i] != 0 ) + if ( zflags[i] != 0 && height-1-i >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } } @@ -341,64 +336,67 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { bnTarget = arith_uint256().SetCompact(nbits); - easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( pblock != 0 ) + if ( height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) { - origtarget = bnTarget; - past = 20; - if ( zflags[0] == 0 ) + easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( pblock != 0 ) { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); - if ( bnTarget < origtarget ) - zawyflag = 2; - } - else - { - for (i=1; inTime,bnTarget,ts,ct,1,2,3,past,i); - if ( bnTarget != origtarget ) - zawyflag = 1; + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); + if ( bnTarget < origtarget ) + zawyflag = 2; } + else + { + for (i=1; inTime,bnTarget,ts,ct,1,2,3,past,i); + if ( bnTarget != origtarget ) + zawyflag = 1; + } + } + /* + // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); + bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20); + if ( 0 ) + { + bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); + bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); + if ( bnTarget6 < bnTarget12 ) + bnTmp = bnTarget6; + else bnTmp = bnTarget12; + if ( bnTmp < bnTarget ) + bnTarget = bnTmp; + }*/ + if ( bnTarget > origtarget ) + bnTarget = origtarget; } - /* - // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); - bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20); - if ( 0 ) + if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { - bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); - bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); - if ( bnTarget6 < bnTarget12 ) - bnTmp = bnTarget6; - else bnTmp = bnTarget12; - if ( bnTmp < bnTarget ) - bnTarget = bnTmp; - }*/ - if ( bnTarget > origtarget ) - bnTarget = origtarget; - } - if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? - { - origtarget = bnTarget; - bnTarget = zawy_exponential(bnTarget,mult); - if ( bnTarget < origtarget || bnTarget > easy ) - { - bnTarget = easy; - fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); - return(KOMODO_MINDIFF_NBITS); + origtarget = bnTarget; + bnTarget = zawy_exponential(bnTarget,mult); + if ( bnTarget < origtarget || bnTarget > easy ) + { + bnTarget = easy; + fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); + return(KOMODO_MINDIFF_NBITS); + } + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; From b1d8ec03d6d6be127790b5458103a21f327e6b6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 05:31:22 -1100 Subject: [PATCH 083/120] Force solving RST --- src/pow.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 401b6c692..0511f6db2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -97,17 +97,24 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { - int64_t outerK; + int64_t outerK; arith_uint256 mintarget = bnTarget / arith_uint256(2); if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) { outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); - fprintf(stderr,"ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); if ( outerK < K ) { bnTarget = ct[0] / arith_uint256(K); bnTarget *= arith_uint256(outerK); } - } else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator); + if ( bnTarget > mintarget ) + bnTarget = mintarget; + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); + } //else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator); return(bnTarget); } @@ -119,17 +126,23 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa bnTarget += ct[i]; bnTarget /= arith_uint256(width * K); innerK = (K * (nTime-ts[0]) * (ts[0]-ts[width])) / (width * T * T); - fprintf(stderr,"ht.%d made it to i == 0, innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); bnTarget *= arith_uint256(innerK); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d made it to i == 0, innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); return(bnTarget); } arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) { - arith_uint256 bnTargetW,bnTargetwidth,bnTmp; int32_t width = outeri+W; + arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t width = outeri+W; fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d\n",outeri,width,(ts[0] - ts[width]),width*T); if ( (ts[0] - ts[width]) < width*T ) { + mintarget = (bnTarget / arith_uint256(5)) * arith_uint256(4); bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); bnTargetwidth = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,width); if ( bnTargetW < bnTargetwidth ) @@ -137,6 +150,8 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar else bnTmp = bnTargetwidth; if ( bnTmp < bnTarget ) bnTarget = bnTmp; + if ( bnTarget > mintarget ) + bnTarget = mintarget; } return(bnTarget); } @@ -301,7 +316,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { - if ( zflags[i] != 0 && height-1-i >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) + if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } } @@ -339,7 +354,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { bnTarget = arith_uint256().SetCompact(nbits); - if ( height >= (int32_t)(sizeof(ct)/sizeof(*ct)) ) + if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) { easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( pblock != 0 ) @@ -378,7 +393,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTmp; }*/ if ( bnTarget > origtarget ) + { bnTarget = origtarget; + zawyflag = 0; + } } if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { From 319a41bf71643500d4991dab9485e4241c4d8801 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 06:21:44 -1100 Subject: [PATCH 084/120] Tweak targets to make it converge faster --- src/pow.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0511f6db2..64a8af75d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -124,7 +124,7 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa bnTarget = ct[0]; for (i=1; i=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d made it to i == 0, innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); + fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); return(bnTarget); } arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) { - arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t width = outeri+W; + arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t factor,elapsed,width = outeri+W; fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d\n",outeri,width,(ts[0] - ts[width]),width*T); - if ( (ts[0] - ts[width]) < width*T ) + if ( (elapsed= (ts[0] - ts[width])) < width*T ) { - mintarget = (bnTarget / arith_uint256(5)) * arith_uint256(4); + if ( (factor= (elapsed - width*T)/T) >= 1 ) + mintarget = (bnTarget / arith_uint256(factor+1)); + else mintarget = (bnTarget / arith_uint256(4)) * arith_uint256(3); bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); bnTargetwidth = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,width); if ( bnTargetW < bnTargetwidth ) @@ -369,9 +371,16 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { + if ( height < 70 ) + { + for (i=0; inTime,bnTarget,ts,ct,1,2,3,past,i); From 49e9e0cfd381e1ddc3780be244f7ab296470b823 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 06:52:16 -1100 Subject: [PATCH 085/120] Fix O detection in I state --- src/pow.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 64a8af75d..5d19b8391 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -139,7 +139,7 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) { arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t factor,elapsed,width = outeri+W; - fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d\n",outeri,width,(ts[0] - ts[width]),width*T); + fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d, deficit %d\n",outeri,width,(ts[0] - ts[width]),width*T,(ts[0] - ts[width]) - width*T); if ( (elapsed= (ts[0] - ts[width])) < width*T ) { if ( (factor= (elapsed - width*T)/T) >= 1 ) @@ -152,6 +152,8 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar else bnTmp = bnTargetwidth; if ( bnTmp < bnTarget ) bnTarget = bnTmp; + if ( factor > 1 ) + bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); if ( bnTarget > mintarget ) bnTarget = mintarget; } @@ -371,16 +373,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { - if ( height < 70 ) - { - for (i=0; inTime,bnTarget,ts,ct,1,2,3,past,i); From 61791622e5007499ee0f64ed68fd69b50a4b79a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 07:30:49 -1100 Subject: [PATCH 086/120] ctBinv --- src/pow.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5d19b8391..5fa13fcb6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -267,6 +267,20 @@ arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) return(bnTarget); } +arith_uint256 zawy_ctBinv(arith_uint256 bnTarget,uint32_t solvetime) +{ + int64_t num; arith_uint256 origtarget = bnTarget; + num = ((int64_t)1000 * solvetime * solvetime * 1000) / (T * T * 784); + if ( num > 1 ) + { + bnTarget /= arith_uint256(num); + bnTarget *= arith_uint256(1000); + if ( bnTarget > origtarget ) + bnTarget = origtarget; + } + return(bnTarget); +} + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -299,10 +313,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 ct[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t zflags[sizeof(ct)/sizeof(*ct)],i,diff,height=0,mult = 0,tipdiff = 0; memset(ts,0,sizeof(ts)); memset(ct,0,sizeof(ct)); + memset(ctinv,0,sizeof(ctinv)); memset(zflags,0,sizeof(zflags)); if ( pindexLast != 0 ) height = (int32_t)pindexLast->GetHeight() + 1; @@ -321,7 +336,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { if ( zflags[i] != 0 ) + { ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); + ctinv[i] = zawy_ctBinv(ct[i],ts[i] - ts[i+1]); + } } } pindexFirst = pindexLast; @@ -343,7 +361,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } if ( zflags[i] != 0 ) - bnTmp = ct[i]; + bnTmp = ctinv[i]; } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; From 00e6355aa9faec399fcbc943c3e35c4f2ac04794 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 07:49:40 -1100 Subject: [PATCH 087/120] Fix elapsed factor sign error --- src/pow.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5fa13fcb6..24c6cb8ba 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -138,12 +138,14 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) { - arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t factor,elapsed,width = outeri+W; - fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d, deficit %d\n",outeri,width,(ts[0] - ts[width]),width*T,(ts[0] - ts[width]) - width*T); - if ( (elapsed= (ts[0] - ts[width])) < width*T ) + arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t expected,factor,elapsed,width = outeri+W; + expected = (width+1) * T; + if ( (elapsed= (ts[0] - ts[width])) < expected ) { - if ( (factor= (elapsed - width*T)/T) >= 1 ) - mintarget = (bnTarget / arith_uint256(factor+1)); + if ( (factor= (expected - elapsed)/T) > 1 ) + mintarget = (bnTarget / arith_uint256(factor)); + else if ( factor == 1 ) + mintarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); else mintarget = (bnTarget / arith_uint256(4)) * arith_uint256(3); bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); bnTargetwidth = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,width); @@ -156,6 +158,7 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); if ( bnTarget > mintarget ) bnTarget = mintarget; + fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); } return(bnTarget); } @@ -361,7 +364,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } if ( zflags[i] != 0 ) - bnTmp = ctinv[i]; + bnTmp = ct[i]; } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; @@ -414,6 +417,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTmp < bnTarget ) bnTarget = bnTmp; }*/ + bnTarget = (bnTarget + ct[0]) / arith_uint256(2); if ( bnTarget > origtarget ) { bnTarget = origtarget; From b88ab15c25a194176cb634a5cc5b8a2ab6e79814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 07:59:33 -1100 Subject: [PATCH 088/120] Disable elapsed factor --- src/pow.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 24c6cb8ba..c21c94f68 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -154,9 +154,9 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar else bnTmp = bnTargetwidth; if ( bnTmp < bnTarget ) bnTarget = bnTmp; - if ( factor > 1 ) + if ( 0 && factor > 1 ) bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); - if ( bnTarget > mintarget ) + if ( 0 && bnTarget > mintarget ) bnTarget = mintarget; fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); } @@ -339,10 +339,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { if ( zflags[i] != 0 ) - { ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); - ctinv[i] = zawy_ctBinv(ct[i],ts[i] - ts[i+1]); - } } } pindexFirst = pindexLast; @@ -364,7 +361,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } } if ( zflags[i] != 0 ) - bnTmp = ct[i]; + bnTmp = (ct[i] / arith_uint256(3)); } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; @@ -417,7 +414,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTmp < bnTarget ) bnTarget = bnTmp; }*/ - bnTarget = (bnTarget + ct[0]) / arith_uint256(2); if ( bnTarget > origtarget ) { bnTarget = origtarget; From 33e9eaaac7fff3a275309193c131ea499ea786e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 09:01:36 -1100 Subject: [PATCH 089/120] Tsa --- src/pow.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index c21c94f68..705f8f55e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -156,7 +156,7 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar bnTarget = bnTmp; if ( 0 && factor > 1 ) bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); - if ( 0 && bnTarget > mintarget ) + if ( 1 && bnTarget > mintarget ) bnTarget = mintarget; fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); } @@ -240,21 +240,26 @@ arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,i return(bnSum); } -arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) +int64_t zawy_exponential_val360000(int32_t num) { int32_t i,n,modval; int64_t A = 1, B = 3600 * 100; - if ( (n= (mult/ASSETCHAINS_BLOCKTIME)) > 0 ) + if ( (n= (num/ASSETCHAINS_BLOCKTIME)) > 0 ) { for (i=1; i<=n; i++) A *= 3; } - if ( (modval= (mult % ASSETCHAINS_BLOCKTIME)) != 0 ) + if ( (modval= (num % ASSETCHAINS_BLOCKTIME)) != 0 ) { B += (3600 * 110 * modval) / ASSETCHAINS_BLOCKTIME; B += (3600 * 60 * modval * modval) / (ASSETCHAINS_BLOCKTIME * ASSETCHAINS_BLOCKTIME); } + return(A * B); +} + +arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) +{ bnTarget /= arith_uint256(100 * 3600); - bnTarget *= arith_uint256(A * B); + bnTarget *= arith_uint256(zawy_exponential_val360000(mult)); return(bnTarget); } @@ -341,6 +346,33 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } + if ( 1 ) + { + arith_uint256 A,B,C; + if ( tipdiff < 2 ) + tipdiff = 2; + bnTarget = ct[0] / arith_uint256(K); + A = bnTarget * arith_uint256(T); + B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff) / 2) / arith_uint256(360000); + C = bnTarget * arith_uint256(T * tipdiff * zawy_exponential_val360000(tipdiff) / 2) / arith_uint256(360000); + bnTarget = (A + B - C) * arith_uint256(K); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d bnTarget -> ",height); + bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," sma\n"); + nbits = bnTarget.GetCompact(); + nbits = (nbits & 0xfffffffc) | 0; + return(nbits); + } } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) From 509d4f2b1565bab405fcac05a6fe1436af97764b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 09:16:16 -1100 Subject: [PATCH 090/120] Tipdiff/2 --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 705f8f55e..9f55f7192 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -353,8 +353,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead tipdiff = 2; bnTarget = ct[0] / arith_uint256(K); A = bnTarget * arith_uint256(T); - B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff) / 2) / arith_uint256(360000); - C = bnTarget * arith_uint256(T * tipdiff * zawy_exponential_val360000(tipdiff) / 2) / arith_uint256(360000); + B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); + C = bnTarget * arith_uint256(T * tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); bnTarget = (A + B - C) * arith_uint256(K); { int32_t z; From 516c28d42492a01af42980ca97e2c75b3da162e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 09:27:34 -1100 Subject: [PATCH 091/120] Use RST --- src/pow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 9f55f7192..d511c8e5d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -346,7 +346,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } - if ( 1 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) { arith_uint256 A,B,C; if ( tipdiff < 2 ) @@ -414,7 +414,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( pblock != 0 ) { origtarget = bnTarget; - past = 20; + past = 30; if ( zflags[0] == 0 ) { bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); @@ -446,6 +446,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTmp < bnTarget ) bnTarget = bnTmp; }*/ + bnTarget = (bnTarget + ct[0]) / arith_uint256(2); if ( bnTarget > origtarget ) { bnTarget = origtarget; From b1f9dbbcecb1883621ef36521ac996860546befb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 09:32:01 -1100 Subject: [PATCH 092/120] Fix TSA overflow and /= tip-off --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index d511c8e5d..59a8d5006 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -346,16 +346,16 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } - if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA { arith_uint256 A,B,C; if ( tipdiff < 2 ) tipdiff = 2; - bnTarget = ct[0] / arith_uint256(K); + bnTarget = ct[0] / arith_uint256(K*T); A = bnTarget * arith_uint256(T); B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - C = bnTarget * arith_uint256(T * tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - bnTarget = (A + B - C) * arith_uint256(K); + C = bnTarget * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); + bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); { int32_t z; for (z=31; z>=0; z--) From bb6e52fcb2a1e30642e92adbd6382c4230c56e8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 09:43:08 -1100 Subject: [PATCH 093/120] Remove averaging --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 59a8d5006..7f2c96a85 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -361,14 +361,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d bnTarget -> ",height); - bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); + fprintf(stderr," ht.%d bnTarget tipdiff.%d\n",height,tipdiff); + /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); { int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," sma\n"); + fprintf(stderr," sma\n");*/ nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | 0; return(nbits); From d8b8bbfda82b172779df8099383319b8ef613631 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 10:21:55 -1100 Subject: [PATCH 094/120] TSA+RST hybrid zawy19 --- src/pow.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 7f2c96a85..d080dc3e4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -361,7 +361,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," ht.%d bnTarget tipdiff.%d\n",height,tipdiff); + fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); { int32_t z; @@ -369,9 +369,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } fprintf(stderr," sma\n");*/ - nbits = bnTarget.GetCompact(); - nbits = (nbits & 0xfffffffc) | 0; - return(nbits); + //nbits = bnTarget.GetCompact(); + //nbits = (nbits & 0xfffffffc) | 0; + //return(nbits); } } pindexFirst = pindexLast; @@ -407,7 +407,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { - bnTarget = arith_uint256().SetCompact(nbits); + if ( ASSETCHAINS_ADAPTIVEPOW != 1 ) // not-TSA + bnTarget = arith_uint256().SetCompact(nbits); if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) { easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); From 855f955e51844b44fa5e64d8ccfc32be8af089e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 10:31:57 -1100 Subject: [PATCH 095/120] Fix --- src/pow.cpp | 57 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index d080dc3e4..1b3b9d199 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -346,33 +346,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } - if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA - { - arith_uint256 A,B,C; - if ( tipdiff < 2 ) - tipdiff = 2; - bnTarget = ct[0] / arith_uint256(K*T); - A = bnTarget * arith_uint256(T); - B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - C = bnTarget * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); - /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," sma\n");*/ - //nbits = bnTarget.GetCompact(); - //nbits = (nbits & 0xfffffffc) | 0; - //return(nbits); - } } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -407,10 +380,36 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { - if ( ASSETCHAINS_ADAPTIVEPOW != 1 ) // not-TSA - bnTarget = arith_uint256().SetCompact(nbits); + bnTarget = arith_uint256().SetCompact(nbits); if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) { + if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA + { + arith_uint256 A,B,C; + if ( tipdiff < 2 ) + tipdiff = 2; + bnTarget = ct[0] / arith_uint256(K*T); + A = bnTarget * arith_uint256(T); + B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); + C = bnTarget * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); + bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); + /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," sma\n");*/ + //nbits = bnTarget.GetCompact(); + //nbits = (nbits & 0xfffffffc) | 0; + //return(nbits); + } easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( pblock != 0 ) { From d1767f967d8bd31fa7123ec9ba89968e5fbc9e40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 10:45:24 -1100 Subject: [PATCH 096/120] TSA only with bug fix --- src/pow.cpp | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1b3b9d199..2630450bb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -346,6 +346,33 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } + if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA + { + arith_uint256 A,B,C; // fix overflow bug on diff stranding + if ( tipdiff < 2 ) + tipdiff = 2; + bnTarget = ct[0] / arith_uint256(K*T); + A = bnTarget * arith_uint256(T); + B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); + C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); + bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); + /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," sma\n");*/ + nbits = bnTarget.GetCompact(); + nbits = (nbits & 0xfffffffc) | 0; + return(nbits); + } } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -383,33 +410,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = arith_uint256().SetCompact(nbits); if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) { - if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA - { - arith_uint256 A,B,C; - if ( tipdiff < 2 ) - tipdiff = 2; - bnTarget = ct[0] / arith_uint256(K*T); - A = bnTarget * arith_uint256(T); - B = bnTarget * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - C = bnTarget * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)) / arith_uint256(360000); - bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); - /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," sma\n");*/ - //nbits = bnTarget.GetCompact(); - //nbits = (nbits & 0xfffffffc) | 0; - //return(nbits); - } easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( pblock != 0 ) { From 0a04ce6009b4754eca1dc14a2bdf27eaae10f5c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 11:08:39 -1100 Subject: [PATCH 097/120] Overflow fixes? --- src/pow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 2630450bb..c832b3287 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -349,13 +349,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA { arith_uint256 A,B,C; // fix overflow bug on diff stranding - if ( tipdiff < 2 ) - tipdiff = 2; + if ( tipdiff < 3 ) + tipdiff = 3; bnTarget = ct[0] / arith_uint256(K*T); A = bnTarget * arith_uint256(T); - B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); - C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); - bnTarget = (A + B - C) * arith_uint256(K*T) / arith_uint256(tipdiff); + B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff*5/9)); + C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff*5/9)); + bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T); { int32_t z; for (z=31; z>=0; z--) From 9d3fdca837e9739858cf21cbbc22abdfbba96ec2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 11:36:17 -1100 Subject: [PATCH 098/120] Boost TSA --- src/pow.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index c832b3287..1da1276cd 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -349,13 +349,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA { arith_uint256 A,B,C; // fix overflow bug on diff stranding - if ( tipdiff < 3 ) - tipdiff = 3; + if ( tipdiff < 4 ) + tipdiff = 4; + tipdiff &= ~1; bnTarget = ct[0] / arith_uint256(K*T); A = bnTarget * arith_uint256(T); - B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff*5/9)); - C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff*5/9)); + B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); + C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T); + if ( (ts[0] - ts[1]) < T/2 ) + bnTarget = (bnTarget * arith_uint256(2)) / arith_uint256(3); + else if ( (ts[0] - ts[1]) > T*2 ) + bnTarget = (bnTarget * arith_uint256(3)) / arith_uint256(2); { int32_t z; for (z=31; z>=0; z--) From 5d3d406c6c8d6c2b533e5f8da35964b51c63aa80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 12:03:58 -1100 Subject: [PATCH 099/120] Average with previous --- src/pow.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1da1276cd..9e888188e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -348,7 +348,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA { - arith_uint256 A,B,C; // fix overflow bug on diff stranding + arith_uint256 A,B,C; if ( tipdiff < 4 ) tipdiff = 4; tipdiff &= ~1; @@ -361,19 +361,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = (bnTarget * arith_uint256(2)) / arith_uint256(3); else if ( (ts[0] - ts[1]) > T*2 ) bnTarget = (bnTarget * arith_uint256(3)) / arith_uint256(2); + bnTarget = (bnTarget + ct[0]) / arith_uint256(2); { int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); - /*bnTarget = (bnTarget + ct[0] + ct[1] + ct[2]) / arith_uint256(4); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," sma\n");*/ nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | 0; return(nbits); From 336929d6c10d55b8b2563f4ebd722d11737d33c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 18:47:45 -1100 Subject: [PATCH 100/120] RST default --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 9e888188e..97eed8c2e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -346,7 +346,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[i] != 0 ) ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } - if ( ASSETCHAINS_ADAPTIVEPOW == 1 ) // TSA + if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) // TSA { arith_uint256 A,B,C; if ( tipdiff < 4 ) From 3079765c7cf194b6fabcfa0e0b0cdf185d2938e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 19:11:28 -1100 Subject: [PATCH 101/120] Hybrid --- src/pow.cpp | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 97eed8c2e..5333d1f93 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -289,6 +289,32 @@ arith_uint256 zawy_ctBinv(arith_uint256 bnTarget,uint32_t solvetime) return(bnTarget); } +arith_uint256 zawy_TSA_EMA(int32_t height,int32_t tipdiff,arith_uint256 prevTarget,int32_t solvetime) +{ + arith_uint256 A,B,C,bnTarget; + if ( tipdiff < 4 ) + tipdiff = 4; + tipdiff &= ~1; + bnTarget = prevTarget / arith_uint256(K*T); + A = bnTarget * arith_uint256(T); + B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); + C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); + bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T); + if ( 0 ) + { + if ( solvetime < T/2 ) + bnTarget = (bnTarget * arith_uint256(2)) / arith_uint256(3); + else if ( solvetime > T*2 ) + bnTarget = (bnTarget * arith_uint256(3)) / arith_uint256(2); + } + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); + return(bnTarget); +} unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -348,26 +374,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) // TSA { - arith_uint256 A,B,C; - if ( tipdiff < 4 ) - tipdiff = 4; - tipdiff &= ~1; - bnTarget = ct[0] / arith_uint256(K*T); - A = bnTarget * arith_uint256(T); - B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); - C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); - bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T); - if ( (ts[0] - ts[1]) < T/2 ) - bnTarget = (bnTarget * arith_uint256(2)) / arith_uint256(3); - else if ( (ts[0] - ts[1]) > T*2 ) - bnTarget = (bnTarget * arith_uint256(3)) / arith_uint256(2); - bnTarget = (bnTarget + ct[0]) / arith_uint256(2); - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff); + bnTarget = zawy_TSA_EMA(height,tipdiff,ct[0],ts[0] - ts[1]); nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | 0; return(nbits); @@ -470,6 +477,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } } + if ( zawyflag == 0 && mult <= 1 ) + bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); + nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; } From 39581ade83b9825ee852780ab01e43570168d9a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 19:16:59 -1100 Subject: [PATCH 102/120] Disable tea for first 64 --- src/pow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5333d1f93..44e4ddc14 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -476,10 +476,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } + if ( zawyflag == 0 && mult <= 1 ) + bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); } - if ( zawyflag == 0 && mult <= 1 ) - bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); - nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; } From 3a148d9e527928b2964b61e3beee7fbdd78b9a57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 19:24:27 -1100 Subject: [PATCH 103/120] Restore full exp --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 44e4ddc14..062f327e8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -389,7 +389,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead blocktime = pindexFirst->nTime; diff = (pblock->nTime - blocktime); //fprintf(stderr,"%d ",diff); - if ( i < 3 ) + if ( i < 12 ) { diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) From 644fa8ea01a632f1ee023969845dfad9376bc2de Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 19:38:24 -1100 Subject: [PATCH 104/120] Move code --- src/pow.cpp | 154 ++++++++++++++++++++++++---------------------------- 1 file changed, 71 insertions(+), 83 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 062f327e8..cd5ae8636 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -95,74 +95,7 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past); #define T ASSETCHAINS_BLOCKTIME #define K ((int64_t)1000000) -arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) -{ - int64_t outerK; arith_uint256 mintarget = bnTarget / arith_uint256(2); - if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) - { - outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); - if ( outerK < K ) - { - bnTarget = ct[0] / arith_uint256(K); - bnTarget *= arith_uint256(outerK); - } - if ( bnTarget > mintarget ) - bnTarget = mintarget; - { - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); - } //else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator); - return(bnTarget); -} - -arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t width) -{ - int32_t i; int64_t innerK; - bnTarget = ct[0]; - for (i=1; i=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); - } - fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); - return(bnTarget); -} - -arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) -{ - arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t expected,factor,elapsed,width = outeri+W; - expected = (width+1) * T; - if ( (elapsed= (ts[0] - ts[width])) < expected ) - { - if ( (factor= (expected - elapsed)/T) > 1 ) - mintarget = (bnTarget / arith_uint256(factor)); - else if ( factor == 1 ) - mintarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); - else mintarget = (bnTarget / arith_uint256(4)) * arith_uint256(3); - bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); - bnTargetwidth = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,width); - if ( bnTargetW < bnTargetwidth ) - bnTmp = bnTargetW; - else bnTmp = bnTargetwidth; - if ( bnTmp < bnTarget ) - bnTarget = bnTmp; - if ( 0 && factor > 1 ) - bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); - if ( 1 && bnTarget > mintarget ) - bnTarget = mintarget; - fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); - } - return(bnTarget); -} - +#ifdef original_algo arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) { //if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small @@ -230,6 +163,74 @@ arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget } return(bnTarget); } +#endif + +arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past) +{ + int64_t outerK; arith_uint256 mintarget = bnTarget / arith_uint256(2); + if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) + { + outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); + if ( outerK < K ) + { + bnTarget = ct[0] / arith_uint256(K); + bnTarget *= arith_uint256(outerK); + } + if ( bnTarget > mintarget ) + bnTarget = mintarget; + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator); + } //else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator); + return(bnTarget); +} + +arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t width) +{ + int32_t i; int64_t innerK; + bnTarget = ct[0]; + for (i=1; i=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); + return(bnTarget); +} + +arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) +{ + arith_uint256 bnTargetW,bnTargetwidth,bnTmp,mintarget; int32_t expected,factor,elapsed,width = outeri+W; + expected = (width+1) * T; + if ( (elapsed= (ts[0] - ts[width])) < expected ) + { + mintarget = (bnTarget / arith_uint256(5)) * arith_uint256(4); + bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); + bnTargetwidth = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,width); + if ( bnTargetW < bnTargetwidth ) + bnTmp = bnTargetW; + else bnTmp = bnTargetwidth; + if ( bnTmp < bnTarget ) + bnTarget = bnTmp; + factor = (expected - elapsed) / T; + if ( factor > 2 ) + bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); + else if ( factor == 2 ) + bnTarget = (bnTarget / arith_uint256(4)) * arith_uint256(3); + if ( 1 && bnTarget > mintarget ) + bnTarget = mintarget; + fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); + } + return(bnTarget); +} arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor) { @@ -275,20 +276,6 @@ arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime) return(bnTarget); } -arith_uint256 zawy_ctBinv(arith_uint256 bnTarget,uint32_t solvetime) -{ - int64_t num; arith_uint256 origtarget = bnTarget; - num = ((int64_t)1000 * solvetime * solvetime * 1000) / (T * T * 784); - if ( num > 1 ) - { - bnTarget /= arith_uint256(num); - bnTarget *= arith_uint256(1000); - if ( bnTarget > origtarget ) - bnTarget = origtarget; - } - return(bnTarget); -} - arith_uint256 zawy_TSA_EMA(int32_t height,int32_t tipdiff,arith_uint256 prevTarget,int32_t solvetime) { arith_uint256 A,B,C,bnTarget; @@ -423,7 +410,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead past = 30; if ( zflags[0] == 0 ) { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); + //bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,3,4,3,past); if ( bnTarget < origtarget ) zawyflag = 2; } From 04673f764e3961920f2b003881d09d461b9f8840 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 19:57:10 -1100 Subject: [PATCH 105/120] Simplify, try to reduce variance --- src/pow.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index cd5ae8636..458b3789c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -194,7 +194,7 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa bnTarget = ct[0]; for (i=1; i 2 ) - bnTarget = (bnTarget / arith_uint256(3)) * arith_uint256(2); - else if ( factor == 2 ) - bnTarget = (bnTarget / arith_uint256(4)) * arith_uint256(3); - if ( 1 && bnTarget > mintarget ) + bnTarget = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); + if ( bnTarget > mintarget ) bnTarget = mintarget; - fprintf(stderr,"inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + } + fprintf(stderr," inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); } return(bnTarget); } From 1bfd4a9fa376b106d92eaa0a5b641ae9393d116a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 20:06:02 -1100 Subject: [PATCH 106/120] Activate 7 and 12 --- src/pow.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 458b3789c..ead3ec965 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -206,15 +206,15 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa return(bnTarget); } -arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri) +arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t W,int32_t outeri) { arith_uint256 mintarget; int32_t expected,factor,elapsed,width = outeri+W; expected = (width+1) * T; if ( (elapsed= (ts[0] - ts[width])) < expected ) { - mintarget = (bnTarget / arith_uint256(5)) * arith_uint256(4); + mintarget = (bnTarget / arith_uint256(11)) * arith_uint256(10); bnTarget = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W); - if ( bnTarget > mintarget ) + if ( bnTarget > mintarget ) // force zawyflag to 1 bnTarget = mintarget; { int32_t z; @@ -281,13 +281,6 @@ arith_uint256 zawy_TSA_EMA(int32_t height,int32_t tipdiff,arith_uint256 prevTarg B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2)); C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2)); bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T); - if ( 0 ) - { - if ( solvetime < T/2 ) - bnTarget = (bnTarget * arith_uint256(2)) / arith_uint256(3); - else if ( solvetime > T*2 ) - bnTarget = (bnTarget * arith_uint256(3)) / arith_uint256(2); - } { int32_t z; for (z=31; z>=0; z--) @@ -408,6 +401,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,3,4,3,past); if ( bnTarget < origtarget ) zawyflag = 2; + else + { + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); + if ( bnTarget < origtarget ) + zawyflag = 2; + else + { + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); + if ( bnTarget < origtarget ) + zawyflag = 2; + } + } } else { @@ -416,7 +421,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead break; if ( i < past ) { - bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past,i); + bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); if ( bnTarget != origtarget ) zawyflag = 1; } @@ -456,7 +461,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); + fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } if ( zawyflag == 0 && mult <= 1 ) bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); From d5750228f1ad2a2b9422411b462c1b00da35402b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 20:12:52 -1100 Subject: [PATCH 107/120] Set past --- src/pow.cpp | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ead3ec965..87f629029 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -403,12 +403,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); + past += 10; + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); + past += 10; + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past); if ( bnTarget < origtarget ) zawyflag = 2; } @@ -416,35 +418,23 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { - for (i=0; inTime,bnTarget,ts,ct,3,i); + bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i); + bnTarget12 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,12,i); + if ( bnTarget6 < bnTarget12 ) + bnTmp = bnTarget6; + else bnTmp = bnTarget12; + if ( bnTmp < bnTarget ) + bnTarget = bnTmp; if ( bnTarget != origtarget ) zawyflag = 1; } } - /* - // bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past); - bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20); - if ( 0 ) - { - bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50); - bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); - if ( bnTarget6 < bnTarget12 ) - bnTmp = bnTarget6; - else bnTmp = bnTarget12; - if ( bnTmp < bnTarget ) - bnTarget = bnTmp; - }*/ - bnTarget = (bnTarget + ct[0]) / arith_uint256(2); - if ( bnTarget > origtarget ) - { - bnTarget = origtarget; - zawyflag = 0; - } } if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { @@ -464,7 +454,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } if ( zawyflag == 0 && mult <= 1 ) - bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); + bnTarget = zawy_TSA_EMA(height,tipdiff,ct[0],ts[0] - ts[1]); } nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; From 4cf54452b5e4a71df6a9c1498f64c1aa5a04a843 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 20:33:47 -1100 Subject: [PATCH 108/120] Back to 1/2 trigger --- src/pow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 87f629029..412af3276 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -397,8 +397,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead past = 30; if ( zflags[0] == 0 ) { - //bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,3,4,3,past); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); if ( bnTarget < origtarget ) zawyflag = 2; else From 3087cbc55296c2150cb55874fdbb54d4ad901d76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 20:37:54 -1100 Subject: [PATCH 109/120] Fix getmininginfo --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 412af3276..1a68aab5c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -388,7 +388,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { bnTarget = arith_uint256().SetCompact(nbits); - if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) ) + if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) && pblock != 0 && tipdiff > 0 ) { easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( pblock != 0 ) From b8dea3d5de602bf5d701bc38bef539dbfa48e542 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 20:47:55 -1100 Subject: [PATCH 110/120] Don't display getminingdiff in css --- src/rpc/mining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index c3317da41..741f02f7b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -415,7 +415,7 @@ UniValue genminingCSV(const UniValue& params, bool fHelp) sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"height,nTime,nBits,bnTarget,bnTargetB,diff,netdiff,solvetime\n"); + fprintf(fp,"height,nTime,nBits,bnTarget,bnTargetB,diff,solvetime\n"); height = komodo_nextheight(); for (i=0; inTime,pindex->nBits,str,str2,GetDifficulty(pindex),GetNetworkDifficulty(pindex),solvetime); + str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),solvetime); prevtime = pindex->nTime; } } From 7d9e7da3a84ee56f57a1360c98e0892f1d3b4fbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 21:03:33 -1100 Subject: [PATCH 111/120] -prints --- src/pow.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1a68aab5c..f9aed7798 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -197,18 +197,19 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa bnTarget /= arith_uint256(width * K); innerK = (K * (nTime-ts[0]) * (ts[0]-ts[width])) / (width * T * T); bnTarget *= arith_uint256(innerK); + if ( 0 ) { int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); + fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); } - fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width); return(bnTarget); } arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t W,int32_t outeri) { - arith_uint256 mintarget; int32_t expected,factor,elapsed,width = outeri+W; + arith_uint256 mintarget; int32_t expected,elapsed,width = outeri+W; expected = (width+1) * T; if ( (elapsed= (ts[0] - ts[width])) < expected ) { @@ -221,7 +222,7 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," inner outeri.%d, width.%d %d vs %d, deficit %d factor.%d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),factor); + fprintf(stderr," inner outeri.%d, width.%d %d vs %d, deficit %d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width])); } return(bnTarget); } @@ -452,8 +453,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } - if ( zawyflag == 0 && mult <= 1 ) - bnTarget = zawy_TSA_EMA(height,tipdiff,ct[0],ts[0] - ts[1]); + if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) + bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); } nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; From f51ad0b409dc7ead4eef7e94d72573b75ed90ddb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 21:19:13 -1100 Subject: [PATCH 112/120] +/-print --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index f9aed7798..20fbe4e07 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -222,7 +222,7 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," inner outeri.%d, width.%d %d vs %d, deficit %d\n",outeri,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width])); + fprintf(stderr," height.%d O.%-2d, W.%-2d width.%-2d %3d vs %3d, deficit %d tip.%d\n",height,outeri,W,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),nTime-ts[0]); } return(bnTarget); } From 47c0757729e38bbfa0abdad2e8f19d2957a978ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 22:16:58 -1100 Subject: [PATCH 113/120] Use ave bnTarget and ct[0] for TSA --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 20fbe4e07..3533ab722 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -454,7 +454,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) - bnTarget = zawy_TSA_EMA(height,tipdiff,bnTarget,ts[0] - ts[1]); + bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0])/arith_uint256(2),ts[0] - ts[1]); } nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; From b2115a226bfbcfd7c5ceacfe03db21e9214705d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Aug 2019 23:18:02 -1100 Subject: [PATCH 114/120] Adjust digishield when TSA --- src/pow.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3533ab722..b6ec783ef 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -222,7 +222,7 @@ arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTar for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]); } - fprintf(stderr," height.%d O.%-2d, W.%-2d width.%-2d %3d vs %3d, deficit %d tip.%d\n",height,outeri,W,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),nTime-ts[0]); + fprintf(stderr," height.%d O.%-2d, W.%-2d width.%-2d %4d vs %-4d, deficit %4d tip.%d\n",height,outeri,W,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),nTime-ts[0]); } return(bnTarget); } @@ -344,7 +344,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++) { - if ( zflags[i] != 0 ) + if ( zflags[i] == 1 || zflags[i] == 2 ) // I, O and if TSA made it harder ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]); } if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) // TSA @@ -396,7 +396,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { origtarget = bnTarget; past = 30; - if ( zflags[0] == 0 ) + if ( zflags[0] == 0 || zflags[0] == 3 ) { bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); if ( bnTarget < origtarget ) @@ -419,7 +419,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else { for (i=0; i<50; i++) - if ( (zflags[i] & 2) != 0 ) + if ( zflags[i] == 2 ) break; if ( i < past ) { @@ -454,7 +454,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) + { bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0])/arith_uint256(2),ts[0] - ts[1]); + zawyflag = 3; + } } nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; From 874ff693acdad2554355cd1b57e1473669288815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 01:14:24 -1100 Subject: [PATCH 115/120] Only set flag3 if TSA makes it harder --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index b6ec783ef..fe933bcfc 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -456,7 +456,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) { bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0])/arith_uint256(2),ts[0] - ts[1]); - zawyflag = 3; + if ( bnTarget < origtarget ) + zawyflag = 3; } } nbits = bnTarget.GetCompact(); From dc5bb72b53438651a8e48c019381a65877653464 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 01:21:21 -1100 Subject: [PATCH 116/120] bnTarget + ct[0] + ct[1] --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index fe933bcfc..455689949 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -455,7 +455,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) { - bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0])/arith_uint256(2),ts[0] - ts[1]); + bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0]+ct[1])/arith_uint256(3),ts[0] - ts[1]); if ( bnTarget < origtarget ) zawyflag = 3; } From b76187156446e8aa90c908eeac777a3abcfd02b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 02:11:05 -1100 Subject: [PATCH 117/120] Tweak past --- src/pow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 455689949..614b7e35c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -373,8 +373,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( zflags[i] != 0 ) - bnTmp = (ct[i] / arith_uint256(3)); + //if ( zflags[i] != 0 && zflags[0] != 0 ) + // bnTmp = (ct[i] / arith_uint256(3)); } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; @@ -395,7 +395,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( pblock != 0 ) { origtarget = bnTarget; - past = 30; + past = 20; if ( zflags[0] == 0 || zflags[0] == 3 ) { bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past); @@ -418,7 +418,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { - for (i=0; i<50; i++) + for (i=0; i<40; i++) if ( zflags[i] == 2 ) break; if ( i < past ) @@ -453,7 +453,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height); } - if ( zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) + if ( 0 && zflags[0] == 0 && zawyflag == 0 && mult <= 1 ) { bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0]+ct[1])/arith_uint256(3),ts[0] - ts[1]); if ( bnTarget < origtarget ) From e86e40a155145ff4b5eab6293f75731798f82324 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 04:35:46 -1100 Subject: [PATCH 118/120] Fix past windows, reduce exp() window from 12 to 6, for zawy20 --- src/pow.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 614b7e35c..e29b7f7a7 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -364,7 +364,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead blocktime = pindexFirst->nTime; diff = (pblock->nTime - blocktime); //fprintf(stderr,"%d ",diff); - if ( i < 12 ) + if ( i < 6 ) { diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) @@ -403,14 +403,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead zawyflag = 2; else { - past += 10; - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past+10); if ( bnTarget < origtarget ) zawyflag = 2; else { - past += 10; - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past+20); if ( bnTarget < origtarget ) zawyflag = 2; } @@ -421,7 +419,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; i<40; i++) if ( zflags[i] == 2 ) break; - if ( i < past ) + if ( i < 40 ) { bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i); From 1ec92e3df2e28b12c392a34191579a0f225cfa03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 04:36:23 -1100 Subject: [PATCH 119/120] Fix nSPV fullnode nServices --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 903ca8555..fa55e8586 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1911,7 +1911,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) PruneAndFlush(); } } - if ( KOMODO_NSPV > 0 ) + if ( KOMODO_NSPV == 0 ) { if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 ) nLocalServices |= NODE_ADDRINDEX; From 53d54c2652a055b1407b2bcb315b9f494488b0d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 04:48:40 -1100 Subject: [PATCH 120/120] Fix easy diff to set zawyflag --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e29b7f7a7..ac27e5d34 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -391,7 +391,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = arith_uint256().SetCompact(nbits); if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) && pblock != 0 && tipdiff > 0 ) { - easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + easy.SetCompact(KOMODO_MINDIFF_NBITS & (~3),&fNegative,&fOverflow); if ( pblock != 0 ) { origtarget = bnTarget; @@ -442,7 +442,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget = easy; fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height); - return(KOMODO_MINDIFF_NBITS); + return(KOMODO_MINDIFF_NBITS & (~3)); } { int32_t z;