Browse Source

Merge pull request #818 from jl777/jl777

Bestmatches precedence over raw matches
pass-iguana-arg
jl777 7 years ago
committed by GitHub
parent
commit
3a5d672c2e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      iguana/dPoW.h
  2. 23
      iguana/dpow/dpow_network.c

2
iguana/dPoW.h

@ -117,7 +117,7 @@ struct dpow_block
struct dpow_entry notaries[DPOW_MAXRELAYS]; struct dpow_entry notaries[DPOW_MAXRELAYS];
uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc,lastnanosend; 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]; 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; cJSON *ratified;
uint8_t ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2]; uint8_t ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2];
char handles[DPOW_MAXRELAYS][32]; char handles[DPOW_MAXRELAYS][32];

23
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) 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(masks,0,sizeof(masks));
memset(bestks,0xff,sizeof(bestks)); memset(bestks,0xff,sizeof(bestks));
memset(counts,0,sizeof(counts)); memset(counts,0,sizeof(counts));
@ -1492,23 +1492,32 @@ void dpow_bestconsensus(struct dpow_info *dp,struct dpow_block *bp)
numdiff++; numdiff++;
} }
} }
besti = -1, best = 0; besti = -1, matches = 0;
for (i=0; i<numdiff; i++) for (i=0; i<numdiff; i++)
{ {
//printf("(%d %llx).%d ",bestks[i],(long long)masks[i],counts[i]); //printf("(%d %llx).%d ",bestks[i],(long long)masks[i],counts[i]);
if ( counts[i] > best && bitweight(masks[i]) >= bp->minsigs ) if ( counts[i] > matches && bitweight(masks[i]) >= bp->minsigs )
{ {
best = counts[i]; matches = counts[i];
besti = i; besti = i;
} }
} }
if ( best > bp->bestmatches && besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (recvmask & masks[besti]) == masks[besti] ) for (i=0; i<bp->numnotaries; 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].bestmask = bp->bestmask = masks[besti];
bp->notaries[bp->myind].bestk = bp->bestk = bestks[besti]; bp->notaries[bp->myind].bestk = bp->bestk = bestks[besti];
if ( bp->myind == 0 ) 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; bp->recvmask |= recvmask;
if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch ) if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch )

Loading…
Cancel
Save