diff --git a/.gitignore b/.gitignore index 5370c8638..5bb42d365 100755 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ agents/* iguana/confs/BTC_hdrs.txt + +.DS_Store diff --git a/iguana/coins/genbtcd b/iguana/coins/genbtcd index 718f77179..7accd6897 100755 --- a/iguana/coins/genbtcd +++ b/iguana/coins/genbtcd @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":11,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"minconfirms\":5}" +curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":11,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":256,\"endpend\":256,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"minconfirms\":5}" diff --git a/iguana/confs/BTCD_peers.txt b/iguana/confs/BTCD_peers.txt index 5226d6ac8..f954be17e 100644 --- a/iguana/confs/BTCD_peers.txt +++ b/iguana/confs/BTCD_peers.txt @@ -7,84 +7,79 @@ 89.248.160.243 89.248.160.244 89.248.160.245 -85.25.217.233 -65.15.37.140 -62.75.145.171 -176.9.13.13 -88.198.15.19 -51.255.38.28 -121.108.241.247 -82.229.201.131 -162.13.4.69 -78.226.160.96 -115.28.42.60 -178.62.185.131 -167.114.249.196 -81.181.155.53 -76.169.236.235 -67.165.77.192 -75.130.163.51 -72.55.148.203 -96.127.136.18 -88.198.53.194 -63.247.147.166 -88.206.186.58 -217.8.62.188 -46.231.137.186 -217.215.190.134 -2.86.63.69 -59.147.43.232 -104.42.224.48 -24.168.17.50 -173.65.129.85 -84.119.62.223 -59.147.43.232 -2.239.61.146 -176.28.45.179 -73.211.90.130 -185.48.78.78 -77.21.104.176 -46.253.169.134 -163.172.156.107 -74.120.222.234 -192.99.233.217 -162.255.117.105 -188.166.91.37 -149.56.122.72 -71.1.13.122 -88.113.76.138 -81.205.30.207 -203.189.127.54 -68.190.213.46 -98.202.147.55 -89.212.19.49 -162.210.92.46 -115.70.19.28 -68.43.220.127 -79.227.171.148 -68.46.103.181 -98.207.117.83 -79.200.255.204 -82.8.59.60 -71.241.204.215 -108.247.198.39 -156.57.141.221 -92.26.168.113 -71.53.157.49 -68.45.147.145 -79.54.185.53 -110.202.11.148 -91.82.171.9 -74.14.104.167 -95.116.195.148 -90.113.82.59 -98.118.105.12 -82.241.71.230 -98.161.16.55 -89.248.160.237 -93.211.231.89 -2.26.181.156 -89.248.160.244 -89.248.160.243 -89.248.160.242 -89.248.160.241 +5.9.102.210 +78.47.196.146 +85.25.217.233:14631 +88.198.53.194:55692 +88.206.186.58:37299 +162.255.117.105:63084 +115.28.42.60:60878 +82.176.15.155:35026 +88.198.15.19:48150 +176.9.13.13:14631 +217.8.62.188:52714 +162.13.4.69:55410 +211.58.177.43:35581 +63.247.147.166:50266 +24.168.17.50:50793 +46.231.137.186:56963 +178.62.185.131:35572 +62.75.145.171:14631 +89.212.19.49:48018 +192.99.233.217:42232 +68.190.213.46:14631 +162.210.92.46:14631 +98.118.105.12:60805 +75.130.163.51:56719 +51.255.38.28:14631 +88.110.117.18:52158 +24.101.114.249:55457 +99.44.222.86:62377 +108.61.166.209:58365 +98.208.113.72:62065 +72.133.226.130:14631 +5.189.144.97:58243 +14.203.46.202:57987 +98.202.147.55:60460 +24.45.172.109:14631 +89.114.38.65:52768 +68.59.64.126:50633 +68.43.220.127:4303 +81.205.30.207:63077 +113.87.28.142:62764 +73.211.90.130:41271 +110.174.129.213:49252 +68.45.147.145:57803 +95.232.175.161:62633 +73.229.133.160:38440 +124.191.14.253:54342 +167.114.249.196:52705 +92.24.168.248:52892 +93.158.216.201:14631 +158.69.27.82:46643 +104.204.109.11:63390 +68.157.88.187:56711 +71.53.152.87:5234 +82.229.201.131:63466 +59.147.42.146:57461 +81.0.91.211:53187 +82.241.71.230:51945 +108.247.198.39:64094 +77.22.227.8:65093 +122.166.169.11:49325 +173.76.182.122:14631 +173.24.82.253:14631 +100.13.54.119:14631 +2.26.181.208:14631 +94.242.213.3:14631 +87.149.45.42:36077 +98.207.117.83:50955 +71.1.8.48:14631 +71.1.8.48:50439 +101.166.241.31:14631 +178.143.154.142:27497 +103.255.7.59:58660 +156.57.132.119:62428 +60.225.171.82:36834 +46.223.149.120:43358 +37.157.215.75:4162 diff --git a/iguana/genbtcloop b/iguana/genbtcloop index 1b8e2d987..7cdd03750 100755 --- a/iguana/genbtcloop +++ b/iguana/genbtcloop @@ -2,5 +2,6 @@ while true do ../agents/iguana coins/genbtc.json sleep 3 +rm -rf tmp done diff --git a/iguana/genbtcloop8 b/iguana/genbtcloop8 index 3fccf5b5c..64686708e 100755 --- a/iguana/genbtcloop8 +++ b/iguana/genbtcloop8 @@ -2,5 +2,6 @@ while true do ../agents/iguana coins/genbtc8.json sleep 3 +rm -rf tmp done diff --git a/iguana/iguana777.c b/iguana/iguana777.c index d60db2cc6..b1dadd4d9 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -538,15 +538,18 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max); sleep(2*IGUANA_NUMHELPERS+3); }*/ - if ( helperid < incr ) + if ( convertflag == 0 ) { - for (hdrsi=helperid; hdrsibundles[hdrsi],convertflag); - } - while ( (n= iguana_convertfinished(coin)) < max ) - { - //printf("helperid.%d convertfinished.%d vs max %d bundlescount.%d\n",helperid,n,max,coin->bundlescount); - sleep(IGUANA_NUMHELPERS+3); + if ( helperid < incr ) + { + for (hdrsi=helperid; hdrsibundles[hdrsi],convertflag); + } + while ( (n= iguana_convertfinished(coin)) < max ) + { + //printf("helperid.%d convertfinished.%d vs max %d bundlescount.%d\n",helperid,n,max,coin->bundlescount); + sleep(IGUANA_NUMHELPERS+3); + } } if ( helperid == 0 ) { @@ -691,7 +694,7 @@ void iguana_helper(void *arg) if ( coin->firstRTheight == 0 ) { if ( coin->spendvectorsaved == 1 ) - iguana_utxogen(myinfo,coin,helperid,0); + iguana_utxogen(myinfo,coin,helperid,1); else if ( coin->spendvectorsaved > 1 && (coin->spendvalidated & (1 << helperid)) == 0 ) { //printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 6da36f98e..e6cd7a80b 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -654,9 +654,10 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan } struct iguana_bundle *bp; int32_t hdrsi; bundlei = (block->height % coin->chain->bundlesize); + hdrsi = (block->height / coin->chain->bundlesize); if ( bundlei == 0 ) { - if ( (hdrsi= block->height/coin->chain->bundlesize) < coin->bundlescount ) + if ( hdrsi < coin->bundlescount ) { if ( (bp= coin->bundles[hdrsi]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[0]) != 0 ) { @@ -673,7 +674,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan } else { - if ( (bp= coin->bundles[block->height / coin->chain->bundlesize]) != 0 ) + if ( (bp= coin->bundles[hdrsi]) != 0 ) { if ( memcmp(bp->hashes[bundlei].bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 || block != bp->blocks[bundlei] ) { @@ -698,6 +699,12 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan iguana_blockunmark(coin,block,bp,bundlei,0); iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2); } + else + { + bp->blocks[bundlei] = block; + bp->hashes[bundlei] = block->RO.hash2; + iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2); + } if ( coin->started != 0 && bundlei == coin->minconfirms && (block->height > coin->longestchain-coin->chain->bundlesize*2 || ((block->height / coin->chain->bundlesize) % 100) == 9) ) { //printf("savehdrs.[%d] ht.%d\n",bp->hdrsi,block->height); @@ -715,7 +722,13 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan process_iguanablock(block->serdata,CHAINPARMS); }*/ iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block); - iguana_RTnewblock(myinfo,coin,block); + if ( coin->RTheight > 0 ) + iguana_RTnewblock(myinfo,coin,block); + block->hdrsi = hdrsi; + block->bundlei = bundlei; + bp = coin->bundles[hdrsi]; + if ( bp->blocks[bundlei] != block || bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 ) + printf("new hwm [%d:%d] mismatched bundle block\n",hdrsi,bundlei); return(block); } } diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index a93f54c2f..936001732 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -1409,21 +1409,6 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch } } } - //printf("lastbp.[%d]\n",lastpending!=0?lastpending->hdrsi:-1); - /*if ( m > 0 ) - { - revsortds(sortbuf,m,sizeof(*sortbuf)*2); - for (i=0; ibundles[(int32_t)sortbuf[i*2 + 1]]) != 0 ) - { - bp->rank = i + 1; - if ( coin->peers.numranked > 0 && i < coin->peers.numranked && (addr= coin->peers.ranked[i]) != 0 ) - addr->bp = bp; - } - } - } - free(sortbuf);*/ coin->numremain = n; coin->blocksrecv = numrecv; uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now(); diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index e01c6a38c..9d6ec1aee 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -255,7 +255,7 @@ int32_t iguana_bundleinitmap(struct supernet_info *myinfo,struct iguana_info *co void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int32_t iter,FILE *fp) { - int32_t j,k,m,c,flag,bundlei,lastheight,height = -1; char checkstr[1024],line[1024]; + int32_t j,k,m,c,flag,bundlei,lastheight,missing=0,height = -1; char checkstr[1024],line[1024]; struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle; if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && iter > 0 ) return; @@ -302,7 +302,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 //printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS); if ( iter == 0 ) { - if ( (m < 8 || (rand() % 2) == 0) && (m < 32 || m < coin->MAXPEERS/2) )//&& m < 77.7 ) + if ( m < coin->MAXPEERS/2 ) { if ( 0 && m == 0 ) { @@ -312,12 +312,16 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); } #ifndef IGUANA_DISABLEPEERS - addr = &coin->peers->active[m++]; - iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line)); - //printf("call initpeer.(%s)\n",addr->ipaddr); - iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + //if ( (rand() % 2) == 0 ) + { + addr = &coin->peers->active[m++]; + iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line)); + //printf("call initpeer.(%s)\n",addr->ipaddr); + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + } //else #endif } + iguana_possible_peer(coin,line); } else { @@ -374,6 +378,11 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 { if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 ) lastbundle = hash2, lastheight = height; + else if ( missing++ > coin->MAXBUNDLES && strcmp("BTC",coin->symbol) == 0 ) + { + printf("missing.%d\n",missing); + break; + } } } } diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 5fdbf9143..e9aee0d86 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -381,7 +381,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS free(unspents); return(0); } - printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount)); + printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen); if ( txobj != 0 && avail >= satoshis+txfee ) { if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 ) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index b245392b0..826059f4f 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -367,14 +367,14 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) } saddr.sin_family = AF_INET; saddr.sin_port = htons(port); -//#ifdef WIN32 -// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1"); -//#else + //#ifdef WIN32 + // saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1"); + //#else memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length); expand_ipbits(checkipaddr,saddr.sin_addr.s_addr); if ( strcmp(ipaddr,checkipaddr) != 0 ) printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr); -//#endif + //#endif if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 ) { if ( errno != ETIMEDOUT ) @@ -392,6 +392,9 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) timeout.tv_sec = 0; timeout.tv_usec = 30000; setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout)); + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + setsockopt(sock,SOL_SOCKET,SO_SNDTIMEO,(void *)&timeout,sizeof(timeout)); } opt = 0; getsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,&slen); @@ -433,7 +436,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) } sleep(13); //continue; - } + } if ( errno != ECONNRESET && errno != ENOTCONN && errno != ECONNREFUSED && errno != ETIMEDOUT && errno != EHOSTUNREACH ) { printf("%s(%s) port.%d failed: %s sock.%d. errno.%d\n",bindflag!=0?"bind":"connect",hostname,port,strerror(errno),sock,errno); @@ -496,25 +499,30 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s #ifdef _WIN32 if ( (numsent= (int32_t)send(usock,serialized,remains,0)) < 0 ) #else - if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) + if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) #endif - { - printf("send errno.%d %s\n",errno,strerror(errno)); - if ( errno != EAGAIN && errno != EWOULDBLOCK ) { - printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",serialized+4,addr->ipaddr,numsent,remains,len,errno,strerror(errno),addr->usock); - printf("bad errno.%d %s zombify.%p\n",errno,strerror(errno),&addr->dead); - addr->dead = (uint32_t)time(NULL); - return(-errno); - } //else usleep(*sleeptimep), *sleeptimep *= 1.1; - } - else if ( remains > 0 ) - { - remains -= numsent; - serialized += numsent; - if ( remains > 0 ) - printf("%s iguana sent.%d remains.%d of len.%d\n",addr->ipaddr,numsent,remains,len); - } + if ( errno == EAGAIN ) + { + addr->persistent_peer = 1; + //sleep(1); + //continue; + } + //if ( errno != EAGAIN && errno != EWOULDBLOCK ) + { + printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",serialized+4,addr->ipaddr,numsent,remains,len,errno,strerror(errno),addr->usock); + printf("bad errno.%d %s zombify.%p\n",errno,strerror(errno),&addr->dead); + addr->dead = (uint32_t)time(NULL); + return(-errno); + } + } + else if ( remains > 0 ) + { + remains -= numsent; + serialized += numsent; + if ( remains > 0 ) + printf("%s iguana sent.%d remains.%d of len.%d\n",addr->ipaddr,numsent,remains,len); + } } addr->totalsent += len; if ( 0 && addr->basilisk != 0 ) @@ -673,7 +681,7 @@ void _iguana_processmsg(struct supernet_info *myinfo,struct iguana_info *coin,in } //addr->dead = 1; } - // printf("%s recv error on hdr errno.%d (%s) -> zombify\n",addr->ipaddr,-recvlen,strerror(-recvlen)); + // printf("%s recv error on hdr errno.%d (%s) -> zombify\n",addr->ipaddr,-recvlen,strerror(-recvlen)); #ifndef IGUANA_DEDICATED_THREADS addr->dead = 1; #endif @@ -874,7 +882,7 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA,stru //else printf("connector null iA\n"); return(0); } - + uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr) { char checkaddr[64],_ipaddr[64]; uint64_t ipbits; uint32_t now = (uint32_t)time(NULL); int32_t i,n; struct iguana_iAddr *iA; struct iguana_peer *addr; @@ -909,12 +917,12 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr) if ( (addr= iguana_peerslot(coin,(uint32_t)ipbits,0)) == 0 ) return((uint32_t)time(NULL)); /*for (i=n=0; ipeers->active[i].ipaddr) == 0 ) - return((uint32_t)time(NULL)); - else if ( coin->peers->active[i].ipaddr[0] != 0 ) - n++; - }*/ + { + if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 ) + return((uint32_t)time(NULL)); + else if ( coin->peers->active[i].ipaddr[0] != 0 ) + n++; + }*/ n = coin->peers->numranked; if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers->numranked >= coin->MAXPEERS ) return((uint32_t)time(NULL)); @@ -1184,11 +1192,11 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, iguana_memreset(mem[i]); } #endif - //addr->pubkey = GENESIS_PUBKEY; + //addr->pubkey = GENESIS_PUBKEY; ipbits = (uint32_t)addr->ipbits; vcalc_sha256(0,addr->iphash.bytes,(uint8_t *)&ipbits,sizeof(ipbits)); //char str[65]; printf("start dedicatedloop.%s addrind.%d %s\n",addr->ipaddr,addr->addrind,bits256_str(str,addr->iphash)); - addr->maxfilehash2 = IGUANA_MAXFILEITEMS; + //addr->maxfilehash2 = IGUANA_MAXFILEITEMS; bufsize = IGUANA_MAXPACKETSIZE; if ( addr->blockspace == 0 ) addr->blockspace = mycalloc('r',1,bufsize + 8192); @@ -1274,10 +1282,10 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, if ( flag != 0 ) run = 0; /*else if ( 0 && addr->supernet != 0 && time(NULL) > lastping+SUPERNET_PINGGAP ) - { - iguana_send_supernet(addr,SUPERNET_GETPEERSTR,0); - lastping = (uint32_t)time(NULL); - }*/ + { + iguana_send_supernet(addr,SUPERNET_GETPEERSTR,0); + lastping = (uint32_t)time(NULL); + }*/ if ( addr->persistent_peer != 0 ) { if ( addr->usock < 0 || addr->dead != 0 ) @@ -1311,8 +1319,8 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, } iguana_iAkill(coin,addr,addr->dead != 0); myfree(buf,bufsize); - if ( addr->filehash2 != 0 ) - myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0; + //if ( addr->filehash2 != 0 ) + // myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0; if ( 0 ) { iguana_mempurge(&addr->RAWMEM); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 7527f7c34..ac831e577 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -93,10 +93,10 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr, if ( block->mainchain != 0 && block->valid != 0 && block->txvalid != 0 ) { /*if ( (bp= coin->bundles[block->bundlei]) != 0 ) - { - bp->hashes[block->bundlei] = block->RO.hash2; - bp->blocks[block->bundlei] = block; - }*/ + { + bp->hashes[block->bundlei] = block->RO.hash2; + bp->blocks[block->bundlei] = block; + }*/ return(0); } } @@ -191,7 +191,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl int32_t bundlei,datalen,checki,hdrsi,fpos; char str[65],str2[65]; FILE *fp; bits256 checkhash2; struct iguana_txblock *txdata = 0; static const bits256 zero; if ( (bundlei= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,ipbits,hash2,zero,1)) >= 0 ) - //if ( (bundlei= iguana_peerfname(coin,&hdrsi,fname,ipbits,hash2)) >= 0 ) + //if ( (bundlei= iguana_peerfname(coin,&hdrsi,fname,ipbits,hash2)) >= 0 ) { if ( (fp= fopen(fname,"rb")) != 0 ) { @@ -497,7 +497,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s txdata->zblock.fpos = 0; req->datalen = txdata->datalen; req->ipbits = txdata->zblock.fpipbits; - } //else printf("cant save block\n"); + } //else printf("cant save block\n"); } if ( txdata->zblock.fpos == 0 ) { @@ -523,7 +523,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s } req->addr = addr; //if ( (bits256_cmp(origtxdata->zblock.RO.hash2,coin->blocks.hwmchain.RO.hash2) == 0 || req->zblock.mainchain == 0 || req->zblock.valid == 0 || req->zblock.txvalid == 0) && iguana_RTrawdata(coin,origtxdata->zblock.RO.hash2,0,&len,&numtx,1) == 0 ) - queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); if ( 0 && strcmp("BTCD",coin->symbol) == 0 ) printf("%s Q.(%s)\n",coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2)); } else printf("nonz fpos.%d %s\n",txdata->zblock.fpos,bits256_str(str,origtxdata->zblock.RO.hash2)); @@ -769,7 +769,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru origtxdata->zblock.RO.recvlen = 0; printf("gotblockM2: error finding block %s\n",bits256_str(str,origtxdata->zblock.RO.hash2)); return; - } else printf("getblockM autoextended.[%d]\n",bp->hdrsi); + } //else printf("getblockM autoextended.[%d]\n",bp->hdrsi); } } if ( bp == 0 ) @@ -973,7 +973,7 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi if ( 0 && coin->RTheight > 0 ) { for (i=1; iRTheight > 0 && newheight == coin->RTheight ) { //printf("newheight.%d is RTheight\n",newheight); - } + } } //if ( 0 && bits256_nonz(prevhash2) > 0 ) // iguana_patch(coin,block); @@ -1388,13 +1388,13 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc if ( 0 && bp == coin->current ) printf("i.%d n.%d match.%d blockhdrs.%s hdrsi.%d\n",i,n,match,bits256_str(str,zblocks[0].RO.hash2),firstbp!=0?firstbp->hdrsi:-1); /*if ( firstbp != 0 && match >= coin->chain->bundlesize-1 ) - { - if ( firstbp->queued == 0 ) - { - //fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight); - iguana_bundleQ(myinfo,coin,firstbp,1000); - } - }*/ + { + if ( firstbp->queued == 0 ) + { + //fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight); + iguana_bundleQ(myinfo,coin,firstbp,1000); + } + }*/ if ( firstbp != 0 && (addr= req->addr) != 0 && n >= coin->chain->bundlesize ) { addr->RThashes[0] = firstbp->hashes[0]; @@ -1561,13 +1561,13 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str //printf("set block->blockhashes[%d]\n",num); } /*if ( (addr= coin->peers->ranked[0]) != 0 ) - { - if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 ) - { - iguana_send(coin,addr,serialized,len); - //char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1])); - } - }*/ + { + if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 ) + { + iguana_send(coin,addr,serialized,len); + //char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1])); + } + }*/ iguana_blockQ("hdr1",coin,0,-1,blockhashes[1],1); } else @@ -1676,7 +1676,7 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig if ( (tmpblock= bp->blocks[i]) != 0 && tmpblock->fpipbits != 0 && tmpblock->fpos >= 0 && ((bp->hdrsi == 0 && i == 0) || bits256_nonz(tmpblock->RO.prev_block) != 0) ) numsaved++; } - // fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d copy.%d mainchain.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block!=0?block->fpipbits:0,numsaved,numrecv,req!=0?req->copyflag:-1,block->mainchain); + // fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d copy.%d mainchain.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block!=0?block->fpipbits:0,numsaved,numrecv,req!=0?req->copyflag:-1,block->mainchain); if ( _iguana_chainlink(myinfo,coin,block) == 0 ) { next = block; @@ -1771,11 +1771,11 @@ int32_t iguana_reqblocks(struct supernet_info *myinfo,struct iguana_info *coin) if ( (bp= coin->bundles[hdrsi]) != 0 ) { /*for (bundlei=0; bundleichain->bundlesize; bundlei++) - if ( (block= bp->blocks[bundlei]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[bundlei]) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 ) - { - char str[65]; printf("%s [%d] bundlei.%d ht.%d vs expected %d\n",bits256_str(str,bp->hashes[bundlei]),hdrsi,bundlei,block->height,bp->bundleheight+bundlei); - bp->blocks[bundlei] = iguana_blockfind("fixit",coin,bp->hashes[bundlei]); - }*/ + if ( (block= bp->blocks[bundlei]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[bundlei]) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 ) + { + char str[65]; printf("%s [%d] bundlei.%d ht.%d vs expected %d\n",bits256_str(str,bp->hashes[bundlei]),hdrsi,bundlei,block->height,bp->bundleheight+bundlei); + bp->blocks[bundlei] = iguana_blockfind("fixit",coin,bp->hashes[bundlei]); + }*/ bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind("reqblocks",coin,bp->hashes[bundlei])) != 0 ) { @@ -1939,10 +1939,10 @@ int32_t iguana_processrecvQ(struct supernet_info *myinfo,struct iguana_info *coi myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; } /*else if ( req->type == 'Q' ) // quotes from inv - { - if ( (req= instantdex_recvquotes(coin,req,req->hashes,req->n)) != 0 ) - myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; - }*/ + { + if ( (req= instantdex_recvquotes(coin,req,req->hashes,req->n)) != 0 ) + myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; + }*/ else printf("iguana_updatebundles unknown type.%c\n",req->type);//, getchar(); //fprintf(stderr,"finished coin->recvQ\n"); if ( req != 0 ) @@ -1954,7 +1954,7 @@ int32_t iguana_processrecvQ(struct supernet_info *myinfo,struct iguana_info *coi int32_t iguana_needhdrs(struct iguana_info *coin) { //if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize ) - return(1); + return(1); //else return(0); } @@ -2029,7 +2029,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle //printf("found valid [%d:%d] in blockQ\n",block!=0?block->hdrsi:-1,block!=0?block->bundlei:-1); return(0); } - //lag = (priority == 0) ? IGUANA_DEFAULTLAG*3 : IGUANA_DEFAULTLAG; + //lag = (priority == 0) ? IGUANA_DEFAULTLAG*3 : IGUANA_DEFAULTLAG; now = (uint32_t)time(NULL); block = iguana_blockfind("blockQ",coin,hash2); if ( priority != 0 || block == 0 )//|| iguana_blockstatus(coin,block) == 0 ) @@ -2238,7 +2238,7 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin coin->disableUTXO = 1; //iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables if ( iguana_balanceflush(myinfo,coin,coin->balanceflush) > 0 ) - printf("balanceswritten.%d flushed coin->balanceflush %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,coin->balanceflush,coin->longestchain/coin->chain->bundlesize); + printf("balanceswritten.%d flushed coin->balanceflush %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,coin->balanceflush,coin->longestchain/coin->chain->bundlesize); //portable_mutex_unlock(&coin->RTmutex); coin->disableUTXO = 0; fprintf(stderr,"%s back balanceflush\n",coin->symbol); diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index c19064a67..98ae3a79e 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -237,8 +237,8 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m *txidp = bits256_doublesha256(txidstr,serialized,len); if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 ) { - //for (i=0; itxid)); return(-1); } diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index d74f1aded..daa5d77c8 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -380,6 +380,33 @@ int32_t iguana_uheight(struct iguana_info *coin,int32_t bundleheight,struct igua else return(bundleheight); } +int32_t iguana_outpt_set(struct iguana_info *coin,struct iguana_outpoint *outpt,struct iguana_unspent *u,uint32_t unspentind,int16_t hdrsi,bits256 txid,int32_t vout) +{ + char scriptstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t rmd160[20],pubkey33[33]; + memset(outpt,0,sizeof(*outpt)); + outpt->txid = txid; + outpt->vout = vout; + outpt->hdrsi = hdrsi; + outpt->isptr = 0; + outpt->unspentind = unspentind; + outpt->value = u->value; + memset(rmd160,0,sizeof(rmd160)); + memset(pubkey33,0,sizeof(pubkey33)); + if ( iguana_scriptget(coin,scriptstr,0,sizeof(scriptstr),outpt->hdrsi,outpt->unspentind,outpt->txid,outpt->vout,rmd160,u->type,pubkey33) != 0 ) + { + outpt->spendlen = (int32_t)strlen(scriptstr) >> 1; + if ( outpt->spendlen < sizeof(outpt->spendscript) ) + decode_hex(outpt->spendscript,outpt->spendlen,scriptstr); + else + { + outpt->spendlen = 0; + printf("error scriptstr.(%s) is too big for %d\n",scriptstr,(int32_t)sizeof(outpt->spendscript)); + return(-1); + } + } + return(0); +} + int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]) { int64_t deposits,crypto777_payment; struct iguana_outpoint lastpt; uint32_t unspentind; int32_t i,j,num,uheight; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_pkhash *P,p; struct iguana_unspent *U,*u; struct iguana_txid *T,*tx; @@ -438,6 +465,13 @@ int32_t iguana_RTscanunspents(struct supernet_info *myinfo,struct iguana_info *c outpt.vout = unspent->vout; outpt.value = unspent->value; outpt.hdrsi = unspent->height / coin->chain->bundlesize; + if ( (outpt.spendlen= unspent->scriptlen) > 0 && outpt.spendlen < sizeof(outpt.spendscript) ) + memcpy(outpt.spendscript,unspent->script,outpt.spendlen); + else + { + printf("spendscript.%d doesnt fit into %d\n",outpt.spendlen,(int32_t)sizeof(outpt.spendscript)); + outpt.spendlen = 0; + } if ( array != 0 ) jaddi(array,iguana_RTunspentjson(myinfo,coin,outpt,txid,unspent->vout,unspent->value,0,rmd160,coinaddr,pubkey33,spentheight,remoteaddr)); *depositsp += unspent->value; @@ -495,13 +529,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info * { //printf("u%u ",unspentind); deposits += U[unspentind].value; - memset(&outpt,0,sizeof(outpt)); - outpt.txid = T[U[unspentind].txidind].txid; - outpt.vout = unspentind - T[U[unspentind].txidind].firstvout; - outpt.hdrsi = lastpt.hdrsi; - outpt.isptr = 0; - outpt.unspentind = unspentind; - outpt.value = U[unspentind].value; + iguana_outpt_set(coin,&outpt,&U[unspentind],unspentind,lastpt.hdrsi,T[U[unspentind].txidind].txid,unspentind - T[U[unspentind].txidind].firstvout); RTspend = 0; if ( iguana_RTspentflag(myinfo,coin,&RTspend,&spentheight,ramchain,outpt,lastheight,minconf,maxconf,U[unspentind].value) == 0 ) { diff --git a/iguana/main.c b/iguana/main.c index 5384d5402..ef6419a38 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -339,7 +339,12 @@ char *SuperNET_JSON(struct supernet_info *myinfo,struct iguana_info *coin,cJSON void iguana_exit(struct supernet_info *myinfo,struct iguana_bundle *bp) { + static int exiting; int32_t i,j,iter; struct iguana_info *coin,*tmp; + if ( exiting != 0 ) + while ( 1 ) + sleep(1); + exiting = 1; if ( myinfo == 0 ) myinfo = SuperNET_MYINFO(0); printf("start EXIT\n"); diff --git a/iguana/tests/rawtx5 b/iguana/tests/rawtx5 new file mode 100755 index 000000000..ce5f72611 --- /dev/null +++ b/iguana/tests/rawtx5 @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"agent\":\"basilisk\",\"method\":\"rawtx\",\"vals\":{\"changeaddr\":\"RD1rFucYCMhCGeEqdztivP3DFdJwVAzXn7\",\"addresses\":[\"RD1rFucYCMhCGeEqdztivP3DFdJwVAzXn7\"],\"timeout\":15000,\"satoshis\":\"130000\",\"spendscript\":\"76a9145da2ae69885741a6946e01ad8aa8b5312eed856088ac\"}}" diff --git a/includes/iguana_defines.h b/includes/iguana_defines.h index bb7473585..b4ed25cce 100755 --- a/includes/iguana_defines.h +++ b/includes/iguana_defines.h @@ -58,16 +58,12 @@ #define IGUANA_MAXBUNDLES (50000000 / 500) #define IGUANA_MINPEERS 64 -#define IGUANA_LOG2MAXPEERS 11 -#define IGUANA_LOG2PEERFILESIZE 23 +#define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield #define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) -#define IGUANA_LOG2PACKETSIZE 21 #define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE) -#define IGUANA_PEERFILESIZE (1 << IGUANA_LOG2PEERFILESIZE) -struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpos:IGUANA_LOG2PEERFILESIZE,datalen:IGUANA_LOG2PACKETSIZE,isdir:1; }; -#define IGUANA_MAXFILEITEMS 8192 +//#define IGUANA_MAXFILEITEMS 8192 #define IGUANA_RECENTPEER (3600 * 24 * 7) #define IGUANA_PERMTHREAD 0 diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index c253b6580..800701b23 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -183,7 +183,7 @@ struct iguana_packet { struct queueitem DL; struct iguana_peer *addr; struct tai struct msgcounts { uint32_t version,verack,getaddr,addr,inv,getdata,notfound,getblocks,getheaders,headers,tx,block,mempool,ping,pong,reject,filterload,filteradd,filterclear,merkleblock,alert; }; -struct iguana_fileitem { bits256 hash2; struct iguana_txdatabits txdatabits; }; +//struct iguana_fileitem { bits256 hash2; struct iguana_txdatabits txdatabits; }; struct iguana_kvitem { UT_hash_handle hh; uint8_t keyvalue[]; }PACKEDSTRUCT; @@ -272,9 +272,9 @@ struct iguana_spend256 { bits256 prevhash2; uint64_t scriptpos:48,vinscriptlen:1 // permanent readonly structs struct iguana_txid { bits256 txid; uint64_t txidind:29,firstvout:28,firstvin:28,bundlei:11,locktime:32,version:32,timestamp:32,extraoffset:32; uint16_t numvouts,numvins; }PACKEDSTRUCT; -struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos; uint16_t scriptlen,hdrsi; uint16_t fileid:11,type:5; int16_t vout; }PACKEDSTRUCT; +struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos,scriptlen:13,fileid:14,type:5; uint16_t hdrsi; int16_t vout; } PACKEDSTRUCT; -struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:15,external:1; }PACKEDSTRUCT; // numsigs:4,numpubkeys:4,p2sh:1,sighash:4 +struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:14,external:1,tbd:1; }PACKEDSTRUCT; // numsigs:4,numpubkeys:4,p2sh:1,sighash:4 struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; }PACKEDSTRUCT; //firstunspentind,pubkeyoffset @@ -349,7 +349,7 @@ struct iguana_peer struct msgcounts msgcounts; struct OS_memspace RAWMEM,TXDATA,HASHMEM; struct iguana_ramchain ramchain; - struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2; + //struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2; FILE *voutsfp,*vinsfp; uint8_t *blockspace;//[IGUANA_MAXPACKETSIZE + 8192]; #ifdef IGUANA_PEERALLOC @@ -391,7 +391,7 @@ struct iguana_bundlereq { struct queueitem DL; struct iguana_info *coin; int32_t type; struct iguana_peer *addr; struct iguana_zblock *blocks; bits256 *hashes,txid; - struct iguana_txdatabits txdatabits; + //struct iguana_txdatabits txdatabits; struct iguana_msghdr H; int32_t allocsize,datalen,n,recvlen,numtx; uint32_t ipbits; struct iguana_zblock zblock;