From 5298d41fae3be91ad831241ae066a4ec623cef29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 14 Mar 2018 21:33:11 +0200 Subject: [PATCH 01/49] Make sure pindexWalk is non-null --- src/chain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chain.cpp b/src/chain.cpp index 9cd13d997..7bb72d5d3 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -81,7 +81,8 @@ CBlockIndex* CBlockIndex::GetAncestor(int height) CBlockIndex* pindexWalk = this; int heightWalk = nHeight; - while (heightWalk > height) { + while ( heightWalk > height && pindexWalk != 0 ) + { int heightSkip = GetSkipHeight(heightWalk); int heightSkipPrev = GetSkipHeight(heightWalk - 1); if (pindexWalk->pskip != NULL && From 18c6cfce1d1a1d37606a4c6d2fafc805ac0ca4d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 14:21:00 +0200 Subject: [PATCH 02/49] MoM support --- src/komodo.h | 86 +++++++++++++++++++++++++++++++++---------- src/komodo_events.h | 6 ++- src/komodo_notary.h | 4 +- src/komodo_structs.h | 10 +++-- src/wallet/wallet.cpp | 3 +- 5 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 129ea3b5f..b655ab8dc 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -73,7 +73,7 @@ int32_t komodo_currentheight() int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,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]; + int32_t func,ht,notarized_height,num,matched=0,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; if ( (func= fgetc(fp)) != EOF ) { if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) @@ -97,7 +97,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char } } else printf("illegal num.%d\n",num); } - else if ( func == 'N' ) + else if ( func == 'N' || func == 'M' ) { if ( fread(¬arized_height,1,sizeof(notarized_height),fp) != sizeof(notarized_height) ) errs++; @@ -105,10 +105,22 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != 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 ( func == 'M' ) + { + if ( fread(&MoM,1,sizeof(MoM),fp) != sizeof(MoM) ) + errs++; + if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) ) + errs++; + if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + } + else + { + memset(&MoM,0,sizeof(MoM)); + MoMdepth = 0; + } //if ( matched != 0 ) global independent states -> inside *sp - komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height,MoM,MoMdepth); } else if ( func == 'U' ) // deprecated { @@ -208,7 +220,7 @@ int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datal 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= -1,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,MoMdepth,num,matched=0; uint256 MoM,notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; if ( fpos < datalen ) { func = filedata[fpos++]; @@ -231,7 +243,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long } } else printf("illegal num.%d\n",num); } - else if ( func == 'N' ) + else if ( func == 'N' || func == 'M' ) { if ( memread(¬arized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) ) errs++; @@ -239,10 +251,21 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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); + if ( func == 'M' ) + { + if ( memread(&MoM,sizeof(MoM),filedata,&fpos,datalen) != sizeof(MoM) ) + errs++; + if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) ) + errs++; + if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + } + else + { + memset(&MoM,0,sizeof(MoM)); + MoMdepth = 0; + } + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height,MoM,MoMdepth); } else if ( func == 'U' ) // deprecated { @@ -326,7 +349,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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) +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,bits256 MoM,int32_t MoMdepth) { static FILE *fp; static int32_t errs,didinit; 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]; @@ -457,7 +480,9 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); if ( sp != 0 ) { - fputc('N',fp); + if ( sp->MoMdepth > 0 && bits256_nonz(sp->MoM) != 0 ) + fputc('M',fp); + else fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) @@ -466,7 +491,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); + if ( sp->MoMdepth > 0 && bits256_nonz(sp->MoM) != 0 ) + { + if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) ) + errs++; + if ( fwrite(&sp->MoMdepth,1,sizeof(sp->MoMdepth),fp) != sizeof(sp->MoMdepth) ) + errs++; + } + komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT,sp->MoM,sp->MoMdepth); } } fflush(fp); @@ -542,7 +574,21 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; sp->NOTARIZED_DESTTXID = desttxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); + if ( len+36 <= opretlen ) + { + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&sp->MoM); + len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); + if ( bits256_nonz(sp->MoM) == 0 || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) + { + memset(sp->MoM.bytes,0,sizeof(sp->MoM)); + sp->MoMdepth = 0; + } + else + { + printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM,sp->MoMdepth); len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) 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); @@ -567,7 +613,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr //for (i=0; i= KOMODO_MAINNET_START ) @@ -596,7 +642,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } if ( *isratificationp == 0 && (signedmask != 0 || (scriptbuf[len] != 'X' && scriptbuf[len] != 'A')) ) // && scriptbuf[len] != 'I') - komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); + komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0); } } return(notaryid); @@ -655,7 +701,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( pindex->nHeight != hwmheight ) printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight); komodo_event_rewind(sp,symbol,pindex->nHeight); - komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0); + komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } komodo_currentheight_set(chainActive.Tip()->nHeight); if ( pindex != 0 ) @@ -787,7 +833,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0); printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); } @@ -796,7 +842,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height); if ( pindex->nHeight == hwmheight ) - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); } else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n"); //KOMODO_INITDONE = (uint32_t)time(NULL); //fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); diff --git a/src/komodo_events.h b/src/komodo_events.h index ff054c3bb..315a78686 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -37,7 +37,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char return(ep); } -void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) +void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) @@ -53,10 +53,12 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig N.blockhash = notarized_hash; N.desttxid = notarized_desttxid; N.notarizedheight = notarizedheight; + N.MoM = MoM; + N.MoMdepth = MoMdepth; strcpy(N.dest,dest); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); if ( sp != 0 ) - komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); + komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid,MoM,MoMdepth); } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 438d81809..c82087549 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -357,7 +357,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33, return(modval); } -void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid) +void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid,uint256 MoM,int32_t MoMdepth) { struct notarized_checkpoint *np; if ( notarized_height > nHeight ) @@ -375,6 +375,8 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; + sp->MoM = np->MoM = MoM; + sp->MoMdepth = np->MoMdepth = MoMdepth; portable_mutex_unlock(&komodo_mutex); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 5c554b9a5..b424d5386 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -80,12 +80,16 @@ struct pax_transaction struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; -struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; +struct notarized_checkpoint +{ + uint256 notarized_hash,notarized_desttxid,MoM; + int32_t nHeight,notarized_height,MoMdepth; +}; struct komodo_state { - uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; - int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT; + uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID,MoM; + int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,MoMdepth; uint32_t SAVEDTIMESTAMP; uint64_t deposited,issued,withdrawn,approved,redeemed,shorted; struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS,last_NPOINTSi; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9dc96f10c..00def9a0b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2779,8 +2779,6 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt extern int32_t USE_EXTERNAL_PUBKEY; extern std::string NOTARY_PUBKEY; if ( USE_EXTERNAL_PUBKEY == 0 ) { - //fprintf(stderr,"use notary pubkey\n"); - //scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; bool ret; ret = reservekey.GetReservedKey(vchPubKey); assert(ret); // should never fail, as we just unlocked @@ -2788,6 +2786,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt } else { + //fprintf(stderr,"use notary pubkey\n"); scriptChange = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; } } From 582c741ff3ef5b362e90674ff1a2cb9c444aad7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 14:43:49 +0200 Subject: [PATCH 03/49] Test --- src/komodo.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b655ab8dc..92adc8b9a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -571,13 +571,15 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { + int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; sp->NOTARIZED_DESTTXID = desttxid; if ( len+36 <= opretlen ) { - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&sp->MoM); - len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); + len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); + len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); + printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM) == 0 || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { memset(sp->MoM.bytes,0,sizeof(sp->MoM)); @@ -585,11 +587,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM),sp->MMoM,sp->MoMdepth); - len += 4; + len += nameoffset; if ( ASSETCHAINS_SYMBOL[0] != 0 ) 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 ) From 3f41df7562ccac0b550a98fb0bea49f6629610a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 14:53:30 +0200 Subject: [PATCH 04/49] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 92adc8b9a..bf36b46fb 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -618,8 +618,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0); } } - } else if ( height >= KOMODO_MAINNET_START ) - printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); + } //else if ( height >= KOMODO_MAINNET_START ) + printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); } else if ( i == 0 && j == 1 && opretlen == 149 ) { From ed7bd562529d35568893aa31bc20ae6708b0ca76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 14:57:50 +0200 Subject: [PATCH 05/49] Test --- src/komodo.h | 6 +++--- src/komodo_structs.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index bf36b46fb..5b5e94eaf 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -480,7 +480,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); if ( sp != 0 ) { - if ( sp->MoMdepth > 0 && bits256_nonz(sp->MoM) != 0 ) + if ( sp->MoMdepth > 0 && sp->MoM != zero ) fputc('M',fp); else fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) @@ -491,7 +491,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - if ( sp->MoMdepth > 0 && bits256_nonz(sp->MoM) != 0 ) + if ( sp->MoMdepth > 0 && sp->MoM != zero ) { if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) ) errs++; @@ -580,7 +580,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM) == 0 || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) + if ( sp->MoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { memset(sp->MoM.bytes,0,sizeof(sp->MoM)); sp->MoMdepth = 0; diff --git a/src/komodo_structs.h b/src/komodo_structs.h index b424d5386..e5ec737ee 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -53,7 +53,7 @@ typedef union _bits320 bits320; struct komodo_kv { UT_hash_handle hh; bits256 pubkey; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; -struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; +struct komodo_event_notarized { uint256 blockhash,desttxid,MoM; int32_t notarizedheight,MoMdepth; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; }; struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; }; From c88fa588dec5cc57f1d998d6daf1708b26842cf8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 15:13:15 +0200 Subject: [PATCH 06/49] Test --- src/bitcoin-cli.cpp | 2 +- src/komodo.h | 8 ++++---- src/komodo_globals.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 253c49366..87c5e6f76 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -76,7 +76,7 @@ public: #include "komodo_cJSON.c" #include "komodo_notary.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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) +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,uint256 MoM,int32_t MoMdepth) { } diff --git a/src/komodo.h b/src/komodo.h index 5b5e94eaf..9bc8647c6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -351,7 +351,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,bits256 MoM,int32_t MoMdepth) { - static FILE *fp; static int32_t errs,didinit; + static FILE *fp; static int32_t errs,didinit; static uint256 zero; 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 ) { @@ -579,15 +579,15 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); - printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM.ToString().c_str(),sp->MMoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { - memset(sp->MoM.bytes,0,sizeof(sp->MoM)); + memset(&sp->MoM,0,sizeof(sp->MoM)); sp->MoMdepth = 0; } else { - printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,bits256_str(str,sp->MoM),sp->MMoM.ToString().c_str(),sp->MMoM,sp->MoMdepth); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 6c2e56f5b..beeb252b0 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -15,7 +15,7 @@ #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_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,uint256 MoM,int32_t MoMdepth); void komodo_init(int32_t height); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port); From 2ff8e0e5d9df48c2dcf442a10f17b645396805ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 15:18:58 +0200 Subject: [PATCH 07/49] Test --- src/komodo.h | 4 ++-- src/komodo_notary.h | 4 ++-- src/komodo_pax.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9bc8647c6..d5de6c013 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -579,7 +579,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); - printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MMoM.ToString().c_str(),sp->MoMdepth); if ( sp->MoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { memset(&sp->MoM,0,sizeof(sp->MoM)); @@ -587,7 +587,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MMoM.ToString().c_str(),sp->MoMdepth); } } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c82087549..f30f388e7 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -459,6 +459,7 @@ void komodo_init(int32_t height) static int didinit; uint256 zero; int32_t k,n; uint8_t pubkeys[64][33]; if ( 0 && height != 0 ) printf("komodo_init ht.%d didinit.%d\n",height,didinit); + memset(&zero,0,sizeof(zero)); if ( didinit == 0 ) { pthread_mutex_init(&komodo_mutex,NULL); @@ -474,7 +475,6 @@ void komodo_init(int32_t height) } komodo_notarysinit(0,pubkeys,k); } - memset(&zero,0,sizeof(zero)); //for (i=0; i Date: Thu, 22 Mar 2018 15:27:45 +0200 Subject: [PATCH 08/49] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index d5de6c013..e91cb4753 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -349,7 +349,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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,bits256 MoM,int32_t MoMdepth) +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,bits256 MoM,int32_t MoMdepth) { static FILE *fp; static int32_t errs,didinit; static uint256 zero; 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]; From 25bf4d686ed4a1c9499834debf3181fc6ac00a7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 15:43:59 +0200 Subject: [PATCH 09/49] Test --- src/komodo.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e91cb4753..aa69646ab 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -349,7 +349,8 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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,bits256 MoM,int32_t MoMdepth) +//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,bits256 MoM,int32_t MoMdepth) +void komodo_stateupdate(int, unsigned char (*) [33], unsigned char, unsigned char, uint256, unsigned long, unsigned char, unsigned int*, unsigned char, int, unsigned int, unsigned long, unsigned char*, unsigned short, unsigned short, uint256, int) { static FILE *fp; static int32_t errs,didinit; static uint256 zero; 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]; From c130fb54bb31036de664d86b4f61ad93e08e2975 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 15:55:15 +0200 Subject: [PATCH 10/49] Test --- src/komodo.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index aa69646ab..a933a9eb4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -349,8 +349,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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,bits256 MoM,int32_t MoMdepth) -void komodo_stateupdate(int, unsigned char (*) [33], unsigned char, unsigned char, uint256, unsigned long, unsigned char, unsigned int*, unsigned char, int, unsigned int, unsigned long, unsigned char*, unsigned short, unsigned short, uint256, int) +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,uint256 MoM,int32_t MoMdepth) { static FILE *fp; static int32_t errs,didinit; static uint256 zero; 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]; @@ -579,7 +578,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( len+36 <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); - len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(*notarizedheightp),(uint8_t *)&sp->MoMdepth); + len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(sp->MoMdepth),(uint8_t *)&sp->MoMdepth); printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); if ( sp->MoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { From e8f0f0d67a4f0982923382583595b9dbeba0dd4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 16:13:10 +0200 Subject: [PATCH 11/49] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 76f6765ad..e9f8c3818 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -471,7 +471,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { - //printf("HEX.(%s)\n",hexstr); + printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH); From 98b7faf6e284bef184183c115087edabfe246e49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 16:18:04 +0200 Subject: [PATCH 12/49] Test --- src/komodo.h | 2 ++ src/komodo_bitcoind.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index a933a9eb4..91ab3e815 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -569,6 +569,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); + if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen >= 110 ) + notarized = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9f8c3818..9f23727a7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -471,7 +471,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { - printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); + //printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH); From e35bc6fea31bd9834d8430eff72e5d9374a62ceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 16:23:32 +0200 Subject: [PATCH 13/49] Test --- src/komodo.h | 3 +++ src/komodo_bitcoind.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 91ab3e815..cd2e43cb5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -570,7 +570,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen >= 110 ) + { notarized = 1; + printf("notht.%d sp.%d ht.%d current.%d\n",*notarizedheightp,sp->NOTARIZED_HEIGHT,height,sp->CURRENT_HEIGHT); + } if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9f23727a7..e9f8c3818 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -471,7 +471,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { - //printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); + printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH); From 279fac9187e31b85b66abb5a5ed1ec9900218745 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 16:56:41 +0200 Subject: [PATCH 14/49] Test --- src/komodo_bitcoind.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9f8c3818..5960862a7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -474,6 +474,16 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); + if ( script[1] == 0x4c ) + { + script++; + len--; + } + else if ( script[1] == 0x4d ) + { + script += 2; + len -= 2; + } retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH); } } From 3da303b505b24f579d271be1108a58e54cb0dbd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 16:58:48 +0200 Subject: [PATCH 15/49] Test --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5960862a7..dd0b973c9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -420,7 +420,8 @@ int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len, int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { - char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; + char params[256],*jsonstr,*hexstr; uint8_t *script,_script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; + script = _script; /*params[0] = '['; params[1] = '"'; for (i=0; i<32; i++) From 895977bf2ec21d32eedc66edc5ccfec5556a66c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 17:07:27 +0200 Subject: [PATCH 16/49] Test --- src/komodo.h | 7 +++---- src/komodo_bitcoind.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index cd2e43cb5..e1a3da8a9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -580,11 +580,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; sp->NOTARIZED_DESTTXID = desttxid; - if ( len+36 <= opretlen ) + if ( len+36+nameoffset <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(sp->MoMdepth),(uint8_t *)&sp->MoMdepth); - printf("%s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); if ( sp->MoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 ) { memset(&sp->MoM,0,sizeof(sp->MoM)); @@ -598,7 +597,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,sp->MoM,sp->MoMdepth); len += nameoffset; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - 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); + printf("[%s] %s ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,(char *)&scriptbuf[68],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 ) @@ -623,7 +622,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0); } } - } //else if ( height >= KOMODO_MAINNET_START ) + } else if ( height >= KOMODO_MAINNET_START ) printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); } else if ( i == 0 && j == 1 && opretlen == 149 ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index dd0b973c9..bc5fb1057 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -414,7 +414,7 @@ int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len, printf(" notarized, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&hash)[i]); - printf(" opreturn from [%s] ht.%d\n",ASSETCHAINS_SYMBOL,height); + printf(" opreturn from [%s] ht.%d MISMATCHED\n",ASSETCHAINS_SYMBOL,height); return(-1); } @@ -472,7 +472,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { - printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); + //printf("HEX.(%s) vs hash.%s\n",hexstr,NOTARIZED_HASH.ToString().c_str()); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); if ( script[1] == 0x4c ) From f1a96e3bbd12723dc401092d41d5e4423f23e193 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 17:11:31 +0200 Subject: [PATCH 17/49] Test --- src/komodo.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e1a3da8a9..5d697b28a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -569,10 +569,9 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen >= 110 ) + if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen == 110 ) { notarized = 1; - printf("notht.%d sp.%d ht.%d current.%d\n",*notarizedheightp,sp->NOTARIZED_HEIGHT,height,sp->CURRENT_HEIGHT); } if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { @@ -591,13 +590,13 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); + //printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); } } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); len += nameoffset; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("[%s] %s ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,(char *)&scriptbuf[68],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); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %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,sp->MoM.ToString().c_str(),sp->MoMdepth); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) From 0ab5b335943c2763d021641cf411655267d4e159 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 18:09:08 +0200 Subject: [PATCH 18/49] Test --- src/komodo_bitcoind.h | 16 +++++++++++++++- src/komodo_notary.h | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bc5fb1057..0306b434e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -811,9 +811,23 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],uint32_t timestamp return(0); } +int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,int32_t nHeight) +{ + int32_t depth,notarized_ht; uint256 MoM; + depth = komodo_MoMdata(¬arized_ht,&MoM,nHeight); + memset(MoMp,0,sizeof(*MoMp)); + *notarized_heightp = 0; + if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight < notarized_ht ) + { + *MoMp = MoM; + *notarized_heightp = notarized_ht; + } + return(depth); +} + int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { - int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex; + int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex; if ( (pindex= chainActive.Tip()) == 0 ) return(-1); notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f30f388e7..1f2f21005 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -398,6 +398,26 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) } } +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight) +{ + struct komodo_state *sp; struct notarized_checkpoint *np = 0; + np = 0; + for (i=sp->NUM_NPOINTS-1; i>=0; i--) + { + np = &sp->NPOINTS[i]; + if ( np->MoMdepth > 0 && nHeight > np->nHeight-np->MoMdepth && nHeight <= np->nHeight ) + { + printf("komodo_MoMdata %d i.%d np->ht %d MoMdepth.%d\n",nHeight,i,np->nHeight,np->MoMdepth); + *notarized_htp = np->nHeight; + *MoMp = np->MoM; + return(np->MoMdepth); + } + } + *notarized_htp = 0; + memset(MoMp,0,sizeof(*MoMp)); + return(0); +} + 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[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; From c26fb215f4f651085e460f6fc97e8a57b67e4351 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 18:10:32 +0200 Subject: [PATCH 19/49] Test --- src/komodo_globals.h | 1 + src/komodo_notary.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index beeb252b0..b35a2a8da 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -17,6 +17,7 @@ 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,uint256 MoM,int32_t MoMdepth); void komodo_init(int32_t height); +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port); void komodo_init(int32_t height); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1f2f21005..f7d6982d0 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -400,7 +400,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight) { - struct komodo_state *sp; struct notarized_checkpoint *np = 0; + int32_t i; struct komodo_state *sp; struct notarized_checkpoint *np = 0; np = 0; for (i=sp->NUM_NPOINTS-1; i>=0; i--) { From f850a97b77ae45c7ede7f8993e6fbbae21808fd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 18:15:25 +0200 Subject: [PATCH 20/49] Test --- src/komodo.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo.h b/src/komodo.h index 5d697b28a..95d3ad0ff 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -579,6 +579,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; sp->NOTARIZED_DESTTXID = desttxid; + memset(&sp->MoM,0,sizeof(sp->MoM)); + sp->MoMdepth = 0; if ( len+36+nameoffset <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); From 617c9c6178c3f7961bb4fcd51723a79ad78396de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Mar 2018 18:19:13 +0200 Subject: [PATCH 21/49] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 95d3ad0ff..d45b87859 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -581,7 +581,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_DESTTXID = desttxid; memset(&sp->MoM,0,sizeof(sp->MoM)); sp->MoMdepth = 0; - if ( len+36+nameoffset <= opretlen ) + if ( len+36 <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM); len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(sp->MoMdepth),(uint8_t *)&sp->MoMdepth); @@ -592,7 +592,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - //printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); + printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); } } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); From 4329679df7d5d0d2239ddd716b32b3b4bd690d30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 12:59:36 +0200 Subject: [PATCH 22/49] height_MoM rpc --- src/komodo.h | 2 +- src/komodo_notary.h | 4 +- src/rpcblockchain.cpp | 92 +++++++++++++++++++++++++++---------------- src/rpcclient.cpp | 3 +- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 6 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d45b87859..5a1dc62f8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -592,7 +592,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); + //printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth); } } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f7d6982d0..e4b2a650e 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -127,12 +127,12 @@ const char *Notaries_elected0[][2] = }; #define KOMODO_NOTARIES_TIMESTAMP1 1600000000 -#define KOMODO_NOTARIES_HEIGHT1 ((800000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) +#define KOMODO_NOTARIES_HEIGHT1 ((900000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] = { - { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, + { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "0_kolo_testA", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" }, { "artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, { "artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 91f694abb..9961fe4f7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -527,6 +527,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, //uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight); /*uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_t *pass,int32_t passlen); @@ -579,6 +580,28 @@ UniValue kvsearch(const UniValue& params, bool fHelp) return ret; } +UniValue height_MoM(const UniValue& params, bool fHelp) +{ + int32_t height,depth,notarized_height; uint256 MoM; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); + if ( fHelp || params.size() != 1 ) + throw runtime_error("height_MoM needs height\n"); + LOCK(cs_main); + height = atoi(params[0].get_str().c_str()); + if ( height <= 0 ) + height = chainActive.Tip()->nHeight; + depth = komodo_MoMdata(¬arized_height,&MoM,height); + ret.push_back(Pair("coin",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSSETCHAINS_SYMBOL)); + ret.push_back(Pair("height",height)); + if ( depth > 0 ) + { + ret.push_back(Pair("depth",depth)); + ret.push_back(Pair("notarized_height",notarized_height)); + ret.push_back(Pair("MoM",MoM.GetHex())); + } else ret.push_back(Pair("error",(char *)"no MoM for height")); + + return ret; +} + UniValue minerids(const UniValue& params, bool fHelp) { uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); uint8_t minerids[2000],pubkeys[65][33]; int32_t i,j,n,numnotaries,tally[129]; @@ -639,57 +662,56 @@ UniValue minerids(const UniValue& params, bool fHelp) UniValue notaries(const UniValue& params, bool fHelp) { UniValue a(UniValue::VARR); uint32_t timestamp=0; UniValue ret(UniValue::VOBJ); int32_t i,j,n,m; char *hexstr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; - if ( fHelp || params.size() != 1 ) - throw runtime_error("notaries height\n"); + if ( fHelp || (params.size() != 1 && params.size() != 2) ) + throw runtime_error("notaries height timestamp\n"); LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); + if ( params.size() == 2 ) + timestamp = (uint32_t)atol(params[1].get_str().c_str()); + else timestamp = (uint32_t)time(NULL); if ( height < 0 ) { height = chainActive.Tip()->nHeight; timestamp = chainActive.Tip()->GetBlockTime(); } - else + else if ( params.size() < 2 ) { CBlockIndex *pblockindex = chainActive[height]; if ( pblockindex != 0 ) timestamp = pblockindex->GetBlockTime(); } - //fprintf(stderr,"notaries as of height.%d\n",height); - //if ( height > chainActive.Height()+20000 ) - // throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); - //else + if ( (n= komodo_notaries(pubkeys,height,timestamp)) > 0 ) { - if ( (n= komodo_notaries(pubkeys,height,timestamp)) > 0 ) + for (i=0; i Date: Sat, 24 Mar 2018 13:16:16 +0200 Subject: [PATCH 23/49] Test --- src/rpcblockchain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9961fe4f7..877102c1d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -590,8 +590,9 @@ UniValue height_MoM(const UniValue& params, bool fHelp) if ( height <= 0 ) height = chainActive.Tip()->nHeight; depth = komodo_MoMdata(¬arized_height,&MoM,height); - ret.push_back(Pair("coin",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSSETCHAINS_SYMBOL)); + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height",height)); + ret.push_back(Pair("timestamp",(uint64_t)timestamp)); if ( depth > 0 ) { ret.push_back(Pair("depth",depth)); @@ -711,7 +712,7 @@ UniValue notaries(const UniValue& params, bool fHelp) ret.push_back(Pair("notaries", a)); ret.push_back(Pair("numnotaries", n)); ret.push_back(Pair("height", height)); - ret.push_back(Pair("timestamp", timestamp)); + ret.push_back(Pair("timestamp", (uint64_t)timestamp)); return ret; } From 66b1416d7d52d8ec02ab30bc7d3bb68845a92af9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:02:43 +0200 Subject: [PATCH 24/49] Fix --- src/komodo_notary.h | 23 ++++++++++++++--------- src/rpcblockchain.cpp | 8 ++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e4b2a650e..deb0dd8f6 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -398,23 +398,28 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) } } -int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight) +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight) { - int32_t i; struct komodo_state *sp; struct notarized_checkpoint *np = 0; + int32_t i; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; struct notarized_checkpoint *np = 0; np = 0; - for (i=sp->NUM_NPOINTS-1; i>=0; i--) + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { - np = &sp->NPOINTS[i]; - if ( np->MoMdepth > 0 && nHeight > np->nHeight-np->MoMdepth && nHeight <= np->nHeight ) + for (i=sp->NUM_NPOINTS-1; i>=0; i--) { - printf("komodo_MoMdata %d i.%d np->ht %d MoMdepth.%d\n",nHeight,i,np->nHeight,np->MoMdepth); - *notarized_htp = np->nHeight; - *MoMp = np->MoM; - return(np->MoMdepth); + np = &sp->NPOINTS[i]; + if ( np->MoMdepth > 0 && nHeight > np->nHeight-np->MoMdepth && nHeight <= np->nHeight ) + { + printf("komodo_MoMdata.(%s -> %s) %d i.%d np->ht %d MoMdepth.%d\n",symbol,dest,nHeight,i,np->nHeight,np->MoMdepth); + *notarized_htp = np->nHeight; + *MoMp = np->MoM; + *kmdtxidp = np->NOTARIZED_DESTTXID; + return(np->MoMdepth); + } } } *notarized_htp = 0; memset(MoMp,0,sizeof(*MoMp)); + memset(kmdtxidp,0,sizeof(*kmdtxidp)); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 877102c1d..4bb4050cc 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -588,7 +588,15 @@ UniValue height_MoM(const UniValue& params, bool fHelp) LOCK(cs_main); height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) + { + if ( chainActive.Tip() == 0 ) + { + ret.push_back(Pair("error",(char *)"no active chain yet")); + return(ret) + } height = chainActive.Tip()->nHeight; + } + fprintf(stderr,"height_MoM height.%d\n",height); depth = komodo_MoMdata(¬arized_height,&MoM,height); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height",height)); From e9115be059c4f1a69c09505fc522a023ae51142c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:04:24 +0200 Subject: [PATCH 25/49] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index deb0dd8f6..1c5e9c9e2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -412,7 +412,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in printf("komodo_MoMdata.(%s -> %s) %d i.%d np->ht %d MoMdepth.%d\n",symbol,dest,nHeight,i,np->nHeight,np->MoMdepth); *notarized_htp = np->nHeight; *MoMp = np->MoM; - *kmdtxidp = np->NOTARIZED_DESTTXID; + *kmdtxidp = np->notarized_desttxid; return(np->MoMdepth); } } From 682ee10f6b4a4f55880a15e7abff92c668d1fd84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:06:20 +0200 Subject: [PATCH 26/49] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4bb4050cc..9a6453cb3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -592,7 +592,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) if ( chainActive.Tip() == 0 ) { ret.push_back(Pair("error",(char *)"no active chain yet")); - return(ret) + return(ret); } height = chainActive.Tip()->nHeight; } From 8b8c54db0734b90c68e0b6e6bbfe9662245a9a7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:07:49 +0200 Subject: [PATCH 27/49] Test --- src/rpcblockchain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9a6453cb3..8a9b796eb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -582,7 +582,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp) UniValue height_MoM(const UniValue& params, bool fHelp) { - int32_t height,depth,notarized_height; uint256 MoM; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); + int32_t height,depth,notarized_height; uint256 MoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); if ( fHelp || params.size() != 1 ) throw runtime_error("height_MoM needs height\n"); LOCK(cs_main); @@ -597,7 +597,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) height = chainActive.Tip()->nHeight; } fprintf(stderr,"height_MoM height.%d\n",height); - depth = komodo_MoMdata(¬arized_height,&MoM,height); + depth = komodo_MoMdata(¬arized_height,&MoM,&kmdtxid,height); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height",height)); ret.push_back(Pair("timestamp",(uint64_t)timestamp)); @@ -606,6 +606,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) ret.push_back(Pair("depth",depth)); ret.push_back(Pair("notarized_height",notarized_height)); ret.push_back(Pair("MoM",MoM.GetHex())); + ret.push_back(Pair("kmdtxid",kmdtxid.GetHex())); } else ret.push_back(Pair("error",(char *)"no MoM for height")); return ret; From 2b7b4c274cc0c1bc545ee74cc7c0f4549aa27ce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:08:45 +0200 Subject: [PATCH 28/49] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8a9b796eb..2293e6eb7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -527,7 +527,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, //uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); -int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight); +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); /*uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_t *pass,int32_t passlen); From aa5ca00101a3967a7b3508ada802bbba279e89e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:10:59 +0200 Subject: [PATCH 29/49] Test --- src/komodo_bitcoind.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0306b434e..535e1ad81 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -811,16 +811,18 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],uint32_t timestamp return(0); } -int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,int32_t nHeight) +int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight) { - int32_t depth,notarized_ht; uint256 MoM; - depth = komodo_MoMdata(¬arized_ht,&MoM,nHeight); + int32_t depth,notarized_ht; uint256 MoM,kmdtxid; + depth = komodo_MoMdata(¬arized_ht,&MoM,&kmdtxid,nHeight); memset(MoMp,0,sizeof(*MoMp)); + memset(*kmdtxidp,0,sizeof(*kmdtxidp)); *notarized_heightp = 0; if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight < notarized_ht ) { *MoMp = MoM; *notarized_heightp = notarized_ht; + *kmdtxidp = kmdtxid; } return(depth); } From 5473ce392a718f9fb128ec31b01205ea3b1a0355 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:11:57 +0200 Subject: [PATCH 30/49] Test --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2293e6eb7..888c797f3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -527,7 +527,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, //uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); -int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); +int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); /*uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_t *pass,int32_t passlen); @@ -597,7 +597,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) height = chainActive.Tip()->nHeight; } fprintf(stderr,"height_MoM height.%d\n",height); - depth = komodo_MoMdata(¬arized_height,&MoM,&kmdtxid,height); + depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height",height)); ret.push_back(Pair("timestamp",(uint64_t)timestamp)); From 663304d9634fd3f7efb75260508cdbbb6d74dfe7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:12:10 +0200 Subject: [PATCH 31/49] Test --- src/rpcblockchain.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 888c797f3..5075fb200 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -528,22 +528,6 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); -/*uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_t *pass,int32_t passlen); - - -UniValue passphrasewif(const UniValue& params, bool fHelp) -{ - UniValue ret(UniValue::VOBJ); char *passphrase,wifstr[64],coinaddr[64]; uint8_t tmptype,pubkey33[33]; void *ctx; uint256 privkey,pubkey; - passphrase = params[0].get_str().c_str(); - conv_NXTpassword((void *)&privkey,(void *)&pubkey,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); - ctx = bitcoin_ctx(); - bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,0,60); - bitcoin_priv2wif(0,wifstr,privkey,188); - free(ctx); - ret.push_back(Pair("address",coinaddr)); - ret.push_back(Pair("wif",wifstr)); - return ret; -}*/ UniValue kvsearch(const UniValue& params, bool fHelp) { From b3548b524daa2875de8f73c5339ec17a139baec5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:16:00 +0200 Subject: [PATCH 32/49] Test --- src/komodo_bitcoind.h | 2 +- src/komodo_globals.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 535e1ad81..d6e36cfde 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -816,7 +816,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t depth,notarized_ht; uint256 MoM,kmdtxid; depth = komodo_MoMdata(¬arized_ht,&MoM,&kmdtxid,nHeight); memset(MoMp,0,sizeof(*MoMp)); - memset(*kmdtxidp,0,sizeof(*kmdtxidp)); + memset(kmdtxidp,0,sizeof(*kmdtxidp)); *notarized_heightp = 0; if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight < notarized_ht ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index b35a2a8da..7c4077d8d 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -17,7 +17,7 @@ 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,uint256 MoM,int32_t MoMdepth); void komodo_init(int32_t height); -int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,int32_t nHeight); +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port); void komodo_init(int32_t height); From 16ed777a8c7ae8e3d7605aa555a7781ee7795fd4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:28:18 +0200 Subject: [PATCH 33/49] Fix off by ones --- src/komodo_bitcoind.h | 2 +- src/komodo_notary.h | 4 ++-- src/rpcblockchain.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d6e36cfde..3603b4135 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -818,7 +818,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in memset(MoMp,0,sizeof(*MoMp)); memset(kmdtxidp,0,sizeof(*kmdtxidp)); *notarized_heightp = 0; - if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight < notarized_ht ) + if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) { *MoMp = MoM; *notarized_heightp = notarized_ht; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1c5e9c9e2..32a9673f8 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -409,8 +409,8 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in np = &sp->NPOINTS[i]; if ( np->MoMdepth > 0 && nHeight > np->nHeight-np->MoMdepth && nHeight <= np->nHeight ) { - printf("komodo_MoMdata.(%s -> %s) %d i.%d np->ht %d MoMdepth.%d\n",symbol,dest,nHeight,i,np->nHeight,np->MoMdepth); - *notarized_htp = np->nHeight; + //printf("komodo_MoMdata.(%s -> %s) %d i.%d np->ht %d MoMdepth.%d\n",symbol,dest,nHeight,i,np->nHeight,np->MoMdepth); + *notarized_htp = np->notarized_height; *MoMp = np->MoM; *kmdtxidp = np->notarized_desttxid; return(np->MoMdepth); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5075fb200..7c167afc4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -580,7 +580,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) } height = chainActive.Tip()->nHeight; } - fprintf(stderr,"height_MoM height.%d\n",height); + //fprintf(stderr,"height_MoM height.%d\n",height); depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height",height)); From 6bc6362031737b2e420f136db3efbc5ba56db1b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 14:54:19 +0200 Subject: [PATCH 34/49] Test --- src/komodo_notary.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 32a9673f8..9b9515792 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -398,7 +398,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) } } -int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight) +int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height) { int32_t i; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; struct notarized_checkpoint *np = 0; np = 0; @@ -407,9 +407,8 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in for (i=sp->NUM_NPOINTS-1; i>=0; i--) { np = &sp->NPOINTS[i]; - if ( np->MoMdepth > 0 && nHeight > np->nHeight-np->MoMdepth && nHeight <= np->nHeight ) + if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height ) { - //printf("komodo_MoMdata.(%s -> %s) %d i.%d np->ht %d MoMdepth.%d\n",symbol,dest,nHeight,i,np->nHeight,np->MoMdepth); *notarized_htp = np->notarized_height; *MoMp = np->MoM; *kmdtxidp = np->notarized_desttxid; From ecf9c398f9dc2b25d17403f4523f9a0e8a6e1cd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 15:36:15 +0200 Subject: [PATCH 35/49] Test --- src/komodo_notary.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 9b9515792..9d40adf7c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -207,6 +207,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam n = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); for (i=0; i Date: Sat, 24 Mar 2018 15:39:49 +0200 Subject: [PATCH 36/49] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3603b4135..6d52ddbe3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -727,7 +727,7 @@ int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t hei int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) { int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; - if ( pubkey33 == 0 && (pindex= chainActive[height]) != 0 ) + if ( (pindex= chainActive[height]) != 0 ) { timestamp = pindex->GetBlockTime(); if ( pubkey33 == 0 ) From 78f9d61210a59982a66ad92529da33e138561423 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 15:53:08 +0200 Subject: [PATCH 37/49] Test --- src/komodo_notary.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 9d40adf7c..a87325d84 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -200,6 +200,12 @@ const char *Notaries_elected1[][2] = int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; + if ( timestamp == 0 ) + { + CBlockIndex *pblockindex = chainActive[height]; + if ( pblockindex != 0 ) + timestamp = pblockindex->GetBlockTime(); + } if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { if ( timestamp < KOMODO_NOTARIES_TIMESTAMP1 || height < KOMODO_NOTARIES_HEIGHT1 ) From 1f37849a4c7810ee3e2a8dc6e8944ed3c11eec5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 15:55:26 +0200 Subject: [PATCH 38/49] Test --- src/komodo_notary.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index a87325d84..fb7a8f426 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -200,12 +200,8 @@ const char *Notaries_elected1[][2] = int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; - if ( timestamp == 0 ) - { - CBlockIndex *pblockindex = chainActive[height]; - if ( pblockindex != 0 ) - timestamp = pblockindex->GetBlockTime(); - } + if ( timestamp == 0 && (timestamp= komodo_heightstamp(height)) == 0 ) + timestamp = (uint32_t)time(NULL) - 777; if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { if ( timestamp < KOMODO_NOTARIES_TIMESTAMP1 || height < KOMODO_NOTARIES_HEIGHT1 ) From 709a9861eedc8e6369073455a51c8f6cba6c8d57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 15:56:43 +0200 Subject: [PATCH 39/49] Test --- src/komodo_globals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 7c4077d8d..518d22cbd 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -15,6 +15,7 @@ #include "komodo_defs.h" +uint32_t komodo_heightstamp(int32_t height); 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,uint256 MoM,int32_t MoMdepth); void komodo_init(int32_t height); int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight); From 6e1d2e7dc98c02e724a83770b8189ac9343ca7c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 15:59:48 +0200 Subject: [PATCH 40/49] Test --- src/bitcoin-cli.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 87c5e6f76..178f0baed 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -81,6 +81,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } +uint32_t komodo_heightstamp(int32_t height) +{ + return(0); +} + static bool AppInitRPC(int argc, char* argv[]) { // From b91ef9cf13d8a1930e0986bb232eda05b6442e89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 16:02:25 +0200 Subject: [PATCH 41/49] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6d52ddbe3..6de981165 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -693,7 +693,7 @@ uint32_t komodo_heightstamp(int32_t height) CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) return(ptr->nTime); - else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); + //else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } From 15280cb441fdc21bb6a48eef59e2b374c737c8cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 16:22:18 +0200 Subject: [PATCH 42/49] Test --- src/komodo_bitcoind.h | 4 ++-- src/komodo_notary.h | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6de981165..97abb9429 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -621,7 +621,7 @@ int32_t komodo_block2height(CBlock *block) //for (i=0; i<6; i++) // printf("%02x",ptr[i]); n = ptr[0]; - for (i=0; iGetBlockTime(); if ( pubkey33 == 0 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index fb7a8f426..9a9073221 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -200,18 +200,16 @@ const char *Notaries_elected1[][2] = int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; - if ( timestamp == 0 && (timestamp= komodo_heightstamp(height)) == 0 ) - timestamp = (uint32_t)time(NULL) - 777; if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( timestamp < KOMODO_NOTARIES_TIMESTAMP1 || height < KOMODO_NOTARIES_HEIGHT1 ) + if ( (timestamp != 0 && timestamp < KOMODO_NOTARIES_TIMESTAMP1) || height < KOMODO_NOTARIES_HEIGHT1 ) { n = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); for (i=0; i Date: Sat, 24 Mar 2018 16:30:46 +0200 Subject: [PATCH 43/49] Test --- src/komodo_notary.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 9a9073221..e86be55e2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -126,8 +126,8 @@ const char *Notaries_elected0[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -#define KOMODO_NOTARIES_TIMESTAMP1 1600000000 -#define KOMODO_NOTARIES_HEIGHT1 ((900000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) +#define KOMODO_NOTARIES_TIMESTAMP1 1400000000 +#define KOMODO_NOTARIES_HEIGHT1 ((700000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] = { @@ -214,6 +214,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam n = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); for (i=0; i Date: Sat, 24 Mar 2018 16:38:12 +0200 Subject: [PATCH 44/49] Test --- src/komodo_notary.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e86be55e2..894756802 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -207,14 +207,16 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam n = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); for (i=0; inotaryid < n ) From 98598a7094036003c3d65337e3457899af345273 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 16:43:51 +0200 Subject: [PATCH 45/49] Test --- src/komodo.h | 4 ++-- src/komodo_notary.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 5a1dc62f8..ded368381 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -573,7 +573,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { notarized = 1; } - if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) + if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-64 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; sp->NOTARIZED_HEIGHT = *notarizedheightp; @@ -623,7 +623,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0); } } - } else if ( height >= KOMODO_MAINNET_START ) + } else if ( height >= sp->CURRENT_HEIGHT-64 )//KOMODO_MAINNET_START ) printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); } else if ( i == 0 && j == 1 && opretlen == 149 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 894756802..cf3038109 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -126,8 +126,8 @@ const char *Notaries_elected0[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -#define KOMODO_NOTARIES_TIMESTAMP1 1400000000 -#define KOMODO_NOTARIES_HEIGHT1 ((700000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) +#define KOMODO_NOTARIES_TIMESTAMP1 1530921600 // 7/7/2017 +#define KOMODO_NOTARIES_HEIGHT1 ((900000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] = { From a192131ddc7964225e49ed8331b07bd60b8263d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 16:46:33 +0200 Subject: [PATCH 46/49] Test --- src/komodo_notary.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index cf3038109..6bf447ab8 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -126,7 +126,7 @@ const char *Notaries_elected0[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -#define KOMODO_NOTARIES_TIMESTAMP1 1530921600 // 7/7/2017 +#define KOMODO_NOTARIES_TIMESTAMP1 1521902703 //1530921600 // 7/7/2017 #define KOMODO_NOTARIES_HEIGHT1 ((900000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] = @@ -207,8 +207,8 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam n = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); for (i=0; i Date: Sat, 24 Mar 2018 16:51:57 +0200 Subject: [PATCH 47/49] Test --- src/komodo_notary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 6bf447ab8..db58e0784 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -200,6 +200,8 @@ const char *Notaries_elected1[][2] = int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; + if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + timestamp = komodo_heightstamp(height); if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { if ( (timestamp != 0 && timestamp < KOMODO_NOTARIES_TIMESTAMP1) || height < KOMODO_NOTARIES_HEIGHT1 ) From f99c2ff39e4c10c1bca5eb117266530097ac8200 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Mar 2018 16:53:48 +0200 Subject: [PATCH 48/49] Test --- src/komodo_notary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index db58e0784..c852224db 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -217,7 +217,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam n = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); for (i=0; i Date: Sat, 24 Mar 2018 16:55:47 +0200 Subject: [PATCH 49/49] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c852224db..56f0cc19a 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -126,7 +126,7 @@ const char *Notaries_elected0[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -#define KOMODO_NOTARIES_TIMESTAMP1 1521902703 //1530921600 // 7/7/2017 +#define KOMODO_NOTARIES_TIMESTAMP1 1530921600 // 7/7/2017 #define KOMODO_NOTARIES_HEIGHT1 ((900000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] =