From 2c1ea2350a6905f2aec22931c7d04cb2e2d586e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 15:51:25 +0300 Subject: [PATCH 01/75] Remove print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 185bfa347..c5057646f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -407,7 +407,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) From 31e342b831a486fa3b5fbb1f52ca7c87a166eadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 30 Oct 2017 21:03:20 +0200 Subject: [PATCH 02/75] Notarize CHIPS --- src/dpowassets | 1 + src/komodo_interest.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index fde738e44..5e0facea0 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -23,6 +23,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 1795a64bf..c5a35492d 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -90,7 +90,7 @@ uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { uint64_t interest = 0; - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( txheight < 7777777 && komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) interest = _komodo_interestnew(nValue,nLockTime,tiptime); return(interest); } @@ -101,6 +101,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin activation = 1491350400; // 1491350400 5th April if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(0); + if ( txheight >= 7777777 ) + return(0); if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) From 314350e695f07001e2188e87bc37064b96e40e05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 3 Nov 2017 19:22:56 +0200 Subject: [PATCH 03/75] KOMODO_ENDOFERA --- src/komodo.h | 1 + src/komodo_interest.h | 8 +++++--- src/main.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c5057646f..95aa1583a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -25,6 +25,7 @@ #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) +#define KOMODO_ENDOFERA 7777777 #include #include diff --git a/src/komodo_interest.h b/src/komodo_interest.h index c5a35492d..917791498 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -19,6 +19,7 @@ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% int64_t MAX_MONEY = 200000000 * 100000000LL; +#ifdef notanymore uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; @@ -73,6 +74,7 @@ uint64_t komodo_moneysupply(int32_t height) return(0); else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); } +#endif uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { @@ -90,7 +92,7 @@ uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { uint64_t interest = 0; - if ( txheight < 7777777 && komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( txheight < KOMODO_ENDOFERA && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && interest = _komodo_interestnew(nValue,nLockTime,tiptime); return(interest); } @@ -101,9 +103,9 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin activation = 1491350400; // 1491350400 5th April if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(0); - if ( txheight >= 7777777 ) + if ( txheight >= KOMODO_ENDOFERA ) return(0); - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) { diff --git a/src/main.cpp b/src/main.cpp index 8f028dbb7..e86a665ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1490,7 +1490,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) return true; } -uint64_t komodo_moneysupply(int32_t height); +//uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[16]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_SUPPLY; @@ -1502,7 +1502,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( nHeight == 1 ) return(100000000 * COIN); // ICO allocation - else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) + else if ( nHeight < KOMODO_ENDOFERA ) //komodo_moneysupply(nHeight) < MAX_MONEY ) return(3 * COIN); else return(0); } @@ -2365,8 +2365,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; control.Add(vChecks); } - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - komodo_earned_interest(pindex->nHeight,sum); + //if ( ASSETCHAINS_SYMBOL[0] == 0 ) + // komodo_earned_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); From e8cb981dd050908bf29b3a007fa8cd2621b995a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 3 Nov 2017 19:24:53 +0200 Subject: [PATCH 04/75] Test --- src/komodo.h | 1 - src/komodo_interest.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 95aa1583a..c5057646f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -25,7 +25,6 @@ #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) -#define KOMODO_ENDOFERA 7777777 #include #include diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 917791498..798eda48e 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -16,6 +16,7 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define KOMODO_ENDOFERA 7777777 #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% int64_t MAX_MONEY = 200000000 * 100000000LL; From 17746e454a750f5c9a4ccd09d5886812f60aa17a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:50:59 +0200 Subject: [PATCH 05/75] Faster init test --- src/komodo.h | 133 ++++++++++++++++++++++++++++++++++++++++++- src/komodo_gateway.h | 62 +++++++++++++++++++- 2 files changed, 192 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c5057646f..d555dd941 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -192,7 +192,138 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char return(func); } else return(-1); } - + +int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datalen) +{ + if ( *fposp+size <= datalen ) + { + memcpy(dest,&filedata[*fposp],size); + (*fposp) += size; + return(size); + } + return(-1); +} + +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) +{ + static int32_t errs; + int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; + if ( fpos < datalen ) + { + func = filedata[fpos++]; + if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) + matched = 1; + else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); + if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) ) + errs++; + if ( func == 'P' ) + { + if ( (num= filedata[fpos++]) <= 64 ) + { + if ( memread(pubkeys,33*num,filedata,&fpos,datalen) != 33*num ) + errs++; + else + { + //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht); + if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) ) + komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys); + } + } else printf("illegal num.%d\n",num); + } + else if ( func == 'N' ) + { + if ( memread(¬arized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) ) + errs++; + if ( memread(¬arized_hash,sizeof(notarized_hash),filedata,&fpos,datalen) != sizeof(notarized_hash) ) + errs++; + if ( memread(¬arized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) ) + errs++; + //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); + //if ( matched != 0 ) global independent states -> inside *sp + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); + } + else if ( func == 'U' ) // deprecated + { + uint8_t n,nid; uint256 hash; uint64_t mask; + n = filedata[fpos++]; + nid = filedata[fpos++]; + //printf("U %d %d\n",n,nid); + if ( memread(&mask,sizeof(mask),filedata,&fpos,datalen) != sizeof(mask) ) + errs++; + if ( memread(&hash,sizeof(hash),filedata,&fpos,datalen) != sizeof(hash) ) + errs++; + } + else if ( func == 'K' ) + { + int32_t kheight; + if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) ) + errs++; + komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0); + } + else if ( func == 'T' ) + { + int32_t kheight,ktimestamp; + if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) ) + errs++; + if ( memread(&ktimestamp,sizeof(ktimestamp),filedata,&fpos,datalen) != sizeof(ktimestamp) ) + errs++; + //if ( matched != 0 ) global independent states -> inside *sp + //printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp); + komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp); + } + else if ( func == 'R' ) + { + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; + if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) + errs++; + if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) + errs++; + if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) + errs++; + if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) + errs++; + if ( olen < sizeof(opret) ) + { + if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) + errs++; + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + { + int32_t i; for (i=0; i global PAX + } else + { + int32_t i; + for (i=0; i global PVALS + //printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht); + komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); + //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + } else printf("error loading pvals[%d]\n",numpvals); + } + else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + *fposp = fpos; + return(fpos); + } else return(-1); +} + void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 225d1a927..f7ad35e6a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,11 +1351,59 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) +{ + FILE *fp; + long filesize,buflen = *allocsizep; + char *buf = *bufp; + *lenp = 0; + if ( (fp= fopen(fname,"rb")) != 0 ) + { + fseek(fp,0,SEEK_END); + filesize = ftell(fp); + if ( filesize == 0 ) + { + fclose(fp); + *lenp = 0; + printf("OS_loadfile null size.(%s)\n",fname); + return(0); + } + if ( filesize > buflen-1 ) + { + *allocsizep = filesize+1; + *bufp = buf = realloc(buf,(long)*allocsizep); + } + rewind(fp); + if ( buf == 0 ) + printf("Null buf ???\n"); + else + { + if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) + printf("error reading filesize.%ld\n",(long)filesize); + buf[filesize] = 0; + } + fclose(fp); + *lenp = filesize; + //printf("loaded.(%s)\n",buf); + } //else printf("OS_loadfile couldnt load.(%s)\n",fname); + return(buf); +} + +uint8_t *OS_fileptr(long *allocsizep,char *fname) +{ + long filesize = 0; char *buf = 0; void *retptr; + *allocsizep = 0; + retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); + return(retptr); +} + +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); + void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) @@ -1411,7 +1459,17 @@ void komodo_passport_iteration() komodo_nameset(symbol,dest,base); sp = komodo_stateptrget(symbol); n = 0; - if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + fpos = 0; + while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) + ; + printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + lastpos[baseid] = fpos; + free(filedata), filedata = 0; + datalen = 0; + } + else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); if ( ftell(fp) > lastpos[baseid] ) From e9c761589b93f2c69c2891db0312e6396fbc62cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:53:04 +0200 Subject: [PATCH 06/75] Test --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f7ad35e6a..2472f6770 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,11 +1351,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } -void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) +void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) { FILE *fp; long filesize,buflen = *allocsizep; - char *buf = *bufp; + uint8_t *buf = *bufp; *lenp = 0; if ( (fp= fopen(fname,"rb")) != 0 ) { @@ -1371,7 +1371,7 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) if ( filesize > buflen-1 ) { *allocsizep = filesize+1; - *bufp = buf = realloc(buf,(long)*allocsizep); + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); } rewind(fp); if ( buf == 0 ) @@ -1391,10 +1391,10 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) uint8_t *OS_fileptr(long *allocsizep,char *fname) { - long filesize = 0; char *buf = 0; void *retptr; + long filesize = 0; uint8_t *buf = 0; void *retptr; *allocsizep = 0; retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); - return(retptr); + return((uint8_t *)retptr); } long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); From b356016e7782f3495e27a586e4ffdb9a4ae91ef5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:53:37 +0200 Subject: [PATCH 07/75] Test --- 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 2472f6770..ae15e1019 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1397,7 +1397,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); void komodo_passport_iteration() { From f7ec3a985a0e9ab22018476392d5218dd049fcd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:04:26 +0200 Subject: [PATCH 08/75] Test --- src/komodo.h | 2 +- src/komodo_gateway.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d555dd941..1bcc477ac 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -238,7 +238,7 @@ long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *f errs++; if ( memread(¬arized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) ) errs++; - //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ae15e1019..ca00f1531 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1452,7 +1452,7 @@ void komodo_passport_iteration() base = (char *)CURRENCIES[baseid]; if ( baseid+1 != refid ) { - if ( baseid == 32 || ASSETCHAINS_SYMBOL[0] == 0 ) + if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) { refsp->RTmask &= ~(1LL << baseid); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); @@ -1462,6 +1462,7 @@ void komodo_passport_iteration() if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; + printf("processing %s %ldKB\n",fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); @@ -1472,6 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); + printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024) if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 5b32c90080cfa03e1ded7224a002a032b2d71835 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:05:55 +0200 Subject: [PATCH 09/75] Test --- 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 ca00f1531..2495bd9b6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024) + printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 13b0e935d8a5a4b55de7d975af27147ddedce7b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:14:59 +0200 Subject: [PATCH 10/75] Test --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2495bd9b6..dc427eaff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1442,7 +1442,6 @@ void komodo_passport_iteration() return; } lasttime = starttime; - //printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); for (baseid=32; baseid>=0; baseid--) { if ( time(NULL) >= starttime+maxseconds ) @@ -1450,6 +1449,7 @@ void komodo_passport_iteration() sp = 0; isrealtime = 0; base = (char *)CURRENCIES[baseid]; + printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); if ( baseid+1 != refid ) { if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) @@ -1462,10 +1462,10 @@ void komodo_passport_iteration() if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; - printf("processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; - printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); lastpos[baseid] = fpos; free(filedata), filedata = 0; datalen = 0; @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); + fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) @@ -1498,7 +1498,7 @@ void komodo_passport_iteration() printf("from.(%s) lastpos[%s] %ld isrt.%d\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid],komodo_isrealtime(&ht)); } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); fclose(fp); - } //else printf("error.(%s) %p\n",fname,sp); + } else fprintf(stderr,"load error.(%s) %p\n",fname,sp); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"rb")) != 0 ) { From 08775bc1faacce1aa0a5c7b44041fa17482b90f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:20:45 +0200 Subject: [PATCH 11/75] Test --- src/komodo.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 1bcc477ac..bb4735f49 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -345,10 +345,23 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) - ; + uint8_t *filedata; long datalen,fpos; + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + fpos = 0; + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) + ; + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + free(filedata); + fseek(fp,fpos,SEEK_SET); + } + else + { + while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) + ; + } } else fp = fopen(fname,"wb+"); - printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); } if ( height <= 0 ) From 0cd5ab88aa74f32bb0f092c375e151519763ca3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:25:59 +0200 Subject: [PATCH 12/75] Test --- src/komodo_gateway.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dc427eaff..5d7716259 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1449,23 +1449,23 @@ void komodo_passport_iteration() sp = 0; isrealtime = 0; base = (char *)CURRENCIES[baseid]; - printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); - if ( baseid+1 != refid ) + //printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); + if ( baseid+1 != refid ) // only need to import state from a different coin { - if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) + if ( baseid == 32 ) // only care about KMD's state { refsp->RTmask &= ~(1LL << baseid); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); komodo_nameset(symbol,dest,base); sp = komodo_stateptrget(symbol); n = 0; - if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + if ( lastpos[baseid] == 0 && (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"%s processing %s %ldKB\n",ASSETCHAINS_SYMBOL,fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; - fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + fprintf(stderr,"%s took %d seconds to process %s %ldKB\n",ASSETCHAINS_SYMBOL,(int32_t)(time(NULL)-starttime),fname,datalen/1024); lastpos[baseid] = fpos; free(filedata), filedata = 0; datalen = 0; @@ -1494,7 +1494,7 @@ void komodo_passport_iteration() n++; } lastpos[baseid] = ftell(fp); - if ( lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 ) + if ( 0 && lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 ) printf("from.(%s) lastpos[%s] %ld isrt.%d\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid],komodo_isrealtime(&ht)); } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); fclose(fp); From 9ddeeba22691915fb0377aab10e45131dcc47e57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:27:08 +0200 Subject: [PATCH 13/75] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index bb4735f49..dd5ffa869 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -345,7 +345,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - uint8_t *filedata; long datalen,fpos; + uint8_t *filedata; long datalen,fpos; uint32_t starttime = (uint32_t)time(NULL); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; From 58f293eb9882106258b8b970257bd913b26204c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:36:09 +0200 Subject: [PATCH 14/75] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index dd5ffa869..9e332a34f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -354,7 +354,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar ; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); free(filedata); - fseek(fp,fpos,SEEK_SET); + fseek(fp,0,SEEK_END); } else { From cb7f1d47c1fba2409997ed305f4aaa0b2d5726a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:39:44 +0200 Subject: [PATCH 15/75] Test --- 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 5d7716259..3ecf453c5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1370,7 +1370,7 @@ void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) } if ( filesize > buflen-1 ) { - *allocsizep = filesize+1; + *allocsizep = filesize; *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); } rewind(fp); From 211f7541264e2bb6c87ae8a719eccd18df6940ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:48:50 +0200 Subject: [PATCH 16/75] Test --- 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 3ecf453c5..441544d0b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); + //fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 3b40d63139bba4890e927369b5b1c8fce812b913 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:06:10 +0200 Subject: [PATCH 17/75] komodostate.ind --- src/komodo.h | 20 +++---- src/komodo_gateway.h | 122 ++++++++++++++++++++++++++++++++++++++++++- src/purge | 5 ++ 3 files changed, 132 insertions(+), 15 deletions(-) create mode 100755 src/purge diff --git a/src/komodo.h b/src/komodo.h index 9e332a34f..f057e1e86 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -204,10 +204,10 @@ int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datal return(-1); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) { static int32_t errs; - int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; + int32_t func= -1,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; if ( fpos < datalen ) { func = filedata[fpos++]; @@ -320,8 +320,9 @@ long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *f } else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); *fposp = fpos; - return(fpos); - } else return(-1); + return(func); + } + return(-1); } void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) @@ -345,17 +346,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - uint8_t *filedata; long datalen,fpos; uint32_t starttime = (uint32_t)time(NULL); - if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) - { - fpos = 0; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); - while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) - ; - fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); - free(filedata); + if ( komodo_faststateinit(sp,fname) == 0 ) fseek(fp,0,SEEK_END); - } else { while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 441544d0b..ffb07918e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,6 +1351,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) +{ + uint8_t func; long fpos; + komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); + // scan backwards to set all the sp-> fields to the current valid value +} + void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) { FILE *fp; @@ -1397,7 +1404,120 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); + +long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) +{ + FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + *indcounterp = *prevpos100p = 0; + if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) + { + if ( (fsize % sizeof(uint32_t)) == 0 ) + { + n = (int32_t)(fsize / sizeof(uint32_t)); + for (i=0; i> 8); + fpos = prevpos100 + offset; + if ( fpos >= datalen || filedata[fpos] != func ) + { + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); + return(-1); + } + } + } + *indcounterp = n; + *prevpos100p = prevpos100; + printf("%s validated[%d] fpos.%ld datalen.%ld\n",indfname,i,fpos,datalen); + if ( sp != 0 ) + komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + free(inds); + return(fpos); + } else printf("wrong filesize %s %ld\n",indfname,fsize); + } + free(inds); + return(-1); +} + +long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long newfpos,uint8_t func,uint32_t *indcounterp) +{ + uint32_t tmp; + if ( indfp != 0 ) + { + tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); + if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) + printf("indfp fpos %ld -> ind.%d vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); + fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; + if ( (*indcounterp % 100) == 0 ) + { + *prevpos100p = (uint32_t)newfpos; + fwrite(prevpos100p,1,sizeof(*prevpos100p),indfp), (*indcounterp)++; + } + } + return(newfpos); +} + +int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) +{ + FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; + stattime = (uint32_t)time(NULL); + safecopy(indfname,fname,sizeof(indfname)-4); + strcat(indfname,".ind"); + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter)) < 0 ) + { + lastfpos = fpos = 0; + indcounter = prevpos100 = 0; + if ( (indfp= fopen(indfname,"wb")) != 0 ) + fwrite(&prevpos100,1,sizeof(prevpos100),indfp), indcounter++; + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + } + if ( indfp != 0 ) + { + fclose(indfp); + if ( komodo_stateind_validate(0,indfname,filedata,datalen,symbol,dest) < 0 ) + printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); + else printf("%s validated\n",indfname); + } + finished = 1; + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + } + else if ( processed > 0 ) + { + if ( (indfp= fopen(indfname,"rb+")) != 0 ) + { + lastfpos = fpos = processed; + fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); + if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) + { + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + } + fclose(indfp); + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,system,dest) < 0 ) + printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); + else + { + printf("%s validated updated from processed.%ld to %ld [%ld]\n",indfname,processed,fpos,fpos-processed); + finished = 1; + } + } + } else printf("komodo_faststateinit unexpected case\n"); + free(filedata); + return(finished == 1); + } + return(-1); +} void komodo_passport_iteration() { diff --git a/src/purge b/src/purge new file mode 100755 index 000000000..08928e922 --- /dev/null +++ b/src/purge @@ -0,0 +1,5 @@ +rm -rf ~/.komodo/$1/chainstate +rm -rf ~/.komodo/$1/database +rm -rf ~/.komodo/$1/blocks +rm -rf ~/.komodo/$1/komodostate + From 52129d3054a7b919d08f4e0156a9aee7a94c2179 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:07:13 +0200 Subject: [PATCH 18/75] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index f057e1e86..e49eb7452 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -346,7 +346,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( komodo_faststateinit(sp,fname) == 0 ) + if ( komodo_faststateinit(sp,fname,symbol,dest) == 0 ) fseek(fp,0,SEEK_END); else { From 3d40ead2a476510b216f21ea12d9acd227d868cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:08:52 +0200 Subject: [PATCH 19/75] Test --- 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 ffb07918e..3ebf22bc4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1471,7 +1471,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter)) < 0 ) + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; From af786d5de8702d100a5b71bb8ebfcc4d79c8a3a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:10:29 +0200 Subject: [PATCH 20/75] Test --- 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 3ebf22bc4..ec006c9ee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,10 +1351,12 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); + void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { uint8_t func; long fpos; - komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); + //komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); // scan backwards to set all the sp-> fields to the current valid value } @@ -1404,8 +1406,6 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); - long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; @@ -1466,7 +1466,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) { FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; - stattime = (uint32_t)time(NULL); + starttime = (uint32_t)time(NULL); safecopy(indfname,fname,sizeof(indfname)-4); strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) From b8359369fba6746e389aaeb415ac96e4c9532614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:12:10 +0200 Subject: [PATCH 21/75] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ec006c9ee..7dae417b5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1452,7 +1452,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long { tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) - printf("indfp fpos %ld -> ind.%d vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); + printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { @@ -1485,7 +1485,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( indfp != 0 ) { fclose(indfp); - if ( komodo_stateind_validate(0,indfname,filedata,datalen,symbol,dest) < 0 ) + if ( komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else printf("%s validated\n",indfname); } @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,system,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcountersystem,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 79a6f2aee26b7681d0fa49132a31c76d8144b325 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:13:18 +0200 Subject: [PATCH 22/75] Test --- 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 7dae417b5..a7228f2aa 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcountersystem,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,system,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 4c87a8df446b54ab703b4340c638ebff99ef08cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:16:19 +0200 Subject: [PATCH 23/75] Test --- 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 a7228f2aa..c0b3a5845 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,system,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 6cc0f9de1289468903d2e61219ed0aa5598f3928 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:21:05 +0200 Subject: [PATCH 24/75] Test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c0b3a5845..b82f96714 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1442,6 +1442,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); + fprintf(stderr,"indvalidate return -1\n"); return(-1); } @@ -1471,6 +1472,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { + fprintf(stderr,"faststateinit %s datalen.%ld\n",indfname,datalen); if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; @@ -1516,6 +1518,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch free(filedata); return(finished == 1); } + fprintf(stderr,"faststateinit return -1\n"); return(-1); } From 1ff645e6f5e33dc2750595b2e9fc5512fbf44fbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:29:26 +0200 Subject: [PATCH 25/75] Test --- src/komodo_gateway.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b82f96714..e93d0836c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1466,20 +1466,19 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) { - FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; + FILE *indfp; char indfname[1024]; uint8_t *filedata; long validated=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; starttime = (uint32_t)time(NULL); safecopy(indfname,fname,sizeof(indfname)-4); strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - fprintf(stderr,"faststateinit %s datalen.%ld\n",indfname,datalen); - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; if ( (indfp= fopen(indfname,"wb")) != 0 ) fwrite(&prevpos100,1,sizeof(prevpos100),indfp), indcounter++; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"processing %s %ldKB, validated.%ld\n",fname,datalen/1024,validated); while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) { lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); @@ -1494,11 +1493,12 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch finished = 1; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); } - else if ( processed > 0 ) + else if ( validated > 0 ) { if ( (indfp= fopen(indfname,"rb+")) != 0 ) { - lastfpos = fpos = processed; + lastfpos = fpos = validated; + fprintf(stderr,"validated %ld -> %ld vs indcounter %u, prevpos100 %u offset.%ld\n",validated,validated/sizeof(uint32_t),indcounter,prevpos100,indcounter * sizeof(uint32_t)); fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { @@ -1510,7 +1510,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from processed.%ld to %ld [%ld]\n",indfname,processed,fpos,fpos-processed); + printf("%s validated updated from validated.%ld to %ld [%ld]\n",indfname,validated,fpos,fpos-validated); finished = 1; } } @@ -1518,7 +1518,6 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch free(filedata); return(finished == 1); } - fprintf(stderr,"faststateinit return -1\n"); return(-1); } From e75dc69d019f79fafbd60a787e020650a3363ae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:37:14 +0200 Subject: [PATCH 26/75] Test --- src/komodo_gateway.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e93d0836c..673f37a7c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -274,7 +274,7 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che return(0); else { - if ( kmdheight >= 238000 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("ht.%d ignore mismatched %s value %lld vs checkvalue %lld -> ratio.%d\n",kmdheight,symbol,(long long)value,(long long)checkvalue,ratio); return(-1); } @@ -1418,6 +1418,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi for (i=0; i n-10 ) + printf("%d: tmp.%08x prevpos100.%u\n",i,tmp,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; else @@ -1498,7 +1500,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( (indfp= fopen(indfname,"rb+")) != 0 ) { lastfpos = fpos = validated; - fprintf(stderr,"validated %ld -> %ld vs indcounter %u, prevpos100 %u offset.%ld\n",validated,validated/sizeof(uint32_t),indcounter,prevpos100,indcounter * sizeof(uint32_t)); + fprintf(stderr,"validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { @@ -1510,7 +1512,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from validated.%ld to %ld [%ld]\n",indfname,validated,fpos,fpos-validated); + printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); finished = 1; } } From 8c18d226b342b9d5fba6ffd7a6fe1a556e148132 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:39:07 +0200 Subject: [PATCH 27/75] Test --- src/komodo.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e49eb7452..77f7dc04b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -328,7 +328,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; - struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; if ( didinit == 0 ) { portable_mutex_init(&KOMODO_KV_mutex); @@ -346,10 +346,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( komodo_faststateinit(sp,fname,symbol,dest) == 0 ) + if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) == 0 ) fseek(fp,0,SEEK_END); else { + fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);) while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; } From a3a7ec859293365158a4b7fe035ce4fd9375ce76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:40:11 +0200 Subject: [PATCH 28/75] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 77f7dc04b..f3d21d634 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -350,7 +350,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fseek(fp,0,SEEK_END); else { - fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);) + fprintf(stderr,"komodo_faststateinit retval.%d\n",retval); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; } From f7f9608782eacfd9d803e220edd81bf352fd94de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:48:02 +0200 Subject: [PATCH 29/75] Test --- src/komodo.h | 2 +- src/komodo_gateway.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f3d21d634..02253950e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -346,7 +346,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) == 0 ) + if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) > 0 ) fseek(fp,0,SEEK_END); else { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 673f37a7c..e4d368a34 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1412,6 +1412,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { + fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1419,7 +1420,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { memcpy(&tmp,&inds[i * sizeof(uint32_t)],sizeof(uint32_t)); if ( i > n-10 ) - printf("%d: tmp.%08x prevpos100.%u\n",i,tmp,prevpos100); + printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; else From 1f14a5164a418d6752922d749b80bfd5a35e744a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:00:24 +0200 Subject: [PATCH 30/75] Test --- src/komodo_gateway.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e4d368a34..abba20564 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1457,7 +1457,8 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; + fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { *prevpos100p = (uint32_t)newfpos; @@ -1506,7 +1507,11 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + if ( lastfpos != fpos ) + fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + } } fclose(indfp); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) @@ -1528,7 +1533,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) @@ -1589,9 +1594,9 @@ void komodo_passport_iteration() fpos = 0; fprintf(stderr,"%s processing %s %ldKB\n",ASSETCHAINS_SYMBOL,fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) - ; + lastfpos = fpos; fprintf(stderr,"%s took %d seconds to process %s %ldKB\n",ASSETCHAINS_SYMBOL,(int32_t)(time(NULL)-starttime),fname,datalen/1024); - lastpos[baseid] = fpos; + lastpos[baseid] = lastfpos; free(filedata), filedata = 0; datalen = 0; } From 01c8221f8dcfee9bd3e5d7a5edc114f635f9c636 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:21:35 +0200 Subject: [PATCH 31/75] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index abba20564..78b9c0908 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1441,7 +1441,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); - return(fpos); + return(datalen); } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); @@ -1490,9 +1490,9 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( indfp != 0 ) { fclose(indfp); - if ( komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) + if ( (fpos= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); - else printf("%s validated\n",indfname); + else printf("%s validated fpos.%ld\n",indfname,fpos); } finished = 1; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); From 052562c1a2e1875b2a742c54370a04cd6d698eb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:27:22 +0200 Subject: [PATCH 32/75] Test --- src/komodo_gateway.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 78b9c0908..57b3a0163 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1534,7 +1534,7 @@ void komodo_passport_iteration() static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; - //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); + printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) { @@ -1566,11 +1566,6 @@ void komodo_passport_iteration() starttime = (uint32_t)time(NULL); if ( callcounter++ < 1 ) limit = 10000; - if ( 0 && starttime == lasttime ) - { - usleep(1000); - return; - } lasttime = starttime; for (baseid=32; baseid>=0; baseid--) { From 5b5c0bf3eb3d03d28174c2f4879eacdca78f36e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:51:17 +0200 Subject: [PATCH 33/75] test --- src/komodo_gateway.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 57b3a0163..9d29a2441 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,10 +1408,11 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { + lastfpos = 0; fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); if ( (fsize % sizeof(uint32_t)) == 0 ) { @@ -1428,12 +1429,13 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( fpos >= datalen || filedata[fpos] != func ) + if ( fpos >= datalen || filedata[lastfpos] != func ) { printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); return(-1); } } + lastfpos = fpos; } *indcounterp = n; *prevpos100p = prevpos100; @@ -1441,7 +1443,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); - return(datalen); + return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); @@ -1454,7 +1456,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long uint32_t tmp; if ( indfp != 0 ) { - tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); + tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); @@ -1534,7 +1536,6 @@ void komodo_passport_iteration() static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; - printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) { From 5d5c720dbf2b9c6554bc09bb33ef7ef4fbba09e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:23:38 +0200 Subject: [PATCH 34/75] Test --- 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 9d29a2441..edacc2664 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1429,9 +1429,9 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( fpos >= datalen || filedata[lastfpos] != func ) + if ( lastfpos >= datalen || filedata[lastfpos] != func ) { - printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c)\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos]); return(-1); } } From 75f0def0129b31fe31ba17431d170be2e712f14f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:33:18 +0200 Subject: [PATCH 35/75] Test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index edacc2664..1116b639d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); + fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1431,7 +1431,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi fpos = prevpos100 + offset; if ( lastfpos >= datalen || filedata[lastfpos] != func ) { - printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c)\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos]); + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c) lastfpos.%ld\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos],lastfpos); + exit(-1); return(-1); } } From ac7d572b6904ee5093de89889c60cda916b5fb97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:37:48 +0200 Subject: [PATCH 36/75] Test --- 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 1116b639d..fe48c9718 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,7 +1408,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,lastfpos,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos=0,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { From d60660744902fadc0fdeae31163feee54d1d2355 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:40:16 +0200 Subject: [PATCH 37/75] Test --- 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 fe48c9718..9a2a9e840 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,7 +1408,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,lastfpos=0,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos=0,fpos=0; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { From 651ce5743f530ef5ac11af6bec0c22a35c589711 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:54:47 +0200 Subject: [PATCH 38/75] Test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9a2a9e840..49dc005d1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); + //fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1432,7 +1432,6 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( lastfpos >= datalen || filedata[lastfpos] != func ) { printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c) lastfpos.%ld\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos],lastfpos); - exit(-1); return(-1); } } @@ -1460,7 +1459,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { From 95880660c64cc6289955968ad672ff40aa83a7c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:02:23 +0200 Subject: [PATCH 39/75] Test --- 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 49dc005d1..68367718e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1420,7 +1420,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi for (i=0; i n-10 ) + if ( 0 && i > n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; @@ -1439,7 +1439,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } *indcounterp = n; *prevpos100p = prevpos100; - printf("%s validated[%d] fpos.%ld datalen.%ld\n",indfname,i,fpos,datalen); + printf("%s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); From e3c63db23b06ddd35c0ef000851aad517f4c906f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:06:37 +0200 Subject: [PATCH 40/75] Test --- src/komodo_gateway.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 68367718e..766df3995 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1459,7 +1459,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { @@ -1504,18 +1504,21 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( (indfp= fopen(indfname,"rb+")) != 0 ) { lastfpos = fpos = validated; - fprintf(stderr,"validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); - fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); - if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) + fprintf(stderr,"datalen.%ld validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",datalen,validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + if ( fpos < datalen ) { - while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); + if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { - lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); - if ( lastfpos != fpos ) - fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + if ( lastfpos != fpos ) + fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + } } + fclose(indfp); } - fclose(indfp); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else From b883389a8207fa9e5ac74024df6faa40d0f67804 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:12:47 +0200 Subject: [PATCH 41/75] Test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 766df3995..ca43d184d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - //fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); + fprintf(stderr,"inds.%p validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",inds,indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1439,9 +1439,9 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } *indcounterp = n; *prevpos100p = prevpos100; - printf("%s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); @@ -1519,6 +1519,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } fclose(indfp); } + printf("call validate datalen.%ld\n",datalen); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else @@ -1528,6 +1529,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } } } else printf("komodo_faststateinit unexpected case\n"); + printf("free filedata.%p\n",filedata); free(filedata); return(finished == 1); } From 3e394a57e006a922b7df173a2fef6de1526dfbfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:16:04 +0200 Subject: [PATCH 42/75] Test --- 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 ca43d184d..4e2bbcabf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1418,7 +1418,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { n = (int32_t)(fsize / sizeof(uint32_t)); for (i=0; i n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); From 05d9b22010c98eca43beeb29aa20e7f17f1a3f90 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:18:10 +0200 Subject: [PATCH 43/75] Test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4e2bbcabf..62957da3b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1437,6 +1437,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } lastfpos = fpos; } +fpos=datalen; *indcounterp = n; *prevpos100p = prevpos100; if ( sp != 0 ) From 37c74e15e16baa35eef934c9d84a920a4d230cfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:20:09 +0200 Subject: [PATCH 44/75] Test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 62957da3b..53e31317f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1418,7 +1418,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { n = (int32_t)(fsize / sizeof(uint32_t)); for (i=0; i n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); @@ -1437,13 +1437,12 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } lastfpos = fpos; } -fpos=datalen; *indcounterp = n; *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + else free(inds); printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); - free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } From 2baa86a396ca67826f05269b18857f82b2f2b29e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:22:53 +0200 Subject: [PATCH 45/75] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 53e31317f..4f5abb2fc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1377,10 +1377,10 @@ void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) printf("OS_loadfile null size.(%s)\n",fname); return(0); } - if ( filesize > buflen-1 ) + if ( filesize > buflen ) { *allocsizep = filesize; - *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); } rewind(fp); if ( buf == 0 ) @@ -1441,8 +1441,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); - else free(inds); printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); + free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } From dbd0722f1c2806a004a9e3f6407bcb3d71259ebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:25:59 +0200 Subject: [PATCH 46/75] Test --- src/komodo_gateway.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4f5abb2fc..c795f5b74 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1441,7 +1441,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); - printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); + //printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); @@ -1519,17 +1519,15 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } fclose(indfp); } - printf("call validate datalen.%ld\n",datalen); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld | elapsed %d seconds\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t),(int32_t)(time(NULL) - starttime)); finished = 1; } } } else printf("komodo_faststateinit unexpected case\n"); - printf("free filedata.%p\n",filedata); free(filedata); return(finished == 1); } From 43430608217eddac9cc2745f1aa51b216c6a36be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:22:06 +0200 Subject: [PATCH 47/75] Test --- src/komodo_gateway.h | 129 ++++++++++++++++++++++++++++++++++++--- src/wallet/rpcwallet.cpp | 2 + 2 files changed, 124 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c795f5b74..fe0e13b7e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1036,8 +1036,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 //printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL); return("assetchain"); } - //else if ( KOMODO_PAX == 0 ) - // return("nopax"); memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); memset(srcvalues,0,sizeof(srcvalues)); @@ -1048,8 +1046,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( opretbuf[0] == 'K' && opretlen != 40 ) { komodo_kvupdate(opretbuf,opretlen,value); + return("kv"); } - else if ( opretbuf[0] == 'D' ) + else if ( KOMODO_PAX == 0 ) + return("nopax"); + if ( opretbuf[0] == 'D' ) { tokomodo = 0; if ( opretlen == 38 ) // any KMD tx @@ -1355,9 +1356,123 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long fpos; - //komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); - // scan backwards to set all the sp-> fields to the current valid value + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100; + count = numN = numV = numn = numv = 0; + lastK = lastT = lastN = lastV; + for (iter=0; iter<2; iter++) + { + for (prevpos100=i=0; i> 8); + fpos = prevpos100 + offset; + if ( lastfpos >= datalen || filedata[lastfpos] != func ) + printf("lastfpos.%ld >= datalen.%ld or [%d] != fund.%d\n",lastfpos,datalen,filedata[lastfpos],func); + else if ( iter == 0 ) + { + switch ( func ) + { + default: case 'P': case 'U': case 'D': + inds[i] &= 0xffffff00; + break; + case 'K': + lastK = lastfpos; + inds[i] &= 0xffffff00; + break; + case 'T': + lastT = lastfpos; + inds[i] &= 0xffffff00; + break; + case 'N': + lastN = lastfpos; + numN++; + break; + case 'V': + lastV = lastfpos; + numV++; + break; + case 'R': break; + } + } + else + { + doissue = 0; + if ( func == 'K' ) + { + if ( lastK == lastfpos ) + doissue = 1, printf("trigger lastK\n"); + } + else if ( func == 'T' ) + { + if ( lastT == lastfpos ) + doissue = 1, printf("trigger lastT\n"); + } + else if ( func == 'N' ) + { + if ( numn > numN-128 ) + doissue = 1; + numn++; + } + else if ( func == 'V' ) + { + if ( numv > numV-1440 ) + doissue = 1; + numv++; + } + else if ( func == 'R' ) + doissue = 1; + if ( doissue != 0 ) + { + printf("issue %c total.%d lastfpos.%ld\n",func,count,lastfpos); + komodo_parsestatefiledata(sp,filedata,&lastfpos,datalen,symbol,dest); + count++; + } + } + } + lastfpos = fpos; + } + } + + else if ( func == 'K' ) // KMD height: stop after 1st + else if ( func == 'T' ) // KMD height+timestamp: stop after 1st + + else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; + else if ( func == 'V' ) // price feed: can stop after 1440+ + else if ( func == 'R' ) // opreturn: + { + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; + if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) + errs++; + if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) + errs++; + if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) + errs++; + if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) + errs++; + if ( olen < sizeof(opret) ) + { + if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) + errs++; + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + { + int32_t i; for (i=0; i global PAX + } else + { + int32_t i; + for (i=0; i ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 21ee626f6..269b306cc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -612,6 +612,8 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) { uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; + if ( KOMODO_PAX == 0 ) + throw JSONRPCError(RPC_TYPE_ERROR, "paxdeposit disabled, since pax not enabled with komodod -pax"); if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) From bf9c62be24aa97eb83487c9bed2c16ecc6620277 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:24:33 +0200 Subject: [PATCH 48/75] Test --- src/komodo_gateway.h | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fe0e13b7e..1fb2e3b23 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1356,7 +1356,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100; + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; count = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV; for (iter=0; iter<2; iter++) @@ -1437,42 +1437,12 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastfpos = fpos; } } - - else if ( func == 'K' ) // KMD height: stop after 1st + /*else if ( func == 'K' ) // KMD height: stop after 1st else if ( func == 'T' ) // KMD height+timestamp: stop after 1st else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; else if ( func == 'V' ) // price feed: can stop after 1440+ - else if ( func == 'R' ) // opreturn: - { - uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; - if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) - errs++; - if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) - errs++; - if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) - errs++; - if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) - errs++; - if ( olen < sizeof(opret) ) - { - if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) - errs++; - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) - { - int32_t i; for (i=0; i global PAX - } else - { - int32_t i; - for (i=0; i Date: Sun, 5 Nov 2017 16:26:53 +0200 Subject: [PATCH 49/75] Test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 269b306cc..ee9fb71bb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -480,6 +480,7 @@ uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pu int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" extern char ASSETCHAINS_SYMBOL[16]; +extern int32_t KOMODO_PAX; int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t komodo_isrealtime(int32_t *kmdheightp); From 4978e8cfda68f3dd1514f3572683aa2631f2f8cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:31:02 +0200 Subject: [PATCH 50/75] Test --- 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 1fb2e3b23..a757624fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1371,8 +1371,8 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( lastfpos >= datalen || filedata[lastfpos] != func ) - printf("lastfpos.%ld >= datalen.%ld or [%d] != fund.%d\n",lastfpos,datalen,filedata[lastfpos],func); + if ( lastfpos >= datalen || (filedata[lastfpos] != func && func != 0) ) + printf("lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",lastfpos,datalen,filedata[lastfpos],func); else if ( iter == 0 ) { switch ( func ) From 40537f140ba1d27caca9f3c10e13f3bcb2309f52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:32:59 +0200 Subject: [PATCH 51/75] Test --- src/komodo_gateway.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a757624fd..5969fb4c0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1357,8 +1357,8 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; - count = numN = numV = numn = numv = 0; - lastK = lastT = lastN = lastV; + count = numR = numN = numV = numn = numv = 0; + lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { for (prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:34:01 +0200 Subject: [PATCH 52/75] Test --- 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 5969fb4c0..aecb9fbf5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1356,7 +1356,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; count = numR = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) From 0c6f830182cc68845b7e221f5b8dfa3b877e8009 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:43:51 +0200 Subject: [PATCH 53/75] Test --- 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 aecb9fbf5..20cdbc05f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1372,7 +1372,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ offset = (tmp >> 8); fpos = prevpos100 + offset; if ( lastfpos >= datalen || (filedata[lastfpos] != func && func != 0) ) - printf("lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",lastfpos,datalen,filedata[lastfpos],func); + printf("i.%d/n.%d lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",i,n,lastfpos,datalen,filedata[lastfpos],func); else if ( iter == 0 ) { switch ( func ) @@ -1422,7 +1422,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ } else if ( func == 'V' ) { - if ( numv > numV-1440 ) + if ( KOMODO_PAX != 0 || numv > numV-1440 ) doissue = 1; numv++; } From 7730b5c45ab863e7abe90f8030de73b843e255fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:46:02 +0200 Subject: [PATCH 54/75] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 20cdbc05f..a7ee5eaa2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1149,7 +1149,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( baseids[i] < 0 ) { static uint32_t counter; - if ( counter++ < 3 ) + if ( ++counter < 1 ) printf("%d of %d illegal baseid.%d, this can be ignored\n",i,n,baseids[i]); continue; } @@ -1356,12 +1356,12 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; + uint8_t func; long lastK,lastT,lastN,lastV,fpos,lastfpos; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; count = numR = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:46:45 +0200 Subject: [PATCH 55/75] Test --- 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 a7ee5eaa2..8a9baee45 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1361,7 +1361,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (latfpos=fpos=prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:50:37 +0200 Subject: [PATCH 56/75] Test --- src/komodo_gateway.h | 9 +++++---- src/komodo_kv.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8a9baee45..5655db040 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,8 +1048,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - else if ( KOMODO_PAX == 0 ) - return("nopax"); + //else if ( KOMODO_PAX == 0 ) + // return("nopax"); + printf("OPRET.%c\n",opretbuf[0]); if ( opretbuf[0] == 'D' ) { tokomodo = 0; @@ -1149,7 +1150,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( baseids[i] < 0 ) { static uint32_t counter; - if ( ++counter < 1 ) + if ( counter++ < 0 ) printf("%d of %d illegal baseid.%d, this can be ignored\n",i,n,baseids[i]); continue; } @@ -1361,7 +1362,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (lastfpos=fpos=prevpos100=i=0; i opretlen ) { static uint32_t counter; - if ( counter++ < 3 ) + if ( ++counter < 1 ) printf("komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen); return; } From ddef24809caee31a594aa60a50446f7ff606ff91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:51:54 +0200 Subject: [PATCH 57/75] Test --- 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 5655db040..c8004a23d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1362,7 +1362,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (latfpos=fpos=prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:54:41 +0200 Subject: [PATCH 58/75] Test --- src/komodo_gateway.h | 1 - src/komodo_utils.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c8004a23d..ca54983bc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1050,7 +1050,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } //else if ( KOMODO_PAX == 0 ) // return("nopax"); - printf("OPRET.%c\n",opretbuf[0]); if ( opretbuf[0] == 'D' ) { tokomodo = 0; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92577dae0..7db4f6fff 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,7 @@ void komodo_args(char *argv0) { USE_EXTERNAL_PUBKEY = 1; KOMODO_PAX = 1; - } else KOMODO_PAX = GetArg("-pax",0); + } else KOMODO_PAX = GetArg("-pax",1); name = GetArg("-ac_name",""); if ( argv0 != 0 ) { From 02b20e4022ff130a619d1596065bdaa1f3edd488 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:56:47 +0200 Subject: [PATCH 59/75] Test --- src/komodo_gateway.h | 4 ++-- src/komodo_utils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ca54983bc..07187c41c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,8 +1048,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - //else if ( KOMODO_PAX == 0 ) - // return("nopax"); + else if ( KOMODO_PAX == 0 ) + return("nopax"); if ( opretbuf[0] == 'D' ) { tokomodo = 0; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7db4f6fff..92577dae0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,7 @@ void komodo_args(char *argv0) { USE_EXTERNAL_PUBKEY = 1; KOMODO_PAX = 1; - } else KOMODO_PAX = GetArg("-pax",1); + } else KOMODO_PAX = GetArg("-pax",0); name = GetArg("-ac_name",""); if ( argv0 != 0 ) { From 3a48f81a308dece1c8c3d8c7a05a7a4830a4f25b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:58:04 +0200 Subject: [PATCH 60/75] Test --- 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 07187c41c..b69857141 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,7 +1048,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - else if ( KOMODO_PAX == 0 ) + else if ( ASSETCHAINS_SYMBOL[0] == 0 && KOMODO_PAX == 0 ) return("nopax"); if ( opretbuf[0] == 'D' ) { @@ -1566,7 +1566,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) + if ( 1 )//datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; From e31b96160784943af2bf5f29373afdbc941bc794 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 18:47:09 +0200 Subject: [PATCH 61/75] Remove prints --- 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 b69857141..d4d72781d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1407,12 +1407,12 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ if ( func == 'K' ) { if ( lastK == lastfpos ) - doissue = 1, printf("trigger lastK\n"); + doissue = 1; } else if ( func == 'T' ) { if ( lastT == lastfpos ) - doissue = 1, printf("trigger lastT\n"); + doissue = 1; } else if ( func == 'N' ) { From e9d73912befb3fa9dc9952e1a0e8a7f34ad3dcfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 13:52:29 +0200 Subject: [PATCH 62/75] Fix help error --- src/komodo_gateway.h | 2 +- src/wallet/rpcwallet.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d4d72781d..1bdc6034c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1422,7 +1422,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ } else if ( func == 'V' ) { - if ( KOMODO_PAX != 0 || numv > numV-1440 ) + if ( KOMODO_PAX != 0 && numv > numV-1440 ) doissue = 1; numv++; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ee9fb71bb..c72527c01 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -614,7 +614,9 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; if ( KOMODO_PAX == 0 ) - throw JSONRPCError(RPC_TYPE_ERROR, "paxdeposit disabled, since pax not enabled with komodod -pax"); + { + throw runtime_error("paxdeposit dispabled without -pax"); + } if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) From 7c130297c27fadb9557b89d155e836eb5c99f02f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:07:36 +0200 Subject: [PATCH 63/75] KOMODO_ASSETCHAIN_MAXLEN -> 65 --- src/bitcoind.cpp | 2 +- src/chainparams.cpp | 2 +- src/coins.cpp | 2 +- src/komodo.h | 10 +++++----- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 12 ++++++------ src/komodo_globals.h | 3 ++- src/komodo_notary.h | 4 ++-- src/komodo_structs.h | 4 ++-- src/komodo_utils.h | 2 +- src/main.cpp | 2 +- src/miner.cpp | 2 +- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- src/util.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 2 +- src/zcash/CreateJoinSplit.cpp | 2 +- 18 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 050305117..6bff57071 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -42,7 +42,7 @@ */ static bool fDaemon; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; void komodo_passport_iteration(); void WaitForShutdown(boost::thread_group* threadGroup) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 17b5dab6e..c6b3f393f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -30,7 +30,7 @@ using namespace std; * + Contains no strange transactions */ void *chainparams_commandline(void *ptr); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_PORT; extern uint32_t ASSETCHAIN_INIT; extern uint32_t ASSETCHAINS_MAGIC; diff --git a/src/coins.cpp b/src/coins.cpp index 27cac5a6f..aa858eeb8 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -387,7 +387,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const //uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { diff --git a/src/komodo.h b/src/komodo.h index 02253950e..fb2160da7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -56,14 +56,14 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char void komodo_currentheight_set(int32_t height) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) sp->CURRENT_HEIGHT = height; } int32_t komodo_currentheight() { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) return(sp->CURRENT_HEIGHT); else return(0); @@ -328,7 +328,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; - struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; + struct komodo_state *sp; char fname[512],symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; if ( didinit == 0 ) { portable_mutex_init(&KOMODO_KV_mutex); @@ -475,7 +475,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) { static uint256 zero; static FILE *signedfp; - int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; + int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -633,7 +633,7 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; - uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp; + uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; memset(&zero,0,sizeof(zero)); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e4d216741..d356bd6bf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -559,7 +559,7 @@ uint32_t komodo_txtime(uint256 hash) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; //fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight); komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1bdc6034c..a83bac7d5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -105,7 +105,7 @@ void komodo_paxdelete(struct pax_transaction *pax) void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,uint8_t type,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context { - struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s; + struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN],*s; //if ( KOMODO_PAX == 0 ) // return; //if ( strcmp(symbol,ASSETCHAINS_SYMBOL) != 0 ) @@ -197,7 +197,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[KOMODO_ASSETCHAIN_MAXLEN]; //if ( KOMODO_PAX == 0 ) // return(0); incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); @@ -290,7 +290,7 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che uint64_t komodo_paxtotal() { - struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[16],dest[16],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp; + struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp; if ( KOMODO_PASSPORT_INITDONE == 0 ) //KOMODO_PAX == 0 || return(0); if ( komodo_isrealtime(&ht) == 0 ) @@ -464,7 +464,7 @@ int32_t komodo_pending_withdraws(char *opretstr) // todo: enforce deterministic int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t tokomodo) { - struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask,sum = 0; + struct pax_transaction *pax,*tmp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask,sum = 0; if ( KOMODO_PASSPORT_INITDONE == 0 )//KOMODO_PAX == 0 || return(0); struct komodo_state *kmdsp = komodo_stateptrget((char *)"KMD"); @@ -652,7 +652,7 @@ void komodo_passport_iteration(); int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; - int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[16],base[16]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; + int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; activation = 235300; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); @@ -1626,7 +1626,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; expired = 0; while ( KOMODO_INITDONE == 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2976deb8e..bd01daa53 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -30,6 +30,7 @@ pthread_mutex_t komodo_mutex; #define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) #define IGUANA_MAXSCRIPTSIZE 10001 +#define KOMODO_ASSETCHAIN_MAXLEN 65 struct pax_transaction *PAX; int32_t NUM_PRICES; uint32_t *PVALS; @@ -45,7 +46,7 @@ int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; -char ASSETCHAINS_SYMBOL[16]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t ASSETCHAINS_PORT; uint32_t ASSETCHAIN_INIT; uint32_t ASSETCHAINS_MAGIC = 2387029918; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5e6b1707f..c725f03c4 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -307,7 +307,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not //struct komodo_state *komodo_stateptr(char *symbol,char *dest); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { *hashp = sp->NOTARIZED_HASH; @@ -324,7 +324,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { - struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[16],dest[16]; struct komodo_state *sp; + struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NUM_NPOINTS > 0 ) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 8db0a6f43..e56ef751e 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -60,7 +60,7 @@ struct komodo_event uint16_t len; int32_t height; uint8_t type,reorged; - char symbol[16]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN]; uint8_t space[]; }; @@ -71,7 +71,7 @@ struct pax_transaction uint64_t komodoshis,fiatoshis,validated; int32_t marked,height,otherheight,approved,didstats,ready; uint16_t vout; - char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],type,buf[35]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],source[KOMODO_ASSETCHAIN_MAXLEN],coinaddr[64]; uint8_t rmd160[20],type,buf[35]; }; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92577dae0..c6469a350 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1402,7 +1402,7 @@ void komodo_configfile(char *symbol,uint16_t port) uint16_t komodo_userpass(char *userpass,char *symbol) { - FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[16]; + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; userpass[0] = 0; if ( strcmp("KMD",symbol) == 0 ) { diff --git a/src/main.cpp b/src/main.cpp index e86a665ec..e06749072 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1491,7 +1491,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) } //uint64_t komodo_moneysupply(int32_t height); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_SUPPLY; diff --git a/src/miner.cpp b/src/miner.cpp index 721b19cef..bbdbe93da 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -110,7 +110,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define KOMODO_ELECTION_GAP 2000 #define ROUNDROBIN_DELAY 61 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33]; uint32_t Mining_start,Mining_height; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8088da58f..5375187dd 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -515,7 +515,7 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 54f49798c..3f3b4c5e0 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -144,7 +144,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) out.push_back(Pair("value", ValueFromAmount(txout.nValue))); if ( pindex != 0 && tx.nLockTime != 0 && (tipindex= chainActive.Tip()) != 0 ) { - extern char ASSETCHAINS_SYMBOL[16]; + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime); if ( 0 && strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 ) fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)tipindex->nTime); diff --git a/src/util.cpp b/src/util.cpp index ec83e17ce..4005d36c4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -441,13 +441,13 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread) strMiscWarning = message; } -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; //int64_t MAX_MONEY = 200000000 * 100000000LL; boost::filesystem::path GetDefaultDataDir() { namespace fs = boost::filesystem; - char symbol[16]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN]; if ( ASSETCHAINS_SYMBOL[0] != 0 ) strcpy(symbol,ASSETCHAINS_SYMBOL); else symbol[0] = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c72527c01..1dd95ebd1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -479,7 +479,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern int32_t KOMODO_PAX; int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a2aa33661..283eb7953 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -38,7 +38,7 @@ bool bSpendZeroConfChange = true; bool fSendFreeTransactions = false; bool fPayAtLeastCustomFee = true; extern int32_t KOMODO_EXCHANGEWALLET; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) diff --git a/src/zcash/CreateJoinSplit.cpp b/src/zcash/CreateJoinSplit.cpp index f29b2ec82..1f1d09f29 100644 --- a/src/zcash/CreateJoinSplit.cpp +++ b/src/zcash/CreateJoinSplit.cpp @@ -6,7 +6,7 @@ #include "primitives/transaction.h" #include "zcash/JoinSplit.hpp" #include "libsnark/common/profiling.hpp" -char ASSETCHAINS_SYMBOL[16]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; uint16_t BITCOIND_PORT = 7771; From 261c245b7b677e8a25de144b79de0dcafa739875 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:08:41 +0200 Subject: [PATCH 64/75] Test --- src/bitcoind.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 6bff57071..bf4934da4 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -42,6 +42,7 @@ */ static bool fDaemon; +#define KOMODO_ASSETCHAIN_MAXLEN 65 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; void komodo_passport_iteration(); From cc30b05e0d3d88b68147133fcddb8a3433d8dec1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:10:09 +0200 Subject: [PATCH 65/75] Test --- src/komodo_structs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index e56ef751e..cd3adfa00 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -40,6 +40,7 @@ #define KOMODO_KVPROTECTED 1 #define KOMODO_KVBINARY 2 #define KOMODO_KVDURATION 1440 +#define KOMODO_ASSETCHAIN_MAXLEN 65 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; From 5416af1ddc0ca2c69386dea5cb17b1b6f7e016b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:15:34 +0200 Subject: [PATCH 66/75] KOMODO_DEFS_H --- src/komodo-tx.cpp | 1 + src/komodo.h | 1 + src/komodo_bitcoind.h | 2 ++ src/komodo_defs.h | 9 +++++++++ src/komodo_events.h | 1 + src/komodo_gateway.h | 1 + src/komodo_globals.h | 2 ++ src/komodo_interest.h | 2 ++ src/komodo_jumblr.h | 1 + src/komodo_kv.h | 2 ++ src/komodo_notary.h | 2 ++ src/komodo_pax.h | 2 ++ src/komodo_structs.h | 2 ++ src/komodo_utils.h | 2 ++ src/miner.cpp | 5 ++--- 15 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/komodo_defs.h diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 19d0440dd..645bc30a2 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -27,6 +27,7 @@ using namespace std; #include "arith_uint256.h" #include "komodo_structs.h" #include "komodo_globals.h" +#include "komodo_defs.h" #include "komodo_interest.h" diff --git a/src/komodo.h b/src/komodo.h index fb2160da7..e8ab6d6be 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -15,6 +15,7 @@ #ifndef H_KOMODO_H #define H_KOMODO_H +#include "komodo_defs.h" #ifdef _WIN32 #define printf(...) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d356bd6bf..29849f295 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,6 +23,8 @@ #include #endif +#include "komodo_defs.h" + //#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr)) struct MemoryStruct { char *memory; size_t size; }; diff --git a/src/komodo_defs.h b/src/komodo_defs.h new file mode 100644 index 000000000..db792c44e --- /dev/null +++ b/src/komodo_defs.h @@ -0,0 +1,9 @@ +#ifndef KOMODO_DEFS_H +#define KOMODO_DEFS_H + +#define ASSETCHAINS_MINHEIGHT 128 +#define KOMODO_ELECTION_GAP 2000 +#define ROUNDROBIN_DELAY 61 +#define KOMODO_ASSETCHAIN_MAXLEN 65 + +#endif diff --git a/src/komodo_events.h b/src/komodo_events.h index 753413e9f..ff054c3bb 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -15,6 +15,7 @@ #ifndef H_KOMODOEVENTS_H #define H_KOMODOEVENTS_H +#include "komodo_defs.h" struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a83bac7d5..d655f2aa5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -14,6 +14,7 @@ ******************************************************************************/ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse +#include "komodo_defs.h" int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bd01daa53..e945beeee 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint32_t ktime,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout); void komodo_init(int32_t height); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 798eda48e..97f288b4c 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index baafc6dbe..a5eff09a5 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -27,6 +27,7 @@ #ifdef _WIN32 #include #endif +#include "komodo_defs.h" #define JUMBLR_ADDR "RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t" #define JUMBLR_BTCADDR "18RmTJe9qMech8siuhYfMtHo8RtcN1obC6" diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 6d080069a..0d86fadd0 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -16,6 +16,8 @@ #ifndef H_KOMODOKV_H #define H_KOMODOKV_H +#include "komodo_defs.h" + int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) { if ( refvalue == 0 && value == 0 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c725f03c4..a306f848f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #include "komodo_cJSON.h" #define KOMODO_MAINNET_START 178999 diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d1713e234..bcf6fa5d7 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #define USD 0 #define EUR 1 #define JPY 2 diff --git a/src/komodo_structs.h b/src/komodo_structs.h index cd3adfa00..40212c3e3 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #include "uthash.h" #include "utlist.h" diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c6469a350..ef64ad75c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -12,6 +12,8 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ +#include "komodo_defs.h" + #ifdef _WIN32 #include #include diff --git a/src/miner.cpp b/src/miner.cpp index bbdbe93da..5c12d0af6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -106,9 +106,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } -#define ASSETCHAINS_MINHEIGHT 128 -#define KOMODO_ELECTION_GAP 2000 -#define ROUNDROBIN_DELAY 61 +#include "komodo_defs.h" + extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; From fa09a600b899f32d2d611d433adaffa90894b645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:17:16 +0200 Subject: [PATCH 67/75] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5375187dd..10f617765 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -512,6 +512,8 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) return ret; } +#include "komodo_defs.h" + #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 From 037a30c3d14ca75c78a84953da4ee0639757ceed Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:18:39 +0200 Subject: [PATCH 68/75] Test --- src/rpcrawtransaction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 3f3b4c5e0..dac9d49e8 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -22,6 +22,8 @@ #include "wallet/wallet.h" #endif +#include "komodo_defs.h" + #include #include From b978bc5b67a7629f393aeeb09c1640c1af4317ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:20:03 +0200 Subject: [PATCH 69/75] Test --- src/chainparams.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c6b3f393f..13409c8c4 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -30,6 +30,8 @@ using namespace std; * + Contains no strange transactions */ void *chainparams_commandline(void *ptr); +#include "komodo_defs.h" + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_PORT; extern uint32_t ASSETCHAIN_INIT; From 997cf5a1d23943171e1c628d6a09d3af39d6f618 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:20:58 +0200 Subject: [PATCH 70/75] Test --- src/coins.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coins.cpp b/src/coins.cpp index aa858eeb8..37d969010 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -8,6 +8,7 @@ #include "random.h" #include "version.h" #include "policy/fees.h" +#include "komodo_defs.h" #include From 7ce53ed0507edcd6777614c6fe6d5155e5070f33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:21:59 +0200 Subject: [PATCH 71/75] Test --- src/util.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.cpp b/src/util.cpp index 4005d36c4..be7517573 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -15,6 +15,7 @@ #include "sync.h" #include "utilstrencodings.h" #include "utiltime.h" +#include "komodo_defs.h" #include From bdc72415977cf159337e4b88c805ff2541b9e78f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:23:11 +0200 Subject: [PATCH 72/75] Test --- src/wallet/rpcwallet.cpp | 1 + src/wallet/wallet.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1dd95ebd1..dbc3aab84 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -471,6 +471,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) return wtx.GetHash().GetHex(); } +#include "komodo_defs.h" #define KOMODO_KVPROTECTED 1 #define KOMODO_KVBINARY 2 diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 283eb7953..67f7a7fe0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -37,6 +37,8 @@ unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; bool bSpendZeroConfChange = true; bool fSendFreeTransactions = false; bool fPayAtLeastCustomFee = true; +#include "komodo_defs.h" + extern int32_t KOMODO_EXCHANGEWALLET; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; From 9282f3e9fc0f6f83124d78f18245af544bc50047 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:24:54 +0200 Subject: [PATCH 73/75] Test --- src/zcash/CreateJoinSplit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zcash/CreateJoinSplit.cpp b/src/zcash/CreateJoinSplit.cpp index 1f1d09f29..9c7760e4f 100644 --- a/src/zcash/CreateJoinSplit.cpp +++ b/src/zcash/CreateJoinSplit.cpp @@ -6,6 +6,7 @@ #include "primitives/transaction.h" #include "zcash/JoinSplit.hpp" #include "libsnark/common/profiling.hpp" +#include "komodo_defs.h" char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; uint16_t BITCOIND_PORT = 7771; From eea03b7b5db7764503858514e1c9951f5216add5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Nov 2017 10:53:16 +0400 Subject: [PATCH 74/75] jumblr_pause and jumblr_resume Thanks to @amigo for the feature request --- src/komodo_globals.h | 2 +- src/komodo_interest.h | 2 +- src/komodo_jumblr.h | 2 ++ src/rpcmisc.cpp | 22 +++++++++++++++++++++- src/rpcserver.cpp | 2 ++ src/rpcserver.h | 2 ++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index e945beeee..144064d7a 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,7 +44,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; -int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED; +int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 97f288b4c..63d0152ca 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -82,7 +82,7 @@ uint64_t komodo_moneysupply(int32_t height) uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t interest = 0; - if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) + if ( tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index a5eff09a5..951ed9de0 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -630,6 +630,8 @@ void jumblr_iteration() { static int32_t lastheight; static uint32_t lasttime; char *zaddr,*addr,*retstr,secretaddr[64]; cJSON *array; int32_t i,iter,height,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; + if ( JUMBLR_PAUSE != 0 ) + return; if ( lasttime == 0 ) { if ( (retstr= jumblr_zlistaddresses()) != 0 ) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 42307470f..6008e341d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -47,7 +47,7 @@ uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); int32_t komodo_whoami(char *pubkeystr,int32_t height); -extern int32_t KOMODO_LASTMINED; +extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; extern char ASSETCHAINS_SYMBOL[]; int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" @@ -224,6 +224,26 @@ UniValue jumblr_secret(const UniValue& params, bool fHelp) return(result); } +UniValue jumblr_pause(const UniValue& params, bool fHelp) +{ + int32_t retval; UniValue result(UniValue::VOBJ); + if (fHelp ) + throw runtime_error("jumblr_pause\n"); + JUMBLR_PAUSE = 1; + result.push_back(Pair("result", "paused")); + return(result); +} + +UniValue jumblr_resume(const UniValue& params, bool fHelp) +{ + int32_t retval; UniValue result(UniValue::VOBJ); + if (fHelp ) + throw runtime_error("jumblr_resume\n"); + JUMBLR_PAUSE = 0; + result.push_back(Pair("result", "resumed")); + return(result); +} + UniValue validateaddress(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 518ba4693..94521004d 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -338,6 +338,8 @@ static const CRPCCommand vRPCCommands[] = { "util", "z_validateaddress", &z_validateaddress, true }, /* uses wallet if enabled */ { "util", "jumblr_deposit", &jumblr_deposit, true }, { "util", "jumblr_secret", &jumblr_secret, true }, + { "util", "jumblr_pause", &jumblr_pause, true }, + { "util", "jumblr_resume", &jumblr_resume, true }, /* Not shown in help */ { "hidden", "invalidateblock", &invalidateblock, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index ecf7b0573..f59972472 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -248,6 +248,8 @@ extern UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp); extern UniValue jumblr_deposit(const UniValue& params, bool fHelp); extern UniValue jumblr_secret(const UniValue& params, bool fHelp); +extern UniValue jumblr_pause(const UniValue& params, bool fHelp); +extern UniValue jumblr_resume(const UniValue& params, bool fHelp); extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp extern UniValue listunspent(const UniValue& params, bool fHelp); From 67030c8be03e07afa34e8b7a4fb6bee745669a30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Nov 2017 22:01:00 +0400 Subject: [PATCH 75/75] MSHARK --- src/assetchains | 1 + src/assetchains.old | 1 + src/dpowassets | 1 + src/fiat-cli | 1 + src/fiat/mshark | 2 ++ 5 files changed, 6 insertions(+) create mode 100755 src/fiat/mshark diff --git a/src/assetchains b/src/assetchains index f220139cf..6b80a62ea 100755 --- a/src/assetchains +++ b/src/assetchains @@ -36,6 +36,7 @@ komodo_asset BET 999999 komodo_asset CRYPTO 999999 komodo_asset HODL 9999999 komodo_asset SHARK 1401 +komodo_asset MSHARK 1400000 komodo_asset BOTS 999999 komodo_asset MGW 999999 #komodo_asset MVP 1000000 diff --git a/src/assetchains.old b/src/assetchains.old index e7584afcd..601eda111 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -13,6 +13,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 & +./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & #./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 & diff --git a/src/dpowassets b/src/dpowassets index 5e0facea0..6c1c75c2c 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -14,6 +14,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index e83a7f757..5c8940f82 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -41,6 +41,7 @@ echo bet; fiat/bet $1 $2 $3 $4 echo crypto; fiat/crypto $1 $2 $3 $4 echo hodl; fiat/hodl $1 $2 $3 $4 echo shark; fiat/shark $1 $2 $3 $4 +echo mshark; fiat/mshark $1 $2 $3 $4 echo bots; fiat/bots $1 $2 $3 $4 echo mgw; fiat/mgw $1 $2 $3 $4 #echo mvp; fiat/mvp $1 $2 $3 $4 diff --git a/src/fiat/mshark b/src/fiat/mshark new file mode 100755 index 000000000..1f0c950c6 --- /dev/null +++ b/src/fiat/mshark @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=MSHARK $1 $2 $3 $4 $5 $6