From b9e5251d3d982b6f0d35c86edeb6649eb1c0f1c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Nov 2016 18:53:05 -0300 Subject: [PATCH] test --- iguana/dPoW.h | 6 +++--- iguana/dpow/dpow_network.c | 26 +++++++++++++++++++++++--- iguana/dpow/dpow_tx.c | 9 ++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index c2048afd1..50c6393de 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -63,7 +63,7 @@ struct dpow_entry { bits256 commit,beacon,ratifysrcutxo,ratifydestutxo; uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask,bestmask,ratifyrecvmask,ratifybestmask; - int32_t height; + int32_t height; uint32_t pendingcrcs[2]; uint16_t ratifysrcvout,ratifydestvout; int8_t bestk,ratifybestk; uint8_t pubkey[33],ratifysigs[2][76],ratifysiglens[2]; @@ -100,12 +100,12 @@ struct dpow_block uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2]; struct dpow_entry notaries[DPOW_MAXRELAYS]; uint32_t state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch; - int32_t height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS]; + int32_t rawratifiedlens[2],height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS]; int8_t bestk,ratifybestk,pendingbestk,pendingratifybestk; cJSON *ratified; uint8_t myind,ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][76],ratifysiglens[2]; char handles[DPOW_MAXRELAYS][32]; - char signedtx[32768];//,rawtx[32768]; + char signedtx[32768]; uint8_t ratifyrawtx[2][32768]; uint32_t pendingcrcs[2]; }; struct pax_transaction diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 6c657e3f4..45e98a5ab 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -28,7 +28,7 @@ struct dpow_nanomsghdr { bits256 srchash,desthash; struct dpow_nanoutxo ratify,notarize; - uint32_t channel,height,size,datalen,crc32,myipbits,numipbits,ipbits[64]; + uint32_t channel,height,size,datalen,crc32,myipbits,numipbits,ipbits[64],pendingcrcs[2]; char symbol[16]; uint8_t senderind,version0,version1,packet[]; } PACKED; @@ -184,7 +184,7 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][76]) { - int8_t bestks[64]; int32_t counts[64],i,j,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64]; + int8_t bestks[64]; int32_t counts[64],i,j,numcrcs,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask; uint32_t crcval; //char str[65],str2[65]; //printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo)); if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 ) @@ -192,6 +192,8 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct memset(masks,0,sizeof(masks)); memset(bestks,0xff,sizeof(bestks)); memset(counts,0,sizeof(counts)); + for (i=0; i<2; i++) + bp->notaries[senderind].pendingcrcs[i] = np->pendingcrcs[i]; bp->notaries[senderind].ratifysrcutxo = srcutxo; bp->notaries[senderind].ratifysrcvout = srcvout; bp->notaries[senderind].ratifydestutxo = destutxo; @@ -277,15 +279,31 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct bp->notaries[bp->myind].ratifyrecvmask = bp->ratifyrecvmask; if ( bp->ratifybestk >= 0 ) { - for (i=0; inumnotaries; i++) + for (matchesmask=i=0; inumnotaries; i++) { if ( bp->ratifybestk >= 0 && bp->notaries[i].ratifybestk == bp->ratifybestk && bp->notaries[i].ratifybestmask == bp->ratifybestmask ) { matches++; if ( ((1LL << i) & bp->ratifybestmask) != 0 ) + { + matchesmask |= (1LL << i); bestmatches++; + } + } + } + crcval = 0; + numcrcs = 0; + for (i=0; inumnotaries; i++) + { + if ( ((1LL << i) & matchesmask) != 0 ) + { + if ( numcrcs == 0 ) + numcrcs++, crcval = bp->notaries[i].pendingcrcs[bp->state < 1000]; + else if ( numcrcs > 0 && crcval == bp->notaries[i].pendingcrcs[bp->state < 1000] ) + numcrcs++; } } + printf("crcval.%x numcrcs.%d bestmatches.%d matchesmask.%llx\n",crcval,numcrcs,bestmatches,(long long)matchesmask); if ( bestmatches >= bp->minsigs ) { if ( bp->pendingratifybestk != bp->ratifybestk || bp->pendingratifybestmask != bp->ratifybestmask ) @@ -435,6 +453,8 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo np->size = size; np->datalen = datalen; np->crc32 = crc32; + for (i=0; i<2; i++) + np->pendingcrcs[i] = bp->pendingcrcs[i]; for (i=0; i<32; i++) np->srchash.bytes[i] = dp->minerkey33[i+1]; //np->srchash = srchash; diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 822306557..d663ff39c 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -415,7 +415,7 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t myind,uint32_t deprec,int32_t src_or_dest,int32_t useratified) { - int32_t j,m,numsigs,retval=-1; char rawtx[32768],*jsonstr,*rawtx2,*signedtx,*sigstr; cJSON *item,*sobj,*vins,*vin,*txobj2,*signobj; bits256 txid,srchash,zero; struct dpow_entry *ep; + int32_t j,m,numsigs,len,retval=-1; char rawtx[32768],*jsonstr,*rawtx2,*signedtx,*sigstr; cJSON *item,*sobj,*vins,*vin,*txobj2,*signobj; bits256 txid,srchash,zero; struct dpow_entry *ep; ep = &bp->notaries[myind]; memset(&zero,0,sizeof(zero)); if ( bestk < 0 ) @@ -430,6 +430,13 @@ int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struc { if ( useratified != 0 ) { + len = (int32_t)strlen(rawtx) >> 1; + if ( len <= sizeof(bp->ratifyrawtx[0]) ) + { + decode_hex(bp->ratifyrawtx[src_or_dest],len,rawtx), bp->rawratifiedlens[src_or_dest] = len; + bp->pendingcrcs[src_or_dest] = calc_crc32(0,bp->ratifyrawtx[src_or_dest],bp->rawratifiedlens[src_or_dest]); + bp->notaries[bp->myind].pendingcrcs[src_or_dest] = bp->pendingcrcs[src_or_dest]; + } if ( (jsonstr= dpow_signrawtransaction(myinfo,coin,rawtx,vins)) != 0 ) { if ( (signobj= cJSON_Parse(jsonstr)) != 0 )