From e58b81a475ebdf3e37ec7bac423d9b61d809b028 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 12:06:04 -1100 Subject: [PATCH 01/16] Fix miner --- src/miner.cpp | 1 + src/pow.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 676a41b57..c48af0212 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2049,6 +2049,7 @@ void static BitcoinMiner() { UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); HASHTarget.SetCompact(pblock->nBits); + hashTarget = HASHTarget; //hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } /*if ( NOTARY_PUBKEY33[0] == 0 ) diff --git a/src/pow.cpp b/src/pow.cpp index 175137f06..eecccb340 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -78,7 +78,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; - fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); + //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++) { From 527ee64eb33c7ee857de4dba4913af78657d7714 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 12:57:43 -1100 Subject: [PATCH 02/16] Fix miner bug --- src/miner.cpp | 1 + src/pow.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index c48af0212..35512a7e2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2050,6 +2050,7 @@ void static BitcoinMiner() UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); HASHTarget.SetCompact(pblock->nBits); hashTarget = HASHTarget; + savebits = pblock->nBits; //hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } /*if ( NOTARY_PUBKEY33[0] == 0 ) diff --git a/src/pow.cpp b/src/pow.cpp index eecccb340..49b0b43fe 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -112,6 +112,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,(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()); nbits = bnTarget.GetCompact(); } From 4e3e3a34e1e323640d30fb14133d7e65f648d0cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 00:38:48 -1100 Subject: [PATCH 03/16] Speed up response to higher hash rate --- src/pow.cpp | 56 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 49b0b43fe..5ad080451 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -74,8 +74,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; arith_uint256 bnTarget,bnTot {0}; - uint32_t nbits; int32_t diff,mult = 0; - if ( pindexFirst != 0 && pblock != 0 ) + uint32_t nbits,blocktime,maxdiff=0,block4diff=0; int32_t diff,mult = 0; + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); @@ -85,14 +85,21 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead arith_uint256 bnTmp; bnTmp.SetCompact(pindexFirst->nBits); bnTot += bnTmp; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && i < 12 && pblock != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 ) { - diff = pblock->nTime - pindexFirst->nTime - (8+i)*ASSETCHAINS_BLOCKTIME; - if ( diff > mult ) + blocktime = pindexFirst->nTime; + diff = (pblock->nTime - blocktime); + if ( i < 12 ) { - fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); - mult = diff; - } + if ( i == 3 ) + block4diff = diff; + diff -= (8+i)*ASSETCHAINS_BLOCKTIME; + if ( diff > mult ) + { + fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); + mult = diff; + } + } else maxdiff = diff; } pindexFirst = pindexFirst->pprev; } @@ -103,17 +110,34 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && mult > 1 ) // jl777: this test of mult > 1 failed when it was int64_t??? + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) // jl777: test of mult > 1 failed when it was int64_t??? { origtarget = bnTarget = arith_uint256().SetCompact(nbits); - bnTarget = bnTarget * arith_uint256(mult * mult); - easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( bnTarget < origtarget || bnTarget > easy ) + if ( mult > 1 ) { - 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()); + bnTarget = bnTarget * arith_uint256(mult * mult); + easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + 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()); + return(KOMODO_MINDIFF_NBITS); + } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); + } + else + { + if ( block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + { + block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; + bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); + fprintf(stderr,"4 blocks happened in %d adjust by %.4f\n",block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); + } + if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger + { + bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); + fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME); + } + } nbits = bnTarget.GetCompact(); } return(nbits); From c05c4da605336109e5056071a30887bc767e2ca7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 02:39:41 -1100 Subject: [PATCH 04/16] Simplify data --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5ad080451..ac6dce13c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -132,11 +132,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); fprintf(stderr,"4 blocks happened in %d adjust by %.4f\n",block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } - if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger + /*if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger { bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME); - } + }*/ } nbits = bnTarget.GetCompact(); } From f0fcb174f2f5df1968fada751a79069d7839c94f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 04:09:11 -1100 Subject: [PATCH 05/16] +prints --- src/pow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index ac6dce13c..022b43367 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -89,6 +89,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 == 3 ) @@ -103,7 +104,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } pindexFirst = pindexFirst->pprev; } - + fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight()); // Check we have enough blocks if (pindexFirst == NULL) return nProofOfWorkLimit; @@ -130,11 +131,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); - fprintf(stderr,"4 blocks happened in %d adjust by %.4f\n",block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); + fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } /*if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger { - bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); + bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); // way too strong fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME); }*/ } From fd5e54dc9f41df4a7883587fdc24cfeca8c71a56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 04:15:35 -1100 Subject: [PATCH 06/16] Fix bug --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 022b43367..fc8319445 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,7 +127,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else { - if ( block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); From 40f18eeca566f950993f82605b9cf1f7372785e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 04:27:44 -1100 Subject: [PATCH 07/16] -priont --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index fc8319445..fc03bf766 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -97,7 +97,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) { - fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); + //fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); mult = diff; } } else maxdiff = diff; From 3cf10af4ee810bfbfdd009ec8d5452d73b7f8ac0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 05:01:38 -1100 Subject: [PATCH 08/16] Tet --- src/main.cpp | 2 +- src/miner.cpp | 9 +++++---- src/pow.cpp | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9cffe8a76..f7dbebd58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5296,7 +5296,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 30 ) + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 || nHeight < 30 ) { if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) { diff --git a/src/miner.cpp b/src/miner.cpp index 35512a7e2..54af1d021 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -123,12 +123,13 @@ public: void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { - if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); else pblock->nTime = std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime()); // Updating time can change work required on testnet: - if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) { + if (ASSETCHAINS_ADAPTIVEPOW > 0 || consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) + { pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } } @@ -569,7 +570,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime()); //pblock->nTime = blocktime + 1; @@ -644,7 +645,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; //fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; - if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); else txNew.nLockTime = std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime()); diff --git a/src/pow.cpp b/src/pow.cpp index fc03bf766..4a918d047 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -89,7 +89,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { blocktime = pindexFirst->nTime; diff = (pblock->nTime - blocktime); - fprintf(stderr,"%d ",diff); + //fprintf(stderr,"%d ",diff); if ( i < 12 ) { if ( i == 3 ) @@ -104,7 +104,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } pindexFirst = pindexFirst->pprev; } - fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight()); + //fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight()); // Check we have enough blocks if (pindexFirst == NULL) return nProofOfWorkLimit; From 4e7be623364c2f41cb34b6f57b236f3c63658505 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 21:35:22 -1100 Subject: [PATCH 09/16] Zawy6 targetMA and exponential --- src/pow.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 4a918d047..db3e1284d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,6 +42,33 @@ 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); +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t divisor) +{ + bnTarget /= arith_uint256(divisor); + bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); + if ( bnTarget > easy ) + bnTarget = easy; + return(bnTarget); +} + +arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) +{ + int32_t i,n,modval; int64_t A = 1, B = 3600 * 100; + if ( (n= (mult/ASSETCHAINS_BLOCKTIME)) > 0 ) + { + for (i=1; i<=n; i++) + A *= 3; + } + if ( (modval= (mult % ASSETCHAINS_BLOCKTIME)) != 0 ) + { + B += (3600 * 110 * modval) / ASSETCHAINS_BLOCKTIME; + B += (3600 * 60 * modval * modval) / (ASSETCHAINS_BLOCKTIME * ASSETCHAINS_BLOCKTIME); + } + bnTarget /= arith_uint256(100 * 3600); + bnTarget *= arith_uint256(A * B); + return(bnTarget); +} + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) @@ -73,8 +100,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTarget,bnTot {0}; - uint32_t nbits,blocktime,maxdiff=0,block4diff=0; int32_t diff,mult = 0; + arith_uint256 bnTmp,bnTarget,bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; + uint32_t nbits,blocktime,maxdiff=0,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; @@ -82,7 +109,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { - arith_uint256 bnTmp; bnTmp.SetCompact(pindexFirst->nBits); bnTot += bnTmp; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 ) @@ -94,12 +120,21 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { if ( i == 3 ) block4diff = diff; + else if ( i == 6 ) + block7diff = diff; + else if ( i == 11 ) + block12diff = diff; diff -= (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) { //fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); mult = diff; } + if ( i < 4 ) + bnSum4 += bnTmp; + if ( i < 7 ) + bnSum7 += bnTmp; + bnSum12 += bnTmp; } else maxdiff = diff; } pindexFirst = pindexFirst->pprev; @@ -111,13 +146,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bool fNegative,fOverflow; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); - if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) // jl777: test of mult > 1 failed when it was int64_t??? + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { origtarget = bnTarget = arith_uint256().SetCompact(nbits); - if ( mult > 1 ) + easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( mult > 1 ) // chain is stuck case, jl777: test of mult > 1 failed when it was int64_t??? { - bnTarget = bnTarget * arith_uint256(mult * mult); - easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnTarget = zawy_exponential(bnTarget,mult); //replaces: bnTarget * arith_uint256(mult * mult); if ( bnTarget < origtarget || bnTarget > easy ) { bnTarget = easy; @@ -125,15 +160,44 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return(KOMODO_MINDIFF_NBITS); } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); } - else + else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); + bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); + bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); + if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + { + if ( bnSum4 < bnSum7 ) + bnTmp = bnSum4; + else bnTmp = bnSum7; + if ( bnSum12 < bnTmp ) + bnTmp = bnSum12; + if ( bnTmp < bnTarget ) + { + fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + bnTarget = bnTmp; + } + } + else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) + { + 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; + } + } + /*if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } - /*if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger + if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger { bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); // way too strong fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME); From a54f052342927a1ea66f3611d268e91ac508cc8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 21:37:53 -1100 Subject: [PATCH 10/16] Simplify code --- src/pow.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index db3e1284d..8dd6d7482 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -119,22 +119,26 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead 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 ) { //fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); mult = diff; } - if ( i < 4 ) - bnSum4 += bnTmp; - if ( i < 7 ) - bnSum7 += bnTmp; - bnSum12 += bnTmp; } else maxdiff = diff; } pindexFirst = pindexFirst->pprev; From b8e2d23fc8b6995bf750277d833757a944dd33ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 21:39:28 -1100 Subject: [PATCH 11/16] -print --- src/pow.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 8dd6d7482..e48e0aab1 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,bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; - uint32_t nbits,blocktime,maxdiff=0,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; + uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; @@ -139,7 +139,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead //fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i)); mult = diff; } - } else maxdiff = diff; + } } pindexFirst = pindexFirst->pprev; } @@ -201,11 +201,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } - if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger - { - bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4); // way too strong - fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME); - }*/ + */ } nbits = bnTarget.GetCompact(); } From d54c1d533054ed709e0531aa4af468d27f46bd97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 21:55:48 -1100 Subject: [PATCH 12/16] +print --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e48e0aab1..f8e793d95 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -180,7 +180,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); bnTarget = bnTmp; - } + } else fprintf(stderr,"nothing smaller\n"); } else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) { @@ -193,7 +193,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); bnTarget = bnTmp; - } + } else fprintf(stderr,"nothing bigger\n"); } /*if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { @@ -202,7 +202,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } */ - } + } else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); } return(nbits); From 1c95d3d787edf24b3f386e597f0f5f2080509d31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 22:00:07 -1100 Subject: [PATCH 13/16] -print --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index f8e793d95..a48927340 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -180,7 +180,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); bnTarget = bnTmp; - } else fprintf(stderr,"nothing smaller\n"); + } //else fprintf(stderr,"nothing smaller\n"); } else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) { @@ -193,7 +193,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); bnTarget = bnTmp; - } else fprintf(stderr,"nothing bigger\n"); + } //else fprintf(stderr,"nothing bigger\n"); } /*if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases { From 2cb3ce2690683be865170a2a8882ff038dea4075 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 22:03:04 -1100 Subject: [PATCH 14/16] Asymmetric --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index a48927340..03efbd771 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -169,7 +169,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + if ( (1) || block12diff < ASSETCHAINS_BLOCKTIME*11 ) { if ( bnSum4 < bnSum7 ) bnTmp = bnSum4; From 872fbeb0925a39c732a133c3f0d324c60852a62d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 22:15:45 -1100 Subject: [PATCH 15/16] Evert --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 03efbd771..a48927340 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -169,7 +169,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); - if ( (1) || block12diff < ASSETCHAINS_BLOCKTIME*11 ) + if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { if ( bnSum4 < bnSum7 ) bnTmp = bnSum4; From b4d67e7aad894b715ae9e6e5f961d5b245e11b7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 23:08:39 -1100 Subject: [PATCH 16/16] -print --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index a48927340..406fca63c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -202,7 +202,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2)); } */ - } else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); + } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); } return(nbits);