Browse Source

Merge pull request #738 from jl777/jl777

parallel command queue
also activate MoM and reduce utxo size to 0.0001 for notaries
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
d2f3cf86ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      iguana/dPoW.h
  2. 2
      iguana/dpow/dpow_rpc.c
  3. 2
      iguana/dpow/dpow_tx.c
  4. 2
      iguana/exchanges/DEXstats.h
  5. 24
      iguana/exchanges/LP_commands.c
  6. 4
      iguana/exchanges/LP_nativeDEX.c
  7. 3
      iguana/exchanges/LP_network.c
  8. 6
      iguana/exchanges/fasttest
  9. 3
      iguana/exchanges/getfee
  10. 2
      iguana/exchanges/mm.c
  11. 44
      iguana/exchanges/stats.c

4
iguana/dPoW.h

@ -23,8 +23,8 @@
#define DPOW_MIN_ASSETCHAIN_SIGS 11
//#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x1781
#define DPOW_UTXOSIZE 50000
#define DPOW_VERSION 0x1782
#define DPOW_UTXOSIZE 10000//50000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 600
#define DPOW_RATIFYDURATION (3600 * 24)

2
iguana/dpow/dpow_rpc.c

@ -230,7 +230,7 @@ int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp,bits256 MoM,uint32_t Mo
{
struct iguana_info *coin; char *retstr,*hexstr; cJSON *retjson; int32_t n=0; uint32_t paxwdcrc;
paxwdcrc = 0;
if ( Notaries_port != DPOW_SOCKPORT )
//if ( Notaries_port != DPOW_SOCKPORT )
{
n += iguana_rwbignum(1,&hex[n],sizeof(MoM),MoM.bytes);
n += iguana_rwnum(1,&hex[n],sizeof(MoMdepth),(uint32_t *)&MoMdepth);

2
iguana/dpow/dpow_tx.c

@ -232,7 +232,7 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
printf("%02x",extras[i]);
printf(" <- withdraw.%d %08x\n",n,paxwdcrc);
}
else if ( Notaries_port != DPOW_SOCKPORT && bp->MoMdepth > 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 ) // only testnets for now
else if ( bp->MoMdepth > 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 ) // Notaries_port != DPOW_SOCKPORT &&
{
n = dpow_paxpending(extras,&paxwdcrc,bp->MoM,bp->MoMdepth);
//n += iguana_rwbignum(1,&extras[n],sizeof(bp->MoM),bp->MoM.bytes);

2
iguana/exchanges/DEXstats.h

@ -928,7 +928,7 @@ char *stats_prices(char *symbol,char *dest,struct DEXstats_disp *prices,int32_t
#ifndef FROM_MARKETMAKER
#ifndef FROM_PRIVATEBET
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port)
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port)
{
char *method,*agent,*retstr,*source,*dest; struct tai T; uint32_t endtimestamp; struct DEXstats_disp prices[365]; int32_t leftdatenum,seconds,numdates;
if ( (method= jstr(argjson,"method")) == 0 )

24
iguana/exchanges/LP_commands.c

@ -32,7 +32,7 @@ char *LP_numutxos()
return(jprint(retjson,1));
}
char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
{
char *method,*userpass,*base,*rel,*coin,*passphrase,*retstr = 0; int32_t authenticated=0,changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
method = jstr(argjson,"method");
@ -168,6 +168,8 @@ timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\
opreturndecrypt(coin, txid, passphrase)\n\
getendpoint(port=5555)\n\
getfee(coin)\n\
sleep(seconds=60)\n\
listtransactions(coin, address, count=10, skip=0)\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}"));
@ -317,6 +319,13 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
LP_millistats_update(0);
return(clonestr("{\"result\":\"success\"}"));
}
else if ( strcmp(method,"sleep") == 0 )
{
if ( jint(argjson,"seconds") == 0 )
sleep(60);
else sleep(jint(argjson,"seconds"));
return(clonestr("{\"result\":\"success\",\"status\":\"feeling good after sleeping\"}"));
}
else if ( strcmp(method,"getprices") == 0 )
return(LP_prices());
else if ( strcmp(method,"getpeers") == 0 )
@ -584,6 +593,19 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
return(jprint(LP_address_balance(ptr,jstr(argjson,"address"),1),1));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"getfee") == 0 )
{
uint64_t txfee;
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
txfee = LP_txfeecalc(ptr,0,0);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"coin",coin);
jaddnum(retjson,"txfee",dstr(txfee));
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"electrum") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )

4
iguana/exchanges/LP_nativeDEX.c

@ -204,7 +204,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson
return(0);
if ( stats_JSONonly != 0 || LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",stats_JSONonly)) != 0 )
if ( (retstr= stats_JSON(ctx,0,myipaddr,pubsock,argjson,"127.0.0.1",stats_JSONonly)) != 0 )
{
//printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
//if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 &&
@ -425,7 +425,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
//portable_mutex_lock(&LP_commandmutex);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 )
if ( (retstr= stats_JSON(ctx,0,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 )
free(retstr);
}
//portable_mutex_unlock(&LP_commandmutex);

3
iguana/exchanges/LP_network.c

@ -445,7 +445,7 @@ void LP_commandQ_loop(void *ctx)
portable_mutex_unlock(&LP_commandQmutex);
if ( ptr->stats_JSONonly < 0 ) // broadcast passthrough
{
if ( 1 && ptr->responsesock >= 0 )
if ( ptr->responsesock >= 0 )
{
if ( (result= cJSON_Parse(ptr->msg)) != 0 )
{
@ -461,6 +461,7 @@ void LP_commandQ_loop(void *ctx)
}
else if ( (argjson= cJSON_Parse(ptr->msg)) != 0 )
{
//printf("deQ.(%s)\n",jprint(argjson,0));
if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 )
{
if ( ptr->retstrp != 0 )

6
iguana/exchanges/fasttest

@ -0,0 +1,6 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\",\"seconds\":10}" &
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}"
curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"getcoin\",\"coin\":\"REVS\",\"rel\":\"KMD\"}"

3
iguana/exchanges/getfee

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getfee\",\"coin\":\"BTC\"}"

2
iguana/exchanges/mm.c

@ -37,7 +37,7 @@ void PNACL_message(char *arg,...)
uint32_t DOCKERFLAG;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
#include "stats.c"
void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]);

44
iguana/exchanges/stats.c

@ -28,7 +28,7 @@
#define STATS_DESTDIR "/var/www/html"
#define STATS_DEST "/var/www/html/DEXstats.json"
#include "DEXstats.h"
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly,uint32_t queueid);
extern uint32_t DOCKERFLAG;
@ -331,6 +331,10 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
extern void *bitcoin_ctx();
extern int32_t IPC_ENDPOINT;
extern portable_mutex_t LP_gcmutex,LP_commandmutex;
extern struct rpcrequest_info *LP_garbage_collector;
uint16_t RPC_port;
static int32_t spawned,maxspawned;
char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
@ -530,7 +534,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
if ( (retstr= stats_JSON(ctx,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 )
if ( (retstr= stats_JSON(ctx,0,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 )
{
if ( (retitem= cJSON_Parse(retstr)) != 0 )
jaddi(retarray,retitem);
@ -543,7 +547,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
if ( (retstr= stats_JSON(ctx,myipaddr,-1,argjson,remoteaddr,port)) != 0 )
if ( (retstr= stats_JSON(ctx,0,myipaddr,-1,argjson,remoteaddr,port)) != 0 )
{
if ( (retitem= cJSON_Parse(retstr)) != 0 )
jaddi(retarray,retitem);
@ -557,7 +561,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
}
else
{
cJSON *arg; char *buf;
cJSON *arg; char *buf,*method; int32_t fastflag;
if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 )
{
arg = jobj(argjson,"params");
@ -567,16 +571,24 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
//printf("ARGJSON.(%s)\n",jprint(arg,0));
if ( userpass != 0 && jstr(arg,"userpass") == 0 )
jaddstr(arg,"userpass",userpass);
if ( (fastflag= jint(arg,"fast")) == 0 )
{
if ( (method= jstr(arg,"method")) != 0 && (strcmp(method,"orderbook") == 0 || strcmp(method,"portfolio") == 0) )
fastflag = 1;
}
if ( fastflag == 0 )
portable_mutex_lock(&LP_commandmutex);
#ifdef FROM_MARKETMAKER
if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 )
{
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
{
buf = jprint(arg,0);
//printf("Q command\n");
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf);
retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}");
} else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port);
} else retstr = stats_JSON(ctx,jint(arg,"fast"),"127.0.0.1",-1,arg,remoteaddr,port);
} else retstr = clonestr("{\"error\":\"invalid remote method\"}");
#else
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
@ -584,8 +596,10 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
buf = jprint(arg,0);
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf);
} else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
} else retstr = stats_JSON(ctx,jint(arg,"fast"),myipaddr,-1,arg,remoteaddr,port);
#endif
if ( fastflag == 0 )
portable_mutex_unlock(&LP_commandmutex);
}
free_json(argjson);
}
@ -625,13 +639,8 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen)
return(recvlen);
}
uint16_t RPC_port;
extern portable_mutex_t LP_commandmutex,LP_gcmutex;
extern struct rpcrequest_info *LP_garbage_collector;
void LP_rpc_processreq(void *_ptr)
{
static uint32_t spawned,maxspawned;
char filetype[128],content_type[128];
int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len;
char helpname[512],remoteaddr[64],*buf,*retstr,space[8192],space2[32786],*jsonbuf; struct rpcrequest_info *req = _ptr;
@ -641,11 +650,11 @@ void LP_rpc_processreq(void *_ptr)
sock = req->sock;
recvlen = flag = 0;
retstr = 0;
//space = calloc(1,size);
jsonbuf = calloc(1,size);
//printf("alloc jsonbuf.%p\n",jsonbuf);
remains = size-1;
buf = jsonbuf;
if ( spawned < 0 )
spawned = 0;
spawned++;
if ( spawned > maxspawned )
{
@ -708,9 +717,7 @@ void LP_rpc_processreq(void *_ptr)
if ( recvlen > 0 )
{
jsonflag = postflag = 0;
//portable_mutex_lock(&LP_commandmutex);
retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,req->port);
//portable_mutex_unlock(&LP_commandmutex);
if ( filetype[0] != 0 )
{
static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize;
@ -795,6 +802,7 @@ void LP_rpc_processreq(void *_ptr)
//printf("free req.%p\n",req);
free(req);
}
if ( spawned > 0 )
spawned--;
}
@ -854,14 +862,14 @@ void stats_rpcloop(void *args)
continue;
}
req = calloc(1,sizeof(*req));
//printf("alloc req.%p\n",req);
//printf("LP_rpc_processreq req.%p\n",req);
req->sock = sock;
req->ipbits = ipbits;
req->port = port;
if ( spawned > 0 )
LP_rpc_processreq(req);
continue;
// this might lead to "cant open file errors"
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
else if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
printf("error launching rpc handler on port %d, retval.%d\n",port,retval);
LP_rpc_processreq(req);

Loading…
Cancel
Save