From ce2b6b330c64fecb79bef0c9608c8c8b3e3690e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 07:41:16 -1100 Subject: [PATCH 1/6] Steepen PoW diff easement --- src/komodo_bitcoind.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 25bd2b831..ddfe7c6eb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1332,7 +1332,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); + if ( bnTarget > easydiff ) + bnTarget = easydiff; if ( 1 ) { for (i=31; i>=24; i--) From 43ff67f5fceadd67d277ce2d028d00f65fd5097d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 08:57:03 -1100 Subject: [PATCH 2/6] Handle 100% PoS for -ac_target = < 100 --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ddfe7c6eb..e9bcb0389 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1313,7 +1313,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ave = (sum / arith_uint256(n)); if ( ave > target ) ave = target; - } else return(target); + } else ave = easydiff; //else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); From 4cc33bf81ee66f3e864b53c170663c440b44e80c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:10:51 -1100 Subject: [PATCH 3/6] Test --- src/komodo_bitcoind.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bcb0389..58b037a62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,19 +1267,37 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; + CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - for (i=n=0; i<100; i++) + for (i=n=m=0; i<100; i++) { ht = height - 100 + i; if ( ht <= 1 ) continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + if ( komodo_segid(ht) >= 0 ) + { + n++; + percPoS++; + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"0"); + } + else + { + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"1"); + sum += hashval; + m++; + n++; + } + } + /*if ( (pindex= komodo_chainactive(ht)) != 0 ) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); @@ -1298,9 +1316,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); } - if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) - fprintf(stderr," %d, ",percPoS); - } + }*/ + if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) + fprintf(stderr," %d, ",percPoS); } if ( n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; @@ -1308,9 +1326,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); - if ( n > 0 ) + if ( m > 0 ) { - ave = (sum / arith_uint256(n)); + ave = (sum / arith_uint256(m)); if ( ave > target ) ave = target; } else ave = easydiff; //else return(target); From 153a7898146c872ac4647b4f68184670bf0d662c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:12:39 -1100 Subject: [PATCH 4/6] Neutral diff for PoW --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58b037a62..3eff2a882 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1104,9 +1104,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] - PoW mining on PoS chain must solve a harder diff that adjusts, but never less than KOMODO_POWMINMULT */ -#define KOMODO_POWMINMULT 16 +//#define KOMODO_POWMINMULT 16 uint64_t komodo_commission(const CBlock *pblock) { @@ -1325,7 +1324,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; - target = (target / arith_uint256(KOMODO_POWMINMULT)); + //target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( m > 0 ) { ave = (sum / arith_uint256(m)); From 9e1a6d76c4e0b72d1d0ffabb1888932ca08d50f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:45:35 -1100 Subject: [PATCH 5/6] Fix null hashval --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3eff2a882..f405f2571 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1291,7 +1291,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"1"); - sum += hashval; + sum += UintToArith256(pindex->GetBlockHash()); m++; n++; } From ae2d90651b0651ac548bba99a934d91032b4e790 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 10:09:58 -1100 Subject: [PATCH 6/6] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f405f2571..afd1fe46e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1351,7 +1351,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); - if ( bnTarget > easydiff ) + if ( bnTarget > easydiff || bnTarget < ave ) bnTarget = easydiff; if ( 1 ) {