|
@ -335,6 +335,65 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) |
|
|
dpow_addnotary(myinfo,0,ipaddr); |
|
|
dpow_addnotary(myinfo,0,ipaddr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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,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)); |
|
|
|
|
|
recvmask = 0; |
|
|
|
|
|
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 ) |
|
|
|
|
|
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 && (recvmask & masks[besti]) == masks[besti] ) |
|
|
|
|
|
{ |
|
|
|
|
|
bp->bestmask = masks[besti]; |
|
|
|
|
|
bp->bestk = bestks[besti]; |
|
|
|
|
|
printf("set best to (%d %llx) recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)recvmask); |
|
|
|
|
|
} |
|
|
|
|
|
bp->recvmask = recvmask; |
|
|
|
|
|
if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch )
|
|
|
|
|
|
{ |
|
|
|
|
|
bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk); |
|
|
|
|
|
if ( 0 && (time(NULL) / 180) != bp->lastepoch ) |
|
|
|
|
|
{ |
|
|
|
|
|
bp->lastepoch = (uint32_t)(time(NULL) / 180); |
|
|
|
|
|
printf("epoch %u\n",bp->lastepoch % bp->numnotaries); |
|
|
|
|
|
sleep(1 + (rand() % 3)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify) |
|
|
void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify) |
|
|
{ |
|
|
{ |
|
|
int32_t i; |
|
|
int32_t i; |
|
@ -561,65 +620,6 @@ 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,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)); |
|
|
|
|
|
recvmask = 0; |
|
|
|
|
|
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 ) |
|
|
|
|
|
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 && (recvmask & masks[besti]) == masks[besti] ) |
|
|
|
|
|
{ |
|
|
|
|
|
bp->bestmask = masks[besti]; |
|
|
|
|
|
bp->bestk = bestks[besti]; |
|
|
|
|
|
printf("set best to (%d %llx) recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)recvmask); |
|
|
|
|
|
} |
|
|
|
|
|
bp->recvmask = recvmask; |
|
|
|
|
|
if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch )
|
|
|
|
|
|
{ |
|
|
|
|
|
bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk); |
|
|
|
|
|
if ( 0 && (time(NULL) / 180) != bp->lastepoch ) |
|
|
|
|
|
{ |
|
|
|
|
|
bp->lastepoch = (uint32_t)(time(NULL) / 180); |
|
|
|
|
|
printf("epoch %u\n",bp->lastepoch % bp->numnotaries); |
|
|
|
|
|
sleep(1 + (rand() % 3)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
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,paxbestmatches = 0; |
|
|
int32_t i,bestmatches = 0,matches = 0,paxmatches = 0,paxbestmatches = 0; |
|
|