From e80685bc2d98c539aa4dff5fd1f41ea089995736 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:27:03 -1100 Subject: [PATCH] Retry loop --- src/komodo_nSPV_superlite.h | 41 ++++++++++++++++++++++++++----------- src/wallet/rpcdump.cpp | 2 +- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 585784eec..3caf8473e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -97,24 +97,41 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { - int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); - if ( pnode == 0 ) + int32_t iter,num; CNode *firstpnode = 0; uint32_t timestamp = (uint32_t)time(NULL); + while ( pnode == 0 ) { LOCK(cs_vNodes); - BOOST_FOREACH(CNode *ptr,vNodes) + num = 0; + for (iter=0; iter<2; iter++) { - if ( ptr->prevtimes[ind] > timestamp ) - ptr->prevtimes[ind] = 0; - if ( ptr->hSocket == INVALID_SOCKET ) - continue; - if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) + BOOST_FOREACH(CNode *ptr,vNodes) { - flag = 1; - pnode = ptr; + if ( ptr->prevtimes[ind] > timestamp ) + ptr->prevtimes[ind] = 0; + if ( ptr->hSocket == INVALID_SOCKET ) + continue; + if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) + { + if ( firstpnode == 0 ) + firstpnode = ptr; + if ( iter != 0 ) + { + if ( num == 1 || (rand() % num) == 0 ) + { + pnode = ptr; + break; + } + } else num++; + } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } + if ( iter == 0 && num == 0 ) break; - } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + if ( pnode == 0 ) + pnode = firstpnode; } - } else flag = 1; + if ( pnode != 0 && time(NULL) > timestamp+2 ) + break; + } if ( pnode != 0 ) { std::vector request; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 071e3d8a7..b197b73b0 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1071,7 +1071,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; - fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str())); + //fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str())); if ( satoshis < 1000 ) throw runtime_error("amount too small\n"); return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis));