From b713f43487e2171b700dfa85ccd1428d33c3a712 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 1 Sep 2021 14:46:53 -0400 Subject: [PATCH] Clean up dead code and cruft --- src/crypto/equihash.h | 2 +- src/hush.h | 76 +++++++++++----------------------------- src/hush_bitcoind.h | 7 ++-- src/hush_ccdata.h | 2 +- src/hush_events.h | 2 +- src/hush_gateway.h | 2 +- src/hush_pax.h | 2 +- src/hush_utils.h | 2 +- src/wallet/rpcwallet.cpp | 8 ++--- 9 files changed, 35 insertions(+), 68 deletions(-) diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h index 3b977dffc..968fbdd79 100644 --- a/src/crypto/equihash.h +++ b/src/crypto/equihash.h @@ -204,7 +204,7 @@ public: #include "equihash.tcc" /* -* Equihash 200,9 (KMD/Zcash) +* Equihash 200,9 (HUSH/ZEC and other ASIC coins) * Equihash 150,5 (beam) * Equihash 144,5 (SnowGem) * Equihash 96,5 (Minex) diff --git a/src/hush.h b/src/hush.h index cb8a60a6c..c09d2eea6 100644 --- a/src/hush.h +++ b/src/hush.h @@ -82,9 +82,7 @@ int32_t hush_parsestatefile(struct hush_state *sp,FILE *fp,char *symbol,char *de 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 ( SMART_CHAIN_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) - matched = 1; - else matched = (strcmp(symbol,SMART_CHAIN_SYMBOL) == 0); + matched = (strcmp(symbol,SMART_CHAIN_SYMBOL) == 0); if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; if ( 0 && SMART_CHAIN_SYMBOL[0] != 0 && func != 'T' ) @@ -98,7 +96,7 @@ int32_t hush_parsestatefile(struct hush_state *sp,FILE *fp,char *symbol,char *de else { //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht); - if ( (HUSH_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && HUSH_EXTERNAL_NOTARIES == 0) ) + if ( (HUSH_EXTERNAL_NOTARIES != 0 && matched != 0) ) hush_eventadd_pubkeys(sp,symbol,ht,num,pubkeys); } } else printf("illegal num.%d\n",num); @@ -228,10 +226,9 @@ int32_t hush_parsestatefiledata(struct hush_state *sp,uint8_t *filedata,long *fp 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++]; - if ( SMART_CHAIN_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) - matched = 1; - else matched = (strcmp(symbol,SMART_CHAIN_SYMBOL) == 0); + func = filedata[fpos++]; + matched = (strcmp(symbol,SMART_CHAIN_SYMBOL) == 0); + if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) ) errs++; if ( func == 'P' ) @@ -243,7 +240,7 @@ int32_t hush_parsestatefiledata(struct hush_state *sp,uint8_t *filedata,long *fp else { //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht); - if ( (HUSH_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && HUSH_EXTERNAL_NOTARIES == 0) ) + if ( (HUSH_EXTERNAL_NOTARIES != 0 && matched != 0) ) hush_eventadd_pubkeys(sp,symbol,ht,num,pubkeys); } } else printf("illegal num.%d\n",num); @@ -353,7 +350,7 @@ int32_t hush_parsestatefiledata(struct hush_state *sp,uint8_t *filedata,long *fp return(-1); } -void hush_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) +void hush_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 HUSHheight,uint32_t HUSHtimestamp,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 hush_state *sp; char fname[512],symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; @@ -394,30 +391,26 @@ void hush_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotarie if ( fp != 0 ) // write out funcid, height, other fields, call side effect function { //printf("fpos.%ld ",ftell(fp)); - if ( KMDheight != 0 ) + if ( HUSHheight != 0 ) { - if ( KMDtimestamp != 0 ) + if ( HUSHtimestamp != 0 ) { fputc('T',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; - if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) + if ( fwrite(&HUSHheight,1,sizeof(HUSHheight),fp) != sizeof(HUSHheight) ) errs++; - if ( fwrite(&KMDtimestamp,1,sizeof(KMDtimestamp),fp) != sizeof(KMDtimestamp) ) + if ( fwrite(&HUSHtimestamp,1,sizeof(HUSHtimestamp),fp) != sizeof(HUSHtimestamp) ) errs++; - } - else - { + } else { fputc('K',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; - if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) + if ( fwrite(&HUSHheight,1,sizeof(HUSHheight),fp) != sizeof(HUSHheight) ) errs++; } - hush_eventadd_kmdheight(sp,symbol,height,KMDheight,KMDtimestamp); - } - else if ( opretbuf != 0 && opretlen > 0 ) - { + hush_eventadd_kmdheight(sp,symbol,height,HUSHheight,HUSHtimestamp); + } else if ( opretbuf != 0 && opretlen > 0 ) { uint16_t olen = opretlen; fputc('R',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) @@ -432,8 +425,7 @@ void hush_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotarie errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; -//printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); - //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); + //printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); hush_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } else if ( notarypubs != 0 && numnotaries > 0 ) @@ -687,7 +679,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi } else { - komodo_rwccdata(SMART_CHAIN_SYMBOL,1,&ccdata,&MoMoMdata); + hush_rwccdata(SMART_CHAIN_SYMBOL,1,&ccdata,&MoMoMdata); if ( matched != 0 ) printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",SMART_CHAIN_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } @@ -696,8 +688,6 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi memset(&ccdata,0,sizeof(ccdata)); memset(&MoMoMdata,0,sizeof(MoMoMdata)); } - else if ( SMART_CHAIN_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) - komodo_rwccdata((char *)"KMD",1,&ccdata,0); if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { @@ -711,36 +701,12 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi } hush_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); //if ( SMART_CHAIN_SYMBOL[0] != 0 ) - printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL[0]==0?"KMD":SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),SMART_CHAIN_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),"HUSH",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); - if ( SMART_CHAIN_SYMBOL[0] == 0 ) - { - if ( signedfp == 0 ) - { - char fname[512]; - hush_statefname(fname,SMART_CHAIN_SYMBOL,(char *)"hushsignedmasks"); - if ( (signedfp= fopen(fname,"rb+")) == 0 ) - signedfp = fopen(fname,"wb"); - else fseek(signedfp,0,SEEK_END); - } - if ( signedfp != 0 ) - { - fwrite(&height,1,sizeof(height),signedfp); - fwrite(&signedmask,1,sizeof(signedmask),signedfp); - fflush(signedfp); - } - if ( opretlen > len && scriptbuf[len] == 'A' ) - { - //for (i=0; i 600000 && matched != 0 ) - printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL[0]==0?"KMD":SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen); + printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen); } else if ( matched != 0 && i == 0 && j == 1 && opretlen == 149 ) { @@ -752,7 +718,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi //int32_t k; for (k=0; k= 32*2+4 && strcmp(SMART_CHAIN_SYMBOL[0]==0?"KMD":SMART_CHAIN_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) + if ( opretlen >= 32*2+4 && strcmp(SMART_CHAIN_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { for (k=0; k<32; k++) if ( scriptbuf[len+k] != 0 ) @@ -985,7 +951,7 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } } if ( !fJustCheck && IS_HUSH_NOTARY != 0 && SMART_CHAIN_SYMBOL[0] == 0 ) - printf("%s ht.%d\n",SMART_CHAIN_SYMBOL[0] == 0 ? "KMD" : SMART_CHAIN_SYMBOL,height); + printf("%s ht.%d\n",SMART_CHAIN_SYMBOL,height); if ( !fJustCheck && pindex->GetHeight() == hwmheight ) hush_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); } diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index 4fa823997..69ace9a3a 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -15,7 +15,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ -// Hush functions that interact with bitcoind C++ +// Hush functions that interact with hushd C++ #include #include #include "consensus/params.h" @@ -408,6 +408,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *hushnotarized_hei if ( (item= jobj(json,(char *)"result")) != 0 ) { height = jint(item,(char *)"blocks"); + //TODO: which key to use? *hushnotarized_heightp = strcmp(dest,"KMD") == 0 ? jint(item,(char *)"notarized") : height; } free_json(json); @@ -570,7 +571,7 @@ CScript hush_makeopret(CBlock *pblock, bool fNew) } free_json(result); } - printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash); + printf("HUSH3 hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash); free(jsonstr); } return(hash); @@ -1032,7 +1033,7 @@ int32_t hush_nextheight() int32_t komodo_isrealtime(int32_t *kmdheightp) { struct hush_state *sp; CBlockIndex *pindex; - if ( (sp= hush_stateptrget((char *)"KMD")) != 0 ) + if ( (sp= hush_stateptrget((char *)"HUSH3")) != 0 ) *kmdheightp = sp->CURRENT_HEIGHT; else *kmdheightp = 0; if ( (pindex= chainActive.LastTip()) != 0 && pindex->GetHeight() >= (int32_t)hush_longestchain() ) diff --git a/src/hush_ccdata.h b/src/hush_ccdata.h index c45cd3c62..edfb70c2c 100644 --- a/src/hush_ccdata.h +++ b/src/hush_ccdata.h @@ -203,7 +203,7 @@ void komodo_purge_ccdata(int32_t height) } // this is just a demo of ccdata processing to create example data for the MoMoM and allMoMs calls -int32_t komodo_rwccdata(char *thischain,int32_t rwflag,struct hush_ccdata *ccdata,struct hush_ccdataMoMoM *MoMoMdata) +int32_t hush_rwccdata(char *thischain,int32_t rwflag,struct hush_ccdata *ccdata,struct hush_ccdataMoMoM *MoMoMdata) { uint256 hash,zero; bits256 tmp; int32_t i,nonz; struct hush_ccdata *ptr; struct notarized_checkpoint *np; return(0); // disable this path as libscott method is much better diff --git a/src/hush_events.h b/src/hush_events.h index 18553e143..ab92521ec 100644 --- a/src/hush_events.h +++ b/src/hush_events.h @@ -69,7 +69,7 @@ void hush_eventadd_notarized(struct hush_state *sp,char *symbol,int32_t height,c void hush_eventadd_pubkeys(struct hush_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) { struct hush_event_pubkeys P; - //printf("eventadd pubkeys ht.%d\n",height); + fprintf(stderr, "%s: eventadd pubkeys height=%d\n",__func__,height); memset(&P,0,sizeof(P)); P.num = num; memcpy(P.pubkeys,pubkeys,33 * num); diff --git a/src/hush_gateway.h b/src/hush_gateway.h index 8b28c9b8c..7eb0bd8b3 100644 --- a/src/hush_gateway.h +++ b/src/hush_gateway.h @@ -610,7 +610,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to for (i=0; ivout.resize(numvouts+1); txNew->vout[numvouts].nValue = 0; txNew->vout[numvouts].scriptPubKey.resize(opretlen); diff --git a/src/hush_pax.h b/src/hush_pax.h index 3ccbc2d74..d953bdcc2 100644 --- a/src/hush_pax.h +++ b/src/hush_pax.h @@ -267,7 +267,7 @@ int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize) } if ( timestamp > time(NULL)-600 ) { - n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + n = hush_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( 0 && lastcrc != crc32 ) { for (i=0; i