Skip to content

Commit

Permalink
Performance improments
Browse files Browse the repository at this point in the history
  • Loading branch information
jl777 committed Mar 1, 2018
1 parent aeb841e commit 39fe1f0
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_NXT.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void NXTventure_liquidation()
cJSON *LP_NXT_redeems()
{
char url[1024],*retstr,*recv,*method,*msgstr,assetname[128]; uint64_t totals[2][sizeof(assetids)/sizeof(*assetids)],mult,txnum,assetid,qty; int32_t i,ind,numtx=0,past_marker=0; cJSON *item,*attach,*decjson,*array,*msgjson,*encjson,*retjson=0;
uint64_t txnum_marker = calc_nxt64bits("4114304329372848717"); // 8537615468620726612"); // set to most recent processed
uint64_t txnum_marker = calc_nxt64bits("2675953695997905027"); // 4114304329372848717, 8537615468620726612"); // set to most recent processed
uint64_t txnum_marker2 = calc_nxt64bits("7256847492742571143"); // dont change, end marker
char *passphrase = "";
char *account = "NXT-MRBN-8DFH-PFMK-A4DBM";
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_RTmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void LP_RTmetrics_swapsinfo(char *refbase,char *refrel,cJSON *swaps,int32_t nums
quoteid = juint(item,"quoteid");
LP_RTmetrics_pendingswap(srcpub,LP_kmdvalue(base,basesatoshis));
LP_RTmetrics_pendingswap(destpub,LP_kmdvalue(rel,relsatoshis));
if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid,0)) != 0 ) // no need for this
if ( 0 && (retstr= basilisk_swapentry(1,requestid,quoteid,0)) != 0 ) // no need for this
{
if ( (swapjson= cJSON_Parse(retstr)) != 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
uint32_t requestid,quoteid;
if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 )
return(basilisk_swapentry(requestid,quoteid,1));
return(basilisk_swapentry(jint(argjson,"fast"),requestid,quoteid,1));
else if ( coin[0] != 0 )
return(basilisk_swapentries(coin,0,jint(argjson,"limit")));
else if ( base[0] != 0 && rel[0] != 0 )
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid);
int32_t LP_txheight(struct iguana_info *coin,bits256 txid);
int32_t LP_numpeers();
double LP_CMCbtcprice(double *price_usdp,char *symbol);
char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag);
char *basilisk_swapentry(int32_t fastflag,uint32_t requestid,uint32_t quoteid,int32_t forceflag);
int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance);
int32_t LP_address_utxoadd(int32_t skipsearch,uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
void LP_smartutxos_push(struct iguana_info *coin);
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_instantdex.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob)
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
if ( (swapstr= basilisk_swapentry(sp->Q.R.requestid,sp->Q.R.quoteid,0)) != 0 )
if ( (swapstr= basilisk_swapentry(1,sp->Q.R.requestid,sp->Q.R.quoteid,0)) != 0 )
{
if ( (swapjson= cJSON_Parse(swapstr)) != 0 )
{
Expand Down
7 changes: 4 additions & 3 deletions iguana/exchanges/LP_nativeDEX.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void LP_millistats_update(struct LP_millistats *mp)
}

#include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex,LP_commandQmutex,LP_blockinit_mutex,LP_pendswap_mutex;
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex,LP_commandQmutex,LP_blockinit_mutex,LP_pendswap_mutex,LP_listmutex;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
Expand Down Expand Up @@ -961,7 +961,7 @@ void LP_swapsloop(void *ctx)
char *retstr; cJSON *retjson; uint32_t requestid,quoteid; int32_t nonz; struct LP_pendswap *sp,*tmp;
strcpy(LP_swapsloop_stats.name,"LP_swapsloop");
LP_swapsloop_stats.threshold = 605000.;
if ( (retstr= basilisk_swapentry(0,0,1)) != 0 )
if ( (retstr= basilisk_swapentry(0,0,0,1)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
Expand Down Expand Up @@ -1342,6 +1342,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_commandQmutex);
portable_mutex_init(&LP_blockinit_mutex);
portable_mutex_init(&LP_pendswap_mutex);
portable_mutex_init(&LP_listmutex);
myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32
#ifndef FROM_JS
Expand Down Expand Up @@ -1592,7 +1593,7 @@ void LP_fromjs_iter()
{
LP_notify_pubkeys(ctx,LP_mypubsock);
LP_privkey_updates(ctx,LP_mypubsock,0);
if ( (retstr= basilisk_swapentry(0,0,0)) != 0 )
if ( (retstr= basilisk_swapentry(0,0,0,0)) != 0 )
free(retstr);
}
}
Expand Down
4 changes: 4 additions & 0 deletions iguana/exchanges/LP_ordermatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_bobloop,(void *)swap) == 0 )
{
reqjson = LP_quotejson(qp);
LP_swapsfp_update(qp->R.requestid,qp->R.quoteid);
jaddstr(reqjson,"method","connected");
jaddstr(reqjson,"pair",pairstr);
if ( (kmdcoin= LP_coinfind("KMD")) != 0 )
Expand Down Expand Up @@ -677,6 +678,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
{
retjson = LP_quotejson(qp);
jaddstr(retjson,"result","success");
LP_swapsfp_update(qp->R.requestid,qp->R.quoteid);
//jaddnum(retjson,"requestid",qp->R.requestid);
//jaddnum(retjson,"quoteid",qp->R.quoteid);
}
Expand Down Expand Up @@ -1370,6 +1372,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
}
if ( strcmp(method,"request") == 0 ) // bob
{
if ( LP_Alicemaxprice != 0. )
return(retval);
bestprice = LP_bob_competition(&counter,aliceid,qprice,-1);
if ( Qtrades == 0 )//|| (bits256_cmp(Q.srchash,G.LP_mypub25519) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0) )
LP_trades_gotrequest(ctx,&Q,&Q2,jstr(argjson,"pair"));
Expand Down
22 changes: 11 additions & 11 deletions iguana/exchanges/LP_remember.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap)
return(numspent);
}

cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly)
cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly)
{
static void *ctx;
struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512],bobtomic[128],alicetomic[128],bobstr[65],alicestr[65]; cJSON *item,*txoutobj,*retjson; bits256 rev,revAm,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize;
Expand Down Expand Up @@ -1167,14 +1167,14 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",rswap.alicecoin,alice->inactive,rswap.bobcoin,bob->inactive);
return(cJSON_Parse("{\"error\":\"inactive bob or alice coin\"}"));
}
portable_mutex_lock(&LP_swaplistmutex);
//printf("src.(Adest %s, Bdest %s), dest.(Adest %s, Bdest %s)\n",srcAdest,srcBdest,destAdest,destBdest);
//printf("iambob.%d finishedflag.%d %s %.8f txfee, %s %.8f txfee\n",rswap.iambob,rswap.finishedflag,rswap.alicecoin,dstr(rswap.Atxfee),rswap.bobcoin,dstr(rswap.Btxfee));
//printf("privAm.(%s) %p/%p\n",bits256_str(str,rswap.privAm),Adest,AAdest);
//printf("privBn.(%s) %p/%p\n",bits256_str(str,rswap.privBn),Bdest,ABdest);
if ( rswap.finishedflag == 0 && rswap.bobcoin[0] != 0 && rswap.alicecoin[0] != 0 )
if ( fastflag == 0 && rswap.finishedflag == 0 && rswap.bobcoin[0] != 0 && rswap.alicecoin[0] != 0 )
{
//printf("ALICE.(%s) 1st refht %s <- %d, scan %d %d\n",rswap.Adestaddr,alice->symbol,alice->firstrefht,alice->firstscanht,alice->lastscanht);
portable_mutex_lock(&LP_swaplistmutex);
//printf("ALICE.(%s) 1st refht %s <- %d, scan %d %d\n",rswap.Adestaddr,alice->symbol,alice->firstrefht,alice->firstscanht,alice->lastscanht);
//printf("BOB.(%s) 1st refht %s <- %d, scan %d %d\n",rswap.destaddr,bob->symbol,bob->firstrefht,bob->firstscanht,bob->lastscanht);
LP_rswap_checktx(&rswap,rswap.alicecoin,BASILISK_ALICEPAYMENT);
LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBPAYMENT);
Expand Down Expand Up @@ -1429,6 +1429,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf("bobrefund's time %u vs expiration %u\n",(uint32_t)time(NULL),rswap.expiration);
}
}
portable_mutex_unlock(&LP_swaplistmutex);
}
//printf("finish.%d iambob.%d REFUND %d %d %d %d\n",finishedflag,iambob,sentflags[BASILISK_BOBREFUND] == 0,sentflags[BASILISK_BOBDEPOSIT] != 0,bits256_nonz(txids[BASILISK_BOBDEPOSIT]) != 0,bits256_nonz(depositspent) == 0);
if ( rswap.sentflags[BASILISK_ALICESPEND] != 0 || rswap.sentflags[BASILISK_BOBRECLAIM] != 0 )
Expand Down Expand Up @@ -1487,7 +1488,6 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(item);
item = 0;
}
portable_mutex_unlock(&LP_swaplistmutex);
return(item);
}

Expand Down Expand Up @@ -1526,7 +1526,7 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forc
if ( origrequestid != 0 && origquoteid != 0 )
{
//printf("orig req.%u q.%u\n",origrequestid,origquoteid);
if ( (item= basilisk_remember(KMDtotals,BTCtotals,origrequestid,origquoteid,forceflag,0)) != 0 )
if ( (item= basilisk_remember(0,KMDtotals,BTCtotals,origrequestid,origquoteid,forceflag,0)) != 0 )
jaddi(array,item);
//printf("got.(%s)\n",jprint(item,0));
}
Expand Down Expand Up @@ -1568,7 +1568,7 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forc
{
if ( count < sizeof(ridqids)/sizeof(*ridqids) )
ridqids[count++] = ridqid;
if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid,0,pendingonly)) != 0 )
if ( (item= basilisk_remember(0,KMDtotals,BTCtotals,requestid,quoteid,0,pendingonly)) != 0 )
jaddi(array,item);
}
}
Expand Down Expand Up @@ -1601,12 +1601,12 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forc
return(jprint(retjson,1));
}

