From 0c8f9b372921e1aa37a94b40ac35181b5583a831 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:29:07 -1100 Subject: [PATCH 001/108] Add version field --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_defs.h | 2 ++ src/komodo_nSPV_fullnode.h | 1 + src/komodo_nSPV_superlite.h | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9b23cb018..f88afd6c1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -286,6 +286,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->version),&ptr->version); //fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 8eeed8292..a27af170b 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -17,6 +17,7 @@ #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH +#define NSPV_PROTOCOL_VERSION 0x0001 #define NSPV_POLLITERS 100 #define NSPV_POLLMICROS 30000 #define NSPV_MAXVINS 64 @@ -124,6 +125,7 @@ struct NSPV_inforesp uint256 blockhash; int32_t height,hdrheight; struct NSPV_equihdr H; + uint32_t version; }; struct NSPV_txproof diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 5e4ec0b25..897762c3a 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -133,6 +133,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) if ( reqheight == 0 ) reqheight = ptr->height; ptr->hdrheight = reqheight; + ptr->version = NSPV_PROTOCOL_VERSION; if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 ) return(-1); return(sizeof(*ptr)); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d7f11c41b..316a51e45 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -139,7 +139,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + fprintf(stderr,"got version.%d info response %u size.%d height.%d\n",NSPV_inforesult.version,timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status I = NSPV_inforesult; NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); From fdf6f610f9201cef20cff2734b4e14977ed8c868 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:34:57 -1100 Subject: [PATCH 002/108] Add version to netinfo --- src/komodo_nSPV_superlite.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 316a51e45..2babc69a7 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -370,6 +370,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); + result.push_back(Pair("protocolversion",ptr->version)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } From 71610bb2661b74cab2c4fa022cb9e3db9a23a42a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:47:23 -1100 Subject: [PATCH 003/108] Version --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 897762c3a..424a7ce89 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -538,7 +538,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - //fprintf(stderr,"slen.%d\n",slen); + fprintf(stderr,"version.%d\n",I.version); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); From fe89e15065de2dc70d8e2be4e76979ed4816f022 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:47:51 -1100 Subject: [PATCH 004/108] Test --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 2babc69a7..24ceeb6b8 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -370,7 +370,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); - result.push_back(Pair("protocolversion",ptr->version)); + result.push_back(Pair("protocolversion",(int64_t)ptr->version)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } From 8d37c1e4d19f3b41dca04024a9e6ad9963208f37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:48:49 -1100 Subject: [PATCH 005/108] -print --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 424a7ce89..8dbf40d68 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -538,7 +538,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - fprintf(stderr,"version.%d\n",I.version); + //fprintf(stderr,"version.%d\n",I.version); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); From 40cb65a9370426cac28ee4d34c54a2483ca55063 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:52:45 -1100 Subject: [PATCH 006/108] Getoinfo --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f88afd6c1..8c65dc772 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -287,7 +287,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->version),&ptr->version); -//fprintf(stderr,"hdr rwlen.%d\n",len); +fprintf(stderr,"getinfo rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 8dbf40d68..d5e741ebf 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -538,10 +538,10 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - //fprintf(stderr,"version.%d\n",I.version); + fprintf(stderr,"slen.%d version.%d\n",slen,I.version); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { - //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); + fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From a62de7f72b4e57b1903938c679af58ed4e86222e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jul 2019 04:56:21 -1100 Subject: [PATCH 007/108] -print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8c65dc772..4695133c7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -287,7 +287,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->version),&ptr->version); -fprintf(stderr,"getinfo rwlen.%d\n",len); +//fprintf(stderr,"getinfo rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d5e741ebf..ff3156f37 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -538,10 +538,10 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - fprintf(stderr,"slen.%d version.%d\n",slen,I.version); + //fprintf(stderr,"slen.%d version.%d\n",slen,I.version); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { - fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); + //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } From e67ede9c3d3f0d120d576466d487355285fa8c21 Mon Sep 17 00:00:00 2001 From: Alrighttt <36680730+Alrighttt@users.noreply.github.com> Date: Sat, 27 Jul 2019 20:59:53 +0200 Subject: [PATCH 008/108] Revert "payments cc fix" --- src/cc/payments.cpp | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index e329ff5bf..17507a80e 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -75,36 +75,6 @@ */ -// payments cc fix -#if (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) - #undef mpz_set_si - #undef mpz_get_si - #define GMP_LIMB_HIGHBIT ((mp_limb_t) 1 << (GMP_LIMB_BITS - 1)) - #define GMP_NEG_CAST(T,x) (-(int64_t)((T)((x) + 1) - 1)) - - int64_t mpz_get_si (const mpz_t u) - { - mp_size_t us = u->_mp_size; - if (us > 0) - return (int64_t) (u->_mp_d[0] & ~GMP_LIMB_HIGHBIT); - else if (us < 0) - return (int64_t) (- u->_mp_d[0] | GMP_LIMB_HIGHBIT); - else - return 0; - } - - void mpz_set_si (mpz_t r, int64_t x) - { - if (x >= 0) - mpz_set_ui (r, x); - else /* (x < 0) */ - { - r->_mp_size = -1; - r->_mp_d[0] = GMP_NEG_CAST (uint64_t, x); - } - } -#endif - // start of consensus code CScript EncodePaymentsTxidOpRet(int64_t allocation,std::vector scriptPubKey,std::vector destopret) From 914349db60539f386eb6d6dcb8155a6c2c980423 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Jul 2019 00:46:56 +0800 Subject: [PATCH 009/108] add timestamp to getinfo notarizations --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_defs.h | 1 + src/komodo_nSPV_fullnode.h | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9b23cb018..337a61c7f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -255,6 +255,7 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->othertxid),(uint8_t *)&ptr->othertxid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->txidheight),&ptr->txidheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->timestamp),&ptr->timestamp); return(len); } diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 8eeed8292..164ea081a 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -110,6 +110,7 @@ struct NSPV_ntz { uint256 blockhash,txid,othertxid; int32_t height,txidheight; + uint32_t timestamp; }; struct NSPV_ntzsresp diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 5e4ec0b25..00bd099b3 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -121,7 +121,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) { - int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; + int32_t prevMoMheight,len = 0; CBlockIndex *pindex, *pindex2; struct NSPV_ntzsresp pair; if ( (pindex= chainActive.LastTip()) != 0 ) { ptr->height = pindex->GetHeight(); @@ -130,6 +130,9 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) return(-1); ptr->notarization = pair.prevntz; + if ( (pindex2= komodo_chainactive(ptr->notarization.txidheight)) != 0 ) + ptr->notarization.timestamp = pindex->nTime; + fprintf(stderr, "timestamp.%i\n", ptr->notarization.timestamp ); if ( reqheight == 0 ) reqheight = ptr->height; ptr->hdrheight = reqheight; From 4642c0809447e01b969ccce0dce0b9d7c6161634 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jul 2019 06:10:57 -1100 Subject: [PATCH 010/108] Update nspv version --- src/komodo_nSPV_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index bcefcbc95..282e58cab 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -17,7 +17,7 @@ #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH -#define NSPV_PROTOCOL_VERSION 0x0001 +#define NSPV_PROTOCOL_VERSION 0x00000002 #define NSPV_POLLITERS 100 #define NSPV_POLLMICROS 30000 #define NSPV_MAXVINS 64 From 21c8e021475eff8eb3a5bc8478b0c5ffac75c645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jul 2019 06:31:53 -1100 Subject: [PATCH 011/108] -print --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 50f0f8c56..30b11ecb5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -132,7 +132,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) ptr->notarization = pair.prevntz; if ( (pindex2= komodo_chainactive(ptr->notarization.txidheight)) != 0 ) ptr->notarization.timestamp = pindex->nTime; - fprintf(stderr, "timestamp.%i\n", ptr->notarization.timestamp ); + //fprintf(stderr, "timestamp.%i\n", ptr->notarization.timestamp ); if ( reqheight == 0 ) reqheight = ptr->height; ptr->hdrheight = reqheight; From edcba6791ff047648a127ee9284ec0e2f2376910 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Jul 2019 04:27:09 +0800 Subject: [PATCH 012/108] fix other notarizations --- src/komodo_nSPV_fullnode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 00bd099b3..bc2a6a02f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -69,11 +69,14 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight) { + CBlockIndex *pindex; ptr->blockhash = *chainActive[ntzheight]->phashBlock; ptr->height = ntzheight; ptr->txidheight = txidht; ptr->othertxid = desttxid; ptr->txid = ntztxid; + if ( (pindex= komodo_chainactive(ptr->txidheight)) != 0 ) + ptr->timestamp = pindex->nTime; return(0); } From 20f9a16c8015b15febee76ac1d1fd493016526a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 07:08:10 -1100 Subject: [PATCH 013/108] -ac_adaptivepow --- src/komodo_defs.h | 2 +- src/komodo_utils.h | 5 ++++- src/pow.cpp | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 52d76c88c..d1ee2fb46 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -261,7 +261,7 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = //#define PRICES_DAYWINDOW (7) //#endif -extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; +extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC,ASSETCHAINS_ADAPTIVEPOW; int32_t MAX_BLOCK_SIZE(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4ab61b4eb..31e87d82b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1879,6 +1879,7 @@ void komodo_args(char *argv0) ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); + ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0); //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); if ( ASSETCHAINS_CBOPRET != 0 ) { @@ -2065,7 +2066,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -2214,6 +2215,8 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY); } + if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + extraptr[extralen++] = ASSETCHAINS_ADAPTIVEPOW; } addn = GetArg("-seednode",""); diff --git a/src/pow.cpp b/src/pow.cpp index 6f5476abe..a2d1f7327 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -453,6 +453,18 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t arith_uint256 bnMaxPoSdiff; bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + { + arith_uint256 origtarget; + uint32_t elapsed = (blkHeader.nTime - komodo_heightstamp(height)); + if ( elapsed > 777 ) + { + elapsed -= 777; + bnTarget = bnTarget / arith_uint256(elapsed * elapsed); + if ( bnTarget > origtarget ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + } + } // Check proof of work matches claimed amount if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) { From 35f7f057ca658574f742f209a30cc8bb64c54974 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 07:13:29 -1100 Subject: [PATCH 014/108] Tweak -ac_adaptivepow --- src/pow.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index a2d1f7327..09fdf0c9c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -456,13 +456,16 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) { arith_uint256 origtarget; - uint32_t elapsed = (blkHeader.nTime - komodo_heightstamp(height)); + uint32_t elapsed = (blkHeader.nTime - komodo_heightstamp(height-1)); if ( elapsed > 777 ) { elapsed -= 777; - bnTarget = bnTarget / arith_uint256(elapsed * elapsed); - if ( bnTarget > origtarget ) + bnTarget = bnTarget * arith_uint256(elapsed * elapsed); + if ( bnTarget < origtarget ) // deal with underflow + { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + fprintf(stderr,"underflowed, set to mindiff\n"); + } else fprintf(stderr,"elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed); } } // Check proof of work matches claimed amount From 70d31f3dd796155ac717edf8c5c15aba3792d3dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 08:17:03 -1100 Subject: [PATCH 015/108] Mine to the adjusted target --- src/miner.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6f90127cf..ddb1a4bb7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1447,6 +1447,21 @@ void static BitcoinMiner_noeq() HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + { + arith_uint256 origtarget; + uint32_t elapsed = (pblock->nTime - komodo_heightstamp(Mining_height-1)); + if ( elapsed > 777 ) + { + elapsed -= 777; + HASHTarget_POW = HASHTarget * arith_uint256(elapsed * elapsed); + if ( bnTarget < origtarget ) // deal with underflow + { + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + fprintf(stderr,"miner underflowed, set to mindiff\n"); + } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed); + } + } while (true) { @@ -1480,7 +1495,9 @@ void static BitcoinMiner_noeq() } else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 ) hashTarget = HASHTarget; - + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + hashTarget = HASHTarget_POW; + // for speed check NONCEMASK at a time for (i = 0; i < count; i++) { From 439fee9bc7a0d1111aba7971c58e68996d18da21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 08:18:24 -1100 Subject: [PATCH 016/108] ASSETCHAINS_ADAPTIVEPOW --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 22f991edd..de42f12b1 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -50,7 +50,7 @@ uint256 KOMODO_EARLYTXID; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA,ASSETCHAINS_ADAPTIVEPOW; bool VERUS_MINTBLOCKS; std::vector Mineropret; std::vector vWhiteListAddress; From 5d19239884adf5ebbabdee5cacda5ada89121a95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 08:21:00 -1100 Subject: [PATCH 017/108] Set origtargert --- src/miner.cpp | 5 +++-- src/pow.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ddb1a4bb7..791b8ba18 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1449,13 +1449,14 @@ void static BitcoinMiner_noeq() } else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) { - arith_uint256 origtarget; + arith_uint256 origtarget; bool fNegative,fOverflow; uint32_t elapsed = (pblock->nTime - komodo_heightstamp(Mining_height-1)); if ( elapsed > 777 ) { elapsed -= 777; + origtarget = HASHTarget; HASHTarget_POW = HASHTarget * arith_uint256(elapsed * elapsed); - if ( bnTarget < origtarget ) // deal with underflow + if ( HASHTarget < origtarget ) // deal with underflow { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"miner underflowed, set to mindiff\n"); diff --git a/src/pow.cpp b/src/pow.cpp index 09fdf0c9c..47d538031 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -460,6 +460,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t if ( elapsed > 777 ) { elapsed -= 777; + origtarget = bnTarget; bnTarget = bnTarget * arith_uint256(elapsed * elapsed); if ( bnTarget < origtarget ) // deal with underflow { From b55da040258852a5b81f4232b9ec948ee25e1a13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 08:22:32 -1100 Subject: [PATCH 018/108] HASHTarget_POW --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 791b8ba18..16500b60d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1456,9 +1456,9 @@ void static BitcoinMiner_noeq() elapsed -= 777; origtarget = HASHTarget; HASHTarget_POW = HASHTarget * arith_uint256(elapsed * elapsed); - if ( HASHTarget < origtarget ) // deal with underflow + if ( HASHTarget_POW < origtarget ) // deal with underflow { - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + HASHTarget_POW.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"miner underflowed, set to mindiff\n"); } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed); } From 02e68518706699bf266a986eab4cd6886733e1a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 21:25:49 -1100 Subject: [PATCH 019/108] Update adaptivepow to handle variable block times --- src/komodo_bitcoind.h | 23 +++++++++++++++++++++++ src/komodo_defs.h | 1 + src/miner.cpp | 18 ++---------------- src/pow.cpp | 16 +--------------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d34b626c6..0533192a8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1416,6 +1416,29 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 return(addrhash.uints[0]); } +arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime) +{ + arith_uint256 origtarget,easy; int32_t diff,mult; bool fNegative,fOverflow; CBlockIndex *tipindex; + if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) + { + diff = (nTime - tipindex->GetMedianTimePast()); + if ( diff > 20 * ASSETCHAINS_BLOCKTIME ) + { + mult = diff - 19 * ASSETCHAINS_BLOCKTIME; + mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 3; + origtarget = bnTarget; + bnTarget = bnTarget * arith_uint256(mult * mult); + easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow + { + bnTarget = easy; + fprintf(stderr,"miner overflowed, set to mindiff\n"); + } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",diff,mult); + } + } + return(bnTarget); +} + arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { int32_t oldflag = 0,dispflag = 0; diff --git a/src/komodo_defs.h b/src/komodo_defs.h index d1ee2fb46..9d891eeda 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -337,6 +337,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height); +arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime); uint256 Parseuint256(const char *hexstr); diff --git a/src/miner.cpp b/src/miner.cpp index 16500b60d..04d93fd9c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1448,22 +1448,8 @@ void static BitcoinMiner_noeq() LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) - { - arith_uint256 origtarget; bool fNegative,fOverflow; - uint32_t elapsed = (pblock->nTime - komodo_heightstamp(Mining_height-1)); - if ( elapsed > 777 ) - { - elapsed -= 777; - origtarget = HASHTarget; - HASHTarget_POW = HASHTarget * arith_uint256(elapsed * elapsed); - if ( HASHTarget_POW < origtarget ) // deal with underflow - { - HASHTarget_POW.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - fprintf(stderr,"miner underflowed, set to mindiff\n"); - } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed); - } - } - + HASHTarget_POW = komodo_adaptivepow_target(height,HASHTarget,pblock->nTime); + while (true) { arith_uint256 arNonce = UintToArith256(pblock->nNonce); diff --git a/src/pow.cpp b/src/pow.cpp index 47d538031..bc862b835 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -454,21 +454,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) - { - arith_uint256 origtarget; - uint32_t elapsed = (blkHeader.nTime - komodo_heightstamp(height-1)); - if ( elapsed > 777 ) - { - elapsed -= 777; - origtarget = bnTarget; - bnTarget = bnTarget * arith_uint256(elapsed * elapsed); - if ( bnTarget < origtarget ) // deal with underflow - { - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - fprintf(stderr,"underflowed, set to mindiff\n"); - } else fprintf(stderr,"elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed); - } - } + bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); // Check proof of work matches claimed amount if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) { From fc47ea72e715f2b9b3e302ec4945f83b030c40f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 21:42:10 -1100 Subject: [PATCH 020/108] Modify bitcoinminer --- src/miner.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 04d93fd9c..14c666a07 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1448,7 +1448,7 @@ void static BitcoinMiner_noeq() LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) - HASHTarget_POW = komodo_adaptivepow_target(height,HASHTarget,pblock->nTime); + HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); while (true) { @@ -1820,6 +1820,8 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED < 100 ) LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); } + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); gotinvalid = 0; while (true) { @@ -1847,6 +1849,8 @@ void static BitcoinMiner() arith_uint256 hashTarget; if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = #ifdef ENABLE_WALLET @@ -2036,6 +2040,8 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; + if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + UpdateTime(pblock, consensusParams, pindexPrev); /*if ( NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS; From cb90a6d2769b67f88148ea05aa88ac9d80596e9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 21:51:28 -1100 Subject: [PATCH 021/108] chainparams.GetConsensus() --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 14c666a07..19e853479 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2041,7 +2041,7 @@ void static BitcoinMiner() pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) - UpdateTime(pblock, consensusParams, pindexPrev); + UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); /*if ( NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS; From b12e3b07dd2f1dbac1d0b7933dacfbcc10cd6b93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 22:27:35 -1100 Subject: [PATCH 022/108] #include "arith_uint256.h" --- src/komodo_defs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 9d891eeda..10d71ea96 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -15,6 +15,8 @@ #ifndef KOMODO_DEFS_H #define KOMODO_DEFS_H +#include "arith_uint256.h" + #include "komodo_nk.h" #define KOMODO_EARLYTXID_HEIGHT 100 From 8d8db33d1532b3be2103073ef21909843e52574b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 23:25:05 -1100 Subject: [PATCH 023/108] Check Pow in komodo_checkpow --- src/komodo_bitcoind.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0533192a8..84b8eaaf1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1418,7 +1418,7 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime) { - arith_uint256 origtarget,easy; int32_t diff,mult; bool fNegative,fOverflow; CBlockIndex *tipindex; + arith_uint256 origtarget,easy; int32_t diff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex; if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) { diff = (nTime - tipindex->GetMedianTimePast()); @@ -1432,8 +1432,8 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow { bnTarget = easy; - fprintf(stderr,"miner overflowed, set to mindiff\n"); - } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",diff,mult); + fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); + } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",diff,(long long)mult); } } return(bnTarget); @@ -2268,6 +2268,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } hash = pblock->GetHash(); bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); if ( height == 0 ) From b38bc73ebdfcb7dc86a597d591bd1248c7f46a4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jul 2019 23:26:54 -1100 Subject: [PATCH 024/108] Print --- 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 84b8eaaf1..f146d0d03 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1433,7 +1433,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui { bnTarget = easy; fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); - } else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",diff,(long long)mult); + } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); } } return(bnTarget); From 41f4f5daee759484c044efb9036200489b95f189 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 00:58:12 -1100 Subject: [PATCH 025/108] +prints --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f146d0d03..0e8c700a8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1435,7 +1435,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); } - } + } else fprintf(stderr,"cant find height.%d\n",height); return(bnTarget); } @@ -2268,8 +2268,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } hash = pblock->GetHash(); bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) - bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); if ( height == 0 ) @@ -2285,6 +2283,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( height == 0 ) return(0); } + if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget ) { // if proof of stake is active, check if this is a valid PoS block before we fail From dd17d299b11292739cf3e446146e3797fe137872 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 01:40:17 -1100 Subject: [PATCH 026/108] -print --- src/komodo_bitcoind.h | 2 +- src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0e8c700a8..0df145eee 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1435,7 +1435,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); } - } else fprintf(stderr,"cant find height.%d\n",height); + } //else fprintf(stderr,"cant find height.%d\n",height); return(bnTarget); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 24ceeb6b8..51fc373df 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -587,7 +587,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32 { UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); - if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount && filter == NSPV_utxosresult.filter ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); if ( skipcount < 0 ) skipcount = 0; From b065c7ed26807ec8080ef07c65044992afb9591b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 01:45:07 -1100 Subject: [PATCH 027/108] Remove utxo caching --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 51fc373df..29e60aa75 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -587,8 +587,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32 { UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); - if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount && filter == NSPV_utxosresult.filter ) - return(NSPV_utxosresp_json(&NSPV_utxosresult)); + //if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount && filter == NSPV_utxosresult.filter ) + // return(NSPV_utxosresp_json(&NSPV_utxosresult)); if ( skipcount < 0 ) skipcount = 0; NSPV_utxosresp_purge(&NSPV_utxosresult); From fbd69abd802e33a15434eac3fdd609d1adff9679 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 03:37:46 -1100 Subject: [PATCH 028/108] +print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0df145eee..f1caf47c0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1434,8 +1434,8 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui bnTarget = easy; fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); - } - } //else fprintf(stderr,"cant find height.%d\n",height); + } else fprintf(stderr,"diff %d, vs 120\n",diff); + } else fprintf(stderr,"cant find height.%d\n",height); return(bnTarget); } From ab9169210ba36e6ff434cd09d413f2504fc022c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:06:18 -1100 Subject: [PATCH 029/108] Test changing of default --- src/komodo_utils.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 31e87d82b..d2a9e12a1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2431,6 +2431,14 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_DICE); CCENABLE(EVAL_ORACLES); } + if ( (pindex= komodo_activechain(1)) != 0 ) + { + if ( pindex->nTime > 1564499104 ) + { + ASSETCHAINS_ADAPTIVEPOW = 1; + fprintf(stderr,"default activate adaptivepow\n"); + } + } else fprintf(stderr,"cant find height 1\n"); } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) From 96d9bcb45ebc788fb17b2f4e527fd47154024364 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:07:34 -1100 Subject: [PATCH 030/108] Test timestamp --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d2a9e12a1..8f9ece3a0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2433,7 +2433,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } if ( (pindex= komodo_activechain(1)) != 0 ) { - if ( pindex->nTime > 1564499104 ) + if ( pindex->nTime > 1564499104-365*2*1440 ) { ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); From 6fbae7109cf99a0b78288bec490af20f23d4b1b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:09:37 -1100 Subject: [PATCH 031/108] Allow disabling adaptivepow --- src/komodo_bitcoind.h | 2 +- src/komodo_globals.h | 3 ++- src/komodo_utils.h | 2 +- src/miner.cpp | 10 +++++----- src/pow.cpp | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f1caf47c0..2e4461e7b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2283,7 +2283,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( height == 0 ) return(0); } - if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index de42f12b1..817e51027 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -50,7 +50,8 @@ uint256 KOMODO_EARLYTXID; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA,ASSETCHAINS_ADAPTIVEPOW; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; +int8_t ASSETCHAINS_ADAPTIVEPOW; bool VERUS_MINTBLOCKS; std::vector Mineropret; std::vector vWhiteListAddress; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8f9ece3a0..9e470c657 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2431,7 +2431,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_DICE); CCENABLE(EVAL_ORACLES); } - if ( (pindex= komodo_activechain(1)) != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_activechain(1)) != 0 ) { if ( pindex->nTime > 1564499104-365*2*1440 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 19e853479..05a24ca2f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1447,7 +1447,7 @@ void static BitcoinMiner_noeq() HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); while (true) @@ -1482,7 +1482,7 @@ void static BitcoinMiner_noeq() } else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 ) hashTarget = HASHTarget; - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) hashTarget = HASHTarget_POW; // for speed check NONCEMASK at a time @@ -1820,7 +1820,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED < 100 ) LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); } - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); gotinvalid = 0; while (true) @@ -1849,7 +1849,7 @@ void static BitcoinMiner() arith_uint256 hashTarget; if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = @@ -2040,7 +2040,7 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); /*if ( NOTARY_PUBKEY33[0] == 0 ) { diff --git a/src/pow.cpp b/src/pow.cpp index bc862b835..18fda549f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -453,7 +453,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t arith_uint256 bnMaxPoSdiff; bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 ) + else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); // Check proof of work matches claimed amount if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) From 4c0e78bde3048a778d7071375a91ad581f513e95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:14:22 -1100 Subject: [PATCH 032/108] Syntax --- src/komodo_defs.h | 3 ++- src/komodo_utils.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 10d71ea96..c6150f905 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -263,7 +263,8 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = //#define PRICES_DAYWINDOW (7) //#endif -extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC,ASSETCHAINS_ADAPTIVEPOW; +extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; +extern int8_t ASSETCHAINS_ADAPTIVEPOW; int32_t MAX_BLOCK_SIZE(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9e470c657..0e3cbe577 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2433,6 +2433,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_activechain(1)) != 0 ) { + CBlockIndex *pindex; if ( pindex->nTime > 1564499104-365*2*1440 ) { ASSETCHAINS_ADAPTIVEPOW = 1; From 629fb610f6054d47d75afc3f07cb2ea08c6bd7b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:19:38 -1100 Subject: [PATCH 033/108] Syntax --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0e3cbe577..99eb4337b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2431,9 +2431,9 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_DICE); CCENABLE(EVAL_ORACLES); } + CBlockIndex *pindex; if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_activechain(1)) != 0 ) { - CBlockIndex *pindex; if ( pindex->nTime > 1564499104-365*2*1440 ) { ASSETCHAINS_ADAPTIVEPOW = 1; From 68bc9849856424c246119fd686709099b8a68d56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:22:44 -1100 Subject: [PATCH 034/108] Komodo_chainactive --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 99eb4337b..4709a9bb1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2432,7 +2432,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_ORACLES); } CBlockIndex *pindex; - if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_activechain(1)) != 0 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) { if ( pindex->nTime > 1564499104-365*2*1440 ) { From dd67e645ffecc8fc0777a50412ef66e456c6736e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:36:20 -1100 Subject: [PATCH 035/108] Fix timeout error --- src/komodo_nSPV_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 282e58cab..3f1016bb3 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -18,8 +18,8 @@ #define KOMODO_NSPV_DEFSH #define NSPV_PROTOCOL_VERSION 0x00000002 -#define NSPV_POLLITERS 100 -#define NSPV_POLLMICROS 30000 +#define NSPV_POLLITERS 200 +#define NSPV_POLLMICROS 50000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From 9a32570ad09d7186f3e6c1618728be8652f34b63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:41:05 -1100 Subject: [PATCH 036/108] Move to init time check --- src/bitcoind.cpp | 11 ++++++++++- src/komodo_utils.h | 8 -------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 0baadf620..de36ea4ea 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -65,16 +65,25 @@ void komodo_passport_iteration(); uint64_t komodo_interestsum(); int32_t komodo_longestchain(); void komodo_cbopretupdate(int32_t forceflag); +CBlockIndex *komodo_chainactive(int32_t height); void WaitForShutdown(boost::thread_group* threadGroup) { - int32_t i,height; bool fShutdown = ShutdownRequested(); const uint256 zeroid; + int32_t i,height; CBlockIndex *pindex; bool fShutdown = ShutdownRequested(); const uint256 zeroid; // Tell the main threads to shutdown. if (komodo_currentheight()>KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>KOMODO_EARLYTXID_HEIGHT)) { fprintf(stderr,"error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT); StartShutdown(); } + if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) + { + if ( pindex->nTime > 1564499104-365*2*1440 ) + { + ASSETCHAINS_ADAPTIVEPOW = 1; + fprintf(stderr,"default activate adaptivepow\n"); + } + } else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); while (!fShutdown) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4709a9bb1..7533e2376 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2432,14 +2432,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_ORACLES); } CBlockIndex *pindex; - if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) - { - if ( pindex->nTime > 1564499104-365*2*1440 ) - { - ASSETCHAINS_ADAPTIVEPOW = 1; - fprintf(stderr,"default activate adaptivepow\n"); - } - } else fprintf(stderr,"cant find height 1\n"); } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) From dc1973c1152106f1e50eb54a8e670d526870d529 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:41:29 -1100 Subject: [PATCH 037/108] Cleanup --- src/komodo_utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7533e2376..31e87d82b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2431,7 +2431,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); CCENABLE(EVAL_DICE); CCENABLE(EVAL_ORACLES); } - CBlockIndex *pindex; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) From 91ce4a99e63d90d9386352af13fa3cdc90c402c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:47:05 -1100 Subject: [PATCH 038/108] Test --- src/bitcoind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index de36ea4ea..58f4b4930 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -82,7 +82,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) { ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); - } + } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1564499104-365*2*1440) } else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); From 8fbb317419decab5519db41f89d70cd4f22bfdc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:50:27 -1100 Subject: [PATCH 039/108] Use tipdiff also --- src/bitcoind.cpp | 2 +- src/komodo_bitcoind.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 58f4b4930..8ee328dcd 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -82,7 +82,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) { ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); - } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1564499104-365*2*1440) + } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1564499104-365*2*1440); } else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2e4461e7b..c3dbf2d85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1418,10 +1418,13 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime) { - arith_uint256 origtarget,easy; int32_t diff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex; + arith_uint256 origtarget,easy; int32_t diff,tipdiff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex; if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) { diff = (nTime - tipindex->GetMedianTimePast()); + tipdiff = (nTime - tipindex->nTime); + if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) + diff = 13*ASSETCHAINS_BLOCKTIME; if ( diff > 20 * ASSETCHAINS_BLOCKTIME ) { mult = diff - 19 * ASSETCHAINS_BLOCKTIME; From e836664a18ec11b3ddeddd52bfb2ce5aa5f2e2c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:53:46 -1100 Subject: [PATCH 040/108] Test timestamp --- src/bitcoind.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 8ee328dcd..22b48139b 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -78,11 +78,11 @@ void WaitForShutdown(boost::thread_group* threadGroup) } if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) { - if ( pindex->nTime > 1564499104-365*2*1440 ) + if ( pindex->nTime > 1539612702 ) { ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); - } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1564499104-365*2*1440); + } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1539612702); } else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); From 7f7b3aa11d194f669e7c18f7f224128119e6d5d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:55:57 -1100 Subject: [PATCH 041/108] Hardfork adaptivpow activation --- src/bitcoind.cpp | 6 +++--- src/komodo_defs.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 22b48139b..89f070f83 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -76,13 +76,13 @@ void WaitForShutdown(boost::thread_group* threadGroup) fprintf(stderr,"error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT); StartShutdown(); } - if ( ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) + if ( ASSETCHAINS_STAKED == 0 && ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 ) { - if ( pindex->nTime > 1539612702 ) + if ( pindex->nTime > ADAPTIVEPOW_CHANGETO_DEFAULTON ) { ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); - } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,1539612702); + } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,ADAPTIVEPOW_CHANGETO_DEFAULTON); } else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c6150f905..b7b5c9da7 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -20,6 +20,7 @@ #include "komodo_nk.h" #define KOMODO_EARLYTXID_HEIGHT 100 +#define ADAPTIVEPOW_CHANGETO_DEFAULTON 1572480000 #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 7 #define KOMODO_ELECTION_GAP 2000 From 20f1df3472a44423814998e94ce4037b39bef6f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 04:59:35 -1100 Subject: [PATCH 042/108] Fix --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c3dbf2d85..95f609483 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1425,10 +1425,10 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) diff = 13*ASSETCHAINS_BLOCKTIME; - if ( diff > 20 * ASSETCHAINS_BLOCKTIME ) + if ( diff > 13 * ASSETCHAINS_BLOCKTIME ) { - mult = diff - 19 * ASSETCHAINS_BLOCKTIME; - mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 3; + mult = diff - 12 * ASSETCHAINS_BLOCKTIME; + mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2; origtarget = bnTarget; bnTarget = bnTarget * arith_uint256(mult * mult); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); From 0454333ff8e80a18bf90a5bacc4108e0de7e0e24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 05:11:57 -1100 Subject: [PATCH 043/108] Tristate KOMODO_NSPV --- src/bitcoind.cpp | 2 +- src/cc/CCtokens.cpp | 2 +- src/cc/CCtx.cpp | 10 ++++----- src/cc/CCutils.cpp | 6 +++--- src/consensus/upgrades.cpp | 2 +- src/init.cpp | 8 +++---- src/komodo_nSPV_superlite.h | 8 +++---- src/main.cpp | 43 ++++++++++++++++++++----------------- src/net.cpp | 2 +- src/rpc/blockchain.cpp | 4 ++-- src/rpc/misc.cpp | 2 +- src/rpc/rawtransaction.cpp | 4 ++-- src/script/sign.cpp | 8 +++---- src/wallet/rpcdump.cpp | 24 ++++++++++----------- src/wallet/rpcwallet.cpp | 8 +++---- 15 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 89f070f83..cf9b1c20c 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -91,7 +91,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) //fprintf(stderr,"call passport iteration\n"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) komodo_passport_iteration(); for (i=0; i<10; i++) { diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 39daede80..07b9efbb1 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -957,7 +957,7 @@ UniValue TokenInfo(uint256 tokenid) result.push_back(Pair("error", "cant find tokenid")); return(result); } - if ( KOMODO_NSPV == 0 && hashBlock.IsNull()) { + if ( KOMODO_NSPV <= 0 && hashBlock.IsNull()) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "the transaction is still in mempool")); return(result); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 01cb02211..8692be7da 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -162,7 +162,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran utxovout = mtx.vin[i].prevout.n; if ( vintx.vout[utxovout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); @@ -344,7 +344,7 @@ void NSPV_CCtxids(std::vector > &txids,char void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag) { int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector > addresses; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { NSPV_CCunspents(unspentOutputs,coinaddr,ccflag); return; @@ -368,7 +368,7 @@ void SetCCunspents(std::vector > &addressIndex,char *coinaddr,bool ccflag) { int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector > addresses; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { NSPV_CCtxids(addressIndex,coinaddr,ccflag); return; @@ -555,7 +555,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,&NSPV_U)); #ifdef ENABLE_WALLET assert(pwalletMain != NULL); @@ -652,7 +652,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NSPV_U)); utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 7e376e0ce..b2125d3a4 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -450,7 +450,7 @@ extern uint32_t NSPV_logintime; bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { @@ -590,7 +590,7 @@ int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t C int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr) { int32_t i,n; char destaddr[64]; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) return(NSPV_coinaddr_inmempool(logcategory,coinaddr,1)); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { @@ -619,7 +619,7 @@ int32_t myGet_mempool_txs(std::vector &txs,uint8_t evalcode,uint8_ { int i=0; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { CTransaction tx; uint256 hashBlock; diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 786e58510..e23137a7b 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -101,7 +101,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) { uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) return(NSPV_BRANCHID); return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId; } diff --git a/src/init.cpp b/src/init.cpp index 9296d17ac..51d6cb435 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1066,7 +1066,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) RegisterAllCoreRPCCommands(tableRPC); #ifdef ENABLE_WALLET bool fDisableWallet = GetBoolArg("-disablewallet", false); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { fDisableWallet = true; nLocalServices = 0; @@ -1147,7 +1147,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Option to startup with mocktime set (used for regression testing): SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { if (GetBoolArg("-peerbloomfilters", true)) nLocalServices |= NODE_BLOOM; @@ -1306,7 +1306,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) libsnark::inhibit_profiling_info = true; libsnark::inhibit_profiling_counters = true; - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { // Initialize Zcash circuit parameters ZC_LoadParams(chainparams); @@ -1487,7 +1487,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } #endif - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { std::vector vImportFiles; threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 29e60aa75..37f1c3c44 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -214,7 +214,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) return(0); if ( pnode == 0 ) { @@ -243,7 +243,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - if ( (0) && KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV > 0 ) fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; @@ -279,7 +279,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages return; if ( pto->prevtimes[NSPV_INFO>>1] > timestamp ) pto->prevtimes[NSPV_INFO>>1] = 0; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { @@ -537,7 +537,7 @@ UniValue NSPV_login(char *wifstr) result.push_back(Pair("address",NSPV_address)); result.push_back(Pair("pubkey",HexStr(pubkey))); strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str()); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) decode_hex(NOTARY_PUBKEY33,33,NSPV_pubkeystr); result.push_back(Pair("wifprefix",(int64_t)data[0])); result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); diff --git a/src/main.cpp b/src/main.cpp index 34b84058e..c47ae67cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2227,7 +2227,7 @@ bool myAddtomempool(CTransaction &tx, CValidationState *pstate, bool fSkipExpiry bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) { memset(&hashBlock,0,sizeof(hashBlock)); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { int64_t rewardsum = 0; int32_t i,retval,txheight,currentheight,height=0,vout = 0; for (i=0; i 0 ) { int64_t rewardsum = 0; int32_t i,retval,height=0,vout = 0; for (i=0; i 0 ) return(true); if ( KOMODO_STOPAT != 0 && pindex->GetHeight() > KOMODO_STOPAT ) return(false); @@ -4011,7 +4011,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) { void FlushStateToDisk() { CValidationState state; - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) FlushStateToDisk(state, FLUSH_STATE_ALWAYS); } @@ -4162,7 +4162,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0))) { #ifdef ENABLE_WALLET - if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV == 0 ) + if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV <= 0 ) pwalletMain->EraseFromWallet(tx.GetHash()); #endif } @@ -4267,7 +4267,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Get the current commitment tree SproutMerkleTree oldSproutTree; SaplingMerkleTree oldSaplingTree; - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree)); assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree)); @@ -4296,13 +4296,13 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * mapBlockSource.erase(pindexNew->GetBlockHash()); nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2; LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) assert(view.Flush()); } int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3; LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001); // Write the chain state to disk, if necessary. - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) return false; @@ -4318,7 +4318,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Update chainActive & related variables. UpdateTip(pindexNew); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { // Tell wallet about transactions that went from mempool // to conflicted: @@ -4346,7 +4346,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * komodo_broadcast(pblock,8); else if ( ASSETCHAINS_SYMBOL[0] != 0 ) komodo_broadcast(pblock,4);*/ - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesupdate(pindexNew->GetHeight(),pblock); @@ -6547,7 +6547,7 @@ bool InitBlockIndex() { if (!ActivateBestChain(true, state, &block)) return error("LoadBlockIndex(): genesis block cannot be activated"); // Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) return FlushStateToDisk(state, FLUSH_STATE_ALWAYS); else return(true); } catch (const std::runtime_error& e) { @@ -7107,7 +7107,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); - //if ( KOMODO_NSPV != 0 ) + //if ( KOMODO_NSPV > 0 ) //if ( strCommand != "version" && strCommand != "verack" ) // fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) @@ -7282,7 +7282,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { if ( (pfrom->nServices & NODE_NSPV) == 0 ) { @@ -7482,14 +7482,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else if (strCommand == "getnSPV") { - std::vector payload; - vRecv >> payload; - komodo_nSPVreq(pfrom,payload); + if ( KOMODO_NSPV == 0 ) + { + std::vector payload; + vRecv >> payload; + komodo_nSPVreq(pfrom,payload); + } return(true); } else if (strCommand == "nSPV") { - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { std::vector payload; vRecv >> payload; @@ -7497,7 +7500,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } return(true); } - else if ( KOMODO_NSPV != 0 ) + else if ( KOMODO_NSPV > 0 ) return(true); else if (strCommand == "inv") { @@ -8287,7 +8290,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } state.fShouldBan = false; } - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { komodo_nSPV(pto); return(true); @@ -8498,7 +8501,7 @@ extern "C" const char* getDataDir() CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight) { CMutableTransaction mtx; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { mtx.fOverwintered = true; mtx.nExpiryHeight = 0; diff --git a/src/net.cpp b/src/net.cpp index 02cddd3e2..255d5efd5 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1843,7 +1843,7 @@ bool StopNode() for (int i=0; ipost(); - if (KOMODO_NSPV == 0 && fAddressesInitialized) + if (KOMODO_NSPV <= 0 && fAddressesInitialized) { DumpAddresses(); fAddressesInitialized = false; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index deb198aa6..c63def984 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -396,7 +396,7 @@ bool NSPV_inmempool(uint256 txid); bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout) { int32_t vini = 0; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) return(NSPV_spentinmempool(spenttxid,spentvini,txid,vout)); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { @@ -420,7 +420,7 @@ bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid, bool mytxid_inmempool(uint256 txid) { - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 384b487b2..050d42ace 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -243,7 +243,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("prevMoMheight", prevMoMheight)); obj.push_back(Pair("notarizedhash", notarized_hash.ToString())); obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString())); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height); if ( txid_height > 0 ) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 209126a5a..343673bd4 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( KOMODO_NSPV == 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) + if ( KOMODO_NSPV <= 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight()); @@ -1366,7 +1366,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) bool fOverrideFees = false; if (params.size() > 1) fOverrideFees = params[1].get_bool(); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { CCoinsViewCache &view = *pcoinsTip; const CCoins* existingCoins = view.AccessCoins(hashTx); diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 678a1565a..e6ac9fffa 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -53,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } } SIG_TXHASH = hash; - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) key = DecodeSecret(NSPV_wifstr); else if (pprivKey) key = *pprivKey; @@ -74,7 +74,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } vchSig = CCSigVec(cc); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) memset((uint8_t *)key.begin(),0,32); return true; } @@ -100,7 +100,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } vchSig.push_back((unsigned char)nHashType); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) memset((uint8_t *)key.begin(),0,32); return true; } @@ -381,7 +381,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } else { - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) { CPubKey vch; creator.KeyStore().GetPubKey(keyID, vch); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 5fa7dee9d..2d39de120 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -993,7 +993,7 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) int32_t reqht = 0; if ( fHelp || params.size() > 1 ) throw runtime_error("nspv_getinfo [hdrheight]\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 1 ) reqht = atoi((char *)params[0].get_str().c_str()); @@ -1004,7 +1004,7 @@ UniValue nspv_logout(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 0 ) throw runtime_error("nspv_logout\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_logout()); } @@ -1013,7 +1013,7 @@ UniValue nspv_login(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_login wif\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_login((char *)params[0].get_str().c_str())); } @@ -1023,7 +1023,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { @@ -1048,7 +1048,7 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp) memset(&txid,0,sizeof(txid)); if ( fHelp || params.size() > 5 ) throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); funcid = atoi((char *)params[0].get_str().c_str()); coinaddr = (char *)params[1].get_str().c_str(); @@ -1068,7 +1068,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { @@ -1093,7 +1093,7 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp) uint256 txid; int32_t vout; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_spentinfo txid vout\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); vout = atoi((char *)params[1].get_str().c_str()); @@ -1105,7 +1105,7 @@ UniValue nspv_notarizations(const UniValue& params, bool fHelp) int32_t height; if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_notarizations height\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); height = atoi((char *)params[0].get_str().c_str()); return(NSPV_notarizations(height)); @@ -1116,7 +1116,7 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) int32_t prevheight,nextheight; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_hdrsproof prevheight nextheight\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); prevheight = atoi((char *)params[0].get_str().c_str()); nextheight = atoi((char *)params[1].get_str().c_str()); @@ -1128,7 +1128,7 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) uint256 txid; int32_t height; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_txproof txid height\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); @@ -1140,7 +1140,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) uint64_t satoshis; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_spend address amount\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); @@ -1155,7 +1155,7 @@ UniValue nspv_broadcast(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_broadcast hex\n"); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV <= 0 ) throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_broadcast((char *)params[0].get_str().c_str())); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 365399a7d..a1114de61 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -162,7 +162,7 @@ void OS_randombytes(unsigned char *x,long xlen); UniValue getnewaddress(const UniValue& params, bool fHelp) { - if ( KOMODO_NSPV == 0 && !EnsureWalletIsAvailable(fHelp) ) + if ( KOMODO_NSPV <= 0 && !EnsureWalletIsAvailable(fHelp) ) return NullUniValue; if (fHelp || params.size() > 1) @@ -178,7 +178,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) + HelpExampleRpc("getnewaddress", "") ); - if ( KOMODO_NSPV != 0 ) + if ( KOMODO_NSPV > 0 ) { UniValue result(UniValue::VOBJ); uint8_t priv32[32]; #ifndef __WIN32 @@ -2974,7 +2974,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { #ifdef ENABLE_WALLET - if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV <= 0 ) { uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; @@ -7002,7 +7002,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( (0) && KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV > 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); From 7e9308be695136406231d851a4476ad517996fb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 05:31:53 -1100 Subject: [PATCH 044/108] Fix of by one --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 95f609483..f0baa74ba 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1425,7 +1425,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) diff = 13*ASSETCHAINS_BLOCKTIME; - if ( diff > 13 * ASSETCHAINS_BLOCKTIME ) + if ( diff >= 13 * ASSETCHAINS_BLOCKTIME ) { mult = diff - 12 * ASSETCHAINS_BLOCKTIME; mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2; @@ -1437,7 +1437,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui bnTarget = easy; fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); - } else fprintf(stderr,"diff %d, vs 120\n",diff); + } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); } else fprintf(stderr,"cant find height.%d\n",height); return(bnTarget); } From 9496986ca908a29606d48ba2ea9addb96799aff7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 06:09:41 -1100 Subject: [PATCH 045/108] Fix silly bug --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f0baa74ba..bd7de534d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,7 +1424,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui diff = (nTime - tipindex->GetMedianTimePast()); tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) - diff = 13*ASSETCHAINS_BLOCKTIME; + diff = tipdiff; if ( diff >= 13 * ASSETCHAINS_BLOCKTIME ) { mult = diff - 12 * ASSETCHAINS_BLOCKTIME; @@ -1435,10 +1435,10 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow { bnTarget = easy; - fprintf(stderr,"miner overflowed mult.%lld, set to mindiff\n",(long long)mult); - } else fprintf(stderr,"miner elapsed %d, adjust by factor of %lld\n",diff,(long long)mult); + fprintf(stderr,"height.%d miner overflowed mult.%lld, set to mindiff\n",height,(long long)mult); + } else fprintf(stderr,"height.%d miner elapsed %d, adjust by factor of %lld\n",height,diff,(long long)mult); } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); - } else fprintf(stderr,"cant find height.%d\n",height); + } // else fprintf(stderr,"cant find height.%d\n",height); return(bnTarget); } From 1aab14606302eddc7abbb3bfa0706be7fcf68ec6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 06:55:35 -1100 Subject: [PATCH 046/108] Recall hashtarget --- src/bitcoind.cpp | 2 +- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index cf9b1c20c..e293d6926 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -83,7 +83,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) ASSETCHAINS_ADAPTIVEPOW = 1; fprintf(stderr,"default activate adaptivepow\n"); } else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,ADAPTIVEPOW_CHANGETO_DEFAULTON); - } else fprintf(stderr,"cant find height 1\n"); + } //else fprintf(stderr,"cant find height 1\n"); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); while (!fShutdown) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bd7de534d..2d1ff91a1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1435,10 +1435,10 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow { bnTarget = easy; - fprintf(stderr,"height.%d miner overflowed mult.%lld, set to mindiff\n",height,(long long)mult); - } else fprintf(stderr,"height.%d miner elapsed %d, adjust by factor of %lld\n",height,diff,(long long)mult); + fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tippdiff,diff,height,(long long)mult); + } else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult); } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); - } // else fprintf(stderr,"cant find height.%d\n",height); + } else fprintf(stderr,"adaptive cant find height.%d\n",height); return(bnTarget); } diff --git a/src/miner.cpp b/src/miner.cpp index 05a24ca2f..c72660651 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2041,7 +2041,11 @@ void static BitcoinMiner() pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + { + fprintf(stderr,"update time in miner\n"); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + hashtarget = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + } /*if ( NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS; From 9ccc4fd560b79c13e2e8eee4b513e5c1120c667b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 06:57:09 -1100 Subject: [PATCH 047/108] Tip-off --- 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 2d1ff91a1..bc0692cac 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1435,7 +1435,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow { bnTarget = easy; - fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tippdiff,diff,height,(long long)mult); + fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tipdiff,diff,height,(long long)mult); } else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult); } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); } else fprintf(stderr,"adaptive cant find height.%d\n",height); From 467f59272b9b763566300fb00dc417621f2a5f10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 06:59:05 -1100 Subject: [PATCH 048/108] hashTarget --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c72660651..7c31b1ee7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2044,7 +2044,7 @@ void static BitcoinMiner() { fprintf(stderr,"update time in miner\n"); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - hashtarget = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + hashTarget = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } /*if ( NOTARY_PUBKEY33[0] == 0 ) { From b8ae0496895129390626070ad2a0293505734dc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 07:09:36 -1100 Subject: [PATCH 049/108] -print --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bc0692cac..84a84935b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1437,7 +1437,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui bnTarget = easy; fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tipdiff,diff,height,(long long)mult); } else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult); - } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); + } //else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); } else fprintf(stderr,"adaptive cant find height.%d\n",height); return(bnTarget); } diff --git a/src/miner.cpp b/src/miner.cpp index 7c31b1ee7..90020fc43 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2042,7 +2042,6 @@ void static BitcoinMiner() pblock->nBits = savebits; if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { - fprintf(stderr,"update time in miner\n"); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); hashTarget = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } From d9020b8aa2922be1ba8b11f1483b4b2be3ded073 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 07:24:07 -1100 Subject: [PATCH 050/108] HASHTarget_POW = --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 90020fc43..6d404161f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -2043,7 +2043,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - hashTarget = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } /*if ( NOTARY_PUBKEY33[0] == 0 ) { From 753f2f1d6299be0701fa437e682d129529b9e192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 07:30:41 -1100 Subject: [PATCH 051/108] +print --- 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 84a84935b..bc0692cac 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1437,7 +1437,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui bnTarget = easy; fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tipdiff,diff,height,(long long)mult); } else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult); - } //else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); + } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); } else fprintf(stderr,"adaptive cant find height.%d\n",height); return(bnTarget); } From 8b5cbc45bfd9e6ac623f6b31bcfe6f69ae1ed890 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jul 2019 08:38:01 -1100 Subject: [PATCH 052/108] -print --- 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 bc0692cac..84a84935b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1437,7 +1437,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui bnTarget = easy; fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tipdiff,diff,height,(long long)mult); } else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult); - } else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); + } //else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME); } else fprintf(stderr,"adaptive cant find height.%d\n",height); return(bnTarget); } From 50eebd236e6e37eba1adc2c6cc6282b3434676cd Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Wed, 31 Jul 2019 22:50:01 +0700 Subject: [PATCH 053/108] Minor fixes and TODOs --- qa/rpc-tests/{src => }/nspv_client_test.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) rename qa/rpc-tests/{src => }/nspv_client_test.py (89%) diff --git a/qa/rpc-tests/src/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py similarity index 89% rename from qa/rpc-tests/src/nspv_client_test.py rename to qa/rpc-tests/nspv_client_test.py index fbf0e5360..aecff3696 100644 --- a/qa/rpc-tests/src/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -3,19 +3,22 @@ sys.path.append('../../src/tui') from lib import tuilib import unittest +import time ''' specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' -wif = '' -dest_address = 'RMjy5VkHFJkXTJDTJ3XX1zVzukP48sKyva' +wif = 'UsJgUBrmcsthJEGbyBBfD77tZ1FuRMkB68jqkP8E3PEE88eXesEH' +dest_address = 'RNvAWip4DuFrZf8WhqdTBEcAg1bWjd4rKr' amount = '0.1' chain = 'ILN' rpc_proxy = tuilib.def_credentials(chain) +# TODO: recheck nspv_login_timeout, nspv_notarizations +# TODO: add brand new methods, add one-utxo-only addr for test purpose class TestNspvClient(unittest.TestCase): @@ -31,14 +34,14 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_notarizations("2000") self.assertEqual(result["result"], "success") self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2002) + self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") self.assertEqual(result["result"], "success") - self.assertEqual(result["numhdrs"], 101) + self.assertEqual(result["numhdrs"], 113) time.sleep(1) def test_nspv_login(self): @@ -54,7 +57,8 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["result"], "success") time.sleep(1) result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - self.assertEqual(result["result"], "error") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") def test_nspv_spend(self): print("testing nspv_spend") From f878c9e05ecf77e2ddaf3b9539489096e5c62b78 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Wed, 31 Jul 2019 23:35:54 +0700 Subject: [PATCH 054/108] More fixes less TODOs --- qa/rpc-tests/nspv_client_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index aecff3696..aecc05fb7 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -17,8 +17,7 @@ chain = 'ILN' rpc_proxy = tuilib.def_credentials(chain) -# TODO: recheck nspv_login_timeout, nspv_notarizations -# TODO: add brand new methods, add one-utxo-only addr for test purpose +# TODO: add brand new methods, add one-utxo-only addr for test purpose, recheck test once more at least class TestNspvClient(unittest.TestCase): @@ -107,7 +106,7 @@ class TestNspvClient(unittest.TestCase): def test_nspv_login_timout(self): print("testing auto-logout in 777 seconds") rpc_proxy.nspv_login(wif) - time.sleep(777) + time.sleep(778) result = rpc_proxy.nspv_spend(dest_address, amount) self.assertEqual(result["result"], "error") self.assertEqual(result["error"], "wif expired") From a875f690220c253e30f46dcd7855426e6ae69655 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 08:49:29 -1100 Subject: [PATCH 055/108] Fix zawys zcash issue 4021 --- src/timedata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timedata.cpp b/src/timedata.cpp index daeb7bae0..9a7a6f6fa 100644 --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -94,7 +94,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample) int64_t nMedian = vTimeOffsets.median(); std::vector vSorted = vTimeOffsets.sorted(); // Only let other nodes change our time by so much - if (abs64(nMedian) < 70 * 60) + if (abs64(nMedian) < 30) // thanks to zawy for pointing this out!! zcash issues 4021 //70 * 60) { nTimeOffset = nMedian; } From 199d8db0193216edb6181479ee97cb20d013eddc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 19:02:44 -1100 Subject: [PATCH 056/108] Fix zawy attack --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 +- src/miner.cpp | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 84a84935b..e2bc2b7f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1425,7 +1425,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) diff = tipdiff; - if ( diff >= 13 * ASSETCHAINS_BLOCKTIME ) + if ( diff >= 13 * ASSETCHAINS_BLOCKTIME && (height < 3000 || tipdiff > 2*ASSETCHAINS_BLOCKTIME) ) { mult = diff - 12 * ASSETCHAINS_BLOCKTIME; mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2; diff --git a/src/main.cpp b/src/main.cpp index c47ae67cf..d83f5f169 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5288,7 +5288,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) + if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) { return state.Invalid(error("%s: block's timestamp is too early", __func__), REJECT_INVALID, "time-too-old"); diff --git a/src/miner.cpp b/src/miner.cpp index 6d404161f..fe7ca068a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -123,7 +123,7 @@ public: void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { - pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1 + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); // Updating time can change work required on testnet: if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) { @@ -567,7 +567,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); @@ -596,8 +596,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else { blocktime = GetAdjustedTime(); - //if ( blocktime > pindexPrev->GetMedianTimePast()+60 ) - // blocktime = pindexPrev->GetMedianTimePast() + 60; siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig); // if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock. // This has been moved from the mining loop to save CPU, and to also make ac_staked work with the verus miner. @@ -642,7 +640,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; - txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; From 4f64b197d20152e387b66b528f18dcb57d009dee Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 19:32:41 -1100 Subject: [PATCH 057/108] Fix --- src/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d83f5f169..8505b974b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5288,10 +5288,21 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 1000 ) { - return state.Invalid(error("%s: block's timestamp is too early", __func__), - REJECT_INVALID, "time-too-old"); + if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) + { + return state.Invalid(error("%s: block's timestamp is too early", __func__), + REJECT_INVALID, "time-too-old"); + } + } + else + { + if ( block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) + { + return state.Invalid(error("%s: block's timestamp is too early2", __func__), + REJECT_INVALID, "time-too-old"); + } } // Check that timestamp is not too far in the future From 733949c4f96e9c56e8b94b72abaa1b8b22cf9bb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 19:38:14 -1100 Subject: [PATCH 058/108] <2000 --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8505b974b..301c0c071 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5288,10 +5288,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 1000 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 2000 ) { if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) { + fprintf(stderr,"too early %u vs %u\n",(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); return state.Invalid(error("%s: block's timestamp is too early", __func__), REJECT_INVALID, "time-too-old"); } @@ -5300,6 +5301,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta { if ( block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) { + fprintf(stderr,"too early2 %u vs %u\n",(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); return state.Invalid(error("%s: block's timestamp is too early2", __func__), REJECT_INVALID, "time-too-old"); } From 81eb5548c65eec1f55ce2e842bee7443c01dc632 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 19:45:26 -1100 Subject: [PATCH 059/108] <3000 --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 301c0c071..14c8e05ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5288,11 +5288,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 2000 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 3000 ) { if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) { - fprintf(stderr,"too early %u vs %u\n",(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); + fprintf(stderr,"ht.%d too early %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); return state.Invalid(error("%s: block's timestamp is too early", __func__), REJECT_INVALID, "time-too-old"); } @@ -5301,7 +5301,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta { if ( block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) { - fprintf(stderr,"too early2 %u vs %u\n",(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); + fprintf(stderr,"ht.%d too early2 %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); return state.Invalid(error("%s: block's timestamp is too early2", __func__), REJECT_INVALID, "time-too-old"); } From aa1539afd08cd82afff4f5f7e78a1321f8fc4fb7 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 14:31:20 +0700 Subject: [PATCH 060/108] added nspv_listtransactions call test --- qa/rpc-tests/nspv_client_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index aecc05fb7..d5d1e4bba 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -21,6 +21,17 @@ rpc_proxy = tuilib.def_credentials(chain) class TestNspvClient(unittest.TestCase): + def test_nspv_listtransactions(self): + print("testing nspv_listtransactions") + rpc_proxy.nspv_login(wif) + result = rpc_proxy.nspv_listtransactions() + self.assertEqual(result["result"], "success") + time.sleep(1) + result = rpc_proxy.nspv_listtransactions("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + rpc_proxy.nspv_logout() + def test_nspv_getinfo(self): print("testing nspv_getinfo") result = rpc_proxy.nspv_getinfo() @@ -36,6 +47,16 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) + def test_nspv_listtransactions(self): + print("testing nspv_listtransactions") + result = rpc_proxy.nspv_listtransactions() + self.assertEqual(result["result"], "success") + time.sleep(1) + result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + + def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") From 75c034113ef15837b656ffbc3bb69d5be83ab50f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 21:20:58 -1100 Subject: [PATCH 061/108] Calculate correct target in getblocktemplate for adaptivepow --- src/rpc/mining.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 4814d34dd..479edff45 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -837,7 +837,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("PoSperc", (int64_t)PoSperc)); result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED)); result.push_back(Pair("origtarget", hashTarget.GetHex())); - } else result.push_back(Pair("target", hashTarget.GetHex())); + } + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime))); + else result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); From a74bd537a4dacd4204416c5346d92b15d4738bd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jul 2019 21:22:17 -1100 Subject: [PATCH 062/108] .GetHex() --- 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 479edff45..e31dbd396 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -839,7 +839,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("origtarget", hashTarget.GetHex())); } else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) - result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime))); + result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime).GetHex())); else result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); From 887d54fd813d6093060c3a1d30a1ffd171595a17 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 16:13:30 +0700 Subject: [PATCH 063/108] cleanup and recheck --- qa/rpc-tests/nspv_client_test.py | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index d5d1e4bba..e247a45a2 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -10,26 +10,36 @@ specify chain ticker (daemon should be up), wif which will be imported and addre added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' -wif = 'UsJgUBrmcsthJEGbyBBfD77tZ1FuRMkB68jqkP8E3PEE88eXesEH' -dest_address = 'RNvAWip4DuFrZf8WhqdTBEcAg1bWjd4rKr' +wif = '' +dest_address = '' amount = '0.1' chain = 'ILN' +if not wif or not dest_address: + raise Exception("Please set test wif and address to send transactions to.") + rpc_proxy = tuilib.def_credentials(chain) -# TODO: add brand new methods, add one-utxo-only addr for test purpose, recheck test once more at least class TestNspvClient(unittest.TestCase): + def test_nspv_mempool(self): + print("testing nspv_mempool") + result = rpc_proxy.nspv_mempool("0", dest_address, "0") + self.assertEqual(result["result"], "success") + self.assertEqual(result["address"], dest_address) + self.assertEqual(result["isCC"], 0) + time.sleep(1) + def test_nspv_listtransactions(self): print("testing nspv_listtransactions") rpc_proxy.nspv_login(wif) result = rpc_proxy.nspv_listtransactions() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listtransactions("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + result = rpc_proxy.nspv_listtransactions("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") rpc_proxy.nspv_logout() def test_nspv_getinfo(self): @@ -47,16 +57,6 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour time.sleep(1) - def test_nspv_listtransactions(self): - print("testing nspv_listtransactions") - result = rpc_proxy.nspv_listtransactions() - self.assertEqual(result["result"], "success") - time.sleep(1) - result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") - - def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") result = rpc_proxy.nspv_hdrsproof("2000", "2100") @@ -76,9 +76,9 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listunspent() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + result = rpc_proxy.nspv_listunspent("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") def test_nspv_spend(self): print("testing nspv_spend") From ad6f142a92e20442a48505fb22c0d3bf0d995490 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Thu, 1 Aug 2019 16:34:50 +0700 Subject: [PATCH 064/108] final cleanup lowered coins amount --- qa/rpc-tests/nspv_client_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index e247a45a2..63b7f78d1 100644 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -12,11 +12,11 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.1' +amount = '0.01' chain = 'ILN' if not wif or not dest_address: - raise Exception("Please set test wif and address to send transactions to.") + raise Exception("Please set test wif and address to send transactions to") rpc_proxy = tuilib.def_credentials(chain) @@ -54,7 +54,7 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_notarizations("2000") self.assertEqual(result["result"], "success") self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2008) # check suspicious behaviour + self.assertEqual(result["next"]["notarized_height"], 2008) time.sleep(1) def test_nspv_hdrsproof(self): @@ -85,7 +85,7 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_login(wif) result = rpc_proxy.nspv_spend(dest_address, amount) self.assertEqual(result["result"], "success") - self.assertEqual(result["vout"][0]["valueZat"], 10000000) + self.assertEqual(result["vout"][0]["valueZat"], 1000000) time.sleep(1) def test_nspv_broadcast(self): From 1cefd54af14fc10ae2eead39814db825e5875627 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 00:38:59 -1100 Subject: [PATCH 065/108] Fix zawy attack, thanks zawy! --- src/main.cpp | 4 ++-- src/miner.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 14c8e05ac..aeab7cadc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5299,9 +5299,9 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } else { - if ( block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) + if ( block.GetBlockTime() <= pindexPrev->nTime ) { - fprintf(stderr,"ht.%d too early2 %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); + fprintf(stderr,"ht.%d too early2 %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->nTime); return state.Invalid(error("%s: block's timestamp is too early2", __func__), REJECT_INVALID, "time-too-old"); } diff --git a/src/miner.cpp b/src/miner.cpp index fe7ca068a..01a41f5b8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -123,7 +123,9 @@ public: void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { - pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1 + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); + if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + else pblock->nTime = std::max(pindexPrev->nTime+1, GetAdjustedTime()); // Updating time can change work required on testnet: if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) { @@ -567,7 +569,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); + if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + else blocktime = 1 + std::max(pindexPrev->nTime+1, GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); @@ -640,7 +644,10 @@ 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; - txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); + if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) + txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + else txNew.nLockTime = std::max(pindexPrev->nTime+1, GetAdjustedTime()); + if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; From 4aa44715aa4e5c39fc54323d3fc5f6a0af2380f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 00:43:39 -1100 Subject: [PATCH 066/108] Syntax --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 01a41f5b8..b7447500d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -125,7 +125,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, { if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - else pblock->nTime = std::max(pindexPrev->nTime+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) { @@ -646,7 +646,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.nExpiryHeight = 0; if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - else txNew.nLockTime = std::max(pindexPrev->nTime+1, GetAdjustedTime()); + else txNew.nLockTime = std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime()); if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) From 41f752ff4bf1ba4d452a03b2c1e3fc5425076627 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 00:44:56 -1100 Subject: [PATCH 067/108] int64_t --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b7447500d..d19faee7d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -571,7 +571,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockSize = nBlockSize; if ( ASSETCHAINS_ADAPTIVEPOW == 0 ) blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - else blocktime = 1 + std::max(pindexPrev->nTime+1, GetAdjustedTime()); + else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); From 716e089fab83c4f62c1c14faf4213cf8a8f7a619 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 00:56:26 -1100 Subject: [PATCH 068/108] Fix AddCClibtxfee --- src/cc/cclib.cpp | 2 +- src/init.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index dddd59f59..4c182e721 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -542,7 +542,7 @@ int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe char coinaddr[64]; int64_t nValue,txfee = 10000; uint256 txid,hashBlock; CTransaction vintx; int32_t vout; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr,true); + SetCCunspents(unspentOutputs,coinaddr,false); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; diff --git a/src/init.cpp b/src/init.cpp index 51d6cb435..903ca8555 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1911,11 +1911,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) PruneAndFlush(); } } - if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 ) - nLocalServices |= NODE_ADDRINDEX; - if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 ) - nLocalServices |= NODE_SPENTINDEX; -fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)); + if ( KOMODO_NSPV > 0 ) + { + if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 ) + nLocalServices |= NODE_ADDRINDEX; + if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 ) + nLocalServices |= NODE_SPENTINDEX; + fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)); + } // ********************************************************* Step 10: import blocks if (mapArgs.count("-blocknotify")) From 8074aabefd3492257b3400245e8b84f75b25324d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 01:12:20 -1100 Subject: [PATCH 069/108] Revert --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 4c182e721..dddd59f59 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -542,7 +542,7 @@ int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe char coinaddr[64]; int64_t nValue,txfee = 10000; uint256 txid,hashBlock; CTransaction vintx; int32_t vout; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr,false); + SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 7a4f8b3401a67e505eaa68fa74974b585a08e23e Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Fri, 2 Aug 2019 03:05:47 +0700 Subject: [PATCH 070/108] Prolonged Proxy timeout Added support for multiple test chains --- qa/rpc-tests/nspv_client_test.py | 77 ++++++++++++++++++++++---------- src/tui/lib/tuilib.py | 20 ++++++++- 2 files changed, 73 insertions(+), 24 deletions(-) mode change 100644 => 100755 qa/rpc-tests/nspv_client_test.py diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py old mode 100644 new mode 100755 index 63b7f78d1..ddc1d8093 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -7,19 +7,48 @@ import time ''' specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast +change chain parameters if needed or add a new chain to test below added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) ''' wif = '' dest_address = '' amount = '0.01' -chain = 'ILN' +chain = 'KMD' if not wif or not dest_address: raise Exception("Please set test wif and address to send transactions to") rpc_proxy = tuilib.def_credentials(chain) +chain_params = {"KMD": { + 'tx_list_address': 'RGShWG446Pv24CKzzxjA23obrzYwNbs1kA', + 'min_chain_height': 1468080, + 'notarization_height': '1468000', + 'prev_notarization_h': 1467980, + 'next_notarization_h': 1468020, + 'hdrs_proof_low': '1468100', + 'hdrs_proof_high': '1468200', + 'numhdrs_expected': 151, + 'tx_proof_id': 'f7beb36a65bc5bcbc9c8f398345aab7948160493955eb4a1f05da08c4ac3784f', + 'tx_spent_height': 1456212, + 'tx_proof_height': '1468520', + }, + "ILN": { + 'tx_list_address': 'RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu', + 'min_chain_height': 3689, + 'notarization_height': '2000', + 'prev_notarization_h': 1998, + 'next_notarization_h': 2008, + 'hdrs_proof_low': '2000', + 'hdrs_proof_high': '2100', + 'numhdrs_expected': 113, + 'tx_proof_id': '67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418', + 'tx_spent_height': 2681, + 'tx_proof_height': '2690', + } + } + class TestNspvClient(unittest.TestCase): @@ -37,31 +66,32 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listtransactions() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listtransactions("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + result = rpc_proxy.nspv_listtransactions(chain_params.get(chain).get("tx_list_address")) self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address")) rpc_proxy.nspv_logout() def test_nspv_getinfo(self): print("testing nspv_getinfo") result = rpc_proxy.nspv_getinfo() self.assertEqual(result["result"], "success") - self.assertGreater(result["height"], 2689) + self.assertGreater(result["height"], chain_params.get(chain).get("min_chain_height")) time.sleep(1) def test_nspv_notarizations(self): print("testing nspv_notarizations") - result = rpc_proxy.nspv_notarizations("2000") + result = rpc_proxy.nspv_notarizations(chain_params.get(chain).get("notarization_height")) self.assertEqual(result["result"], "success") - self.assertEqual(result["prev"]["notarized_height"], 1998) - self.assertEqual(result["next"]["notarized_height"], 2008) + self.assertEqual(result["prev"]["notarized_height"], chain_params.get(chain).get("prev_notarization_h")) + self.assertEqual(result["next"]["notarized_height"], chain_params.get(chain).get("next_notarization_h")) time.sleep(1) def test_nspv_hdrsproof(self): print("testing nspv_hdrsproof") - result = rpc_proxy.nspv_hdrsproof("2000", "2100") + result = rpc_proxy.nspv_hdrsproof(chain_params.get(chain).get("hdrs_proof_low"), + chain_params.get(chain).get("hdrs_proof_high")) self.assertEqual(result["result"], "success") - self.assertEqual(result["numhdrs"], 113) + self.assertEqual(result["numhdrs"], chain_params.get(chain).get("numhdrs_expected")) time.sleep(1) def test_nspv_login(self): @@ -76,9 +106,9 @@ class TestNspvClient(unittest.TestCase): result = rpc_proxy.nspv_listunspent() self.assertEqual(result["result"], "success") time.sleep(1) - result = rpc_proxy.nspv_listunspent("RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + result = rpc_proxy.nspv_listunspent(chain_params.get(chain).get("tx_list_address")) self.assertEqual(result["result"], "success") - self.assertEqual(result["address"], "RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu") + self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address")) def test_nspv_spend(self): print("testing nspv_spend") @@ -113,25 +143,26 @@ class TestNspvClient(unittest.TestCase): def test_nspv_spentinfo(self): print("testing nspv_spent_info") - result = rpc_proxy.nspv_spentinfo("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "1") + result = rpc_proxy.nspv_spentinfo(chain_params.get(chain).get("tx_proof_id"), "1") self.assertEqual(result["result"], "success") - self.assertEqual(result["spentheight"], 2681) + self.assertEqual(result["spentheight"], chain_params.get(chain).get("tx_spent_height")) time.sleep(1) def test_nspv_txproof(self): print("testing nspv_txproof") - result = rpc_proxy.nspv_txproof("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "2673") - self.assertEqual(result["txid"], "67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418") + result = rpc_proxy.nspv_txproof(chain_params.get(chain).get("tx_proof_id"), + chain_params.get(chain).get("tx_proof_height")) + self.assertEqual(result["txid"], chain_params.get(chain).get("tx_proof_id")) time.sleep(1) - def test_nspv_login_timout(self): - print("testing auto-logout in 777 seconds") - rpc_proxy.nspv_login(wif) - time.sleep(778) - result = rpc_proxy.nspv_spend(dest_address, amount) - self.assertEqual(result["result"], "error") - self.assertEqual(result["error"], "wif expired") - time.sleep(1) + def test_nspv_login_timout(self): + print("testing auto-logout in 777 seconds") + rpc_proxy.nspv_login(wif) + time.sleep(778) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) if __name__ == '__main__': diff --git a/src/tui/lib/tuilib.py b/src/tui/lib/tuilib.py index 9a2fed639..afb4fad63 100755 --- a/src/tui/lib/tuilib.py +++ b/src/tui/lib/tuilib.py @@ -21,6 +21,24 @@ if operating_system != 'Win64' and operating_system != 'Windows': import readline +class CustomProxy(Proxy): + def __init__(self, + service_url=None, + service_port=None, + conf_file=None, + timeout=3000): + config = dict() + if conf_file: + config = slickrpc.ConfigObj(conf_file) + if service_url: + config.update(self.url_to_conf(service_url)) + if service_port: + config.update(rpcport=service_port) + elif not config.get('rpcport'): + config['rpcport'] = 7771 + self.conn = self.prepare_connection(config, timeout=timeout) + + def colorize(string, color): colors = { @@ -97,7 +115,7 @@ def def_credentials(chain): print("check "+coin_config_file) exit(1) - return(Proxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport)))) + return(CustomProxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport)))) def getinfo_tui(rpc_connection): From 1108c4cb32b8c5537ac9cbd73363867c6666d297 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Fri, 2 Aug 2019 03:06:38 +0700 Subject: [PATCH 071/108] typo fix --- qa/rpc-tests/nspv_client_test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index ddc1d8093..5611e1e31 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -155,14 +155,14 @@ class TestNspvClient(unittest.TestCase): self.assertEqual(result["txid"], chain_params.get(chain).get("tx_proof_id")) time.sleep(1) - def test_nspv_login_timout(self): - print("testing auto-logout in 777 seconds") - rpc_proxy.nspv_login(wif) - time.sleep(778) - result = rpc_proxy.nspv_spend(dest_address, amount) - self.assertEqual(result["result"], "error") - self.assertEqual(result["error"], "wif expired") - time.sleep(1) + def test_nspv_login_timout(self): + print("testing auto-logout in 777 seconds") + rpc_proxy.nspv_login(wif) + time.sleep(778) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) if __name__ == '__main__': From 23ca86df3a7031e0cfee52b364aa137b8219ba3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 09:14:07 -1100 Subject: [PATCH 072/108] Zawys new algo 1) FTL 4 seconds 2) MTP from 11 -> 1 3) must calc MAX(diff[I]) for past 11 blocks 4) bnTarget *= mult*mult 5) bnTarget.nBits -> onchain --- src/komodo_bitcoind.h | 8 ++++---- src/main.cpp | 12 ++++++++++-- src/miner.cpp | 19 ++++++++++--------- src/pow.cpp | 31 ++++++++++++++++++++++++------- src/rpc/mining.cpp | 5 +++-- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e2bc2b7f2..c0850006b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1419,13 +1419,13 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime) { arith_uint256 origtarget,easy; int32_t diff,tipdiff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex; - if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) + if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) // disable offchain diffchange { diff = (nTime - tipindex->GetMedianTimePast()); tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) diff = tipdiff; - if ( diff >= 13 * ASSETCHAINS_BLOCKTIME && (height < 3000 || tipdiff > 2*ASSETCHAINS_BLOCKTIME) ) + if ( diff >= 13 * ASSETCHAINS_BLOCKTIME && (height < 30 || tipdiff > 2*ASSETCHAINS_BLOCKTIME) ) { mult = diff - 12 * ASSETCHAINS_BLOCKTIME; mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2; @@ -2286,8 +2286,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( height == 0 ) return(0); } - if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) - bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); + //if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + // bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget ) { // if proof of stake is active, check if this is a valid PoS block before we fail diff --git a/src/main.cpp b/src/main.cpp index aeab7cadc..9cffe8a76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5043,7 +5043,15 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, } } *futureblockp = 0; - if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + { + if (blockhdr.GetBlockTime() > GetAdjustedTime() + 4) + { + //LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime()); + return false; + } + } + else if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { /*CBlockIndex *tipindex; //fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); @@ -5288,7 +5296,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 3000 ) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 30 ) { if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) { diff --git a/src/miner.cpp b/src/miner.cpp index d19faee7d..676a41b57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1452,8 +1452,8 @@ void static BitcoinMiner_noeq() HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } - else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) - HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) + // HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); while (true) { @@ -1487,8 +1487,8 @@ void static BitcoinMiner_noeq() } else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 ) hashTarget = HASHTarget; - else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) - hashTarget = HASHTarget_POW; + //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) + // hashTarget = HASHTarget_POW; // for speed check NONCEMASK at a time for (i = 0; i < count; i++) @@ -1825,8 +1825,8 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED < 100 ) LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); } - else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) - HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + // HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); gotinvalid = 0; while (true) { @@ -1854,8 +1854,8 @@ void static BitcoinMiner() arith_uint256 hashTarget; if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; - else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) - hashTarget = HASHTarget_POW; + //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) + // hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = #ifdef ENABLE_WALLET @@ -2048,7 +2048,8 @@ void static BitcoinMiner() if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + HASHTarget.SetCompact(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 18fda549f..19eb28629 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -73,11 +73,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTot {0}; - for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { + arith_uint256 bnTarget,bnTot {0}; + uint32_t nbits; int64_t diff,mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; + for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) + { arith_uint256 bnTmp; bnTmp.SetCompact(pindexFirst->nBits); bnTot += bnTmp; + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && i < 12 ) + { + diff = pblock->nTime - pindexFirst->nTime - (8+i)*ASSETCHAINS_BLOCKTIME; + if ( diff > mult ) + mult = diff; + } pindexFirst = pindexFirst->pprev; } @@ -85,9 +93,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow}; - - return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); + 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 ) + { + origtarget = bnTarget = arith_uint256().SetCompact(nbits); + bnTarget = bnTarget * arith_uint256(mult * mult); + easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( bnTarget < origtarget || bnTarget > easy ) + bnTarget = easy; + nbits = bnTarget.GetCompact(); + } + return(nbits); } unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, @@ -453,8 +470,8 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t arith_uint256 bnMaxPoSdiff; bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } - else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) - bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); + //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) + // bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); // Check proof of work matches claimed amount if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e31dbd396..d70f198f1 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -838,9 +838,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED)); result.push_back(Pair("origtarget", hashTarget.GetHex())); } - else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + /*else if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime).GetHex())); - else result.push_back(Pair("target", hashTarget.GetHex())); + else*/ + result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); From a8f5005a7f81219bffb017c82486392c6e9b2c31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 09:54:24 -1100 Subject: [PATCH 073/108] Fix crash --- src/pow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 19eb28629..a91b48dc1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -74,7 +74,9 @@ 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; int64_t diff,mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; + uint32_t nbits; int64_t diff,mult = 0; + if ( pindexFirst != 0 ) + mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { arith_uint256 bnTmp; From 61e4db43325195e0907d45403b2c7305aa71939e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:01:55 -1100 Subject: [PATCH 074/108] Fix null access --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index a91b48dc1..c98928d3e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -75,14 +75,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead const CBlockIndex* pindexFirst = pindexLast; arith_uint256 bnTarget,bnTot {0}; uint32_t nbits; int64_t diff,mult = 0; - if ( pindexFirst != 0 ) + if ( pindexFirst != 0 && pblock != 0 ) mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { arith_uint256 bnTmp; bnTmp.SetCompact(pindexFirst->nBits); bnTot += bnTmp; - if ( ASSETCHAINS_ADAPTIVEPOW > 0 && i < 12 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && i < 12 && pblock != 0 ) { diff = pblock->nTime - pindexFirst->nTime - (8+i)*ASSETCHAINS_BLOCKTIME; if ( diff > mult ) From f5e59c37fe41a96389c4dc2a6c85f4d7044ef3e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:21:55 -1100 Subject: [PATCH 075/108] +print --- src/pow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index c98928d3e..e305d347d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -76,7 +76,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead arith_uint256 bnTarget,bnTot {0}; uint32_t nbits; int64_t diff,mult = 0; 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(),mult,pblock->nTime, pindexFirst->nTime); + } for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { arith_uint256 bnTmp; @@ -103,7 +106,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnTarget = bnTarget * arith_uint256(mult * mult); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( bnTarget < origtarget || bnTarget > easy ) + { bnTarget = easy; + fprintf(stderr,"mult.%d ht.%d -> easy target\n",(int32_t)mult,(int32_t)pindexLast->GetHeight()); + } else fprintf(stderr,"mult.%d for ht.%d\n",(int32_t)mult,(int32_t)pindexLast->GetHeight()); nbits = bnTarget.GetCompact(); } return(nbits); From 28c82425212af9a84e9de1b9521861a182192c56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:24:04 -1100 Subject: [PATCH 076/108] Print --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index e305d347d..bff20b446 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(),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 45fcb5bcde9364394cfd158154221f234a812f4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:26:46 -1100 Subject: [PATCH 077/108] +print --- src/pow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index bff20b446..e8a9dca10 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -89,7 +89,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { diff = pblock->nTime - pindexFirst->nTime - (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; + } } pindexFirst = pindexFirst->pprev; } From cd6b8c738e02c0bb055067397cb3a91f2633c47c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:30:26 -1100 Subject: [PATCH 078/108] +print --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e8a9dca10..038f130e8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -111,8 +111,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if ( bnTarget < origtarget || bnTarget > easy ) { bnTarget = easy; - fprintf(stderr,"mult.%d ht.%d -> easy target\n",(int32_t)mult,(int32_t)pindexLast->GetHeight()); - } else fprintf(stderr,"mult.%d for ht.%d\n",(int32_t)mult,(int32_t)pindexLast->GetHeight()); + fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); + } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); nbits = bnTarget.GetCompact(); } return(nbits); From 58704437ced8622e123667d8158c0ba618d8c845 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:32:58 -1100 Subject: [PATCH 079/108] int32_t --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 038f130e8..0a37dc8fb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -74,7 +74,7 @@ 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; int64_t diff,mult = 0; + uint32_t nbits; int32_t diff,mult = 0; if ( pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; From 977c6aa1b3d292ea95ffefefa71f5ef08bb25ef8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 10:56:54 -1100 Subject: [PATCH 080/108] Remove adjustment limits --- src/pow.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0a37dc8fb..175137f06 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -103,7 +103,7 @@ 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 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && mult > 1 ) // jl777: this test of mult > 1 failed when it was int64_t??? { origtarget = bnTarget = arith_uint256().SetCompact(nbits); bnTarget = bnTarget * arith_uint256(mult * mult); @@ -129,11 +129,13 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, nActualTimespan = params.AveragingWindowTimespan() + (nActualTimespan - params.AveragingWindowTimespan())/4; LogPrint("pow", " nActualTimespan = %d before bounds\n", nActualTimespan); - if (nActualTimespan < params.MinActualTimespan()) - nActualTimespan = params.MinActualTimespan(); - if (nActualTimespan > params.MaxActualTimespan()) - nActualTimespan = params.MaxActualTimespan(); - + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) + { + if (nActualTimespan < params.MinActualTimespan()) + nActualTimespan = params.MinActualTimespan(); + if (nActualTimespan > params.MaxActualTimespan()) + nActualTimespan = params.MaxActualTimespan(); + } // Retarget arith_uint256 bnLimit; if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) From e58b81a475ebdf3e37ec7bac423d9b61d809b028 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Aug 2019 12:06:04 -1100 Subject: [PATCH 081/108] 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 082/108] 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 083/108] 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 084/108] 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 085/108] +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 086/108] 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 4509efcc63114d7e27faf701aaadb0cd3ca0ddbb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 2 Aug 2019 23:22:20 +0800 Subject: [PATCH 087/108] fix NSPV addressindex --- src/init.cpp | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 903ca8555..6f7f91988 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; diff --git a/src/main.cpp b/src/main.cpp index 9cffe8a76..c232b44ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7503,7 +7503,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else if (strCommand == "getnSPV") { - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV == 0 && KOMODO_INSYNC != 0 ) { std::vector payload; vRecv >> payload; From 40f18eeca566f950993f82605b9cf1f7372785e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Aug 2019 04:27:44 -1100 Subject: [PATCH 088/108] -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 089/108] 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 090/108] 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 091/108] 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 092/108] -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 093/108] +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 094/108] -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 095/108] 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 096/108] 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 097/108] -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); From f3e341722bf6fb2189e17f7d38a7a7957e3130de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 02:30:24 -1100 Subject: [PATCH 098/108] Zawy7 --- src/pow.cpp | 64 +++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 406fca63c..e1b57f042 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -166,42 +166,44 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - 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 fprintf(stderr,"nothing smaller\n"); - } - 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; - } //else fprintf(stderr,"nothing bigger\n"); - } - /*if ( block4diff > 4 && 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); 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 + { + 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 fprintf(stderr,"nothing smaller\n"); + } + 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; + } //else fprintf(stderr,"nothing bigger\n"); + } + } } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); } From 31ebd139b85787397bcb71098f8be7d0102051e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 02:34:20 -1100 Subject: [PATCH 099/108] /2 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index e1b57f042..3d616dc42 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -166,7 +166,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // for 10x and higher hashrate increases { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); From cdb3980abc0ae37ceb5eebf582988661eaf74c56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:12:13 -1100 Subject: [PATCH 100/108] Fix zawyMA calc --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 3d616dc42..b32bf845f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,10 +42,10 @@ 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) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t numerator) { - bnTarget /= arith_uint256(divisor); - bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); + bnTarget /= arith_uint256(ASSETCHAINS_BLOCKTIME); + bnTarget *= arith_uint256(numerator); if ( bnTarget > easy ) bnTarget = easy; return(bnTarget); @@ -166,7 +166,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // for 10x and higher hashrate increases + if ( (0) && block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // added /2 { block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3; bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2); From ecfec20ff87ae0f9519f4443e6bd6d2385bc5815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:28:48 -1100 Subject: [PATCH 101/108] Zawy9 --- src/pow.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index b32bf845f..d863efa19 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,10 +42,10 @@ 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 numerator) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnTarget,int32_t divisor) { - bnTarget /= arith_uint256(ASSETCHAINS_BLOCKTIME); - bnTarget *= arith_uint256(numerator); + bnTarget /= arith_uint256(divisor); + bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); if ( bnTarget > easy ) bnTarget = easy; return(bnTarget); @@ -166,13 +166,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( (0) && block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME/2 ) // added /2 + 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)); } - else + // else { bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); From e5045e995cc62ca601413eaac55e95b7ca5f5a35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 03:59:52 -1100 Subject: [PATCH 102/108] Zawy10 --- src/pow.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index d863efa19..51850f78b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,13 +42,13 @@ 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) +arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator) { - bnTarget /= arith_uint256(divisor); - bnTarget *= arith_uint256(ASSETCHAINS_BLOCKTIME); - if ( bnTarget > easy ) - bnTarget = easy; - return(bnTarget); + bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num); + bnSum *= arith_uint256(numerator); + if ( bnSum > easy ) + bnSum = easy; + return(bnSum); } arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult) @@ -148,7 +148,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}; + bool fNegative,fOverflow; int32_t flag; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { @@ -166,17 +166,30 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - if ( block4diff > 4 && block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases + flag = 0; + if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) { - 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)); + bnTarget /= arith_uint256(4); + flag = 4; + fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff,0.25); } - // else + if ( block7diff >= 7 && block7diff < ASSETCHAINS_BLOCKTIME/2 ) { - bnSum4 = zawy_targetMA(easy,bnSum4,block4diff * 5); - bnSum7 = zawy_targetMA(easy,bnSum7,block7diff * 3); - bnSum12 = zawy_targetMA(easy,bnSum12,block12diff * 2); + bnTarget /= arith_uint256(7); + flag = 7; + fprintf(stderr,"ht.%d 7 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block7diff,1./7); + } + if ( block12diff >= 12 && block12diff < ASSETCHAINS_BLOCKTIME ) + { + bnTarget /= arith_uint256(12); + flag = 12; + fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); + } + else if ( flag == 0 ) + { + bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5); + bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3); + bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2); if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { if ( bnSum4 < bnSum7 ) From 8dc5c7c60a955ed61dffb17af5d5146f5c03e38d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 05:36:34 -1100 Subject: [PATCH 103/108] zawy11 Fix MA calc, different numerators for max() --- src/pow.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 51850f78b..e4678bfe2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -42,9 +42,9 @@ 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 bnSum,int32_t num,int32_t numerator) +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); + bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num * num * divisor); bnSum *= arith_uint256(numerator); if ( bnSum > easy ) bnSum = easy; @@ -187,11 +187,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( flag == 0 ) { - bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5); - bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3); - bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2); if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { + 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; @@ -205,6 +205,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) { + 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; From 62a57c1ebd69620a7499a42a3a4565fc1090957b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 05:49:38 -1100 Subject: [PATCH 104/108] Remove boosters for zawy11 --- src/pow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index e4678bfe2..7d084141b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -167,7 +167,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { flag = 0; - if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) + /*if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) { bnTarget /= arith_uint256(4); flag = 4; @@ -185,7 +185,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead flag = 12; fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); } - else if ( flag == 0 ) + else if ( flag == 0 )*/ { if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { From 4fa1f639e21f912665c101428385f897c2cf72c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 06:24:09 -1100 Subject: [PATCH 105/108] Zawy12, reduce noise ave with bnPrev --- src/pow.cpp | 83 ++++++++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 7d084141b..2e5e03539 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -100,11 +100,12 @@ 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}; + 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; if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) { mult = pblock->nTime - pindexFirst->nTime - 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); } for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -148,7 +149,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; int32_t flag; 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 ) { @@ -166,59 +167,37 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) { - flag = 0; - /*if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 ) + if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) { - bnTarget /= arith_uint256(4); - flag = 4; - fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff,0.25); - } - if ( block7diff >= 7 && block7diff < ASSETCHAINS_BLOCKTIME/2 ) - { - bnTarget /= arith_uint256(7); - flag = 7; - fprintf(stderr,"ht.%d 7 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block7diff,1./7); - } - if ( block12diff >= 12 && block12diff < ASSETCHAINS_BLOCKTIME ) - { - bnTarget /= arith_uint256(12); - flag = 12; - fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12); - } - else if ( flag == 0 )*/ - { - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + 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 ) { - 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 ) - { - 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 ) + fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); + bnTarget = (bnTmp + bnPrev) / arith_uint256(2); + } //else fprintf(stderr,"nothing smaller\n"); + } + else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) + { + 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 ) { - 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; - } //else fprintf(stderr,"nothing bigger\n"); - } + 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); + } //else fprintf(stderr,"nothing bigger\n"); } } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); nbits = bnTarget.GetCompact(); From 7a7788419fcdaa423d8f91a868ffa5a38a911f2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Aug 2019 06:51:46 -1100 Subject: [PATCH 106/108] Implement precedence of digishield, max(), e^x, min() --- src/pow.cpp | 69 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 2e5e03539..a84db0015 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -149,15 +149,30 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; - bool fNegative,fOverflow; 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 ) + if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 ) { origtarget = bnTarget = arith_uint256().SetCompact(nbits); 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??? + 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 = zawy_exponential(bnTarget,mult); //replaces: bnTarget * arith_uint256(mult * mult); + 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); + flag = 1; + } + else 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); if ( bnTarget < origtarget || bnTarget > easy ) { bnTarget = easy; @@ -165,41 +180,23 @@ 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 if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) + if ( flag == 0 ) { - if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) + 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 ) { - 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 ) - { - fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); - bnTarget = (bnTmp + bnPrev) / arith_uint256(2); - } //else fprintf(stderr,"nothing smaller\n"); + 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; } - else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) - { - 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); - } //else fprintf(stderr,"nothing bigger\n"); - } - } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); + } nbits = bnTarget.GetCompact(); } return(nbits); From c07f73e217304ae6ee6b005648224699cafdb585 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Sun, 4 Aug 2019 01:29:20 +0700 Subject: [PATCH 107/108] change default chain to ILN --- qa/rpc-tests/nspv_client_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index 5611e1e31..8487105ff 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -13,8 +13,8 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.01' -chain = 'KMD' +amount = '0.001' +chain = 'ILN' if not wif or not dest_address: raise Exception("Please set test wif and address to send transactions to") From cf844ce5a49318dbb1e4fb2ffe9f0c34c7e7df56 Mon Sep 17 00:00:00 2001 From: SirSevenG Date: Sun, 4 Aug 2019 01:29:50 +0700 Subject: [PATCH 108/108] def amount change --- qa/rpc-tests/nspv_client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index 8487105ff..26f88cf5a 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -13,7 +13,7 @@ added 1 second sleep after each case to surely not face the nSPV server limitati wif = '' dest_address = '' -amount = '0.001' +amount = '0.01' chain = 'ILN' if not wif or not dest_address: