From 37ea8361fdec0a8c60611881478cba9c10bad3ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 06:53:57 -1100 Subject: [PATCH 1/5] Zawy21 changes --- src/pow.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ac27e5d34..d6cbc2e19 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 && zflags[0] != 0 ) - // bnTmp = (ct[i] / arith_uint256(3)); + if ( zflags[i] != 0 && zflags[0] == 0 ) + bnTmp = (bnTmp / arith_uint256(8)) * arith_uint256(7); } bnTot += bnTmp; pindexFirst = pindexFirst->pprev; @@ -403,12 +403,12 @@ 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,past+10); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past+15); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past+20); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past+30); if ( bnTarget < origtarget ) zawyflag = 2; } @@ -416,19 +416,22 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { - for (i=0; i<40; i++) + for (i=0; i<50; i++) if ( zflags[i] == 2 ) break; - if ( i < 40 ) + if ( i < 50 ) { - 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); + if ( i < 20 ) + bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); + if ( i < 35 ) + { + bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i); + if ( bnTarget6 < bnTarget ) + bnTarget = bnTarget6; + } 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 ( bnTarget12 < bnTarget) + bnTarget = bnTarget12; if ( bnTarget != origtarget ) zawyflag = 1; } From 738cc59a31c2e55f2368da7f8b31da317a51bfdb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Aug 2019 07:08:33 -1100 Subject: [PATCH 2/5] Fix outer loop --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index d6cbc2e19..188961e8b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -168,7 +168,7 @@ arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget 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 ) + if ( (ts[0] - ts[W+1]) < (T * numerator)/denominator ) { outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); if ( outerK < K ) From 68ff506c325527d0c13564092644b0f940204c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Aug 2019 04:37:58 -1100 Subject: [PATCH 3/5] Zawy22, add W=2 --- src/pow.cpp | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 188961e8b..eb6bd91e2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -322,7 +322,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],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget3,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)); @@ -373,7 +373,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead mult = diff; } } - if ( zflags[i] != 0 && zflags[0] == 0 ) + if ( zflags[i] != 0 && zflags[0] == 0 ) // an RST block, but the most recent has no RST bnTmp = (bnTmp / arith_uint256(8)) * arith_uint256(7); } bnTot += bnTmp; @@ -384,7 +384,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; + 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 ) { @@ -395,22 +395,27 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( pblock != 0 ) { origtarget = bnTarget; - past = 20; if ( zflags[0] == 0 || zflags[0] == 3 ) { - 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,15,100,2,20); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past+15); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,30); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past+30); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,40); 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; + } } } } @@ -419,22 +424,28 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; i<50; i++) if ( zflags[i] == 2 ) break; + if ( i < 20 ) + bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,2,i); + if ( i < 30 ) + { + bnTarget3 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); + if ( bnTarget3 < bnTarget ) + bnTarget = bnTarget3; + } + if ( i < 40 ) + { + bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i); + if ( bnTarget6 < bnTarget ) + bnTarget = bnTarget6; + } if ( i < 50 ) { - if ( i < 20 ) - bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); - if ( i < 35 ) - { - bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i); - if ( bnTarget6 < bnTarget ) - bnTarget = bnTarget6; - } bnTarget12 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,12,i); if ( bnTarget12 < bnTarget) bnTarget = bnTarget12; - if ( bnTarget != origtarget ) - zawyflag = 1; } + if ( bnTarget != origtarget ) + zawyflag = 1; } } if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? From 8f815d2b81242540a47fe5a2b56fa9fea73f6a20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Aug 2019 00:20:34 -1100 Subject: [PATCH 4/5] Zawy23 --- src/pow.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index eb6bd91e2..096188609 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -168,7 +168,7 @@ arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget 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+1]) < (T * numerator)/denominator ) + if ( (ts[0] - ts[W]) < (T * numerator)/denominator ) { outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T)); if ( outerK < K ) @@ -183,7 +183,7 @@ arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTar 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); + fprintf(stderr," ht.%d initial W.%d outerK.%lld %d * %d * %d / %d\n",height,W,(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); } @@ -322,7 +322,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],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget3,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget2,bnTarget3,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)); @@ -397,24 +397,30 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead origtarget = bnTarget; if ( zflags[0] == 0 || zflags[0] == 3 ) { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,15,100,2,20); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,60,1,10); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,30); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,15,100,2,20); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,40); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,1,2,3,30); if ( bnTarget < origtarget ) zawyflag = 2; else { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50); + bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,7,3,6,40); if ( bnTarget < origtarget ) zawyflag = 2; + else + { + bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,12,7,12,50); + if ( bnTarget < origtarget ) + zawyflag = 2; + } } } } @@ -424,8 +430,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead for (i=0; i<50; i++) if ( zflags[i] == 2 ) break; + if ( i < 10 ) + { + bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,i); + if ( bnTarget > origtarget ) + bnTarget = origtarget; + } if ( i < 20 ) - bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,2,i); + { + bnTarget2 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,2,i); + if ( bnTarget2 < bnTarget ) + bnTarget = bnTarget2; + } if ( i < 30 ) { bnTarget3 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i); From ac4d149b0a448f97276134ef141719691acf4463 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Aug 2019 00:43:20 -1100 Subject: [PATCH 5/5] Handle W=1 for ranges of T --- src/pow.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 096188609..a99fcc05c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -397,7 +397,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead origtarget = bnTarget; if ( zflags[0] == 0 || zflags[0] == 3 ) { - bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,60,1,10); + if ( ASSETCHAINS_BLOCKTIME >= 60 && ASSETCHAINS_BLOCKTIME < 100 ) + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,60,1,10); + else if ( ASSETCHAINS_BLOCKTIME >= 100 ) + bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,100,1,10); if ( bnTarget < origtarget ) zawyflag = 2; else