diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 52a6b43e2..d649c8d0c 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -117,7 +117,7 @@ struct dpow_block struct dpow_entry notaries[DPOW_MAXRELAYS]; uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc,lastnanosend; int32_t rawratifiedlens[2],height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS]; - int8_t myind,bestk,ratifybestk,pendingbestk,pendingratifybestk,bestmatches; + int8_t myind,bestk,ratifybestk,pendingbestk,pendingratifybestk,matches,bestmatches; cJSON *ratified; uint8_t ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2]; char handles[DPOW_MAXRELAYS][32]; diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 2907859ac..704cf56aa 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1464,7 +1464,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) void dpow_bestconsensus(struct dpow_info *dp,struct dpow_block *bp) { - int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask,recvmask; uint32_t crcval=0; char srcaddr[64],destaddr[64]; + int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask,recvmask; uint32_t crcval=0; char srcaddr[64],destaddr[64]; memset(masks,0,sizeof(masks)); memset(bestks,0xff,sizeof(bestks)); memset(counts,0,sizeof(counts)); @@ -1492,23 +1492,32 @@ void dpow_bestconsensus(struct dpow_info *dp,struct dpow_block *bp) numdiff++; } } - besti = -1, best = 0; + besti = -1, matches = 0; for (i=0; i best && bitweight(masks[i]) >= bp->minsigs ) + if ( counts[i] > matches && bitweight(masks[i]) >= bp->minsigs ) { - best = counts[i]; + matches = counts[i]; besti = i; } } - if ( best > bp->bestmatches && besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (recvmask & masks[besti]) == masks[besti] ) + for (i=0; inumnotaries; i++) + { + if ( ((1LL << i) & masks[besti]) != 0 ) + { + if ( bp->notaries[i].bestmask == masks[i] ) + bestmatches++; + } + } + if ( (bestmatches > bp->bestmatches || (bestmatches == bp->bestmatches && matches > bp->matches)) && besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (recvmask & masks[besti]) == masks[besti] ) { - bp->bestmatches = best; + bp->matches = matches; + bp->bestmatches = bestmatches; bp->notaries[bp->myind].bestmask = bp->bestmask = masks[besti]; bp->notaries[bp->myind].bestk = bp->bestk = bestks[besti]; if ( bp->myind == 0 ) - printf("%s.%d set best.%d to (%d %llx) recv.%llx\n",dp->symbol,bp->height,best,bp->bestk,(long long)bp->bestmask,(long long)recvmask); + printf("%s.%d set matches.%d best.%d to (%d %llx) recv.%llx\n",dp->symbol,bp->height,bp->matches,bp->bestmatches,bp->bestk,(long long)bp->bestmask,(long long)recvmask); } bp->recvmask |= recvmask; if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch )