From e5d465e6b76f757556c124ffb319aea5349ff07e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 27 Apr 2018 14:14:50 +0300 Subject: [PATCH] issue_calcMoM --- iguana/dpow/dpow_fsm.c | 156 +++++++++-------------------------------- iguana/dpow/dpow_rpc.c | 15 ++++ iguana/iguana_notary.c | 119 ++++++++++++++++++++++++++++++- 3 files changed, 167 insertions(+), 123 deletions(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 048c7197a..228ce1038 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -230,121 +230,7 @@ int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txi return(-1); } -int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height,struct komodo_ccdataMoMoM *mdata) -{ - cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[256]; bits256 spenttxid; uint64_t notarymask=0; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; - if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 ) - { - if ( (vins= jarray(&numvins,txobj,"vin")) != 0 ) - { - if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS ) - { - notarymask = numnotaries = 0; - for (i=0; i>= 1; - decode_hex(script,len,hexstr); - if ( script[0] == 33 && script[34] == 0xac ) - { - for (j=0; j 0 ) - { - if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS ) - { - hasnotarization = 1; - *nothtp = 0; - if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) - { - bits256 blockhash,txid,MoM; uint32_t MoMdepth; char symbol[65];//,str[65],str2[65],str3[65]; - vout = jitem(vouts,numvouts-1); - if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) > 36*2 && len < sizeof(script)*2 ) - { - len >>= 1; - decode_hex(script,len,hexstr); - if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len,mdata) > 0 && strcmp(symbol,coin->symbol) == 0 ) - { - // if ( Notaries_port != DPOW_SOCKPORT ) // keep going till valid MoM found, useful for new chains without any MoM - { - if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 ) - { - *nothtp = 0; - } - } - if ( mdata->pairs != 0 && mdata->numpairs > 0 ) - { - for (j=0; jnumpairs; j++) - { - if ( mdata->pairs[j].notarization_height > coin->MoMoMheight ) - { - coin->MoMoMheight = mdata->pairs[j].notarization_height; - printf("set %s MoMoMheight <- %d\n",coin->symbol,coin->MoMoMheight); - } - } - } - //printf("%s.%d notarizationht.%d %s -> %s MoM.%s [%d]\n",symbol,height,*nothtp,bits256_str(str,blockhash),bits256_str(str2,txid),bits256_str(str3,MoM),MoMdepth); - } - } - } - } - } - } - } - free_json(txobj); - } - if ( hasnotarization != 0 ) - (*signedmaskp) = notarymask; - return(hasnotarization); -} - -int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht,struct komodo_ccdataMoMoM *mdata) -{ - int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray; - *nothtp = 0; - *signedmaskp = 0; - memset(mdata,0,sizeof(*mdata)); - if ( (txarray= jarray(&n,blockjson,"tx")) != 0 ) - { - for (i=0; isymbol,height,MoMdepth); return(MoM); +}*/ + +/*{ + "coin": "PIZZA", + "height": 30623, + "MoMdepth": 10000, + "MoM": "797239cfd3611d359ec515fa493062cc2838172a99fd86de1d0305d009abde40" +}*/ + +bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height) +{ + bits256 MoM; cJSON *MoMjson,*infojson; int32_t prevMoMheight; + *MoMdepthp = 0; + memset(MoM.bytes,0,sizeof(MoM)); + if ( (infojson= dpow_getinfo(myinfo,coin)) != 0 ) + { + if ( (prevMoMheight= jint(infojson,"prevMoMheight")) != 0 ) + { + *MoMdepthp = (height - prevMoMheight); + if ( *MoMdepthp > 0 && (MoMjson= issue_calcMoM(coin,height,*MoMdepthp)) != 0 ) + { + MoM = jbits256(MoMjson,"MoM"); + free_json(MoMjson); + } + } + free_json(infojson); + } + if ( bits256_nonz(MoM) == 0 ) + *MoMdepthp = 0; + return(MoM); } void dpow_statemachinestart(void *ptr) @@ -439,16 +355,14 @@ void dpow_statemachinestart(void *ptr) return; } MoMdepth = 0; - if ( 0 && strcmp(dp->dest,"KMD") == 0 ) - { - portable_mutex_lock(&src->MoM_mutex); - MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height); - portable_mutex_unlock(&src->MoM_mutex); - } else memset(&MoM,0,sizeof(MoM)); + memset(&MoM,0,sizeof(MoM)); if ( strcmp(src->symbol,"KMD") == 0 ) kmdheight = checkpoint.blockhash.height; else if ( strcmp(dest->symbol,"KMD") == 0 ) + { + MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height); kmdheight = dest->longestchain; + } if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) { bp = calloc(1,sizeof(*bp)); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 2fec9399d..808970aaf 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -226,6 +226,21 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c return(blockhash); } +cJSON *issue_calcMoM(struct iguana_info *coin,int32_t height,int32_t MoMdepth) +{ + char buf[128],*retstr=0; cJSON *retjson = 0; + if ( coin->FULLNODE < 0 ) + { + sprintf(buf,"[\"%d\", \"%d\"]",height,MoMdepth); + if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"calc_MoM",buf)) != 0 ) + { + retjson = cJSON_Parse(retstr); + printf("MoM.%s -> %s\n",buf,retstr); + free(retstr); + } + } + return(retjson); +} cJSON *dpow_MoMoMdata(struct iguana_info *coin,char *symbol,int32_t kmdheight) { diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index ecaa0b084..142c71619 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -76,7 +76,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he else freq = 1; } dpow_fifoupdate(myinfo,dp->srcfifo,dp->last); - if ( strcmp(dp->dest,"KMD") == 0 )//|| strcmp(dp->dest,"CHAIN") == 0 ) + /*if ( strcmp(dp->dest,"KMD") == 0 )//|| strcmp(dp->dest,"CHAIN") == 0 ) { //if ( dp->SRCREALTIME == 0 ) // return; @@ -117,7 +117,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he } else return; } else return; } else return; - } + }*/ if ( bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % freq) == 0 ) { if ( (0) && strcmp("KMD",dp->symbol) == 0 ) @@ -579,6 +579,121 @@ void iguana_notarystats(int32_t totals[64],int32_t dispflag) } } +// slow and should be redone to use calc_MoM rpc +int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height,struct komodo_ccdataMoMoM *mdata) +{ + cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[256]; bits256 spenttxid; uint64_t notarymask=0; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; + if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 ) + { + if ( (vins= jarray(&numvins,txobj,"vin")) != 0 ) + { + if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS ) + { + notarymask = numnotaries = 0; + for (i=0; i>= 1; + decode_hex(script,len,hexstr); + if ( script[0] == 33 && script[34] == 0xac ) + { + for (j=0; j 0 ) + { + if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS ) + { + hasnotarization = 1; + *nothtp = 0; + if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) + { + bits256 blockhash,txid,MoM; uint32_t MoMdepth; char symbol[65];//,str[65],str2[65],str3[65]; + vout = jitem(vouts,numvouts-1); + if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) > 36*2 && len < sizeof(script)*2 ) + { + len >>= 1; + decode_hex(script,len,hexstr); + if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len,mdata) > 0 && strcmp(symbol,coin->symbol) == 0 ) + { + // if ( Notaries_port != DPOW_SOCKPORT ) // keep going till valid MoM found, useful for new chains without any MoM + { + if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 ) + { + *nothtp = 0; + } + } + if ( mdata->pairs != 0 && mdata->numpairs > 0 ) + { + for (j=0; jnumpairs; j++) + { + if ( mdata->pairs[j].notarization_height > coin->MoMoMheight ) + { + coin->MoMoMheight = mdata->pairs[j].notarization_height; + printf("set %s MoMoMheight <- %d\n",coin->symbol,coin->MoMoMheight); + } + } + } + //printf("%s.%d notarizationht.%d %s -> %s MoM.%s [%d]\n",symbol,height,*nothtp,bits256_str(str,blockhash),bits256_str(str2,txid),bits256_str(str3,MoM),MoMdepth); + } + } + } + } + } + } + } + free_json(txobj); + } + if ( hasnotarization != 0 ) + (*signedmaskp) = notarymask; + return(hasnotarization); +} + +int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht,struct komodo_ccdataMoMoM *mdata) +{ + int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray; + *nothtp = 0; + *signedmaskp = 0; + memset(mdata,0,sizeof(*mdata)); + if ( (txarray= jarray(&n,blockjson,"tx")) != 0 ) + { + for (i=0; i