From f8b1cc034303c38dd635d48b1e79ae36e41840f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Oct 2016 14:49:33 -0300 Subject: [PATCH] test --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_fsm.c | 70 +++++++++++++++++++++----------------- iguana/dpow/dpow_network.c | 8 ++--- iguana/dpow/dpow_tx.c | 16 ++++++--- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index b930255d2..1199b5d74 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -53,7 +53,7 @@ struct dpow_utxoentry struct dpow_entry { bits256 commit,beacon; - uint64_t masks[DPOW_MAXRELAYS],recvmask,othermask; + uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask; int32_t height; int8_t bestk; uint8_t pubkey[33]; diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index d84590f6b..ee25478db 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -74,7 +74,7 @@ void dpow_utxosync(struct supernet_info *myinfo,struct dpow_block *bp,uint64_t r if ( ((1LL << myind) & recvmask) == 0 ) { i = myind; - printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind); + //printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind); } else { @@ -85,7 +85,7 @@ void dpow_utxosync(struct supernet_info *myinfo,struct dpow_block *bp,uint64_t r if ( ((1LL << i) & bp->recvmask) != 0 && ((1LL << i) & recvmask) == 0 ) break; } - printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i); + //printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i); } memset(&U,0,sizeof(U)); dpow_entry2utxo(&U,bp,&bp->notaries[i]); @@ -157,7 +157,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t { if ( ep->masks[dsig.lastk] == 0 ) { - ep->masks[dsig.lastk] = dsig.mask; + ep->masks[src_or_dest][dsig.lastk] = dsig.mask; cp->siglens[dsig.lastk] = dsig.siglen; memcpy(cp->sigs[dsig.lastk],dsig.sig,dsig.siglen); ep->beacon = dsig.beacon; @@ -204,7 +204,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t { printf("verify (%s) it is properly signed! set ht.%d signedtxid to %s\n",coin->symbol,height,bits256_str(str,txid)); bp->signedtxid = txid; - bp->state = 0xffffffff; + bp->state = src_or_dest != 0 ? 1000 : 0xffffffff; } else { @@ -217,40 +217,48 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t return(0); } -int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t utxochannel,uint32_t sigchannel,uint32_t txidchannel,bits256 srchash,int32_t myind,int32_t src_or_dest) +int32_t dpow_update(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t txidchannel,bits256 srchash,int32_t myind) { - struct dpow_entry *ep; int32_t i,k,len,sendutxo = 1; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U; + struct dpow_entry *ep; int32_t i,k,len,src_or_dest,sendutxo = 1; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U; ep = &bp->notaries[myind]; - if ( (bp->bestk= dpow_bestk(bp,&bp->bestmask)) >= 0 ) + if ( bp->state < 1000 ) { - sendutxo = 0; - for (i=0; inumnotaries; i++) + src_or_dest = 1; + if ( (bp->bestk= dpow_bestk(bp,&bp->bestmask)) >= 0 ) { - k = ((bp->height % bp->numnotaries) + i) % bp->numnotaries; - if ( k == myind ) - continue; - if ( ((1LL << k) & bp->recvmask) != 0 && (bp->notaries[k].recvmask & (1LL << myind)) == 0 ) + sendutxo = 0; + for (i=0; inumnotaries; i++) { - //printf("other notary.%d doesnt have our.%d utxo yet\n",k,myind); - //sendutxo = 1; - break; + k = ((bp->height % bp->numnotaries) + i) % bp->numnotaries; + if ( k == myind ) + continue; + if ( ((1LL << k) & bp->recvmask) != 0 && (bp->notaries[k].recvmask & (1LL << myind)) == 0 ) + { + //printf("other notary.%d doesnt have our.%d utxo yet\n",k,myind); + //sendutxo = 1; + break; + } } + if ( ep->masks[src_or_dest][bp->bestk] == 0 ) + dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,DPOW_SIGBTCCHANNEL,src_or_dest); + //else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel); + } + if ( sendutxo != 0 ) + { + memset(&U,0,sizeof(U)); + dpow_entry2utxo(&U,bp,&bp->notaries[myind]); + if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 ) + dpow_send(myinfo,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len,bp->utxocrcs); } - if ( ep->masks[bp->bestk] == 0 ) - dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,sigchannel,src_or_dest); + if ( ep->masks[src_or_dest][bp->bestk] == 0 ) + dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,"",DPOW_SIGBTCCHANNEL,src_or_dest); //else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel); } - if ( sendutxo != 0 ) - { - memset(&U,0,sizeof(U)); - dpow_entry2utxo(&U,bp,&bp->notaries[myind]); - if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 ) - dpow_send(myinfo,bp,srchash,bp->hashmsg,utxochannel,bp->height,data,len,bp->utxocrcs); - } - if ( bp->state != 0xffffffff ) + else if ( bp->state != 0xffffffff ) { - if ( ep->masks[bp->bestk] == 0 ) - dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,sigchannel,src_or_dest); + src_or_dest = 0; + if ( ep->masks[src_or_dest][bp->bestk] == 0 ) + dpow_signedtxgen(myinfo,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->opret_symbol,DPOW_SIGCHANNEL,src_or_dest); //else dpow_sigsend(myinfo,bp,myind,bp->bestk,bp->bestmask,srchash,sigchannel); } return(bp->state); @@ -278,11 +286,9 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info } bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->DPOW.minerkey33,33); if ( bits256_nonz(bp->hashmsg) == 0 ) - return(0xffffffff); + return(0); for (j=0; jDPOW.minerkey33[j+1]; - if ( bits256_nonz(bp->signedtxid) != 0 ) - bp->state = 0xffffffff; bp->bestk = dpow_bestk(bp,&bp->bestmask); if ( (rand() % 10) == 0 ) printf("[%d] %s ht.%d FSM.%d %s BTC.%d masks.%llx best.(%d %llx) sigsmask.%llx\n",myind,coin->symbol,bp->height,bp->state,coinaddr,bits256_nonz(bp->desttxid)==0,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)bp->destsigsmasks[bp->bestk]); @@ -293,7 +299,7 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info } else { - dpow_update(myinfo,bp,channel,sigchannel,txidchannel,srchash,myind,src_or_dest); + dpow_update(myinfo,bp,txidchannel,srchash,myind); if ( bits256_nonz(bp->signedtxid) != 0 ) bp->state = 0xffffffff; } diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 986864adf..eacb0709f 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -164,14 +164,14 @@ int32_t dpow_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) return(opretlen + offset); } -int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *heightmsgp,bits256 *btctxid,char *src) +int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *heightmsgp,bits256 *desttxid,char *src,bits256 *beaconp) { int32_t i,opretlen = 0; opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*hashmsg),hashmsg->bytes); opretlen += iguana_rwnum(rwflag,&opret[opretlen],sizeof(*heightmsgp),(uint32_t *)heightmsgp); - if ( bits256_nonz(*btctxid) != 0 ) + if ( bits256_nonz(*desttxid) != 0 ) { - opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*btctxid),btctxid->bytes); + opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*desttxid),desttxid->bytes); if ( rwflag != 0 ) { for (i=0; src[i]!=0; i++) @@ -185,7 +185,7 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei src[i] = 0; opretlen++; } - } + } else opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*beaconp),beaconp->bytes); return(opretlen); } diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 74d45f72d..77167874e 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -121,7 +121,7 @@ bits256 dpow_notarytx(char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow serialized[len++] = CHECKSIG; satoshis = 0; len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis); - opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,&bp->desttxid,src); + opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,&bp->desttxid,src,&bp->beacon); opretlen = dpow_opreturnscript(data,opret,opretlen); if ( opretlen < 0xfd ) serialized[len++] = opretlen; @@ -198,13 +198,13 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct iguana_info *coin,struct item = jitem(vin,j); if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 ) { - printf("height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bp->height,bp->height%bp->numnotaries,j,myind,jprint(item,0),j); + printf("%s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",(src_or_dest != 0) ? bp->srccoin->symbol : bp->destcoin->symbol,bp->height,bp->height%bp->numnotaries,j,myind,jprint(item,0),j); cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; if ( src_or_dest != 0 ) bp->destsigsmasks[bestk] |= (1LL << myind); else bp->srcsigsmasks[bestk] |= (1LL << myind); decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); - ep->masks[bestk] = bestmask; + ep->masks[src_or_dest][bestk] = bestmask; ep->beacon = bp->beacon; dpow_sigsend(myinfo,bp,myind,bestk,bestmask,srchash,sigchannel); retval = 0; @@ -260,7 +260,7 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t bits256 txid,srchash,zero; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768]; coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin; memset(zero.bytes,0,sizeof(zero)); - printf("sigscheck myind.%d src_dest.%d state.%x\n",myind,src_or_dest,bp->state); + //printf("sigscheck myind.%d src_dest.%d state.%x\n",myind,src_or_dest,bp->state); if ( bp->state != 0xffffffff && coin != 0 ) { bp->signedtxid = dpow_notarytx(bp->signedtx,&numsigs,coin->chain->isPoS,bp,bp->bestk,bp->bestmask,bp->opret_symbol,1,src_or_dest); @@ -276,13 +276,19 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_block *bp,uint32_t decode_hex(txid.bytes,sizeof(txid),retstr); if ( bits256_cmp(txid,bp->signedtxid) == 0 ) { + if ( src_or_dest != 0 ) + { + bp->desttxid = txid; + dpow_signedtxgen(myinfo,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->srccoin->symbol,DPOW_SIGCHANNEL,0); + } + else bp->srctxid = txid; len = (int32_t)strlen(bp->signedtx) >> 1; decode_hex(txdata+32,len,bp->signedtx); for (j=0; jhashmsg,(channel == DPOW_SIGBTCCHANNEL) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32,bp->txidcrcs); printf("complete statemachine.%s ht.%d\n",coin->symbol,bp->height); - bp->state = 0xffffffff; + bp->state = src_or_dest != 0 ? 1000 : 0xffffffff; } else printf("sendtxid mismatch got %s instead of %s\n",bits256_str(str,txid),bits256_str(str2,bp->signedtxid)); } free(retstr);