From 9badcaf1229d1dd9eceaeaaf7af8703bc89b07f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Oct 2016 09:17:30 -0300 Subject: [PATCH] test --- iguana/dPoW.h | 6 ++++-- iguana/iguana_notary.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 0b51f3bfa..56b62871e 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -31,8 +31,9 @@ struct dpow_entry { bits256 prev_hash,commit,beacon; - uint64_t masks[DPOW_MAXRELAYS]; + uint64_t masks[DPOW_MAXRELAYS],bestmask; int32_t prev_vout,height; + int8_t bestk; uint8_t pubkey[33],siglens[DPOW_MAXRELAYS],sigs[DPOW_MAXRELAYS][76]; }; @@ -58,10 +59,11 @@ struct dpow_block { bits256 hashmsg,btctxid,signedtxid,beacon,commit; struct iguana_info *coin; char *opret_symbol; - uint64_t recvmask,recvsigmask; + uint64_t recvmask,recvsigmask,bestmask; struct dpow_entry notaries[DPOW_MAXRELAYS]; uint32_t state,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2]; int32_t height,numnotaries,completed; + int8_t bestk; char signedtx[32768]; }; diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 2970a9c25..4533037d2 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -169,6 +169,32 @@ uint64_t dpow_lastk_mask(struct dpow_block *bp,int8_t *lastkp) return(mask); } +int32_t dpow_bestk(struct dpow_block *bp,uint64_t *maskp) +{ + int32_t i,j,m; struct dpow_entry *ep; + *maskp = 0; + for (i=0; inumnotaries; i++) + { + ep = &bp->notaries[i]; + if ( ep->bestmask != 0 && ep->bestk >= 0 ) + { + for (m=1,j=i+1; jnumnotaries; j++) + { + if ( bp->notaries[j].bestmask == ep->bestmask && bp->notaries[j].bestk == ep->bestk ) + { + if ( ++m == DPOW_M(bp) ) + { + *maskp = ep->bestmask; + printf("bestk.%d mask.%llx\n",ep->bestk,(long long)ep->bestmask); + return(ep->bestk); + } + } + } + } + } + return(-1); +} + int32_t dpow_numsigs(struct dpow_block *bp,int32_t lastk,uint64_t mask) { int32_t j,m,i; @@ -769,13 +795,15 @@ void dpow_datahandler(struct supernet_info *myinfo,struct dpow_block *bp,uint32_ ep->prev_vout = vout; ep->commit = commit; ep->height = height; + ep->bestk = lastk; + ep->bestmask = mask; bp->recvmask |= (1LL << senderind); - if ( bitweight(bp->recvmask) >= DPOW_M(bp) ) + if ( (bp->bestk= dpow_bestk(bp,&bp->bestmask)) >= 0 ) { if ( ep->masks[lastk] == 0 ) { - if ( dpow_signedtxgen(myinfo,bp->coin,bp,bp->recvmask,lastk,myind,bp->opret_symbol) == 0 ) - printf("created sig for lastk.%d %llx\n",lastk,(long long)bp->recvmask); + if ( dpow_signedtxgen(myinfo,bp->coin,bp,bp->bestmask,bp->bestk,myind,bp->opret_symbol) == 0 ) + printf("created sig for lastk.%d %llx\n",bp->bestk,(long long)bp->bestmask); } } flag = 1; @@ -947,7 +975,7 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info dpow_send(myinfo,bp,srchash,bp->hashmsg,channel,bp->height,data,len,bp->utxocrcs); dpow_channelget(myinfo,bp,channel); //printf("STATE2: RECVMASK.%llx\n",(long long)bp->recvmask); - if ( bitweight(bp->recvmask) >= DPOW_M(bp) ) + if ( bitweight(bp->bestmask) >= DPOW_M(bp) ) bp->state = 3; break; case 3: // create rawtx, sign, send rawtx + sig to all other nodes @@ -955,7 +983,7 @@ uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info //printf("STATE3: %s BTC.%d RECVMASK.%llx mask.%llx\n",coin->symbol,bits256_nonz(bp->btctxid)==0,(long long)bp->recvmask,(long long)mask); if ( bitweight(mask) >= DPOW_M(bp) ) { - if ( dpow_signedtxgen(myinfo,coin,bp,mask,lastk,myind,opret_symbol) == 0 ) + if ( dpow_signedtxgen(myinfo,coin,bp,bp->bestmask,bp->bestk,myind,opret_symbol) == 0 ) { bp->state = 4; }