From f82618ac752363aeb9e7e7823709c7c073e37e69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 08:36:46 -0300 Subject: [PATCH 01/15] test --- iguana/dpow/dpow_network.c | 142 ++++++++++++++++++++++++++++--------- iguana/dpow/dpow_tx.c | 31 ++++---- iguana/iguana777.h | 1 + 3 files changed, 128 insertions(+), 46 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 5feffb787..5c0264ad8 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -13,18 +13,42 @@ * * ******************************************************************************/ +// 1. add rpc hooks, debug +// 2. sig validate in fsm + struct dex_nanomsghdr { uint32_t size,datalen,crc32; uint8_t version0,version1,packet[]; } PACKED; +void dex_init(struct supernet_info *myinfo) +{ + strcpy(myinfo->dexseed_ipaddr,"78.47.196.146"); + myinfo->dexipbits[0] = (uint32_t)calc_ipbits(myinfo->dexseed_ipaddr); + myinfo->numdexipbits = 1; + portable_mutex_init(&myinfo->dexmutex); +} + char *nanomsg_tcpname(char *str,char *ipaddr,uint16_t port) { sprintf(str,"tcp://%s:%u",ipaddr,port); return(str); } +static int _increasing_ipbits(const void *a,const void *b) +{ +#define uint32_a (*(uint32_t *)a) +#define uint32_b (*(uint32_t *)b) + if ( uint32_b > uint32_a ) + return(-1); + else if ( uint32_b < uint32_a ) + return(1); + return(0); +#undef uint32_a +#undef uint32_b +} + void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size) { printf("DEX_PACKET.[%d]\n",size); @@ -32,27 +56,74 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t void dex_reqsend(struct supernet_info *myinfo,uint8_t *data,int32_t datalen) { - struct dex_nanomsghdr *dexp; char ipaddr[64]; int32_t size,recvbytes,sentbytes = 0; uint32_t crc32,*retptr; - crc32 = calc_crc32(0,data,datalen); - size = (int32_t)(sizeof(*dexp) + datalen); - dexp = calloc(1,size); // endian dependent! - dexp->size = size; - dexp->datalen = datalen; - dexp->crc32 = crc32; - dexp->version0 = DEX_VERSION & 0xff; - dexp->version1 = (DEX_VERSION >> 8) & 0xff; - memcpy(dexp->packet,data,datalen); - sentbytes = nn_send(myinfo->reqsock,dexp,size,0); - if ( (recvbytes= nn_recv(myinfo->reqsock,&retptr,NN_MSG,0)) >= 0 ) - { - expand_ipbits(ipaddr,*retptr); - printf("req returned.[%d] %08x %s\n",recvbytes,*retptr,ipaddr); - // add to req list - // subscribe to 1st 3, drop 1st 25% of time - nn_freemsg(retptr); + struct dex_nanomsghdr *dexp; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0; uint32_t crc32,*retptr,ipbits; + if ( myinfo->reqsock < 0 && (myinfo->reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) + { + if ( nn_connect(myinfo->reqsock,nanomsg_tcpname(str,myinfo->dexseed_ipaddr,REP_SOCK)) < 0 ) + { + nn_close(myinfo->reqsock); + myinfo->reqsock = -1; + } + else + { + if ( myinfo->subsock < 0 && (myinfo->subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) + { + if ( nn_connect(myinfo->subsock,nanomsg_tcpname(str,myinfo->dexseed_ipaddr,PUB_SOCK)) < 0 ) + { + nn_close(myinfo->reqsock); + myinfo->reqsock = -1; + nn_close(myinfo->subsock); + myinfo->subsock = -1; + } + else + { + timeout = 1000; + nn_setsockopt(myinfo->reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(myinfo->subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(myinfo->subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); + } + } + } + } + if ( myinfo->reqsock >= 0 ) + { + crc32 = calc_crc32(0,data,datalen); + size = (int32_t)(sizeof(*dexp) + datalen); + dexp = calloc(1,size); // endian dependent! + dexp->size = size; + dexp->datalen = datalen; + dexp->crc32 = crc32; + dexp->version0 = DEX_VERSION & 0xff; + dexp->version1 = (DEX_VERSION >> 8) & 0xff; + memcpy(dexp->packet,data,datalen); + sentbytes = nn_send(myinfo->reqsock,dexp,size,0); + if ( (recvbytes= nn_recv(myinfo->reqsock,&retptr,NN_MSG,0)) >= 0 ) + { + portable_mutex_lock(&myinfo->dexmutex); + ipbits = *retptr; + expand_ipbits(ipaddr,ipbits); + printf("req returned.[%d] %08x %s\n",recvbytes,*retptr,ipaddr); + n = myinfo->numdexipbits; + for (i=0; idexipbits[i] ) + break; + if ( i == n && n < 64 ) + { + myinfo->dexipbits[n++] = ipbits; + qsort(myinfo->dexipbits,n,sizeof(uint32_t),_increasing_ipbits); + if ( (myinfo->numdexipbits= n) < 3 ) + { + if ( myinfo->subsock >= 0 ) + nn_connect(myinfo->subsock,nanomsg_tcpname(str,ipaddr,PUB_SOCK)); + } + } + portable_mutex_unlock(&myinfo->dexmutex); + nn_connect(myinfo->reqsock,nanomsg_tcpname(str,ipaddr,REP_SOCK)); + nn_freemsg(retptr); + } + free(dexp); + printf("DEXREQ.[%d] crc32.%08x datalen.%d sent.%d\n",size,dexp->crc32,datalen,sentbytes); } - free(dexp); - printf("DEXREQ.[%d] crc32.%08x datalen.%d sent.%d\n",size,dexp->crc32,datalen,sentbytes); } int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) @@ -89,7 +160,23 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp return(-1); } -// poll sub sockets +void dex_subsock_poll(struct supernet_info *myinfo) +{ + int32_t size,n=0; struct dex_nanomsghdr *dexp; + while ( (size= nn_recv(myinfo->subsock,&dexp,NN_MSG,0)) >= 0 ) + { + n++; + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + { + printf("SUBSOCK.%08x",dexp->crc32); + dex_packet(myinfo,dexp,size); + } + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; + if ( size == 0 || n++ > 100 ) + break; + } +} #if ISNOTARYNODE @@ -117,19 +204,6 @@ struct dpow_block *dpow_heightfind(struct supernet_info *myinfo,struct dpow_info int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t myind,uint32_t deprec,int32_t src_or_dest,int32_t useratified); void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,int32_t myind,int32_t src_or_dest,int8_t bestk,uint64_t bestmask,uint8_t pubkeys[64][33],int32_t numratified); -static int _increasing_ipbits(const void *a,const void *b) -{ -#define uint32_a (*(uint32_t *)a) -#define uint32_b (*(uint32_t *)b) - if ( uint32_b > uint32_a ) - return(-1); - else if ( uint32_b < uint32_a ) - return(1); - return(0); -#undef uint32_a -#undef uint32_b -} - int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *ipaddr) { char str[512]; uint32_t ipbits,*ptr; int32_t i,iter,n,retval = -1; diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 4c5fe3bf5..c86c189b5 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -387,7 +387,7 @@ cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uin void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,char *rawtx,cJSON *vins,int8_t bestk,uint64_t bestmask,int32_t myind,int32_t src_or_dest) { - int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr; cJSON *signobj,*sobj,*txobj2,*item,*vin; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; + int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr,*pubstr; cJSON *signobj,*sobj,*txobj2,*item,*vin; uint8_t pubkey33[33]; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; if ( bestk < 0 ) return; for (j=0; j 32 ) { - //printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,jprint(item,0),j); - cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; - if ( src_or_dest != 0 ) - bp->destsigsmasks[bestk] |= (1LL << myind); - else bp->srcsigsmasks[bestk] |= (1LL << myind); - decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); - ep->masks[src_or_dest][bestk] = bestmask; - ep->beacon = bp->beacon; - dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); - retval = 0; - break; + if ( (pubstr= jstr(item,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) + { + decode_hex(pubkey33,33,&pubstr[1]); + if ( memcmp(pubkey33,dp->minerkey33,33) == 0 ) + { + printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,jprint(item,0),j); + cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; + if ( src_or_dest != 0 ) + bp->destsigsmasks[bestk] |= (1LL << myind); + else bp->srcsigsmasks[bestk] |= (1LL << myind); + decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); + ep->masks[src_or_dest][bestk] = bestmask; + ep->beacon = bp->beacon; + dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); + retval = 0; + break; + } + } } // else printf("notmine.(%s)\n",jprint(item,0)); } } else printf("no vin[] (%s)\n",jprint(txobj2,0)); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 2f845b6ab..40a731585 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -106,6 +106,7 @@ struct supernet_info struct liquidity_info linfos[64]; struct komodo_notaries NOTARY; char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t dpowmutex; + char dexseed_ipaddr[64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; // compatibility bits256 pangea_category,instantdex_category; uint8_t logs[256],exps[510]; From f98b20c6cd9e9749a176a21608ec3f5bc38a581b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:05:18 -0300 Subject: [PATCH 02/15] test --- iguana/dpow/dpow_rpc.c | 30 +++++++++++++++++++++++++++++- iguana/iguana_notary.c | 32 +++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 94c720493..d3ffaa66a 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -141,7 +141,6 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin, return(blockhash); } - cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash) { char buf[128],str[65],*retstr=0; cJSON *json = 0; @@ -169,6 +168,35 @@ cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits2 return(json); } +int32_t dpow_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address) +{ + char buf[128],*retstr=0; cJSON *ismine,*json = 0; int32_t retval = -1; + if ( coin->FULLNODE < 0 ) + { + sprintf(buf,"\"%s\"",address); + retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"validateaddress",buf); + usleep(10000); + } + else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 ) + { + retstr = bitcoinrpc_validateaddress(myinfo,coin,0,0,address); + } + else + { + return(0); + } + if ( retstr != 0 ) + { + json = cJSON_Parse(retstr); + if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 ) + retval = 1; + else retval = 0; + free(retstr); + + } + return(retval); +} + cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout) { char buf[128],str[65],*retstr=0; cJSON *json = 0; diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 9ed4d49b1..5f5721307 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -213,7 +213,7 @@ void dpow_addresses() TWO_STRINGS(iguana,dpow,symbol,pubkey) { - char *retstr; int32_t i; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows]; + char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows]; if ( myinfo->NOTARY.RELAYID < 0 ) { if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(myinfo->ipaddr),myinfo->myaddr.persistent)) != 0 ) @@ -246,15 +246,9 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey) if ( strcmp(symbol,myinfo->DPOWS[i].symbol) == 0 ) return(clonestr("{\"error\":\"cant dPoW same coin again\"}")); } - char tmp[67]; - safecopy(tmp,pubkey,sizeof(tmp)); - decode_hex(dp->minerkey33,33,tmp); - for (i=0; i<33; i++) - printf("%02x",dp->minerkey33[i]); - printf(" DPOW with pubkey.(%s)\n",tmp); - if ( bitcoin_pubkeylen(dp->minerkey33) <= 0 ) - return(clonestr("{\"error\":\"illegal pubkey\"}")); strcpy(dp->symbol,symbol); + src = iguana_coinfind(dp->symbol); + dest = iguana_coinfind(dp->dest); if ( strcmp(dp->symbol,"KMD") == 0 ) { strcpy(dp->dest,"BTC"); @@ -267,14 +261,30 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey) } if ( dp->srcconfirms > DPOW_FIFOSIZE ) dp->srcconfirms = DPOW_FIFOSIZE; + if ( src == 0 || dest == 0 ) + return(clonestr("{\"error\":\"source coin or dest coin not there\"}")); + char tmp[67]; + safecopy(tmp,pubkey,sizeof(tmp)); + decode_hex(dp->minerkey33,33,tmp); + bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33); + srcvalid = dpow_validateaddress(myinfo,src,srcaddr); + bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33); + destvalid = dpow_validateaddress(myinfo,dest,destaddr); + for (i=0; i<33; i++) + printf("%02x",dp->minerkey33[i]); + printf(" DPOW with pubkey.(%s) %s.valid%d -> %s.valid%d\n",tmp,srcaddr,srcvalid,destaddr,destvalid); + if ( srcvalid <= 0 || destvalid <= 0 ) + return(clonestr("{\"error\":\"source address or dest address has no privkey, importprivkey\"}")); + if ( bitcoin_pubkeylen(dp->minerkey33) <= 0 ) + return(clonestr("{\"error\":\"illegal pubkey\"}")); if ( dp->blocks == 0 ) { dp->maxblocks = 100000; dp->blocks = calloc(dp->maxblocks,sizeof(*dp->blocks)); } - myinfo->numdpows++; + if ( myinfo->numdpows++ == 0 ) + portable_mutex_init(&dp->mutex); PAX_init(); - portable_mutex_init(&dp->mutex); //printf(">>>>>>>>>>>>>>> call paxpending\n"); //uint8_t buf[32768]; //dpow_paxpending(buf); From 6e9db3f88e3e4fed512445e147400dbb249584f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:21:57 -0300 Subject: [PATCH 03/15] test --- iguana/dPoW.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index b8e316cdd..ea781d664 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,10 +19,10 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 11 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 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 0x0768 +#define DPOW_VERSION 0x0769 #define DPOW_UTXOSIZE 10000 #define DPOW_MINOUTPUT 6000 #define DPOW_DURATION 300 From 35917b6dcafefad07c8df2eede005230f0cf1767 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:41:20 -0300 Subject: [PATCH 04/15] test --- iguana/iguana_notary.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 5f5721307..4a9d94362 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -247,8 +247,6 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey) return(clonestr("{\"error\":\"cant dPoW same coin again\"}")); } strcpy(dp->symbol,symbol); - src = iguana_coinfind(dp->symbol); - dest = iguana_coinfind(dp->dest); if ( strcmp(dp->symbol,"KMD") == 0 ) { strcpy(dp->dest,"BTC"); @@ -261,6 +259,8 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey) } if ( dp->srcconfirms > DPOW_FIFOSIZE ) dp->srcconfirms = DPOW_FIFOSIZE; + src = iguana_coinfind(dp->symbol); + dest = iguana_coinfind(dp->dest); if ( src == 0 || dest == 0 ) return(clonestr("{\"error\":\"source coin or dest coin not there\"}")); char tmp[67]; From 232ee6153971a597112e93dedfb2dfe8eb769776 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:45:39 -0300 Subject: [PATCH 05/15] test --- iguana/dPoW.h | 2 +- iguana/iguana_notary.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index ea781d664..2800bc876 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 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 0x0769 diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 4a9d94362..4747617c5 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -272,7 +272,7 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey) destvalid = dpow_validateaddress(myinfo,dest,destaddr); for (i=0; i<33; i++) printf("%02x",dp->minerkey33[i]); - printf(" DPOW with pubkey.(%s) %s.valid%d -> %s.valid%d\n",tmp,srcaddr,srcvalid,destaddr,destvalid); + printf(" DPOW with pubkey.(%s) %s.valid%d %s -> %s %s.valid%d\n",tmp,srcaddr,srcvalid,dp->symbol,dp->dest,destaddr,destvalid); if ( srcvalid <= 0 || destvalid <= 0 ) return(clonestr("{\"error\":\"source address or dest address has no privkey, importprivkey\"}")); if ( bitcoin_pubkeylen(dp->minerkey33) <= 0 ) From c05041fbc47db5b943f2856111d2866f6c1fa568 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:46:45 -0300 Subject: [PATCH 06/15] test --- iguana/dPoW.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 2800bc876..ea781d664 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 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 0x0769 From 04a7d7615a16f929a624f57ca776fb7d98d8ce14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 09:55:16 -0300 Subject: [PATCH 07/15] test --- iguana/dpow/dpow_fsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 2199db67d..15405a0ea 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -391,7 +391,7 @@ void dpow_statemachinestart(void *ptr) //printf("done utxosync start.%u %u\n",starttime,(uint32_t)time(NULL)); while ( time(NULL) < starttime+bp->duration && src != 0 && dest != 0 && bp->state != 0xffffffff ) { - if ( bp->isratify == 0 && dp->ratifying != 0 ) + if ( bp->isratify == 0 && myinfo->DPOWS[0].ratifying != 0 ) break; sleep(1); if ( dp->checkpoint.blockhash.height > checkpoint.blockhash.height ) From e4ff66801770a57baa99aa1f801269e59eff4613 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:01:48 -0300 Subject: [PATCH 08/15] test --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_tx.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index ea781d664..7aa73b1ab 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 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 0x0769 diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index c86c189b5..9dc6f0106 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -426,8 +426,8 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); retval = 0; break; - } - } + } else printf("sig didnt match pubkey? (%s)\n",jprint(item,0)); + } else printf("no scriptPubkey.(%s)\n",jprint(item,0)); } // else printf("notmine.(%s)\n",jprint(item,0)); } } else printf("no vin[] (%s)\n",jprint(txobj2,0)); From 507509dc35c4fbf28987ef39e0bd6789bfee4486 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:02:08 -0300 Subject: [PATCH 09/15] test --- iguana/dPoW.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 7aa73b1ab..ea781d664 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 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 0x0769 From 3c1ba6e868439d326e5ac774d33a5ccd19a91beb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:22:12 -0300 Subject: [PATCH 10/15] test --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_tx.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index ea781d664..7aa73b1ab 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 17 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 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 0x0769 diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 9dc6f0106..80f289e1c 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -387,7 +387,7 @@ cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uin void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,char *rawtx,cJSON *vins,int8_t bestk,uint64_t bestmask,int32_t myind,int32_t src_or_dest) { - int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr,*pubstr; cJSON *signobj,*sobj,*txobj2,*item,*vin; uint8_t pubkey33[33]; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; + int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr,*pubstr; cJSON *signobj,*vinitem,*sobj,*txobj2,*item,*vin; uint8_t pubkey33[33]; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; if ( bestk < 0 ) return; for (j=0; j 32 ) { - if ( (pubstr= jstr(item,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) + if ( (pubstr= jstr(vinitem,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) { decode_hex(pubkey33,33,&pubstr[1]); if ( memcmp(pubkey33,dp->minerkey33,33) == 0 ) @@ -426,8 +427,8 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); retval = 0; break; - } else printf("sig didnt match pubkey? (%s)\n",jprint(item,0)); - } else printf("no scriptPubkey.(%s)\n",jprint(item,0)); + } else printf("sig didnt match pubkey? (%s)\n",jprint(vinitem,0)); + } else printf("no scriptPubkey.(%s)\n",jprint(vinitem,0)); } // else printf("notmine.(%s)\n",jprint(item,0)); } } else printf("no vin[] (%s)\n",jprint(txobj2,0)); From 1d1bc28238bbca9a1dd40582109954d9ed811f0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:22:36 -0300 Subject: [PATCH 11/15] test --- iguana/dPoW.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 7aa73b1ab..6b06e1ccd 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 19 //((height < 90000) ? 7 : 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 0x0769 From 157f0a58a7c0813ccc819f12f0b85c219cee96f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:29:40 -0300 Subject: [PATCH 12/15] test --- iguana/dpow/dpow_tx.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 80f289e1c..4db379017 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -387,7 +387,7 @@ cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uin void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,char *rawtx,cJSON *vins,int8_t bestk,uint64_t bestmask,int32_t myind,int32_t src_or_dest) { - int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr,*pubstr; cJSON *signobj,*vinitem,*sobj,*txobj2,*item,*vin; uint8_t pubkey33[33]; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; + int32_t j,m=0,valid,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr,*pubstr; cJSON *signobj,*vinitem,*sobj,*txobj2,*item,*vin; uint8_t pubkey33[33]; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp; if ( bestk < 0 ) return; for (j=0; j 32 ) { - if ( (pubstr= jstr(vinitem,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) + valid = 0; + if ( dp->ratifying != 0 && j == 0 ) + valid = 1; + else if ( (pubstr= jstr(vinitem,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) { decode_hex(pubkey33,33,&pubstr[1]); if ( memcmp(pubkey33,dp->minerkey33,33) == 0 ) - { - printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,jprint(item,0),j); - cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; - if ( src_or_dest != 0 ) - bp->destsigsmasks[bestk] |= (1LL << myind); - else bp->srcsigsmasks[bestk] |= (1LL << myind); - decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); - ep->masks[src_or_dest][bestk] = bestmask; - ep->beacon = bp->beacon; - dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); - retval = 0; - break; - } else printf("sig didnt match pubkey? (%s)\n",jprint(vinitem,0)); - } else printf("no scriptPubkey.(%s)\n",jprint(vinitem,0)); + valid = 1; + } + if ( valid != 0 ) + { + printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,jprint(item,0),j); + cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1; + if ( src_or_dest != 0 ) + bp->destsigsmasks[bestk] |= (1LL << myind); + else bp->srcsigsmasks[bestk] |= (1LL << myind); + decode_hex(cp->sigs[bestk],cp->siglens[bestk],sigstr); + ep->masks[src_or_dest][bestk] = bestmask; + ep->beacon = bp->beacon; + dpow_sigsend(myinfo,dp,bp,myind,bestk,bestmask,srchash,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL); + retval = 0; + break; + } else printf("sig didnt match pubkey? (%s)\n",jprint(vinitem,0)); } // else printf("notmine.(%s)\n",jprint(item,0)); } } else printf("no vin[] (%s)\n",jprint(txobj2,0)); From d780aa21f7eccb0e30552c942ae1a9ef6e957dc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:48:26 -0300 Subject: [PATCH 13/15] test --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_tx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 6b06e1ccd..7aa73b1ab 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 19 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 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 0x0769 diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 4db379017..8178365df 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -414,7 +414,7 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu valid = 0; if ( dp->ratifying != 0 && j == 0 ) valid = 1; - else if ( (pubstr= jstr(vinitem,"scriptPubkey")) != 0 && is_hexstr(pubstr,0) == 66 ) + else if ( (pubstr= jstr(vinitem,"scriptPubKey")) != 0 && is_hexstr(pubstr,0) == 66 ) { decode_hex(pubkey33,33,&pubstr[1]); if ( memcmp(pubkey33,dp->minerkey33,33) == 0 ) From f4f48a9b555a4c66e4ec7929dc7cef5649bb16f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 10:48:45 -0300 Subject: [PATCH 14/15] test --- iguana/dPoW.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 7aa73b1ab..6b06e1ccd 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,7 +19,7 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS 2 //((height < 90000) ? 7 : 11) +#define DPOW_MINSIGS 19 //((height < 90000) ? 7 : 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 0x0769 From a85fba490805d28911824ff7a8bb1763a5217644 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 29 Nov 2016 11:54:52 -0300 Subject: [PATCH 15/15] test --- iguana/dpow/dpow_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 8178365df..e2d532117 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -416,7 +416,7 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu valid = 1; else if ( (pubstr= jstr(vinitem,"scriptPubKey")) != 0 && is_hexstr(pubstr,0) == 66 ) { - decode_hex(pubkey33,33,&pubstr[1]); + decode_hex(pubkey33,33,&pubstr[2]); if ( memcmp(pubkey33,dp->minerkey33,33) == 0 ) valid = 1; }