char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag)
char *basilisk_swapentry(int32_t fastflag,uint32_t requestid,uint32_t quoteid,int32_t forceflag)
{
cJSON *item; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS];
memset(KMDtotals,0,sizeof(KMDtotals));
memset(BTCtotals,0,sizeof(BTCtotals));
if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid,forceflag,0)) != 0 )
if ( (item= basilisk_remember(fastflag,KMDtotals,BTCtotals,requestid,quoteid,forceflag,0)) != 0 )
return(jprint(item,1));
else return(clonestr("{\"error\":\"cant find requestid-quoteid\"}"));
}
Expand Down Expand Up @@ -1641,7 +1641,7 @@ char *LP_recent_swaps(int32_t limit)
item = cJSON_CreateArray();
jaddinum(item,requestid);
jaddinum(item,quoteid);
if ( (retstr= basilisk_swapentry(requestid,quoteid,0)) != 0 )
if ( (retstr= basilisk_swapentry(1,requestid,quoteid,0)) != 0 )
{
if ( (swapjson= cJSON_Parse(retstr)) != 0 )
{
Expand Down Expand Up @@ -1783,7 +1783,7 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit)
//printf("j.%d count.%d %u %u ridqid.%16llx\n",j,count,requestid,quoteid,(long long)ridqid);
if ( j == count )
{
if ( (retstr2= basilisk_swapentry(requestid,quoteid,0)) != 0 )
if ( (retstr2= basilisk_swapentry(1,requestid,quoteid,0)) != 0 )
{
if ( (swapjson= cJSON_Parse(retstr2)) != 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid)
return(clonestr("{\"result\":\"success\"}"));
}
}
if ( (swapstr= basilisk_swapentry(requestid,quoteid,0)) != 0 )
if ( (swapstr= basilisk_swapentry(1,requestid,quoteid,0)) != 0 )
{
if ( (swapjson= cJSON_Parse(swapstr)) != 0 )
{
Expand Down
16 changes: 9 additions & 7 deletions iguana/exchanges/LP_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,10 @@ int32_t LP_sendwait(char *statename,int32_t timeout,int32_t pairsock,struct basi
return(retval);
}

void LP_swapsfp_update(struct basilisk_request *rp)
void LP_swapsfp_update(uint32_t requestid,uint32_t quoteid)
{
static FILE *swapsfp;
portable_mutex_lock(&LP_listmutex);
if ( swapsfp == 0 )
{
char fname[512];
Expand All @@ -568,10 +569,11 @@ void LP_swapsfp_update(struct basilisk_request *rp)
}
if ( swapsfp != 0 )
{
fwrite(&rp->requestid,1,sizeof(rp->requestid),swapsfp);
fwrite(&rp->quoteid,1,sizeof(rp->quoteid),swapsfp);
fwrite(&requestid,1,sizeof(requestid),swapsfp);
fwrite(&quoteid,1,sizeof(quoteid),swapsfp);
fflush(swapsfp);
}
portable_mutex_unlock(&LP_listmutex);
}

struct basilisk_rawtx *LP_swapdata_rawtx(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx)
Expand Down Expand Up @@ -784,7 +786,7 @@ uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int
}
while ( expiration == 0 || time(NULL) < expiration )
{
if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 )
if ( (retstr= basilisk_swapentry(0,requestid,quoteid,1)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
Expand All @@ -809,7 +811,7 @@ uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int
if ( retjson != 0 )
{
free_json(retjson);
if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 )
if ( (retstr= basilisk_swapentry(0,requestid,quoteid,1)) != 0 )
{
printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>\nSWAP completed! %u-%u %s\n",requestid,quoteid,retstr);
free(retstr);
Expand Down Expand Up @@ -853,7 +855,7 @@ void LP_bobloop(void *_swap)
swap->bobrefund.utxotxid = swap->bobdeposit.I.signedtxid;
basilisk_bobdeposit_refund(swap,swap->I.putduration);
//printf("depositlen.%d\n",swap->bobdeposit.I.datalen);
LP_swapsfp_update(&swap->I.req);
//LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL);
if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_otherfee) < 0 )
{
Expand Down Expand Up @@ -937,7 +939,7 @@ void LP_aliceloop(void *_swap)
printf("basilisk_alicetxs error\n");
else
{
LP_swapsfp_update(&swap->I.req);
//LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL);
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 )
printf("error sending alicefee\n");
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_tradebots.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void LP_tradebot_pauseall()
void LP_tradebot_updatestats(struct LP_tradebot *bot,struct LP_tradebot_trade *tp)
{
char *swapstr,*status; int32_t flag; cJSON *swapjson;
if ( (swapstr= basilisk_swapentry(tp->requestid,tp->quoteid,1)) != 0 )
if ( (swapstr= basilisk_swapentry(0,tp->requestid,tp->quoteid,1)) != 0 )
{
flag = 0;
if ( (swapjson= cJSON_Parse(swapstr)) != 0 )
Expand Down

0 comments on commit 39fe1f0

Please sign in to comment.