From 11d424de8167c9229844b7bdd3957401680cb07e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 03:20:04 -1100 Subject: [PATCH 01/21] +print --- src/komodo_gateway.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ce89cea35..5d96eea06 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2580,12 +2580,13 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) numprices = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); ptr32 = (uint32_t *)calloc(sizeof(uint32_t),numprices * width); ptr64 = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW*3); + fprintf(stderr,"prices update: numprices.%d %p %p\n",numprices,ptr32,ptr64); } if ( _komodo_heightpricebits(&seed,rawprices,pblock) == numprices ) { - //for (i=0; i Date: Thu, 11 Apr 2019 03:23:38 -1100 Subject: [PATCH 02/21] Open files always --- src/komodo_gateway.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5d96eea06..7442bc2eb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2543,30 +2543,31 @@ int64_t komodo_priceave(int64_t *correlated,int32_t cskip) void komodo_pricesinit() { - int32_t i; + int32_t i,createflag = 0; boost::filesystem::path pricefname,pricesdir = GetDataDir() / "prices"; fprintf(stderr,"pricesinit (%s)\n",pricesdir.string().c_str()); if (!boost::filesystem::exists(pricesdir)) + boost::filesystem::create_directories(pricesdir), createflag = 1; + for (i=0; i 0 && PRICES[0].fp != 0 ) - { - fseek(PRICES[0].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(uint32_t) * i,SEEK_SET); - fputc(0,PRICES[0].fp); - fflush(PRICES[0].fp); - } + } + if ( i > 0 && PRICES[0].fp != 0 && createflag != 0 ) + { + fseek(PRICES[0].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(uint32_t) * i,SEEK_SET); + fputc(0,PRICES[0].fp); + fflush(PRICES[0].fp); } } From 900ba27f11878e509fb627e78cf46d101d35e0e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 03:24:38 -1100 Subject: [PATCH 03/21] Ind --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7442bc2eb..a3d3628b3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2585,8 +2585,8 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) } if ( _komodo_heightpricebits(&seed,rawprices,pblock) == numprices ) { - for (i=0; i Date: Thu, 11 Apr 2019 03:34:39 -1100 Subject: [PATCH 04/21] Null pindexFork case --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 593a41e3f..0ebc5c892 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4241,7 +4241,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // stay on the same chain tip! int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); - if ( pindexFork->GetHeight() < notarizedht ) + if ( pindexFork != 0 && pindexFork->GetHeight() < notarizedht ) { fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); return state.DoS(100, error("ActivateBestChainStep(): pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht), From 4f478650b89d1a22aa1760a8bc971454859833d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 03:46:04 -1100 Subject: [PATCH 05/21] +print --- src/komodo_gateway.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a3d3628b3..86ab82583 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2356,6 +2356,9 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int mult = PriceMult[ind]; if ( nonzprices != 0 ) memset(nonzprices,0,sizeof(*nonzprices)*PRICES_DAYWINDOW); + for (i=0; i width ) + if ( height > PRICES_DAYWINDOW ) { fseek(PRICES[0].fp,(height-width+1) * numprices * sizeof(uint32_t),SEEK_SET); if ( fread(ptr32,sizeof(uint32_t),width*numprices,PRICES[0].fp) == width*numprices ) @@ -2612,7 +2615,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) memcpy(&buf[2],&correlated,sizeof(correlated)); if ( fwrite(buf,1,sizeof(buf),PRICES[ind].fp) != sizeof(buf) ) fprintf(stderr,"error fwrite buf for ht.%d ind.%d\n",height,ind); - else + else if ( height > PRICES_DAYWINDOW*2 ) { fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * 3 * sizeof(int64_t),SEEK_SET); if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*3,PRICES[ind].fp) == PRICES_DAYWINDOW*3 ) From 1065ccd67af9f6f8d6412758674a5d8c06a3d9ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:05:04 -1100 Subject: [PATCH 06/21] Sort trick --- src/komodo_gateway.h | 71 ++++++++++++++++++++++++++++++++++++------ src/rpc/blockchain.cpp | 14 ++++++--- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 86ab82583..ee7480c48 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2353,12 +2353,12 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; if ( PRICES_DAYWINDOW < 2 || ind >= KOMODO_MAXPRICES ) return(-1); - mult = PriceMult[ind]; + mult = komodo_pricemult(ind); if ( nonzprices != 0 ) memset(nonzprices,0,sizeof(*nonzprices)*PRICES_DAYWINDOW); - for (i=0; i *(int64_t *)b) return 1; + return 0; +} + +static int64_t sort64(int64_t *l, int32_t llen) +{ + qsort(l,llen,sizeof(uint64_t),cmp_llu); +} + +static int revcmp_llu(const void *a, const void*b) +{ + if(*(int64_t *)a < *(int64_t *)b) return 1; + if(*(int64_t *)a > *(int64_t *)b) return -1; + return 0; +} + +static int64_t revsort64(int64_t *l, int32_t llen) +{ + heapsort(l,llen,sizeof(uint64_t),cmp_llu); +} + +int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) +{ + int32_t i,dir=0; int64_t sum=0,nonzprice,price,halfave,decayprice; if ( PRICES_DAYWINDOW < 2 ) return(0); for (i=0; i price ) // rising prices + { + sort64(buf,PRICES_DAYWINDOW); + decayprice = buf[0]; + for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); + } + else + { + revsort64(buf,PRICES_DAYWINDOW); + decayprice = buf[0]; + for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); + } + return(decayprice); } void komodo_pricesinit() @@ -2576,7 +2626,7 @@ void komodo_pricesinit() void komodo_pricesupdate(int32_t height,CBlock *pblock) { - static int numprices; static uint32_t *ptr32; static int64_t *ptr64; + static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[4]; width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH); if ( numprices == 0 ) @@ -2584,6 +2634,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) numprices = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); ptr32 = (uint32_t *)calloc(sizeof(uint32_t),numprices * width); ptr64 = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW*3); + tmpbuf = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW); fprintf(stderr,"prices update: numprices.%d %p %p\n",numprices,ptr32,ptr64); } if ( _komodo_heightpricebits(&seed,rawprices,pblock) == numprices ) @@ -2620,7 +2671,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * 3 * sizeof(int64_t),SEEK_SET); if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*3,PRICES[ind].fp) == PRICES_DAYWINDOW*3 ) { - if ( (smoothed= komodo_priceave(&ptr64[PRICES_DAYWINDOW*3-1],-3)) > 0 ) + if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[PRICES_DAYWINDOW*3-1],-3)) > 0 ) { fseek(PRICES[ind].fp,(height * 3 + 2) * sizeof(int64_t),SEEK_SET); if ( fwrite(&smoothed,1,sizeof(smoothed),PRICES[ind].fp) != sizeof(smoothed) ) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 07cb8a26d..0d1e7acb3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1176,7 +1176,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int64_t komodo_priceave(int64_t *correlated,int32_t cskip); +int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1185,7 +1185,7 @@ int64_t komodo_pricemult(int32_t ind); int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { - int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; + int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf; width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; komodo_heightpricebits(&seed,rawprices,firstheight + numblocks - 1); if ( firstheight < width ) @@ -1210,8 +1210,10 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t *)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 ) return(-3); } + tmpbuf = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW); for (i=0; i Date: Thu, 11 Apr 2019 04:15:41 -1100 Subject: [PATCH 07/21] Fix nondeterministic qsorts --- src/cc/dilithium.c | 5 +++-- src/cryptoconditions/src/asn/constr_SET_OF.c | 3 +++ src/cryptoconditions/src/threshold.c | 15 ++++++++++++--- src/komodo_gateway.h | 18 +++++++++++------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 7ba522f0f..087dfd9f5 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2717,8 +2717,9 @@ int64_t *tred, *tadd, *tmul, *tround, *tsample, *tpack, *tshake; static int cmp_llu(const void *a, const void*b) { if(*(int64_t *)a < *(int64_t *)b) return -1; - if(*(int64_t *)a > *(int64_t *)b) return 1; - return 0; + else if(*(int64_t *)a > *(int64_t *)b) return 1; + else if ( (uint64_t)a < (uint64_t)b ) return -1; + else return 1; } static int64_t median(int64_t *l, size_t llen) diff --git a/src/cryptoconditions/src/asn/constr_SET_OF.c b/src/cryptoconditions/src/asn/constr_SET_OF.c index 2dbc6e518..25e80cc30 100644 --- a/src/cryptoconditions/src/asn/constr_SET_OF.c +++ b/src/cryptoconditions/src/asn/constr_SET_OF.c @@ -301,6 +301,9 @@ static int _el_buf_cmp(const void *ap, const void *bp) { ret = -1; else if(a->length > b->length) ret = 1; + else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism + ret = -1; + else ret = 1; } return ret; diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c index 82f0e1b0a..7fc801897 100644 --- a/src/cryptoconditions/src/threshold.c +++ b/src/cryptoconditions/src/threshold.c @@ -35,8 +35,15 @@ static uint32_t thresholdSubtypes(const CC *cond) { } -static int cmpCostDesc(const void *a, const void *b) { - return (int) ( *(unsigned long*)b - *(unsigned long*)a ); +static int cmpCostDesc(const void *a, const void *b) +{ + int retval; + retval = (int) ( *(unsigned long*)b - *(unsigned long*)a ); + if ( retval != 0 ) + return(retval); + else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism + return(-1); + else return(1); } @@ -79,7 +86,9 @@ static int cmpConditionBin(const void *a, const void *b) { if (ret == 0) return r0.encoded < r1.encoded ? -1 : 1; - return 0; + else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism + return(-1); + else return(1); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ee7480c48..c7a203c3e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2524,8 +2524,10 @@ void smooth64(int64_t dest[],int64_t src[],int32_t width,int32_t smoothiters) static int cmp_llu(const void *a, const void*b) { if(*(int64_t *)a < *(int64_t *)b) return -1; - if(*(int64_t *)a > *(int64_t *)b) return 1; - return 0; + else if(*(int64_t *)a > *(int64_t *)b) return 1; + else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism + return(-1); + else return(1); } static int64_t sort64(int64_t *l, int32_t llen) @@ -2536,13 +2538,15 @@ static int64_t sort64(int64_t *l, int32_t llen) static int revcmp_llu(const void *a, const void*b) { if(*(int64_t *)a < *(int64_t *)b) return 1; - if(*(int64_t *)a > *(int64_t *)b) return -1; - return 0; + else if(*(int64_t *)a > *(int64_t *)b) return -1; + else if ( (uint64_t)a < (uint64_t)b ) // jl777 prevent nondeterminism + return(-1); + else return(1); } static int64_t revsort64(int64_t *l, int32_t llen) { - heapsort(l,llen,sizeof(uint64_t),cmp_llu); + qsort(l,llen,sizeof(uint64_t),revcmp_llu); } int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) @@ -2575,7 +2579,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) decayprice = buf[0]; for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); @@ -2586,7 +2590,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) decayprice = buf[0]; for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); From 91dacca39b9a0062f422694bae4572ee819c5a7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:15:52 -1100 Subject: [PATCH 08/21] Fix qsorts --- src/pow/tromp/equi.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pow/tromp/equi.h b/src/pow/tromp/equi.h index f6d8803c2..84e566e1a 100644 --- a/src/pow/tromp/equi.h +++ b/src/pow/tromp/equi.h @@ -75,8 +75,14 @@ int verifyrec(const crypto_generichash_blake2b_state *ctx, u32 *indices, uchar * } int compu32(const void *pa, const void *pb) { + int32_t retval; u32 a = *(u32 *)pa, b = *(u32 *)pb; - return a Date: Thu, 11 Apr 2019 04:17:55 -1100 Subject: [PATCH 09/21] Fix --- src/komodo_gateway.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c7a203c3e..45e8b7fe9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2574,27 +2574,15 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) if ( halfave == price ) return(price); else if ( halfave > price ) // rising prices - { sort64(buf,PRICES_DAYWINDOW); - decayprice = buf[0]; - for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); - } - else + else revsort64(buf,PRICES_DAYWINDOW); + decayprice = buf[0]; + for (i=0; i %.4f\n",(double)halfprice/COIN,(double)price/COIN,(double)decayprice/COIN); + decayprice = ((decayprice * 9) + (buf[i] * 1)) / 10; + fprintf(stderr,"%.4f ",(double)buf[i]/COIN); } + fprintf(stderr,"%ssort half %.4f vs %.4f -> %.4f\n",halfave Date: Thu, 11 Apr 2019 04:22:23 -1100 Subject: [PATCH 10/21] Off by 1 --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 45e8b7fe9..953947072 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2661,7 +2661,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) else if ( height > PRICES_DAYWINDOW*2 ) { fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * 3 * sizeof(int64_t),SEEK_SET); - if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*3,PRICES[ind].fp) == PRICES_DAYWINDOW*3 ) + if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*3-1,PRICES[ind].fp) == PRICES_DAYWINDOW*3-1 ) { if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[PRICES_DAYWINDOW*3-1],-3)) > 0 ) { From 00f7ff6f41e9c93f2af745fdb081953f1183b61a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:27:10 -1100 Subject: [PATCH 11/21] Another off by 1 --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 953947072..d3a9cb350 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2663,7 +2663,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * 3 * sizeof(int64_t),SEEK_SET); if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*3-1,PRICES[ind].fp) == PRICES_DAYWINDOW*3-1 ) { - if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[PRICES_DAYWINDOW*3-1],-3)) > 0 ) + if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[PRICES_DAYWINDOW*3-2],-3)) > 0 ) { fseek(PRICES[ind].fp,(height * 3 + 2) * sizeof(int64_t),SEEK_SET); if ( fwrite(&smoothed,1,sizeof(smoothed),PRICES[ind].fp) != sizeof(smoothed) ) From ad9adcf27382187c84abf98b090f5fda3bbec12b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:30:45 -1100 Subject: [PATCH 12/21] .8f --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d3a9cb350..92296a66c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2670,7 +2670,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) fprintf(stderr,"error fwrite smoothed for ht.%d ind.%d\n",height,ind); else { - fprintf(stderr,"%.4f ",(double)smoothed/COIN); + fprintf(stderr,"%.8f ",(double)smoothed/COIN); fflush(PRICES[ind].fp); } } else fprintf(stderr,"error price_smoothed ht.%d ind.%d\n",height,ind); From 3898bb8b2aef62f8e6bf862d739e845cee58e266 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:33:12 -1100 Subject: [PATCH 13/21] +print --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 92296a66c..0de71291f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2670,7 +2670,8 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) fprintf(stderr,"error fwrite smoothed for ht.%d ind.%d\n",height,ind); else { - fprintf(stderr,"%.8f ",(double)smoothed/COIN); + if ( ind == 36 ) + fprintf(stderr,"(%.8f %.8f) ",(double)ptr64[PRICES_DAYWINDOW*3-2]/COIN,(double)smoothed/COIN); fflush(PRICES[ind].fp); } } else fprintf(stderr,"error price_smoothed ht.%d ind.%d\n",height,ind); From 4255005f4de9980c4f5a62d2a743c084d1e79b1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:42:00 -1100 Subject: [PATCH 14/21] Tweak prices --- src/komodo_gateway.h | 13 +++++++------ src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0de71291f..cf6f13174 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2565,11 +2565,12 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) { if ( (price= correlated[i*cskip]) != 0 ) nonzprice = price; - buf[i] = nonzprice; + buf[PRICES_DAYWINDOW+i] = nonzprice; sum += nonzprice; if ( i == PRICES_DAYWINDOW/2 ) halfave = (sum / (PRICES_DAYWINDOW/2)); } + memcp(buf,&buf[PRICES_DAYWINDOW],PRICES_DAYWINDOW*sizeof(*buf)); price = sum / PRICES_DAYWINDOW; if ( halfave == price ) return(price); @@ -2579,11 +2580,11 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) decayprice = buf[0]; for (i=0; i %.4f\n",halfave %.4f\n",halfave Date: Thu, 11 Apr 2019 04:42:47 -1100 Subject: [PATCH 15/21] memcpy --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cf6f13174..5641a1ffc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2570,7 +2570,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) if ( i == PRICES_DAYWINDOW/2 ) halfave = (sum / (PRICES_DAYWINDOW/2)); } - memcp(buf,&buf[PRICES_DAYWINDOW],PRICES_DAYWINDOW*sizeof(*buf)); + memcpy(buf,&buf[PRICES_DAYWINDOW],PRICES_DAYWINDOW*sizeof(*buf)); price = sum / PRICES_DAYWINDOW; if ( halfave == price ) return(price); From 19b8685c211620e3a1cb0137afbf50dff56270dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 04:48:31 -1100 Subject: [PATCH 16/21] 19 --- src/komodo_gateway.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5641a1ffc..f8bfaf048 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2551,7 +2551,7 @@ static int64_t revsort64(int64_t *l, int32_t llen) int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) { - int32_t i,dir=0; int64_t sum=0,nonzprice,price,halfave,decayprice; + int32_t i,dir=0; int64_t sum=0,nonzprice,price,halfave,thirdave,fourthave,decayprice; if ( PRICES_DAYWINDOW < 2 ) return(0); for (i=0; i %.4f\n",halfave Date: Thu, 11 Apr 2019 04:49:43 -1100 Subject: [PATCH 17/21] Halfave --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f8bfaf048..92e0226b4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2588,7 +2588,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) //fprintf(stderr,"%.4f ",(double)buf[i]/COIN); } //fprintf(stderr,"%ssort half %.4f vs %.4f -> %.4f\n",halfave Date: Thu, 11 Apr 2019 04:55:56 -1100 Subject: [PATCH 18/21] +print --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 92e0226b4..555696d56 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2587,7 +2587,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) decayprice = ((decayprice * 97) + (buf[i] * 3)) / 100; //fprintf(stderr,"%.4f ",(double)buf[i]/COIN); } - //fprintf(stderr,"%ssort half %.4f vs %.4f -> %.4f\n",halfave %.8f\n",halfave Date: Thu, 11 Apr 2019 04:59:59 -1100 Subject: [PATCH 19/21] /19 --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 555696d56..3c7027e13 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2587,7 +2587,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) decayprice = ((decayprice * 97) + (buf[i] * 3)) / 100; //fprintf(stderr,"%.4f ",(double)buf[i]/COIN); } - fprintf(stderr,"%ssort half %.8f %.8f %.8f %.8f %.8f %.8f -> %.8f\n",halfave %.8f\n",halfave Date: Thu, 11 Apr 2019 08:07:14 -1100 Subject: [PATCH 20/21] Smaller --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3c7027e13..a4a1b78e3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2576,7 +2576,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) } memcpy(buf,&buf[PRICES_DAYWINDOW],PRICES_DAYWINDOW*sizeof(*buf)); price = sum / PRICES_DAYWINDOW; - if ( halfave == price ) + //if ( halfave == price ) return(price); else if ( halfave > price ) // rising prices sort64(buf,PRICES_DAYWINDOW); From 11694fc7e74dfb1d62937aadf81eb303059ec5b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 08:08:09 -1100 Subject: [PATCH 21/21] return(price); --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a4a1b78e3..6bd03ccfb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2576,7 +2576,8 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) } memcpy(buf,&buf[PRICES_DAYWINDOW],PRICES_DAYWINDOW*sizeof(*buf)); price = sum / PRICES_DAYWINDOW; - //if ( halfave == price ) + return(price); + if ( halfave == price ) return(price); else if ( halfave > price ) // rising prices sort64(buf,PRICES_DAYWINDOW);