From 7f7797c2869e0bc652934078cf183fa384718535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 11:14:19 +0300 Subject: [PATCH 1/6] Increase nn_poll timeout --- iguana/dpow/dpow_network.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index dfa7a592b..557323d37 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -81,7 +81,19 @@ int32_t signed_nn_send(struct supernet_info *myinfo,void *ctx,bits256 privkey,in //printf(" signed pubkey\n"); if ( memcmp(pubkey33,signpubkey33,33) == 0 ) { - sentbytes = nn_send(sock,sigpacket,size + sizeof(*sigpacket),0); + sentbytes = 0; + for (j=0; j<100; j++) + { + struct nn_pollfd pfd; + pfd.fd = sock; + pfd.events = NN_POLLOUT; + if ( nn_poll(&pfd,1,10) > 0 ) + { + sentbytes = nn_send(sock,sigpacket,size + sizeof(*sigpacket),0); + break; + } + usleep(1000); + } //for (i=0; idpowsock; pfd.events = NN_POLLOUT; - if ( nn_poll(&pfd,1,1) > 0 ) + if ( nn_poll(&pfd,1,10) > 0 ) { sentbytes = signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dpowsock,np,size); break; From 726f812d4481a8a67226ed1a78b1b89424b72347 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 12:02:49 +0300 Subject: [PATCH 2/6] +print --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 557323d37..180bb055a 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1948,7 +1948,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - if ( 0 && bp->myind <= 2 ) + if ( bp->myind == 0 ) printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); From 0d4c023529ebf943b29bbbf17f8bb313a2fcb8ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 12:03:23 +0300 Subject: [PATCH 3/6] +print --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 180bb055a..36fc2099f 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1949,7 +1949,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); if ( bp->myind == 0 ) - printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + printf("%s.%d lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",dp->symbol,bp->height,(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } From ebe04958b3c2f02708ff08f205f7726dc79acfbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 12:54:11 +0300 Subject: [PATCH 4/6] Test --- iguana/dpow/dpow_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 36fc2099f..2db7bc83d 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -2030,8 +2030,8 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo printf("maxiters expired for signed_nn_send dpowsock.%d\n",myinfo->dpowsock); //portable_mutex_unlock(&myinfo->dpowmutex); free(np); - if ( 0 && bp->myind <= 2 ) - printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); + if ( bp->myind == 0 ) + printf("%d NANOSEND.%d %s.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,dp->symbol,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t maxipbits,int32_t fromid,uint32_t senderipbits) From 39e1c6864ddebcc50b2f1de5d5b57083629f32bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 13:36:40 +0300 Subject: [PATCH 5/6] Limit nanosend --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_network.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 6412771e4..f9d474787 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -112,7 +112,7 @@ struct dpow_block uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS]; uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2]; struct dpow_entry notaries[DPOW_MAXRELAYS]; - uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc; + 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; cJSON *ratified; diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 2db7bc83d..2da514cf0 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1813,7 +1813,7 @@ cJSON *dpow_recvmasks(struct supernet_info *myinfo,struct dpow_info *dp,struct d 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) { - bits256 srchash; int32_t i,flag,bestmatches = 0,matches = 0,paxmatches = 0,paxbestmatches = 0; + bits256 srchash; uint32_t now; int32_t i,flag,bestmatches = 0,matches = 0,paxmatches = 0,paxbestmatches = 0; if ( bp->myind < 0 ) return; if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 ) @@ -1869,6 +1869,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru if ( bp->bestk >= 0 ) { flag = -1; + now = (uint32_t)time(NULL); for (i=0; inumnotaries; i++) { if ( bp->paxwdcrc == bp->notaries[i].paxwdcrc ) @@ -1885,17 +1886,21 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru } //else printf("?%x ",bp->notaries[i].paxwdcrc); } } - else if ( i == senderind && ((1LL << bp->myind) & bp->bestmask) != 0 && ((1LL << i) & bp->bestmask) != 0 && ((1LL << bp->myind) & bp->notaries[i].recvmask) == 0 ) - flag = senderind; + else if ( i != bp->myind && i == senderind && ((1LL << bp->myind) & bp->bestmask) != 0 && ((1LL << i) & bp->bestmask) != 0 && ((1LL << bp->myind) & bp->notaries[i].recvmask) == 0 ) + { + if ( now > bp->lastnanosend ) + flag = senderind; + } if ( 0 && bp->myind <= 1 && bp->notaries[i].paxwdcrc != 0 ) printf("%d.(%x %d %llx r%llx) ",i,bp->notaries[i].paxwdcrc,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,(long long)bp->notaries[i].recvmask); } - if ( flag >= 0 ) + if ( flag >= 0 || now > bp->lastnanosend+13 ) { //printf("flag.%d -> send\n",flag); for (i=0; iminerkey33[i+1]; dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,0,bp->height,(void *)"ping",0); + bp->lastnanosend = now; } if ( 0 && bp->myind <= 1 ) printf("recv.%llx best.(%d %llx) m.%d p.%d:%d b.%d\n",(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,matches,paxmatches,paxbestmatches,bestmatches); @@ -1949,7 +1954,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); if ( bp->myind == 0 ) - printf("%s.%d lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",dp->symbol,bp->height,(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + printf("%s.%d lag.[%d] RECV.%d %llx (%d %llx) %llx/%llx\n",dp->symbol,bp->height,(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } From a2847aabd64c280f452f86e2953b4b4fce970d43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 May 2018 13:43:29 +0300 Subject: [PATCH 6/6] Test --- iguana/dpow/dpow_tx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index f59e1268d..e1af6520e 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -101,9 +101,8 @@ uint64_t dpow_ratifybest(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp) uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp) { - int32_t m,j,k; uint64_t bestmask,mask = 0;//bp->require0; + int32_t m,j,k; int8_t bestk = -1; uint64_t bestmask,mask = 0;//bp->require0; bestmask = 0; - *lastkp = -1; for (m=j=0; jnumnotaries; j++) { //k = (j + ((uint32_t)time(NULL) / 180)) % bp->numnotaries; @@ -115,12 +114,14 @@ uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp) mask |= (1LL << k); if ( ++m == bp->minsigs )//-bp->require0 ) { - *lastkp = k; + bestk = k; bestmask = mask;// | bp->require0; //printf("m.%d == minsigs.%d (%d %llx)\n",m,bp->minsigs,k,(long long)bestmask); } } } + if ( bestk >= 0 ) + *lastkp = bestk; return(bestmask); }