From e346e784255937ec23fe39bd2683e9ef607a311e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 11:30:22 -0300 Subject: [PATCH] test --- iguana/dPoW.h | 2 ++ iguana/dpow/dpow_fsm.c | 64 +++++++++++++++++++++++++++++++++----- iguana/dpow/dpow_network.c | 45 +++++++++++++++++++++++++-- iguana/dpow/dpow_tx.c | 4 +-- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index eb84cb095..d4f22ecd3 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -28,6 +28,8 @@ #define DPOW_DURATION 300 #define DPOW_RATIFYDURATION (3600 * 24) +#define DPOW_ENTRIESCHANNEL ('e' | ('n' << 8) | ('t' << 16) | ('r' << 24)) +#define DPOW_BTCENTRIESCHANNEL (~DPOW_ENTRIESCHANNEL) #define DPOW_UTXOCHANNEL ('d' | ('P' << 8) | ('o' << 16) | ('W' << 24)) #define DPOW_SIGCHANNEL ('s' | ('i' << 8) | ('g' << 16) | ('s' << 24)) #define DPOW_SIGBTCCHANNEL (~DPOW_SIGCHANNEL) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 8d0d66e92..724f924c7 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -92,7 +92,7 @@ void dpow_utxosync(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow //char str[65],str2[65]; //printf("send.(%s %s)\n",bits256_str(str,bp->notaries[i].dest.prev_hash),bits256_str(str2,bp->notaries[i].src.prev_hash)); if ( (len= dpow_rwutxobuf(1,utxodata,&U,bp)) > 0 ) - dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,utxodata,len,bp->utxocrcs); + dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,utxodata,len); } } @@ -107,7 +107,7 @@ void dpow_sync(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen) { - bits256 txid,commit,srchash; struct dpow_block *bp = 0; uint32_t flag = 0; int32_t src_or_dest,senderind,i,myind = -1; char str[65],str2[65]; struct dpow_sigentry dsig; struct dpow_entry *ep; struct dpow_coinentry *cp; struct dpow_utxoentry U; struct iguana_info *coin; + bits256 txid,commit,srchash,hashmsg; struct dpow_block *bp = 0; uint32_t flag = 0; int32_t src_or_dest,senderind,i,rlen,myind = -1; char str[65],str2[65]; struct dpow_sigentry dsig; struct dpow_entry *ep; struct dpow_coinentry *cp; struct dpow_utxoentry U; struct iguana_info *coin; if ( (bp= dpow_heightfind(myinfo,dp,height)) == 0 ) { if ( (rand() % 100) == 0 && height > 0 ) @@ -122,7 +122,47 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint3 } for (i=0; i<32; i++) srchash.bytes[i] = dp->minerkey33[i+1]; - if ( channel == DPOW_UTXOCHANNEL ) + if ( channel == DPOW_ENTRIESCHANNEL || channel == DPOW_BTCENTRIESCHANNEL ) + { + struct dpow_entry notaries[DPOW_MAXRELAYS]; uint8_t n; int8_t bestk; struct dpow_coinentry *ptr,*refptr; + src_or_dest = (channel == DPOW_BTCENTRIESCHANNEL); + rlen = 0; + bestk = data[rlen++]; + n = data[rlen++]; + rlen += iguana_rwbignum(0,&data[rlen],sizeof(hashmsg),hashmsg.bytes); + if ( bits256_cmp(hashmsg,bp->hashmsg) == 0 ) + { + memset(notaries,0,sizeof(notaries)); + for (i=0; i<64; i++) + notaries[i].bestk = -1; + rlen += dpow_rwcoinentrys(0,&data[rlen],src_or_dest,notaries,n,bestk); + for (i=0; inotaries[i].dest : &bp->notaries[i].src; + if ( bits256_nonz(ptr->prev_hash) != 0 && bits256_nonz(refptr->prev_hash) == 0 ) + { + printf("got utxo.[%d] indirectly\n",i); + refptr->prev_hash = ptr->prev_hash; + refptr->prev_vout = ptr->prev_vout; + bp->recvmask |= (1LL << i); + } + if ( (bestk= notaries[i].bestk) >= 0 ) + { + if ( ptr->siglens[bestk] > 0 && refptr->siglens[bestk] == 0 ) + { + printf("got siglen.%d for [%d] indirectly\n",ptr->siglens[bestk],i); + memcpy(refptr->sigs[bestk],ptr->sigs[bestk],ptr->siglens[bestk]); + refptr->siglens[bestk] = ptr->siglens[bestk]; + if ( src_or_dest != 0 ) + bp->destsigsmasks[bestk] |= (1LL << i); + else bp->srcsigsmasks[bestk] |= (1LL << i); + } + } + } + } + } + else if ( channel == DPOW_UTXOCHANNEL ) { src_or_dest = 1; coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin; @@ -273,7 +313,7 @@ int32_t dpow_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo } if ( ep->masks[src_or_dest][bp->bestk] == 0 ) dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest); - if ( bp->bestk >= 0 )//&& (rand() % 100) == 0 ) + if ( bp->bestk >= 0 && (rand() % 10) == 0 ) dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL); } else sendutxo = 1; if ( sendutxo != 0 ) @@ -281,11 +321,11 @@ int32_t dpow_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo memset(&U,0,sizeof(U)); dpow_entry2utxo(&U,bp,&bp->notaries[myind]); if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 ) - dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len,bp->utxocrcs); + dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len); } if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 ) dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest); - if ( bp->bestk >= 0 ) + if ( bp->bestk >= 0 && (rand() % 10) == 0 ) dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL); } else if ( bp->state != 0xffffffff ) @@ -293,16 +333,21 @@ int32_t dpow_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo src_or_dest = 0; if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 ) dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,src_or_dest); - if ( bp->bestk >= 0 ) + if ( bp->bestk >= 0 && (rand() % 10) == 0 ) dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGCHANNEL); } - if ( (rand() % 10) == 0 || bp->isratify != 0 ) + if ( (rand() % 10) == 0 ) { + if ( bp->isratify != 0 ) + { uint64_t sigsmask,srcmask; if ( bp->bestk < 0 ) sigsmask = srcmask = 0; else sigsmask = bp->destsigsmasks[bp->bestk], srcmask = bp->srcsigsmasks[bp->bestk]; printf("[%d] %s isratify.%d ht.%d FSM.%08x masks.%llx best.(%d %llx) sigsmask.%llx %llx src.%llx\n",myind,src_or_dest != 0 ? bp->destcoin->symbol : bp->srccoin->symbol,bp->isratify,bp->height,bp->state,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)sigsmask,(long long)(sigsmask & bp->bestmask),(long long)srcmask); + } + if ( (rand() % 10) == 0 ) + dpow_sendcoinentrys(myinfo,dp,bp,bp->state < 1000); } if ( bp->state < 1000 && bp->bestk >= 0 && (bp->destsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask ) { @@ -558,7 +603,10 @@ void dpow_statemachinestart(void *ptr) checkpoint.blockhash.height = dp->checkpoint.blockhash.height; dp->blocks[checkpoint.blockhash.height] = bp; for (i=0; i<64; i++) + { bp->notaries[i].recvmask = 0; + bp->notaries[i].bestk = -1; + } memset(bp->destsigsmasks,0,sizeof(bp->destsigsmasks)); memset(bp->notaries[myind].masks,0,sizeof(bp->notaries[myind].masks)); } diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 8024210bb..5f5168ea5 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -75,7 +75,7 @@ int32_t dpow_crc32find(struct supernet_info *myinfo,struct dpow_info *dp,uint32_ return(firstz); } -void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2]) +void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen) { struct dpow_nanomsghdr *np; int32_t size,sentbytes = 0; uint32_t crc32; crc32 = calc_crc32(0,data,datalen); @@ -146,7 +146,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) { } -uint32_t dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2]) +uint32_t dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen) { return(0); } @@ -155,6 +155,45 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) { } #endif +int32_t dpow_rwcoinentry(int32_t rwflag,uint8_t *serialized,struct dpow_coinentry *ptr,int8_t *bestkp) +{ + int8_t bestk; int32_t siglen,len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->prev_hash),ptr->prev_hash.bytes); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prev_vout),(uint32_t *)&ptr->prev_vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(*bestkp),(uint32_t *)bestkp); + if ( (bestk= *bestkp) >= 0 ) + { + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->siglens[bestk]),(uint32_t *)&ptr->siglens[bestk]); + if ( (siglen= ptr->siglens[bestk]) > 0 ) + { + if ( rwflag != 0 ) + memcpy(&serialized[len],ptr->sigs[bestk],siglen); + else memcpy(ptr->sigs[bestk],&serialized[len],siglen); + len += siglen; + } + } + return(len); +} + +int32_t dpow_rwcoinentrys(int32_t rwflag,uint8_t *serialized,int32_t src_or_dest,struct dpow_entry notaries[DPOW_MAXRELAYS],uint8_t numnotaries,int8_t bestk) +{ + int32_t i,len = 0; + for (i=0; ibestk; + data[len++] = bp->numnotaries; + len += iguana_rwbignum(1,&data[len],sizeof(bp->hashmsg),bp->hashmsg.bytes); + len += dpow_rwcoinentrys(1,&data[len],src_or_dest,bp->notaries,bp->numnotaries,bp->bestk); + dpow_send(myinfo,dp,bp,zero,bp->hashmsg,src_or_dest != 0 ? DPOW_BTCENTRIESCHANNEL : DPOW_ENTRIESCHANNEL,bp->height,data,len); + return(len); +} int32_t dpow_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) { @@ -322,7 +361,7 @@ void dpow_sigsend(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_ } memcpy(dsig.senderpub,dp->minerkey33,33); len = dpow_rwsigentry(1,data,&dsig); - dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,sigchannel,bp->height,data,len,bp->sigcrcs); + dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,sigchannel,bp->height,data,len); } uint32_t komodo_assetmagic(char *symbol,uint64_t supply) diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index f94ed3ba7..214f5e7c0 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -315,7 +315,7 @@ int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struc decode_hex(txdata+32,len,rawtx); for (j=0; jhashmsg,(bits256_nonz(bp->btctxid) == 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32,bp->txidcrcs);*/ + dpow_send(myinfo,bp,zero,bp->hashmsg,(bits256_nonz(bp->btctxid) == 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32);*/ dpow_rawtxsign(myinfo,dp,coin,bp,rawtx,vins,bestk,bestmask,myind,src_or_dest); } else printf("signedtxgen zero txid or null rawtx\n"); free_json(vins); @@ -354,7 +354,7 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo decode_hex(txdata+32,len,bp->signedtx); for (j=0; jhashmsg,(src_or_dest != 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32,bp->txidcrcs); + dpow_send(myinfo,dp,bp,txid,bp->hashmsg,(src_or_dest != 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32); printf("complete statemachine.%s ht.%d\n",coin->symbol,bp->height); 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,signedtxid));