From 7fe4c5ca679de3eb2df660a81921df9aed45d577 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Oct 2017 23:53:44 +0300 Subject: [PATCH 01/85] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 7b04dc444..45307bedf 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -126,7 +126,6 @@ int32_t LP_peerindsock(int32_t *peerindp) struct LP_peerinfo *peer,*tmp; int32_t peerind = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { - peerind++; if ( peer->errors < LP_MAXPEER_ERRORS && peer->pushsock >= 0 ) { if ( peerind < *peerindp ) @@ -135,6 +134,7 @@ int32_t LP_peerindsock(int32_t *peerindp) //printf("peerind.%d -> sock %d\n",peerind,peer->pushsock); return(peer->pushsock); } + peerind++; } return(-1); } From a969ae6c9d66e7cf59917005a37efc54ece8300c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 11:53:19 +0300 Subject: [PATCH 02/85] Gui string --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 14 ++++++++++---- iguana/exchanges/LP_signatures.c | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index ff4c59957..141fa9023 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -252,7 +252,7 @@ struct LP_quoteinfo bits256 srchash,desthash,txid,txid2,desttxid,feetxid,privkey; uint64_t satoshis,txfee,destsatoshis,desttxfee; uint32_t timestamp,quotetime; int32_t vout,vout2,destvout,feevout,pair; - char srccoin[16],coinaddr[64],destcoin[16],destaddr[64]; + char srccoin[16],coinaddr[64],destcoin[16],destaddr[64],gui[64]; }; struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 000bcd399..7a9021013 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -299,10 +299,6 @@ int32_t LP_nanomsg_recvs(void *ctx) int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; double milli; if ( (origipaddr= LP_myipaddr) == 0 ) origipaddr = "127.0.0.1"; - milli = OS_milliseconds(); - if ( lastmilli > 0. && milli > lastmilli+3000 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); - lastmilli = milli; //portable_mutex_lock(&LP_nanorecvsmutex); HASH_ITER(hh,LP_peerinfos,peer,tmp) { @@ -317,7 +313,11 @@ int32_t LP_nanomsg_recvs(void *ctx) } } //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); + milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); + if ( lastmilli > 0. && milli > lastmilli+1000 ) + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); + lastmilli = milli; } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -327,7 +327,13 @@ int32_t LP_nanomsg_recvs(void *ctx) nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.); }*/ if ( LP_mypullsock >= 0 ) + { + milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); + if ( lastmilli > 0. && milli > lastmilli+1000 ) + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); + lastmilli = milli; + } //portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index ff428c029..27d47d1f5 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -42,6 +42,7 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch cJSON *LP_quotejson(struct LP_quoteinfo *qp) { double price; cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui); jaddstr(retjson,"base",qp->srccoin); jaddstr(retjson,"rel",qp->destcoin); if ( qp->coinaddr[0] != 0 ) @@ -96,6 +97,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) { + safecopy(qp->gui,LP_gui,sizeof(qp->gui)); safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin)); safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr)); safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin)); From 68ae05ec06549afca7abbe49ec717114a7b7190d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 11:59:43 +0300 Subject: [PATCH 03/85] Test --- iguana/exchanges/LP_prices.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 1b834481f..a7587186d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -186,9 +186,10 @@ struct LP_pubkeyinfo *LP_pubkeyfind(bits256 pubkey) struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) { struct LP_pubkeyinfo *pubp=0; - if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) + portable_mutex_lock(&LP_pubkeymutex); + HASH_FIND(hh,LP_pubkeyinfos,&pubkey,sizeof(pubkey),pubp); + if ( pubp == 0 ) { - portable_mutex_lock(&LP_pubkeymutex); pubp = calloc(1,sizeof(*pubp)); pubp->pubkey = pubkey; if ( bits256_cmp(G.LP_mypub25519,pubkey) == 0 ) @@ -197,10 +198,11 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) memcpy(pubp->pubsecp,G.LP_pubsecp,sizeof(pubp->pubsecp)); } HASH_ADD_KEYPTR(hh,LP_pubkeyinfos,&pubp->pubkey,sizeof(pubp->pubkey),pubp); - portable_mutex_unlock(&LP_pubkeymutex); - if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) + HASH_FIND(hh,LP_pubkeyinfos,&pubkey,sizeof(pubkey),pubp); + if ( pubp == 0 ) printf("pubkeyadd find error after add\n"); } + portable_mutex_unlock(&LP_pubkeymutex); return(pubp); } From 7f2f2edd0712f8667d26092772461b1320ab06e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:14:51 +0300 Subject: [PATCH 04/85] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 6 +++--- iguana/exchanges/LP_utxos.c | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cb5dd3d0f..8348629ac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -798,7 +798,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i break; if ( j != numavoids ) continue; - if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) + if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyfind(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); LP_listunspent_query(base,coinaddr); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index a7587186d..eaebd8212 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -504,7 +504,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) basepp->myprices[relpp->ind] = price; // ask //printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price); //relpp->myprices[basepp->ind] = (1. / price); // bid - if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) + if ( (pubp= LP_pubkeyfind(G.LP_mypub25519)) != 0 ) { pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->matrix[relpp->ind][basepp->ind] = (1. / price); @@ -1063,7 +1063,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) fwrite(&price64,1,sizeof(price64),fp); fflush(fp); } - if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) + if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) { if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { @@ -1074,7 +1074,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); } pubp->timestamp = (uint32_t)time(NULL); - } else printf("error creating pubkey entry\n"); + } else printf("error finding pubkey entry\n"); } //else if ( (rand() % 100) == 0 ) // printf("error finding %s/%s %.8f\n",base,rel,price); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 44cbb2991..ed328c508 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -762,6 +762,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); G.LP_mypriv25519 = checkkey; + LP_pubkeyadd(G.LP_mypub25519); return(privkey); } From d003ecfb2b33cb377b89eddf3b9c008c92c36c34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:16:48 +0300 Subject: [PATCH 05/85] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index eaebd8212..65fa5d04c 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1074,7 +1074,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); } pubp->timestamp = (uint32_t)time(NULL); - } else printf("error finding pubkey entry\n"); + } else printf("error finding pubkey entry %s, ok if rare\n",bits256_str(str,pubkey)); } //else if ( (rand() % 100) == 0 ) // printf("error finding %s/%s %.8f\n",base,rel,price); From 99f4152c5dbfb39ba7373425371911c93a45c466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:20:21 +0300 Subject: [PATCH 06/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7a9021013..974e6e524 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -315,7 +315,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( lastmilli > 0. && milli > lastmilli+1000 ) + if ( lastmilli > 0. && milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } @@ -330,7 +330,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( lastmilli > 0. && milli > lastmilli+1000 ) + if ( lastmilli > 0. && milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } From c17c72d32b4fd7157260ca584b5471998b21380c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:22:22 +0300 Subject: [PATCH 07/85] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 65fa5d04c..4d11b23ef 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1063,7 +1063,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) fwrite(&price64,1,sizeof(price64),fp); fflush(fp); } - if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) + if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) { if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { From c86313c8eef192e6521185894cb89e9a4ea9ade1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:25:34 +0300 Subject: [PATCH 08/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 974e6e524..84a943bb5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -315,7 +315,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( lastmilli > 0. && milli > lastmilli+100 ) + if ( lastmilli > 0. )//&& milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } @@ -330,7 +330,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( lastmilli > 0. && milli > lastmilli+100 ) + if ( lastmilli > 0. )//&& milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } From 3685f8df1105f7e8d2289f2e860f8f8e5394da0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:31:14 +0300 Subject: [PATCH 09/85] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 84a943bb5..1db4c0fba 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -525,7 +525,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( peer->needping != 0 ) { nonz++; - needpings++; if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); peer->needping = 0; @@ -534,7 +533,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( needpings != 0 || (counter % 6000) == 5 ) { nonz++; - //printf("needpings.%d send notify\n",needpings); + printf("needpings.%d send notify\n",needpings); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) From 3cdd2a41844bbfaaa0bc58609592ab89b5bde6a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:37:34 +0300 Subject: [PATCH 10/85] Test --- iguana/exchanges/LP_nativeDEX.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1db4c0fba..123eaddf8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -315,7 +315,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( lastmilli > 0. )//&& milli > lastmilli+100 ) + if ( lastmilli > 0. && milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } @@ -330,7 +330,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( lastmilli > 0. )//&& milli > lastmilli+100 ) + if ( lastmilli > 0. && milli > lastmilli+100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); lastmilli = milli; } @@ -494,7 +494,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 10000) == 0 ) + if ( (rand() % 100000) == 0 ) { peer->errors--; if ( peer->errors < LP_MAXPEER_ERRORS ) @@ -503,7 +503,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+60 || (rand() % 10000) == 0 ) + if ( now > peer->lastpeers+60 )//|| (rand() % 10000) == 0 ) { if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { @@ -517,7 +517,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( peer->diduquery == 0 ) { nonz++; - needpings++; LP_peer_pricesquery(peer); LP_utxos_sync(peer); peer->diduquery = now; @@ -528,9 +527,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); peer->needping = 0; + needpings++; } } - if ( needpings != 0 || (counter % 6000) == 5 ) + if ( needpings != 0 )//|| (counter % 6000) == 5 ) { nonz++; printf("needpings.%d send notify\n",needpings); From ae6d1f1cf520a3614a1ebfeabe0606999c135387 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:40:33 +0300 Subject: [PATCH 11/85] Test --- iguana/exchanges/LP_signatures.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 27d47d1f5..11f66cb9c 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -325,7 +325,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) char *LP_notify_recv(cJSON *argjson) { - char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; + char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; double millis = OS_milliseconds(); pub = jbits256(argjson,"pub"); // LP_checksig if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) @@ -339,7 +339,7 @@ char *LP_notify_recv(cJSON *argjson) //printf("got pubkey.(%s)\n",secpstr); } } - //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); + char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str); } return(clonestr("{\"result\":\"success\",\"notify\":\"received\"}")); } From 2fc24f0d703d9390aab7a802c465870e2c874c57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:49:53 +0300 Subject: [PATCH 12/85] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 8348629ac..cb5dd3d0f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -798,7 +798,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i break; if ( j != numavoids ) continue; - if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyfind(pubkey)) != 0 ) + if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); LP_listunspent_query(base,coinaddr); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 4d11b23ef..98f0e7d40 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -209,7 +209,7 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) int32_t LP_pubkey_istrusted(bits256 pubkey) { struct LP_pubkeyinfo *pubp; - if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) + if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) return(pubp->istrusted != 0); return(0); } @@ -217,7 +217,7 @@ int32_t LP_pubkey_istrusted(bits256 pubkey) char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval) { struct LP_pubkeyinfo *pubp; - if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) + if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) { pubp->istrusted = trustval; return(clonestr("{\"result\":\"success\"}")); @@ -504,7 +504,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) basepp->myprices[relpp->ind] = price; // ask //printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price); //relpp->myprices[basepp->ind] = (1. / price); // bid - if ( (pubp= LP_pubkeyfind(G.LP_mypub25519)) != 0 ) + if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) { pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->matrix[relpp->ind][basepp->ind] = (1. / price); From df197f921c1ee0757559700e6e9fe8c414abff47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:55:10 +0300 Subject: [PATCH 13/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 123eaddf8..729cddfa0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -159,7 +159,6 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, crc32 = calc_crc32(0,&ptr[2],recvlen-2); if ( (crc32 & 0xff) == ptr[0] && ((crc32>>8) & 0xff) == ptr[1] ) encrypted = 1; - portable_mutex_lock(&LP_commandmutex); i = LP_crc32find(&duplicate,-1,crc32); if ( duplicate != 0 ) dup++; @@ -216,14 +215,15 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; + portable_mutex_lock(&LP_commandmutex); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } + portable_mutex_unlock(&LP_commandmutex); free_json(argjson); } } } //else printf("DUPLICATE.(%s)\n",(char *)ptr); - portable_mutex_unlock(&LP_commandmutex); if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 ) free(jsonstr); if ( ptr != 0 ) From 0750aed25cca630475a9c9abab33fe0ac5224985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 12:56:20 +0300 Subject: [PATCH 14/85] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 729cddfa0..365101b7b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -117,6 +117,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *retstr=0; if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) return(0); + double millis = OS_milliseconds(); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) @@ -126,6 +127,8 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); + if ( OS_milliseconds()-millis > 100 ) + printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); } From ff7808783c07d2ca7abcfc4c396da5c495efceb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:00:55 +0300 Subject: [PATCH 15/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 365101b7b..a9bd47d71 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -218,11 +218,13 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; + double millis = OS_milliseconds(); portable_mutex_lock(&LP_commandmutex); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } portable_mutex_unlock(&LP_commandmutex); + printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); free_json(argjson); } } From 573330c0cb403c5c1b3d3b335b5514fd0a159ce0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:06:41 +0300 Subject: [PATCH 16/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a9bd47d71..1c9d62d26 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -159,6 +159,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, { static uint32_t dup,uniq; int32_t i,len,cipherlen,datalen=0,duplicate=0,encrypted=0; char *method,*method2,*tmp,*cipherstr,*retstr=0,*jsonstr=0; cJSON *argjson; uint32_t crc32; + double millis = OS_milliseconds(); crc32 = calc_crc32(0,&ptr[2],recvlen-2); if ( (crc32 & 0xff) == ptr[0] && ((crc32>>8) & 0xff) == ptr[1] ) encrypted = 1; @@ -218,7 +219,6 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - double millis = OS_milliseconds(); portable_mutex_lock(&LP_commandmutex); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { From c4f4a8a3d634a07c5c24fc6a7923b1ce02b17a89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:10:24 +0300 Subject: [PATCH 17/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1c9d62d26..2fcb1e0d1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -535,7 +535,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int needpings++; } } - if ( needpings != 0 )//|| (counter % 6000) == 5 ) + if ( needpings != 0 || (counter % 100000) == 5 ) { nonz++; printf("needpings.%d send notify\n",needpings); From b3057234dba459225472371e92d01e17bdb44e9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:15:15 +0300 Subject: [PATCH 18/85] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2fcb1e0d1..6aba19bdd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -238,7 +238,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth) { - int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < maxdepth && recvlen > 0 ) @@ -250,16 +250,17 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - if ( 0 ) + if ( 1 ) { - cJSON *recvjson; char *mstr,*cstr; + cJSON *recvjson; //char *mstr,*cstr; if ( (recvjson= cJSON_Parse((char *)ptr)) != 0 ) { - if ( (mstr= jstr(recvjson,"method")) != 0 && strcmp(mstr,"uitem") == 0 && + /*if ( (mstr= jstr(recvjson,"method")) != 0 && strcmp(mstr,"uitem") == 0 && (cstr= jstr(recvjson,"coin")) != 0 && strcmp(cstr,"REVS") == 0 ) { printf("%s RECV.(%s)\n",typestr,(char *)ptr); - } + }*/ + safecopy(methodstr,jstr(recvjson,"method"),sizeof(methodstr)); free_json(recvjson); } } @@ -267,6 +268,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int if ( LP_lastcommand != 0 ) free(LP_lastcommand); LP_lastcommand = clonestr((char *)ptr); + double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) @@ -292,6 +294,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } + printf("%.3f LP_process_message %s\n",OS_milliseconds()-millis,methodstr); } } } From 87ccbef35c2fd7fcf30455efbbf6a4b576ac80c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:17:12 +0300 Subject: [PATCH 19/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6aba19bdd..c96c27f22 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -243,6 +243,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int { while ( nonz < maxdepth && recvlen > 0 ) { + nonz++; memset(&pfd,0,sizeof(pfd)); pfd.fd = sock; pfd.events = NN_POLLIN; @@ -264,7 +265,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free_json(recvjson); } } - nonz++; if ( LP_lastcommand != 0 ) free(LP_lastcommand); LP_lastcommand = clonestr((char *)ptr); From d53fa3ea8464cc6a2557b3ca877493ce98aa7c5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:18:54 +0300 Subject: [PATCH 20/85] Test --- iguana/exchanges/LP_nativeDEX.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c96c27f22..0f4722c58 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -303,7 +303,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int int32_t LP_nanomsg_recvs(void *ctx) { - static double lastmilli; int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; double milli; if ( (origipaddr= LP_myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -323,9 +322,8 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( lastmilli > 0. && milli > lastmilli+100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); - lastmilli = milli; + if ( OS_milliseconds()-milli > 100 ) + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -338,9 +336,8 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( lastmilli > 0. && milli > lastmilli+100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:""); - lastmilli = milli; + if ( OS_milliseconds()-milli > 100 ) + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } //portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); From 8c47d8ce4d344dd952dfe5ab54c2c07c12ee07e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:37:18 +0300 Subject: [PATCH 21/85] Test --- iguana/exchanges/LP_portfolio.c | 9 ++++++-- iguana/exchanges/LP_signatures.c | 36 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 482327f49..6d27a07aa 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -596,7 +596,7 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a void prices_loop(void *ignore) { - char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); + char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; uint32_t expiration; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); while ( 1 ) { if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) @@ -634,7 +634,12 @@ void prices_loop(void *ignore) } free(retstr); } - sleep(60); + expiration = (uint32_t)time(NULL) + 60; + while ( time(NULL) < expiration ) + { + if ( LP_utxosQ_process() == 0 ) + usleep(10000); + } } } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 11f66cb9c..b09e548fb 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -260,21 +260,39 @@ void LP_postutxos(char *symbol,char *coinaddr) } } +queue_t utxosQ; +struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; }; + char *LP_postutxos_recv(cJSON *argjson) { - int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array; - //printf("posted.(%s)\n",jprint(argjson,0)); - if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig + struct LP_utxos_qitem *uitem; + uitem = calloc(1,sizeof(*uitem)); + uitem->argjson = jduplicate(argjson); + queue_enqueue("utxosQ",&utxosQ,&uitem->DL); + return(clonestr("{\"result\":\"success\"}")); +} + +int32_t LP_utxosQ_process() +{ + struct LP_utxos_qitem *uitem; int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array; + if ( (uitem= queue_dequeue(&utxosQ)) != 0 ) { - if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) + printf("LP_utxosQ_process.(%s)\n",jprint(uitem->argjson,0)); + if ( (coinaddr= jstr(uitem->argjson,"coinaddr")) != 0 && (symbol= jstr(uitem->argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig { - if ( (array= jarray(&n,argjson,"utxos")) != 0 ) - LP_unspents_array(coin,coinaddr,array); + if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) + { + if ( (array= jarray(&n,uitem->argjson,"utxos")) != 0 ) + LP_unspents_array(coin,coinaddr,array); + } + else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 ) + free_json(array); } - else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 ) - free_json(array); + free_json(uitem->argjson); + free(uitem); + return(1); } - return(clonestr("{\"result\":\"success\"}")); + return(0); } char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price) From 35e651d006272136ee3a75d1d0eae97906d246fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:41:02 +0300 Subject: [PATCH 22/85] Test --- iguana/exchanges/LP_nativeDEX.c | 18 +++++++++--------- iguana/exchanges/LP_signatures.c | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0f4722c58..af0374ab7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -117,7 +117,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *retstr=0; if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) return(0); - double millis = OS_milliseconds(); + //double millis = OS_milliseconds(); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) @@ -127,8 +127,8 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); - if ( OS_milliseconds()-millis > 100 ) - printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); + //if ( OS_milliseconds()-millis > 100 ) + // printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); } @@ -159,7 +159,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, { static uint32_t dup,uniq; int32_t i,len,cipherlen,datalen=0,duplicate=0,encrypted=0; char *method,*method2,*tmp,*cipherstr,*retstr=0,*jsonstr=0; cJSON *argjson; uint32_t crc32; - double millis = OS_milliseconds(); + //double millis = OS_milliseconds(); crc32 = calc_crc32(0,&ptr[2],recvlen-2); if ( (crc32 & 0xff) == ptr[0] && ((crc32>>8) & 0xff) == ptr[1] ) encrypted = 1; @@ -224,7 +224,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, { } portable_mutex_unlock(&LP_commandmutex); - printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); + //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); free_json(argjson); } } @@ -268,7 +268,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int if ( LP_lastcommand != 0 ) free(LP_lastcommand); LP_lastcommand = clonestr((char *)ptr); - double millis = OS_milliseconds(); + //double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) @@ -294,7 +294,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } - printf("%.3f LP_process_message %s\n",OS_milliseconds()-millis,methodstr); + //printf("%.3f LP_process_message %s\n",OS_milliseconds()-millis,methodstr); } } } @@ -322,7 +322,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( OS_milliseconds()-milli > 100 ) + if ( OS_milliseconds()-milli > 3 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht @@ -336,7 +336,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( OS_milliseconds()-milli > 100 ) + if ( OS_milliseconds()-milli > 3 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } //portable_mutex_unlock(&LP_nanorecvsmutex); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index b09e548fb..823698676 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -277,7 +277,7 @@ int32_t LP_utxosQ_process() struct LP_utxos_qitem *uitem; int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array; if ( (uitem= queue_dequeue(&utxosQ)) != 0 ) { - printf("LP_utxosQ_process.(%s)\n",jprint(uitem->argjson,0)); + //printf("LP_utxosQ_process.(%s)\n",jprint(uitem->argjson,0)); if ( (coinaddr= jstr(uitem->argjson,"coinaddr")) != 0 && (symbol= jstr(uitem->argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig { if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) From b310426c72b709e47df9a2988a12786eec264149 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:44:11 +0300 Subject: [PATCH 23/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_signatures.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index af0374ab7..cd2522d60 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,7 +322,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( OS_milliseconds()-milli > 3 ) + if ( OS_milliseconds()-milli > 13 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht @@ -336,7 +336,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( OS_milliseconds()-milli > 3 ) + if ( OS_milliseconds()-milli > 13 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } //portable_mutex_unlock(&LP_nanorecvsmutex); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 823698676..82890b3e6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -357,7 +357,7 @@ char *LP_notify_recv(cJSON *argjson) //printf("got pubkey.(%s)\n",secpstr); } } - char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str); + //char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str); } return(clonestr("{\"result\":\"success\",\"notify\":\"received\"}")); } From 9873b27ad468223a82cfb4d1934a959b463c37b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:50:02 +0300 Subject: [PATCH 24/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_signatures.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cd2522d60..aa3e9c7c7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,7 +322,7 @@ int32_t LP_nanomsg_recvs(void *ctx) //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( OS_milliseconds()-milli > 13 ) + if ( OS_milliseconds()-milli > 100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht @@ -336,7 +336,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( OS_milliseconds()-milli > 13 ) + if ( OS_milliseconds()-milli > 100 ) fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); } //portable_mutex_unlock(&LP_nanorecvsmutex); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 82890b3e6..f674380b4 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -343,7 +343,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) char *LP_notify_recv(cJSON *argjson) { - char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; double millis = OS_milliseconds(); + char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; //double millis = OS_milliseconds(); pub = jbits256(argjson,"pub"); // LP_checksig if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) From c7399d29ff8f44b5b7bc74976471269c6085c834 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:57:07 +0300 Subject: [PATCH 25/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_signatures.c | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index aa3e9c7c7..e597ab390 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -708,7 +708,7 @@ int32_t LP_reserved_msgs() #ifdef __APPLE__ usleep(5000); #else - usleep(1000); + usleep(3000); #endif n++; if ( n > 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cb5dd3d0f..d91db40fe 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -727,6 +727,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); // LP_addsig LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); return(retval); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index f674380b4..87bee3dc4 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -374,7 +374,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -391,12 +391,16 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); + msg2 = clonestr(msg); // LP_addsig printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); - if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs) ) + if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 ) + { Reserved_msgs[num_Reserved_msgs++] = msg; + Reserved_msgs[num_Reserved_msgs++] = msg2; + } else { //if ( 1 && strcmp(method,"request") == 0 ) From a7ee96aa1569ee9b25306e939d05190cc6b49d3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 13:59:43 +0300 Subject: [PATCH 26/85] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e597ab390..fb2a7e8f7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -519,15 +519,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } peer->lastpeers = now; } - if ( peer->diduquery == 0 ) + if ( peer->diduquery == 0 || peer->needping != 0 ) { - nonz++; LP_peer_pricesquery(peer); LP_utxos_sync(peer); peer->diduquery = now; - } - if ( peer->needping != 0 ) - { nonz++; if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); @@ -535,7 +531,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int needpings++; } } - if ( needpings != 0 || (counter % 100000) == 5 ) + if ( needpings != 0 || (counter % 10000) == 5 ) { nonz++; printf("needpings.%d send notify\n",needpings); From 8a7ebabf3bd72a13c65d379b6f58ec2f5e199e94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:02:53 +0300 Subject: [PATCH 27/85] Test --- iguana/exchanges/LP_nativeDEX.c | 11 ++--------- iguana/exchanges/LP_signatures.c | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fb2a7e8f7..9ab921b91 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -54,7 +54,6 @@ int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; int32_t LP_showwif,IAMLP = 0; double LP_profitratio = 1.; -char *LP_lastcommand; struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; }; @@ -265,9 +264,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free_json(recvjson); } } - if ( LP_lastcommand != 0 ) - free(LP_lastcommand); - LP_lastcommand = clonestr((char *)ptr); //double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); @@ -280,9 +276,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int { if ( jobj(argjson,"method") != 0 && strcmp("connect",jstr(argjson,"method")) == 0 ) printf("self.(%s)\n",str); - if ( LP_lastcommand != 0 ) - free(LP_lastcommand); - LP_lastcommand = clonestr(str); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 ) { portable_mutex_lock(&LP_commandmutex); @@ -323,7 +316,7 @@ int32_t LP_nanomsg_recvs(void *ctx) milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); if ( OS_milliseconds()-milli > 100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds\n",OS_milliseconds()-milli); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -337,7 +330,7 @@ int32_t LP_nanomsg_recvs(void *ctx) milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); if ( OS_milliseconds()-milli > 100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",OS_milliseconds()-milli,LP_lastcommand!=0?LP_lastcommand:""); + fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds\n",OS_milliseconds()-milli); } //portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 87bee3dc4..b3ff9a9c9 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -391,13 +391,13 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); - msg2 = clonestr(msg); // LP_addsig printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 ) { + msg2 = clonestr(msg); Reserved_msgs[num_Reserved_msgs++] = msg; Reserved_msgs[num_Reserved_msgs++] = msg2; } From 4f37be01575b7d43b59d238f475b8359235f427f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:08:05 +0300 Subject: [PATCH 28/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_signatures.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9ab921b91..55f5bcb57 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -601,7 +601,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //LP_getestimatedrate(coin); break; } - if ( (counter % 6000) == 60 ) + if ( (counter % 100000) == 90000 ) { if ( (retstr= basilisk_swapentry(0,0)) != 0 ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index b3ff9a9c9..ac006543a 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -374,7 +374,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -395,11 +395,9 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); - if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 ) + if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-1 ) { - msg2 = clonestr(msg); Reserved_msgs[num_Reserved_msgs++] = msg; - Reserved_msgs[num_Reserved_msgs++] = msg2; } else { From 9d0d6cc7422eeb4348679d7ed82c469f1265ba3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:11:03 +0300 Subject: [PATCH 29/85] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- iguana/exchanges/LP_signatures.c | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d91db40fe..80632ac5b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -596,7 +596,7 @@ int32_t LP_aliceonly(char *symbol) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg,*msg2,*retstr,str[65]; int32_t DEXselector = 0; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) { // LP_checksig @@ -726,8 +726,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo->T.lasttime = (uint32_t)time(NULL); printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); // LP_addsig + msg2 = clonestr(msg); LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); - LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); return(retval); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index ac006543a..7a55e0f96 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -315,7 +315,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re char *LP_postprice_recv(cJSON *argjson) { bits256 pubkey; double price; char *base,*rel; - //printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); + printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL ) { pubkey = jbits256(argjson,"pubkey"); @@ -374,7 +374,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -391,13 +391,15 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); + msg2 = clonestr(msg); // LP_addsig printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); - if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-1 ) + if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 ) { Reserved_msgs[num_Reserved_msgs++] = msg; + Reserved_msgs[num_Reserved_msgs++] = msg2; } else { From ba96a477de30a3fd60f11e825bd66cc673251449 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:13:42 +0300 Subject: [PATCH 30/85] Test --- iguana/exchanges/LP_signatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 7a55e0f96..87bee3dc4 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -315,7 +315,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re char *LP_postprice_recv(cJSON *argjson) { bits256 pubkey; double price; char *base,*rel; - printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); + //printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL ) { pubkey = jbits256(argjson,"pubkey"); From ec55a86f316cf14b366ee2135f353f862624e153 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:14:49 +0300 Subject: [PATCH 31/85] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 141fa9023..4a44fe7d2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -44,7 +44,7 @@ #define LP_PEERGOOD_ERRORDECAY 0.9 #define LP_SWAPSTEP_TIMEOUT 30 -#define LP_AUTOTRADE_TIMEOUT 20 +#define LP_AUTOTRADE_TIMEOUT 30 #define LP_MIN_TXFEE 10000 #define LP_MINVOL 20 #define LP_MINCLIENTVOL 50 From 9e5ae025c855a9256ab999a1e558465e70192b0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:17:39 +0300 Subject: [PATCH 32/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 55f5bcb57..48d3f9a99 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -689,8 +689,8 @@ int32_t LP_reserved_msgs() if ( nn_poll(&pfd,1,1) != 1 ) break;*/ num_Reserved_msgs--; + printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); #ifdef __APPLE__ -// printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); #endif LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; From 2d600d8c9ac7c3537bedbc4d84c48b37e3460826 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:21:52 +0300 Subject: [PATCH 33/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 48d3f9a99..43c2af5f6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -689,7 +689,7 @@ int32_t LP_reserved_msgs() if ( nn_poll(&pfd,1,1) != 1 ) break;*/ num_Reserved_msgs--; - printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); + //printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); #ifdef __APPLE__ #endif LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); From d1cfd72f662a9c16a867daac2ba7fc88d61d9098 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:26:51 +0300 Subject: [PATCH 34/85] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 4a44fe7d2..193137fb2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -44,7 +44,7 @@ #define LP_PEERGOOD_ERRORDECAY 0.9 #define LP_SWAPSTEP_TIMEOUT 30 -#define LP_AUTOTRADE_TIMEOUT 30 +#define LP_AUTOTRADE_TIMEOUT 10 #define LP_MIN_TXFEE 10000 #define LP_MINVOL 20 #define LP_MINCLIENTVOL 50 From dc5347636f494fc6913aded6f79835ac384f6b6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:29:35 +0300 Subject: [PATCH 35/85] Test --- iguana/exchanges/LP_signatures.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 87bee3dc4..830759eeb 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -390,6 +390,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ flag = 1; jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); + jaddnum(reqjson,"timestamp",time(NULL)); msg = jprint(reqjson,1); msg2 = clonestr(msg); // LP_addsig From 5f2c362f9663e83a8957265a747ad8b6cfd75361 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:32:54 +0300 Subject: [PATCH 36/85] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 43c2af5f6..fca19aa4c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -250,6 +250,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { + methodstr[0] = 0; if ( 1 ) { cJSON *recvjson; //char *mstr,*cstr; @@ -264,7 +265,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free_json(recvjson); } } - //double millis = OS_milliseconds(); + double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) @@ -287,7 +288,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } - //printf("%.3f LP_process_message %s\n",OS_milliseconds()-millis,methodstr); + printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); } } } From 49d1209967a99ed59ad24268ff9d3ac8d6f394e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:43:27 +0300 Subject: [PATCH 37/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fca19aa4c..416c810a6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -265,7 +265,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free_json(recvjson); } } - double millis = OS_milliseconds(); + //double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) @@ -288,7 +288,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } - printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); + //printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); } } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 80632ac5b..ff1c5d286 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -295,7 +295,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** } else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); } else if ( targetval != 0 && mini >= 0 ) printf("targetval %.8f mini.%d\n",dstr(targetval),mini); - } else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); + } //else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); return(0); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ee152d15b..562ef6b3e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -800,7 +800,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol if ( bypass != 0 ) val = satoshis; else val = LP_txvalue(destaddr,symbol,txid,vout); - if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 ) + /*if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 ) { //printf("%s/v%d spent %d\n",bits256_str(str,txid),vout,up->spendheight); return(-2); @@ -809,7 +809,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol { //printf("%s/v%d spent %d\n",bits256_str(str,txid2),vout2,up->spendheight); return(-3); - } + }*/ txfee = LP_txfeecalc(LP_coinfind(symbol),0,0); if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee ) { From e5d53122267ed270590198b26ffd0c8ca68820fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:48:34 +0300 Subject: [PATCH 38/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 416c810a6..e1678d664 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -528,7 +528,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( needpings != 0 || (counter % 10000) == 5 ) { nonz++; - printf("needpings.%d send notify\n",needpings); + //printf("needpings.%d send notify\n",needpings); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) From 9b9ff4b1f0df0051df0fd1f2c8d7a5af2b7a2bb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 14:49:31 +0300 Subject: [PATCH 39/85] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e1678d664..74a20ecb8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -265,7 +265,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free_json(recvjson); } } - //double millis = OS_milliseconds(); + double millis = OS_milliseconds(); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) @@ -288,7 +288,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } - //printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); + if ( OS_milliseconds()-millis > 100 ) + printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); } } } @@ -297,7 +298,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int int32_t LP_nanomsg_recvs(void *ctx) { - int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; double milli; + int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; if ( (origipaddr= LP_myipaddr) == 0 ) origipaddr = "127.0.0.1"; //portable_mutex_lock(&LP_nanorecvsmutex); @@ -314,10 +315,7 @@ int32_t LP_nanomsg_recvs(void *ctx) } } //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); - milli = OS_milliseconds(); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); - if ( OS_milliseconds()-milli > 100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds\n",OS_milliseconds()-milli); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -328,10 +326,7 @@ int32_t LP_nanomsg_recvs(void *ctx) }*/ if ( LP_mypullsock >= 0 ) { - milli = OS_milliseconds(); nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); - if ( OS_milliseconds()-milli > 100 ) - fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds\n",OS_milliseconds()-milli); } //portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); From 1d8a3fd5048893cbb64424f5c508e3602e9dd9f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 15:52:20 +0300 Subject: [PATCH 40/85] Pubkey sig --- iguana/exchanges/LP_include.h | 12 +++++ iguana/exchanges/LP_nativeDEX.c | 3 +- iguana/exchanges/LP_prices.c | 45 ++++++------------- iguana/exchanges/LP_signatures.c | 77 +++++++++++++++++++++++++++----- iguana/exchanges/LP_utxo.c | 4 +- 5 files changed, 97 insertions(+), 44 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 193137fb2..bcad7e661 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -275,6 +275,18 @@ struct basilisk_swap }; +#define LP_MAXPRICEINFOS 256 +struct LP_pubkeyinfo +{ + UT_hash_handle hh; + bits256 pubkey; + double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; + uint32_t timestamp,istrusted,numerrors; + uint8_t rmd160[20],sig[76],pubsecp[33],siglen; +}; + +void LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); +int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp); void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout); void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); uint32_t basilisk_requestid(struct basilisk_request *rp); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 74a20ecb8..cbc989829 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -37,6 +37,7 @@ int32_t num_Reserved_msgs,max_Reserved_msgs; struct LP_peerinfo *LP_peerinfos,*LP_mypeer; struct LP_forwardinfo *LP_forwardinfos; struct iguana_info *LP_coins; +struct LP_pubkeyinfo *LP_pubkeyinfos; #include "LP_network.c" char *activecoins[] = { "BTC", "KMD" }; @@ -497,7 +498,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+60 )//|| (rand() % 10000) == 0 ) + if ( now > peer->lastpeers+60 || (rand() % 10000) == 0 ) { if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 98f0e7d40..0831173e0 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -20,7 +20,6 @@ struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; -#define LP_MAXPRICEINFOS 256 struct LP_priceinfo { char symbol[16]; @@ -48,15 +47,6 @@ struct LP_cacheinfo uint32_t timestamp; } *LP_cacheinfos; -struct LP_pubkeyinfo -{ - UT_hash_handle hh; - bits256 pubkey; - double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; - uint32_t timestamp,istrusted,numerrors; - uint8_t rmd160[20],pubsecp[33]; -} *LP_pubkeyinfos; - int32_t LP_pricevalid(double price) { if ( price > SMALLVAL && isnan(price) == 0 && price < SATOSHIDEN ) @@ -258,7 +248,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { - int32_t baseid,relid,i,j; char *base,hexstr[67],hexstr2[67]; double price; cJSON *item,*array,*obj; + int32_t baseid,relid,i,j; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj; obj = cJSON_CreateObject(); array = cJSON_CreateArray(); for (baseid=0; baseidpubsecp,sizeof(pubp->pubsecp)); jaddstr(obj,"pubsecp",hexstr2); + if ( pubp->siglen > 0 ) + { + init_hexbytes_noT(sigstr,pubp->sig,pubp->siglen); + jaddstr(obj,"sig",sigstr); + } //printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); + //LP_pubkey_sigadd(obj,pubp->pubkey,pubp->rmd160,pubp->pubsecp); break; } } @@ -316,32 +312,19 @@ char *LP_prices() void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) { - static uint8_t zeroes[20]; - struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr,*pubsecpstr; double askprice; uint32_t now; + struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr; double askprice; uint32_t now; now = (uint32_t)time(NULL); pubkey = jbits256(obj,"pubkey"); if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { if ( (hexstr= jstr(obj,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) - { decode_hex(rmd160,sizeof(rmd160),hexstr); - if ( memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 ) - mismatch = 1; - else mismatch = 0; - if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 ) - peer->needping = 0; - if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) - { - for (i=0; i<20; i++) - printf("%02x",pubp->rmd160[i]); - memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - if ( (pubsecpstr= jstr(obj,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) - { - decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),pubsecpstr); - char str[65]; printf(" -> rmd160.(%s) for %s (%s)\n",hexstr,bits256_str(str,pubkey),pubsecpstr); - } - } - } + if ( memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 ) + mismatch = 1; + else mismatch = 0; + if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 ) + peer->needping = 0; + LP_pubkey_sigcheck(pubp,obj); timestamp = juint(obj,"timestamp"); if ( timestamp > now ) timestamp = now; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 830759eeb..376bbd10a 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -328,6 +328,40 @@ char *LP_postprice_recv(cJSON *argjson) return(clonestr("{\"error\":\"missing fields in posted price\"}")); } +bits256 LP_pubkey_sighash(bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +{ + uint8_t buf[sizeof(pub) + 20 + 33]; bits256 sighash; + memcpy(buf,pub.bytes,sizeof(pub)); + memcpy(&buf[sizeof(pub)],rmd160,20); + memcpy(&buf[sizeof(pub)+20],pubsecp,33); + vcalc_sha256(0,sighash.bytes,buf,sizeof(buf)); + return(sighash); +} + +int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +{ + static void *ctx; + uint8_t sig[128]; int32_t siglen=0; bits256 sighash; char sigstr[256]; + sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,0)) > 0 && siglen < 76 ) + { + init_hexbytes_noT(sigstr,sig,siglen); + jaddstr(item,"sig",sigstr); + return(siglen); + } else return(0); +} + +int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +{ + static void *ctx; + bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + return(bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33)); +} + void LP_notify_pubkeys(void *ctx,int32_t pubsock) { bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); @@ -338,25 +372,48 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) jaddbits256(reqjson,"pub",G.LP_mypub25519); init_hexbytes_noT(secpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",secpstr); + LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); LP_reserved_msg("","",zero,jprint(reqjson,1)); } -char *LP_notify_recv(cJSON *argjson) +void LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { - char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; //double millis = OS_milliseconds(); - pub = jbits256(argjson,"pub"); - // LP_checksig - if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) + int32_t i,siglen,len; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; + if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) { - if ( (pubp= LP_pubkeyadd(pub)) != 0 ) + decode_hex(rmd160,sizeof(rmd160),hexstr); + memset(zeroes,0,sizeof(zeroes)); + if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) { - decode_hex(pubp->rmd160,20,rmd160str); - if ( (secpstr= jstr(argjson,"pubsecp")) != 0 ) + if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { - decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr); - //printf("got pubkey.(%s)\n",secpstr); + decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); + if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) > 70*2 && len < 76*2 ) + { + siglen = len >> 1; + decode_hex(sig,siglen,sigstr); + if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + { + for (i=0; i<20; i++) + printf("%02x",pubp->rmd160[i]); + memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); + memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); + } else printf("sig error\n"); + } } } + } +} + +char *LP_notify_recv(cJSON *argjson) +{ + bits256 pub; struct LP_pubkeyinfo *pubp; + pub = jbits256(argjson,"pub"); + if ( bits256_nonz(pub) != 0 ) + { + if ( (pubp= LP_pubkeyadd(pub)) != 0 ) + LP_pubkey_sigcheck(pubp,argjson); //char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str); } return(clonestr("{\"result\":\"success\",\"notify\":\"received\"}")); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 562ef6b3e..fc5857199 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -787,8 +787,8 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) { - //struct LP_utxoinfo *utxo; - struct LP_address_utxo *up; uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64],str[65]; struct iguana_info *coin = LP_coinfind(symbol); + //struct LP_utxoinfo *utxo; struct LP_address_utxo *up; + uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64],str[65]; struct iguana_info *coin = LP_coinfind(symbol); if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) { printf("null txid not eligible\n"); From ea87a289e29f8632d1aa1593fce2e995124cdd49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 15:52:52 +0300 Subject: [PATCH 41/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cbc989829..e74f5c626 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -289,7 +289,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } free(str); } - if ( OS_milliseconds()-millis > 100 ) + if ( OS_milliseconds()-millis > 1000 ) printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr); } } From 682abbc540a0cf23fffb4b330a954575f84f9222 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 15:58:50 +0300 Subject: [PATCH 42/85] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_signatures.c | 38 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index bcad7e661..75545f2d9 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -285,7 +285,7 @@ struct LP_pubkeyinfo uint8_t rmd160[20],sig[76],pubsecp[33],siglen; }; -void LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); +int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp); void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout); void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 376bbd10a..79fa10ab5 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -362,23 +362,9 @@ int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd return(bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33)); } -void LP_notify_pubkeys(void *ctx,int32_t pubsock) -{ - bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); - // LP_addsig - memset(zero.bytes,0,sizeof(zero)); - jaddstr(reqjson,"method","notify"); - jaddstr(reqjson,"rmd160",G.LP_myrmd160str); - jaddbits256(reqjson,"pub",G.LP_mypub25519); - init_hexbytes_noT(secpstr,G.LP_pubsecp,33); - jaddstr(reqjson,"pubsecp",secpstr); - LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); - LP_reserved_msg("","",zero,jprint(reqjson,1)); -} - -void LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) +int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { - int32_t i,siglen,len; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; + int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) { decode_hex(rmd160,sizeof(rmd160),hexstr); @@ -399,11 +385,29 @@ void LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); - } else printf("sig error\n"); + retval = 0; + } else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); } } } } + return(retval); +} + +void LP_notify_pubkeys(void *ctx,int32_t pubsock) +{ + bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); + // LP_addsig + memset(zero.bytes,0,sizeof(zero)); + jaddstr(reqjson,"method","notify"); + jaddstr(reqjson,"rmd160",G.LP_myrmd160str); + jaddbits256(reqjson,"pub",G.LP_mypub25519); + init_hexbytes_noT(secpstr,G.LP_pubsecp,33); + jaddstr(reqjson,"pubsecp",secpstr); + LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); + if ( LP_pubkey_sigcheck(LP_pubkeyadd(G.LP_mypub25519),reqjson) == 0 ) + printf("sig verified\n"); + LP_reserved_msg("","",zero,jprint(reqjson,1)); } char *LP_notify_recv(cJSON *argjson) From a5ef76640d7e9a863c79738eb7480381060c719e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:02:47 +0300 Subject: [PATCH 43/85] Test --- iguana/exchanges/LP_signatures.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 79fa10ab5..8bd80f48d 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -338,6 +338,15 @@ bits256 LP_pubkey_sighash(bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) return(sighash); } +int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +{ + static void *ctx; + bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + return(bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33)); +} + int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { static void *ctx; @@ -349,19 +358,11 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); + printf("sigadd check: %d %s siglen.%d\n",_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); return(siglen); } else return(0); } -int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) -{ - static void *ctx; - bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); - if ( ctx == 0 ) - ctx = bitcoin_ctx(); - return(bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33)); -} - int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; @@ -407,6 +408,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); if ( LP_pubkey_sigcheck(LP_pubkeyadd(G.LP_mypub25519),reqjson) == 0 ) printf("sig verified\n"); + else printf("sig error\n"); LP_reserved_msg("","",zero,jprint(reqjson,1)); } From 5260c7c3468c711f593cb2a35077cad6795dfb2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:06:56 +0300 Subject: [PATCH 44/85] Test --- iguana/exchanges/LP_secp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_secp.c b/iguana/exchanges/LP_secp.c index 7d4409911..9c7032e23 100644 --- a/iguana/exchanges/LP_secp.c +++ b/iguana/exchanges/LP_secp.c @@ -179,7 +179,7 @@ int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uin secp256k1_ecdsa_signature_parse_der(ctx,&SIG,sig,siglen); if ( secp256k1_ecdsa_verify(ctx,&SIG,txhash2.bytes,&PUB) != 0 ) retval = 0; - } + } else printf("error parsing pubkey\n"); ENDSECP_ENSURE_CTX } return(retval); From 1da8e8a19c9ec92ad7d9e32d608410b11748a68c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:09:18 +0300 Subject: [PATCH 45/85] Test --- iguana/exchanges/LP_signatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 8bd80f48d..0b2f3bca6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -358,7 +358,7 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); - printf("sigadd check: %d %s siglen.%d\n",_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); + printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); return(siglen); } else return(0); } From 703da4406292094808261d5cfa93d37cbfbe12ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:12:17 +0300 Subject: [PATCH 46/85] Test --- iguana/exchanges/LP_signatures.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0b2f3bca6..ca1c84022 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -354,11 +354,11 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); if ( ctx == 0 ) ctx = bitcoin_ctx(); - if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,0)) > 0 && siglen < 76 ) + if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 64 ) { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); - printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); + printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pubsecp,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); return(siglen); } else return(0); } From cb5203e3a65043c70adb773d5529a768a412e746 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:16:11 +0300 Subject: [PATCH 47/85] Test --- iguana/exchanges/LP_signatures.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index ca1c84022..c71fe4f98 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -350,7 +350,7 @@ int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { static void *ctx; - uint8_t sig[128]; int32_t siglen=0; bits256 sighash; char sigstr[256]; + uint8_t sig[128],pub33[33]; int32_t i,siglen=0; bits256 sighash; char sigstr[256]; sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); if ( ctx == 0 ) ctx = bitcoin_ctx(); @@ -358,7 +358,16 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); - printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pubsecp,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); + printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); + if ( memcmp(pub33,pubsecp,33) != 0 ) + { + for (i=0; i<33; i++) + printf("%02x",pubsecp[i]); + printf(" pubsecp -> "); + for (i=0; i<33; i++) + printf("%02x",pub33[i]); + printf(" mismatched recovered pubkey\n"); + } return(siglen); } else return(0); } @@ -375,6 +384,8 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); + memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition + memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) > 70*2 && len < 76*2 ) { siglen = len >> 1; @@ -387,7 +398,7 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); retval = 0; - } else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); } } } From db57dca0bf68cbca37d8cc18940d1adb75218f5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:19:47 +0300 Subject: [PATCH 48/85] Test --- iguana/exchanges/LP_signatures.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index c71fe4f98..2d5d01c95 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -354,7 +354,7 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); if ( ctx == 0 ) ctx = bitcoin_ctx(); - if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 64 ) + if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); @@ -417,9 +417,6 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) init_hexbytes_noT(secpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",secpstr); LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); - if ( LP_pubkey_sigcheck(LP_pubkeyadd(G.LP_mypub25519),reqjson) == 0 ) - printf("sig verified\n"); - else printf("sig error\n"); LP_reserved_msg("","",zero,jprint(reqjson,1)); } From 10d70532a1d51ef2aab6365098d86eb769f082c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:26:54 +0300 Subject: [PATCH 49/85] Test --- iguana/exchanges/LP_signatures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 2d5d01c95..96f70fc52 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -358,7 +358,8 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui { init_hexbytes_noT(sigstr,sig,siglen); jaddstr(item,"sig",sigstr); - printf("sigadd check: %d/%d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,33),_LP_pubkey_sigcheck(sig,siglen,pub,rmd160,pubsecp),sigstr,siglen); + memset(pub33,0,33); + printf("sigadd check: %d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0),sigstr,siglen); if ( memcmp(pub33,pubsecp,33) != 0 ) { for (i=0; i<33; i++) From a6193659389ebf66a00305098343c00cf28885e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:31:18 +0300 Subject: [PATCH 50/85] Test --- iguana/exchanges/LP_signatures.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 96f70fc52..fde4661ba 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -341,10 +341,10 @@ bits256 LP_pubkey_sighash(bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { static void *ctx; - bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); + uint8_t pub33[33]; bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); if ( ctx == 0 ) ctx = bitcoin_ctx(); - return(bitcoin_verify(ctx,sig,siglen,sighash,pubsecp,33)); + return(bitcoin_recoververify(ctx,"sigcheck",sig,sighash,pub33,0)); } int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) @@ -365,6 +365,10 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui for (i=0; i<33; i++) printf("%02x",pubsecp[i]); printf(" pubsecp -> "); + for (i=0; i<33; i++) + printf("%02x",pub33[i]); + printf(" recovered, "); + bitcoin_pubkey33(ctx,pub33,priv); for (i=0; i<33; i++) printf("%02x",pub33[i]); printf(" mismatched recovered pubkey\n"); From 4de545353068e5ff3ed5264187b19baec10e69ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:39:05 +0300 Subject: [PATCH 51/85] Test --- iguana/exchanges/LP_utxos.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index ed328c508..0df37e199 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -721,6 +721,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("WIF.(%s) -> %s or %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkkey)); } } + privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); if ( coin->counter == 0 ) { @@ -762,6 +763,9 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); G.LP_mypriv25519 = checkkey; + char str[65],str2[65]; + if ( bits256_cmp(checkkey,privkey) != 0 ) + printf("??????????? privkey mismatch %s vs %s\n",bits256_str(str,privkey),bits256_str(str2,checkkey)); LP_pubkeyadd(G.LP_mypub25519); return(privkey); } From 9a8313e21248e9421afc8d42727a67c9782c36eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:43:07 +0300 Subject: [PATCH 52/85] Test --- iguana/exchanges/LP_coins.c | 4 ++-- iguana/exchanges/LP_commands.c | 12 ++++++------ iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_signatures.c | 2 +- iguana/exchanges/LP_utxos.c | 6 ++---- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 9a7cb7509..5ef612669 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -188,9 +188,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jaddstr(item,"coin",coin->symbol); if ( showwif != 0 ) { - bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_mypriv25519,coin->wiftype); + bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_privkey,coin->wiftype); bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,wifstr); - if ( bits256_cmp(G.LP_mypriv25519,checkkey) == 0 ) + if ( bits256_cmp(G.LP_privkey,checkkey) == 0 ) jaddstr(item,"wif",wifstr); else jaddstr(item,"wif","error creating wif"); } diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 49dcb96ab..dc9ca2ca5 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -382,9 +382,9 @@ stop()\n\ { //privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR); //LP_utxopurge(0); - if ( bits256_nonz(G.LP_mypriv25519) != 0 ) - LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519); - else printf("no LP_mypriv25519\n"); + if ( bits256_nonz(G.LP_privkey) != 0 ) + LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); + else printf("no LP_privkey\n"); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddstr(retjson,"coin",coin); @@ -483,9 +483,9 @@ stop()\n\ { LP_address(ptr,coinaddr); LP_listunspent_issue(coin,coinaddr,1); - if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_mypriv25519) != 0 ) + if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { - LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519); + LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); //LP_smartutxos_push(ptr); } else @@ -508,7 +508,7 @@ stop()\n\ if ( coinaddr[0] != 0 ) { LP_address(ptr,coinaddr); - if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_mypriv25519) != 0 ) + if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { //printf("ADDR_UNSPENTS %s %s is my address being asked for!\n",ptr->symbol,coinaddr); ptr->addr_listunspent_requested = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e74f5c626..aee72a9d0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -61,7 +61,7 @@ struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; }; struct LP_globals { struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; - bits256 LP_mypub25519,LP_mypriv25519; + bits256 LP_mypub25519,LP_privkey,LP_mypriv25519; uint64_t LP_skipstatus[10000]; uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 6d27a07aa..9bb176b00 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -93,7 +93,7 @@ char *LP_portfolio() continue; if ( iter == 0 ) { - LP_privkey_init(-1,coin,G.LP_mypriv25519,G.LP_mypub25519); + LP_privkey_init(-1,coin,G.LP_privkey,G.LP_mypub25519); coin->balanceA = LP_balance(&coin->valuesumA,0,coin->symbol,coin->smartaddr); coin->balanceB = LP_balance(&coin->valuesumB,1,coin->symbol,coin->smartaddr); if ( strcmp(coin->symbol,"KMD") != 0 ) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index fde4661ba..bf9ce82fd 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -421,7 +421,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) jaddbits256(reqjson,"pub",G.LP_mypub25519); init_hexbytes_noT(secpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",secpstr); - LP_pubkey_sigadd(reqjson,G.LP_mypriv25519,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); + LP_pubkey_sigadd(reqjson,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); LP_reserved_msg("","",zero,jprint(reqjson,1)); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0df37e199..565cfdda2 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -730,6 +730,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); LP_privkeyadd(privkey,G.LP_myrmd160); + G.LP_privkey = privkey; if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) ) printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase); if ( G.counter++ == 0 ) @@ -763,9 +764,6 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); G.LP_mypriv25519 = checkkey; - char str[65],str2[65]; - if ( bits256_cmp(checkkey,privkey) != 0 ) - printf("??????????? privkey mismatch %s vs %s\n",bits256_str(str,privkey),bits256_str(str2,checkkey)); LP_pubkeyadd(G.LP_mypub25519); return(privkey); } @@ -791,7 +789,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) //printf("i.%d of %d\n",i,LP_numcoins); else if ( IAMLP == 0 || coin->inactive == 0 ) { - if ( LP_privkey_init(pubsock,coin,G.LP_mypriv25519,G.LP_mypub25519) == 0 && (rand() % 10) == 0 ) + if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (rand() % 10) == 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } } From 0f5b828564de4a7822f52e1427ecca85b695e8e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:50:25 +0300 Subject: [PATCH 53/85] test --- iguana/exchanges/LP_signatures.c | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index bf9ce82fd..d6391e12c 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -350,31 +350,31 @@ int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { static void *ctx; - uint8_t sig[128],pub33[33]; int32_t i,siglen=0; bits256 sighash; char sigstr[256]; + uint8_t sig[128],pub33[33]; int32_t i,j,siglen=0; bits256 sighash; char sigstr[256]; sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); if ( ctx == 0 ) ctx = bitcoin_ctx(); - if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) + for (j=0; j<100; j++) { - init_hexbytes_noT(sigstr,sig,siglen); - jaddstr(item,"sig",sigstr); - memset(pub33,0,33); - printf("sigadd check: %d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0),sigstr,siglen); - if ( memcmp(pub33,pubsecp,33) != 0 ) + if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) { - for (i=0; i<33; i++) - printf("%02x",pubsecp[i]); - printf(" pubsecp -> "); - for (i=0; i<33; i++) - printf("%02x",pub33[i]); - printf(" recovered, "); - bitcoin_pubkey33(ctx,pub33,priv); - for (i=0; i<33; i++) - printf("%02x",pub33[i]); - printf(" mismatched recovered pubkey\n"); + init_hexbytes_noT(sigstr,sig,siglen); + jaddstr(item,"sig",sigstr); + memset(pub33,0,33); + //printf("sigadd check: %d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0),sigstr,siglen); + if ( memcmp(pub33,pubsecp,33) == 0 ) + return(siglen); + { + for (i=0; i<33; i++) + printf("%02x",pubsecp[i]); + printf(" pubsecp -> "); + for (i=0; i<33; i++) + printf("%02x",pub33[i]); + printf(" mismatched recovered pubkey.%d of %d\n",i,100); + } } - return(siglen); - } else return(0); + } + return(0); } int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) From 6718ce46dfe66f7b46a2d3e5b0221b8883957e7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:52:47 +0300 Subject: [PATCH 54/85] Test --- iguana/exchanges/LP_signatures.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index d6391e12c..883b278a0 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -358,19 +358,20 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui { if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) { - init_hexbytes_noT(sigstr,sig,siglen); - jaddstr(item,"sig",sigstr); memset(pub33,0,33); - //printf("sigadd check: %d %s siglen.%d\n",bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0),sigstr,siglen); - if ( memcmp(pub33,pubsecp,33) == 0 ) + if ( bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0) == 0 && memcmp(pub33,pubsecp,33) == 0 ) + { + init_hexbytes_noT(sigstr,sig,siglen); + jaddstr(item,"sig",sigstr); return(siglen); + } { for (i=0; i<33; i++) printf("%02x",pubsecp[i]); printf(" pubsecp -> "); for (i=0; i<33; i++) printf("%02x",pub33[i]); - printf(" mismatched recovered pubkey.%d of %d\n",i,100); + printf(" mismatched recovered pubkey.%d of %d\n",j,100); } } } From d67d9aed5d27ce48a845d4a6fdc17ddf5ec0041c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:54:28 +0300 Subject: [PATCH 55/85] Test --- iguana/exchanges/LP_signatures.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 883b278a0..bb8105d50 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -390,9 +390,9 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); - memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition - memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); - if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) > 70*2 && len < 76*2 ) + //memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition + //memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) { siglen = len >> 1; decode_hex(sig,siglen,sigstr); From cf8cbfc7b006d3576019b47a41ace3854dc58898 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 16:57:33 +0300 Subject: [PATCH 56/85] Test --- iguana/exchanges/LP_signatures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index bb8105d50..b67bcd3e1 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -365,6 +365,7 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui jaddstr(item,"sig",sigstr); return(siglen); } + if ( 0 ) { for (i=0; i<33; i++) printf("%02x",pubsecp[i]); @@ -385,7 +386,7 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { decode_hex(rmd160,sizeof(rmd160),hexstr); memset(zeroes,0,sizeof(zeroes)); - if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) + if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && memcmp(rmd160,pubp->rmd160,20) != 0 ) { if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { From c61465be750175b77dd0d5d56959b83a81e6f237 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:08:37 +0300 Subject: [PATCH 57/85] Test --- iguana/exchanges/LP_signatures.c | 41 ++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index b67bcd3e1..c8655828b 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -381,33 +381,38 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { - int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; + int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],checkrmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) { decode_hex(rmd160,sizeof(rmd160),hexstr); memset(zeroes,0,sizeof(zeroes)); - if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && memcmp(rmd160,pubp->rmd160,20) != 0 ) + if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) { - if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) + if ( memcmp(rmd160,pubp->rmd160,20) != 0 ) { - decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); - //memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition - //memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); - if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) + if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { - siglen = len >> 1; - decode_hex(sig,siglen,sigstr); - if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); + calc_rmd160(0,checkrmd160,pubsecp,33); + //memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition + //memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + if ( memcmp(checkrmd160,rmd160,20) == 0 && (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) { - for (i=0; i<20; i++) - printf("%02x",pubp->rmd160[i]); - memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); - char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); - retval = 0; - } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + siglen = len >> 1; + decode_hex(sig,siglen,sigstr); + if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + { + for (i=0; i<20; i++) + printf("%02x",pubp->rmd160[i]); + memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); + memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); + retval = 0; + pubp->timestamp = (uint32_t)time(NULL); + } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + } } - } + } else pubp->timestamp = (uint32_t)time(NULL); } } return(retval); From 557557e95e87f0a36ba91c2f0c71ceb9335fb693 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:16:01 +0300 Subject: [PATCH 58/85] Test --- iguana/exchanges/LP_signatures.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index c8655828b..68b832a9f 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -394,8 +394,6 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); calc_rmd160(0,checkrmd160,pubsecp,33); - //memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); // transition - //memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); if ( memcmp(checkrmd160,rmd160,20) == 0 && (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) { siglen = len >> 1; @@ -411,6 +409,15 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) pubp->timestamp = (uint32_t)time(NULL); } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); } + else + { + for (i=0; i<20; i++) + printf("%02x",rmd160[i]); + printf(" rmd160 vs "); + for (i=0; i<20; i++) + printf("%02x",checkrmd160[i]); + printf(" for %s\n",pubsecpstr); + } } } else pubp->timestamp = (uint32_t)time(NULL); } From f5fbe607e7a2c183fbf5b95d818a72cea765c8af Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:17:47 +0300 Subject: [PATCH 59/85] Test --- iguana/exchanges/LP_signatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 68b832a9f..0416630b2 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -393,7 +393,7 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); - calc_rmd160(0,checkrmd160,pubsecp,33); + calc_rmd160_sha256(checkrmd160,pubsecp,33); if ( memcmp(checkrmd160,rmd160,20) == 0 && (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) { siglen = len >> 1; From 85d01b1afb8800b8b315629a195a2383e58ba0ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:19:46 +0300 Subject: [PATCH 60/85] Test --- iguana/exchanges/LP_signatures.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0416630b2..3801752c6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -394,20 +394,23 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr); calc_rmd160_sha256(checkrmd160,pubsecp,33); - if ( memcmp(checkrmd160,rmd160,20) == 0 && (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) + if ( memcmp(checkrmd160,rmd160,20) == 0 ) { - siglen = len >> 1; - decode_hex(sig,siglen,sigstr); - if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 ) { - for (i=0; i<20; i++) - printf("%02x",pubp->rmd160[i]); - memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); - char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); - retval = 0; - pubp->timestamp = (uint32_t)time(NULL); - } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + siglen = len >> 1; + decode_hex(sig,siglen,sigstr); + if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + { + for (i=0; i<20; i++) + printf("%02x",pubp->rmd160[i]); + memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); + memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); + retval = 0; + pubp->timestamp = (uint32_t)time(NULL); + } //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr); + } } else { From c3ae67ee09ffbb54e8dbcde414f28ffe823da92a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:25:01 +0300 Subject: [PATCH 61/85] Test --- iguana/exchanges/LP_signatures.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 3801752c6..4ffc77c36 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -467,7 +467,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -485,7 +485,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddstr(reqjson,"method",method); jaddnum(reqjson,"timestamp",time(NULL)); msg = jprint(reqjson,1); - msg2 = clonestr(msg); + //msg2 = clonestr(msg); // LP_addsig printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); @@ -493,7 +493,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 ) { Reserved_msgs[num_Reserved_msgs++] = msg; - Reserved_msgs[num_Reserved_msgs++] = msg2; + //Reserved_msgs[num_Reserved_msgs++] = msg2; } else { From 23ad3bd9f69f4e40d3c3d0117c58911a1c16f92c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:26:46 +0300 Subject: [PATCH 62/85] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index aee72a9d0..e81edbd8e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -675,29 +675,28 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint int32_t LP_reserved_msgs() { - bits256 zero; int32_t n = 0; //struct nn_pollfd pfd; + bits256 zero; int32_t n = 0; struct nn_pollfd pfd; memset(zero.bytes,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); while ( num_Reserved_msgs > 0 ) { - /*memset(&pfd,0,sizeof(pfd)); + memset(&pfd,0,sizeof(pfd)); pfd.fd = LP_mypubsock; pfd.events = NN_POLLOUT; if ( nn_poll(&pfd,1,1) != 1 ) - break;*/ + break; num_Reserved_msgs--; //printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); #ifdef __APPLE__ #endif LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; -#ifdef __APPLE__ +/*#ifdef __APPLE__ usleep(5000); #else usleep(3000); -#endif - n++; - if ( n > 0 ) +#endif*/ + if ( ++n > 0 ) break; } portable_mutex_unlock(&LP_reservedmutex); From 82776e9f6a1a2547d3461f398939e64075bb8d19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:31:01 +0300 Subject: [PATCH 63/85] Test --- iguana/exchanges/LP_nativeDEX.c | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e81edbd8e..531965a88 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -677,29 +677,35 @@ int32_t LP_reserved_msgs() { bits256 zero; int32_t n = 0; struct nn_pollfd pfd; memset(zero.bytes,0,sizeof(zero)); - portable_mutex_lock(&LP_reservedmutex); - while ( num_Reserved_msgs > 0 ) + while ( 1 ) { - memset(&pfd,0,sizeof(pfd)); - pfd.fd = LP_mypubsock; - pfd.events = NN_POLLOUT; - if ( nn_poll(&pfd,1,1) != 1 ) - break; - num_Reserved_msgs--; - //printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); + portable_mutex_lock(&LP_reservedmutex); + if ( num_Reserved_msgs > 0 ) + { + portable_mutex_unlock(&LP_reservedmutex); + memset(&pfd,0,sizeof(pfd)); + pfd.fd = LP_mypubsock; + pfd.events = NN_POLLOUT; + if ( nn_poll(&pfd,1,1) == 1 ) + { + portable_mutex_lock(&LP_reservedmutex); + num_Reserved_msgs--; + //printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); #ifdef __APPLE__ #endif - LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); - Reserved_msgs[num_Reserved_msgs] = 0; -/*#ifdef __APPLE__ - usleep(5000); -#else - usleep(3000); -#endif*/ + LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); + Reserved_msgs[num_Reserved_msgs] = 0; + /*#ifdef __APPLE__ + usleep(5000); + #else + usleep(3000); + #endif*/ + } + } + portable_mutex_unlock(&LP_reservedmutex); if ( ++n > 0 ) break; } - portable_mutex_unlock(&LP_reservedmutex); return(n); } From da27ffd3e14b06b30db4450fc122db458405bbab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:37:46 +0300 Subject: [PATCH 64/85] Test --- iguana/exchanges/LP_nativeDEX.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 531965a88..c0b495513 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -675,34 +675,31 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint int32_t LP_reserved_msgs() { - bits256 zero; int32_t n = 0; struct nn_pollfd pfd; + bits256 zero; int32_t flag,n = 0; struct nn_pollfd pfd; memset(zero.bytes,0,sizeof(zero)); while ( 1 ) { - portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs > 0 ) { - portable_mutex_unlock(&LP_reservedmutex); - memset(&pfd,0,sizeof(pfd)); - pfd.fd = LP_mypubsock; - pfd.events = NN_POLLOUT; - if ( nn_poll(&pfd,1,1) == 1 ) + flag = 0; + if ( LP_mypubsock >= 0 ) + { + memset(&pfd,0,sizeof(pfd)); + pfd.fd = LP_mypubsock; + pfd.events = NN_POLLOUT; + if ( nn_poll(&pfd,1,1) == 1 ) + flag = 1; + } else flag = 1; + if ( flag == 1 ) { portable_mutex_lock(&LP_reservedmutex); num_Reserved_msgs--; //printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]); -#ifdef __APPLE__ -#endif LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; - /*#ifdef __APPLE__ - usleep(5000); - #else - usleep(3000); - #endif*/ + portable_mutex_unlock(&LP_reservedmutex); } } - portable_mutex_unlock(&LP_reservedmutex); if ( ++n > 0 ) break; } From 90e35d64f5c2e79ef0f9043b61ac349352e6e1f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:44:28 +0300 Subject: [PATCH 65/85] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0831173e0..6a5890f54 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -274,9 +274,9 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); jaddstr(obj,"rmd160",hexstr); - for (j=0; ipubsecp); i++) + for (j=0; jpubsecp); j++) { - if ( pubp->pubsecp[i] != 0 ) + if ( pubp->pubsecp[j] != 0 ) { init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); jaddstr(obj,"pubsecp",hexstr2); From 031792e445819ef9c74612904a995db738539312 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:50:16 +0300 Subject: [PATCH 66/85] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_prices.c | 33 +++++++------------------------- iguana/exchanges/LP_signatures.c | 4 +++- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 75545f2d9..d054999ac 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -282,7 +282,7 @@ struct LP_pubkeyinfo bits256 pubkey; double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; uint32_t timestamp,istrusted,numerrors; - uint8_t rmd160[20],sig[76],pubsecp[33],siglen; + uint8_t rmd160[20],sig[65],pubsecp[33],siglen; }; int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 6a5890f54..0c2535e16 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -248,7 +248,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { - int32_t baseid,relid,i,j; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj; + int32_t baseid,relid; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj; obj = cJSON_CreateObject(); array = cJSON_CreateArray(); for (baseid=0; baseidpubkey); - for (i=0; irmd160); i++) - { - if ( pubp->rmd160[i] != 0 ) - { - init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); - jaddstr(obj,"rmd160",hexstr); - for (j=0; jpubsecp); j++) - { - if ( pubp->pubsecp[j] != 0 ) - { - init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); - jaddstr(obj,"pubsecp",hexstr2); - if ( pubp->siglen > 0 ) - { - init_hexbytes_noT(sigstr,pubp->sig,pubp->siglen); - jaddstr(obj,"sig",sigstr); - } - //printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); - //LP_pubkey_sigadd(obj,pubp->pubkey,pubp->rmd160,pubp->pubsecp); - break; - } - } - break; - } - } + init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); + jaddstr(obj,"rmd160",hexstr); + init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); + jaddstr(obj,"pubsecp",hexstr2); + init_hexbytes_noT(sigstr,pubp->sig,pubp->siglen); + jaddstr(obj,"sig",sigstr); jaddnum(obj,"timestamp",pubp->timestamp); jadd(obj,"asks",array); if ( pubp->istrusted != 0 ) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 4ffc77c36..59d778901 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -381,7 +381,7 @@ int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,ui int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { - int32_t i,siglen,len,retval=-1; uint8_t rmd160[20],checkrmd160[20],pubsecp[33],sig[128],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; + int32_t i,len,siglen,retval=-1; uint8_t rmd160[20],checkrmd160[20],pubsecp[33],sig[65],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr; if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) { decode_hex(rmd160,sizeof(rmd160),hexstr); @@ -406,6 +406,8 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) printf("%02x",pubp->rmd160[i]); memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp)); + memcpy(pubp->sig,sig,sizeof(pubp->sig)); + pubp->siglen = siglen; char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr); retval = 0; pubp->timestamp = (uint32_t)time(NULL); From 5f09dc71d4b94aefab97df054025e74fc89bb341 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:55:34 +0300 Subject: [PATCH 67/85] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index d054999ac..4766854ee 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -44,7 +44,7 @@ #define LP_PEERGOOD_ERRORDECAY 0.9 #define LP_SWAPSTEP_TIMEOUT 30 -#define LP_AUTOTRADE_TIMEOUT 10 +#define LP_AUTOTRADE_TIMEOUT 30 #define LP_MIN_TXFEE 10000 #define LP_MINVOL 20 #define LP_MINCLIENTVOL 50 From f2b97efb7bceedd739758963abd2a111bb875b25 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 17:59:09 +0300 Subject: [PATCH 68/85] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index dc9ca2ca5..622163521 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -548,7 +548,7 @@ stop()\n\ else { memset(zero.bytes,0,sizeof(zero)); -//printf("broadcast.(%s)\n",Broadcaststr); +printf("broadcast.(%s)\n",Broadcaststr); LP_reserved_msg(base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c0b495513..19f9ce125 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -126,7 +126,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); + } else printf("finished tradecommand (%s)\n",jprint(argjson,0)); //if ( OS_milliseconds()-millis > 100 ) // printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); From 36c3712cd6dcc94e6746179e04a54922f845d34e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 18:16:12 +0300 Subject: [PATCH 69/85] Test --- iguana/exchanges/LP_commands.c | 6 +++--- iguana/exchanges/LP_nativeDEX.c | 35 +++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 622163521..af6960311 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -530,7 +530,7 @@ stop()\n\ { if ( IAMLP != 0 ) { - if ( strcmp(method,"broadcast") == 0 ) + /*if ( strcmp(method,"broadcast") == 0 ) { bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) @@ -548,13 +548,13 @@ stop()\n\ else { memset(zero.bytes,0,sizeof(zero)); -printf("broadcast.(%s)\n",Broadcaststr); +//printf("broadcast.(%s)\n",Broadcaststr); LP_reserved_msg(base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); } - else if ( strcmp(method,"psock") == 0 ) + else*/ if ( strcmp(method,"psock") == 0 ) { if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 19f9ce125..855d762c8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -219,12 +219,39 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - portable_mutex_lock(&LP_commandmutex); - if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + if ( strcmp(method,"broadcast") == 0 ) { + bits256 zero; cJSON *reqjson; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; + if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) + { + Broadcaststr = jprint(reqjson,0); + if ( (cipherstr= jstr(reqjson,"cipher")) != 0 ) + { + cipherlen = (int32_t)strlen(cipherstr) >> 1; + if ( cipherlen <= sizeof(cipher) ) + { + decode_hex(cipher,cipherlen,cipherstr); + LP_queuesend(calc_crc32(0,&cipher[2],cipherlen-2),LP_mypubsock,"","",cipher,cipherlen); + } else retstr = clonestr("{\"error\":\"cipher too big\"}"); + } + else + { + memset(zero.bytes,0,sizeof(zero)); + printf("broadcast.(%s)\n",Broadcaststr); + LP_reserved_msg("","",zero,jprint(reqjson,0)); + } + retstr = clonestr("{\"result\":\"success\"}"); + } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); + } + else + { + portable_mutex_lock(&LP_commandmutex); + if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + { + } + portable_mutex_unlock(&LP_commandmutex); + //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); } - portable_mutex_unlock(&LP_commandmutex); - //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); free_json(argjson); } } From 016a2dfcfe511ea48562a435ab13ba1b4c2b5519 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 18:30:21 +0300 Subject: [PATCH 70/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 855d762c8..fd2127aff 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -219,7 +219,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( strcmp(method,"broadcast") == 0 ) + if ( (method= jstr(argjson,"method")) != 0 && strcmp(method,"broadcast") == 0 ) { bits256 zero; cJSON *reqjson; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) From 981fa12ffe72d8d05e79d297ddceb5af9d34fc35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 18:41:17 +0300 Subject: [PATCH 71/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fd2127aff..52a4f71d7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -237,10 +237,12 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, else { memset(zero.bytes,0,sizeof(zero)); - printf("broadcast.(%s)\n",Broadcaststr); + if ( (method= jstr(reqjson,"method")) != 0 && (strcmp(method,"request") == 0 || strcmp(method,"requested") == 0 || strcmp(method,"connect") == 0 || strcmp(method,"connected") == 0) ) + printf("broadcast.(%s)\n",Broadcaststr); LP_reserved_msg("","",zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); + free_json(reqjson); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); } else From f95fd27517ea0324a0055c272398129ab0557f8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 18:42:28 +0300 Subject: [PATCH 72/85] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ff1c5d286..9f10a8e28 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -596,7 +596,7 @@ int32_t LP_aliceonly(char *symbol) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg,*msg2,*retstr,str[65]; int32_t DEXselector = 0; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) { // LP_checksig @@ -726,9 +726,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo->T.lasttime = (uint32_t)time(NULL); printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); // LP_addsig - msg2 = clonestr(msg); + //msg2 = clonestr(msg); LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); - LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); + //LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); return(retval); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } From a9e47dad1438263487d829450c160cf46042d40f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 18:51:39 +0300 Subject: [PATCH 73/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 52a4f71d7..834637e93 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -728,8 +728,8 @@ int32_t LP_reserved_msgs() Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); } - } - if ( ++n > 0 ) + } else break; + if ( ++n > 100 ) break; } return(n); From a0cb92cd3ece409840cd9fd53b4245a94cfeb7fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:01:32 +0300 Subject: [PATCH 74/85] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 834637e93..f0331fd3e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -534,13 +534,14 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int nonz++; LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); peer->diduquery = 0; + LP_peer_pricesquery(peer); LP_utxos_sync(peer); + needpings++; } peer->lastpeers = now; } if ( peer->diduquery == 0 || peer->needping != 0 ) { - LP_peer_pricesquery(peer); LP_utxos_sync(peer); peer->diduquery = now; nonz++; From ba50fce5b88aaf6f469102a74aadb1d2793e4754 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:06:28 +0300 Subject: [PATCH 75/85] Test --- iguana/exchanges/LP_network.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 45307bedf..10d0cd7ca 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -242,6 +242,10 @@ printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg); peerind = (rand() % maxind); else peerind = 0; sock0 = LP_peerindsock(&peerind); + if ( (maxind= LP_numpeers()) > 0 ) + peerind = (rand() % maxind); + else peerind = 0; + sock1 = LP_peerindsock(&peerind); } if ( sock0 >= 0 ) _LP_sendqueueadd(crc32,sock0,msg,msglen,needack * peerind); From 0367785acd148e5c97df3ee689403bcf58198b54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:11:34 +0300 Subject: [PATCH 76/85] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 10d0cd7ca..76d082dda 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -87,7 +87,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { - static uint32_t crcs[64]; static unsigned long dup,total; + static uint32_t crcs[1024]; static unsigned long dup,total; int32_t i; *duplicatep = 0; if ( ind < 0 ) @@ -177,7 +177,7 @@ void queue_loop(void *ignore) printf("found.%u Q.%d err.%d match.%d\n",ptr->crc32,LP_Qenqueued,LP_Qerrors,LP_Qfound); flag = 1; } - else if ( 0 ) // too much beyond duplicate filter when network is busy + else //if ( 0 ) // too much beyond duplicate filter when network is busy { printf("couldnt find.%u peerind.%d Q.%d err.%d match.%d\n",ptr->crc32,ptr->peerind,LP_Qenqueued,LP_Qerrors,LP_Qfound); ptr->peerind++; From 7f5d9773e0fcfd8b54c9a6ca2c09e67b26d002e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:15:28 +0300 Subject: [PATCH 77/85] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f0331fd3e..76df501a3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -728,7 +728,8 @@ int32_t LP_reserved_msgs() LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); - } + usleep(5000); + } else break; } else break; if ( ++n > 100 ) break; From 1a0f4e57b886ff710fa6bd23dfbef754f83e72f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:22:41 +0300 Subject: [PATCH 78/85] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 76d082dda..ae9a8c8c9 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -167,7 +167,7 @@ void queue_loop(void *ignore) else flag = 1; } //else printf("sock not ready to send.%d\n",ptr->msglen); } - else if ( time(NULL) > ptr->starttime+13 ) + else if ( 0 && time(NULL) > ptr->starttime+13 ) { LP_crc32find(&duplicate,-1,ptr->crc32); if ( duplicate > 0 ) @@ -177,7 +177,7 @@ void queue_loop(void *ignore) printf("found.%u Q.%d err.%d match.%d\n",ptr->crc32,LP_Qenqueued,LP_Qerrors,LP_Qfound); flag = 1; } - else //if ( 0 ) // too much beyond duplicate filter when network is busy + else if ( 0 ) // too much beyond duplicate filter when network is busy { printf("couldnt find.%u peerind.%d Q.%d err.%d match.%d\n",ptr->crc32,ptr->peerind,LP_Qenqueued,LP_Qerrors,LP_Qfound); ptr->peerind++; From 4338727a2a53b04c7bae1c2cbb022952d0937949 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:24:00 +0300 Subject: [PATCH 79/85] Test --- iguana/exchanges/LP_network.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index ae9a8c8c9..1419c8b6e 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -126,6 +126,7 @@ int32_t LP_peerindsock(int32_t *peerindp) struct LP_peerinfo *peer,*tmp; int32_t peerind = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { + peerind++; if ( peer->errors < LP_MAXPEER_ERRORS && peer->pushsock >= 0 ) { if ( peerind < *peerindp ) @@ -134,7 +135,6 @@ int32_t LP_peerindsock(int32_t *peerindp) //printf("peerind.%d -> sock %d\n",peerind,peer->pushsock); return(peer->pushsock); } - peerind++; } return(-1); } @@ -158,9 +158,6 @@ void queue_loop(void *ignore) { if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); -#ifdef __APPLE__ -//else printf("%d %p qsent %u msglen.%d peerind.%d (%s)\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind,ptr->msg); -#endif ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); @@ -239,12 +236,12 @@ printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg); else { if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind); - else peerind = 0; + peerind = (rand() % maxind) + 1; + else peerind = 1; sock0 = LP_peerindsock(&peerind); if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind); - else peerind = 0; + peerind = (rand() % maxind) + 1; + else peerind = 1; sock1 = LP_peerindsock(&peerind); } if ( sock0 >= 0 ) From 449c193f5fdc9918b8a63ba145f1be866661c8c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:32:42 +0300 Subject: [PATCH 80/85] Test --- iguana/exchanges/LP_ordermatch.c | 9 ++++++--- iguana/exchanges/LP_signatures.c | 11 +++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9f10a8e28..5baf980a9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -363,7 +363,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ jaddnum(retjson,"quoteid",qp->R.quoteid); // LP_addsig char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,utxo->S.otherpubkey)); - LP_reserved_msg(base,rel,utxo->S.otherpubkey,jprint(retjson,1)); + LP_reserved_msg(base,rel,utxo->S.otherpubkey,jprint(retjson,0)); + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->desthash,jprint(retjson,0)); + free_json(retjson); retval = 0; } else printf("error launching swaploop\n"); } else printf("couldnt bind to any port %s\n",pairstr); @@ -722,13 +724,14 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, jaddbits256(retjson,"desthash",butxo->S.otherpubkey); jaddbits256(retjson,"pubkey",butxo->S.otherpubkey); jaddstr(retjson,"method","reserved"); - msg = jprint(retjson,1); + msg = jprint(retjson,0); butxo->T.lasttime = (uint32_t)time(NULL); printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); // LP_addsig //msg2 = clonestr(msg); LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); - //LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); + LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0)); + free_json(retjson); return(retval); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 59d778901..88476c59f 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -469,7 +469,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -487,7 +487,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddstr(reqjson,"method",method); jaddnum(reqjson,"timestamp",time(NULL)); msg = jprint(reqjson,1); - //msg2 = clonestr(msg); + msg2 = clonestr(msg); // LP_addsig printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); @@ -497,12 +497,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ Reserved_msgs[num_Reserved_msgs++] = msg; //Reserved_msgs[num_Reserved_msgs++] = msg2; } - else - { - //if ( 1 && strcmp(method,"request") == 0 ) - LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); - //else LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); - } + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2); portable_mutex_unlock(&LP_reservedmutex); } From 4e5d040e4d869af2c7443c00343e5afc1710183b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:36:47 +0300 Subject: [PATCH 81/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 76df501a3..5386f47b5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -126,7 +126,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - } else printf("finished tradecommand (%s)\n",jprint(argjson,0)); + } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); //if ( OS_milliseconds()-millis > 100 ) // printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); @@ -728,7 +728,7 @@ int32_t LP_reserved_msgs() LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); - usleep(5000); + usleep(1000); } else break; } else break; if ( ++n > 100 ) From f4564fe08e9ba48597b5f167c750e63f4b3469be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:41:22 +0300 Subject: [PATCH 82/85] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5386f47b5..ef0d40223 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -728,10 +728,10 @@ int32_t LP_reserved_msgs() LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); - usleep(1000); + usleep(5000); } else break; } else break; - if ( ++n > 100 ) + if ( ++n > 1 ) break; } return(n); From 5e8e617a2836b0b2f65de4114760d91a298879bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:47:25 +0300 Subject: [PATCH 83/85] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_prices.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ef0d40223..590de3511 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -518,7 +518,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 100000) == 0 ) + if ( (rand() % 10000) == 0 ) { peer->errors--; if ( peer->errors < LP_MAXPEER_ERRORS ) @@ -540,7 +540,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } peer->lastpeers = now; } - if ( peer->diduquery == 0 || peer->needping != 0 ) + if ( peer->needping != 0 ) { LP_utxos_sync(peer); peer->diduquery = now; @@ -554,7 +554,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( needpings != 0 || (counter % 10000) == 5 ) { nonz++; - //printf("needpings.%d send notify\n",needpings); + printf("needpings.%d send notify\n",needpings); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0c2535e16..2fd10dd8b 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -309,7 +309,7 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) timestamp = juint(obj,"timestamp"); if ( timestamp > now ) timestamp = now; - if ( timestamp > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) + if ( timestamp >= pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) { pubp->timestamp = timestamp; for (i=0; i Date: Sun, 22 Oct 2017 19:54:09 +0300 Subject: [PATCH 84/85] Test --- iguana/exchanges/LP_nativeDEX.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 590de3511..6e481e4b4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -378,8 +378,7 @@ void command_rpcloop(void *myipaddr) else usleep(10000); } else if ( IAMLP == 0 ) - usleep(1000); - else usleep(10); + usleep(100); } } @@ -728,7 +727,7 @@ int32_t LP_reserved_msgs() LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); - usleep(5000); + usleep(3000); } else break; } else break; if ( ++n > 1 ) @@ -924,10 +923,9 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) - usleep(10000); - else if ( IAMLP != 0 ) - usleep(10); - else usleep(10000); + usleep(1000); + else if ( IAMLP == 0 ) + usleep(1000); } } From a96358172fc3ba7220ab83ad17831ef5e146dc85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 19:57:25 +0300 Subject: [PATCH 85/85] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6e481e4b4..19f42f918 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -553,7 +553,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( needpings != 0 || (counter % 10000) == 5 ) { nonz++; - printf("needpings.%d send notify\n",needpings); + //printf("needpings.%d send notify\n",needpings); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 )