Browse Source

test

etomic
jl777 8 years ago
parent
commit
7d0aadc84d
  1. 58
      iguana/dpow/dpow_network.c

58
iguana/dpow/dpow_network.c

@ -412,7 +412,8 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
}
}
//printf("RECV from %d best.(%d %llx) sigs.(%d %d) %llx %llx\n",senderind,bestk,(long long)bestmask,siglens[0],siglens[1],(long long)bp->ratifysigmasks[0],(long long)bp->ratifysigmasks[1]);
bp->ratifyrecvmask = 0;//|= (1LL << senderind) | (1LL << bp->myind);
// generalize for both paths
bp->ratifyrecvmask = 0;
bp->ratifybestmask = 0;
bp->ratifybestk = -1;
for (numdiff=i=0; i<bp->numnotaries; i++)
@ -554,6 +555,52 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct
}
}
void dpow_bestconsensus(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; uint32_t crcval=0; char srcaddr[64],destaddr[64];
memset(masks,0,sizeof(masks));
memset(bestks,0xff,sizeof(bestks));
memset(counts,0,sizeof(counts));
bp->recvmask = 0;
bp->bestmask = 0;
bp->bestk = -1;
for (numdiff=i=0; i<bp->numnotaries; i++)
{
if ( bits256_nonz(bp->notaries[i].src.prev_hash) != 0 && bits256_nonz(bp->notaries[i].dest.prev_hash) != 0 )
bp->recvmask |= (1LL << i);
if ( bp->notaries[i].bestk < 0 || bp->notaries[i].bestmask == 0 )
continue;
if ( bp->require0 != 0 && (bp->notaries[i].bestmask & 1) == 0 )
continue;
for (j=0; j<numdiff; j++)
if ( bp->notaries[i].bestk == bestks[j] && bp->notaries[i].bestmask == masks[j] )
{
counts[j]++;
break;
}
if ( j == numdiff && bp->notaries[i].bestk >= 0 && bp->notaries[i].bestmask != 0 )
{
masks[numdiff] = bp->notaries[i].bestmask;
bestks[numdiff] = bp->notaries[i].bestk;
counts[numdiff]++;
//printf("j.%d numdiff.%d (%d %llx).%d\n",j,numdiff,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,counts[numdiff]);
numdiff++;
}
}
besti = -1, best = 0;
for (i=0; i<numdiff; i++)
{
//printf("(%d %llx).%d ",bestks[i],(long long)masks[i],counts[i]);
if ( counts[i] > best )
{
best = counts[i];
besti = i;
}
}
if ( besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (bp->recvmask & masks[besti]) == masks[besti] )
bp->bestmask = masks[besti], bp->bestk = bestks[besti];
}
void dpow_notarize_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][DPOW_MAXSIGLEN],uint32_t paxwdcrc)
{
int32_t i,bestmatches = 0,matches = 0,paxmatches = 0;
@ -586,8 +633,9 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
else bp->destsigsmasks[bestk] &= ~(1LL << senderind);
}
}
bp->recvmask |= (1LL << senderind) | (1LL << bp->myind);
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
dpow_bestconsensus(bp);
//bp->recvmask |= (1LL << senderind) | (1LL << bp->myind);
//bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc;
bp->notaries[bp->myind].bestk = bp->bestk;
bp->notaries[bp->myind].bestmask = bp->bestmask;
@ -596,11 +644,11 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
{
for (i=0; i<bp->numnotaries; i++)
{
if ( bp->paxwdcrc == bp->notaries[i].paxwdcrc )
paxmatches++;
if ( bp->bestk >= 0 && bp->notaries[i].bestk == bp->bestk && bp->notaries[i].bestmask == bp->bestmask )
{
matches++;
if ( bp->paxwdcrc == bp->notaries[i].paxwdcrc )
paxmatches++;
if ( ((1LL << i) & bp->bestmask) != 0 )
bestmatches++;
} else printf("%d.(%x %llx) ",i,bp->notaries[i].paxwdcrc,(long long)bp->notaries[i].bestmask);

Loading…
Cancel
Save