Browse Source

recv tweaks

notary
dPoW2
jl777 8 years ago
parent
commit
e175982c18
  1. 2
      .gitignore
  2. 2
      iguana/coins/genbtcd
  3. 157
      iguana/confs/BTCD_peers.txt
  4. 1
      iguana/genbtcloop
  5. 1
      iguana/genbtcloop8
  6. 21
      iguana/iguana777.c
  7. 19
      iguana/iguana_blocks.c
  8. 15
      iguana/iguana_bundles.c
  9. 21
      iguana/iguana_init.c
  10. 2
      iguana/iguana_payments.c
  11. 84
      iguana/iguana_peers.c
  12. 74
      iguana/iguana_recv.c
  13. 4
      iguana/iguana_tx.c
  14. 42
      iguana/iguana_unspents.c
  15. 5
      iguana/main.c
  16. 1
      iguana/tests/rawtx5
  17. 8
      includes/iguana_defines.h
  18. 10
      includes/iguana_structs.h

2
.gitignore

@ -33,3 +33,5 @@ agents/*
iguana/confs/BTC_hdrs.txt iguana/confs/BTC_hdrs.txt
.DS_Store

2
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}"

157
iguana/confs/BTCD_peers.txt

@ -7,84 +7,79 @@
89.248.160.243 89.248.160.243
89.248.160.244 89.248.160.244
89.248.160.245 89.248.160.245
85.25.217.233 5.9.102.210
65.15.37.140 78.47.196.146
62.75.145.171 85.25.217.233:14631
176.9.13.13 88.198.53.194:55692
88.198.15.19 88.206.186.58:37299
51.255.38.28 162.255.117.105:63084
121.108.241.247 115.28.42.60:60878
82.229.201.131 82.176.15.155:35026
162.13.4.69 88.198.15.19:48150
78.226.160.96 176.9.13.13:14631
115.28.42.60 217.8.62.188:52714
178.62.185.131 162.13.4.69:55410
167.114.249.196 211.58.177.43:35581
81.181.155.53 63.247.147.166:50266
76.169.236.235 24.168.17.50:50793
67.165.77.192 46.231.137.186:56963
75.130.163.51 178.62.185.131:35572
72.55.148.203 62.75.145.171:14631
96.127.136.18 89.212.19.49:48018
88.198.53.194 192.99.233.217:42232
63.247.147.166 68.190.213.46:14631
88.206.186.58 162.210.92.46:14631
217.8.62.188 98.118.105.12:60805
46.231.137.186 75.130.163.51:56719
217.215.190.134 51.255.38.28:14631
2.86.63.69 88.110.117.18:52158
59.147.43.232 24.101.114.249:55457
104.42.224.48 99.44.222.86:62377
24.168.17.50 108.61.166.209:58365
173.65.129.85 98.208.113.72:62065
84.119.62.223 72.133.226.130:14631
59.147.43.232 5.189.144.97:58243
2.239.61.146 14.203.46.202:57987
176.28.45.179 98.202.147.55:60460
73.211.90.130 24.45.172.109:14631
185.48.78.78 89.114.38.65:52768
77.21.104.176 68.59.64.126:50633
46.253.169.134 68.43.220.127:4303
163.172.156.107 81.205.30.207:63077
74.120.222.234 113.87.28.142:62764
192.99.233.217 73.211.90.130:41271
162.255.117.105 110.174.129.213:49252
188.166.91.37 68.45.147.145:57803
149.56.122.72 95.232.175.161:62633
71.1.13.122 73.229.133.160:38440
88.113.76.138 124.191.14.253:54342
81.205.30.207 167.114.249.196:52705
203.189.127.54 92.24.168.248:52892
68.190.213.46 93.158.216.201:14631
98.202.147.55 158.69.27.82:46643
89.212.19.49 104.204.109.11:63390
162.210.92.46 68.157.88.187:56711
115.70.19.28 71.53.152.87:5234
68.43.220.127 82.229.201.131:63466
79.227.171.148 59.147.42.146:57461
68.46.103.181 81.0.91.211:53187
98.207.117.83 82.241.71.230:51945
79.200.255.204 108.247.198.39:64094
82.8.59.60 77.22.227.8:65093
71.241.204.215 122.166.169.11:49325
108.247.198.39 173.76.182.122:14631
156.57.141.221 173.24.82.253:14631
92.26.168.113 100.13.54.119:14631
71.53.157.49 2.26.181.208:14631
68.45.147.145 94.242.213.3:14631
79.54.185.53 87.149.45.42:36077
110.202.11.148 98.207.117.83:50955
91.82.171.9 71.1.8.48:14631
74.14.104.167 71.1.8.48:50439
95.116.195.148 101.166.241.31:14631
90.113.82.59 178.143.154.142:27497
98.118.105.12 103.255.7.59:58660
82.241.71.230 156.57.132.119:62428
98.161.16.55 60.225.171.82:36834
89.248.160.237 46.223.149.120:43358
93.211.231.89 37.157.215.75:4162
2.26.181.156
89.248.160.244
89.248.160.243
89.248.160.242
89.248.160.241

1
iguana/genbtcloop

@ -2,5 +2,6 @@ while true
do do
../agents/iguana coins/genbtc.json ../agents/iguana coins/genbtc.json
sleep 3 sleep 3
rm -rf tmp
done done

1
iguana/genbtcloop8

@ -2,5 +2,6 @@ while true
do do
../agents/iguana coins/genbtc8.json ../agents/iguana coins/genbtc8.json
sleep 3 sleep 3
rm -rf tmp
done done

21
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); 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); sleep(2*IGUANA_NUMHELPERS+3);
}*/ }*/
if ( helperid < incr ) if ( convertflag == 0 )
{ {
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr) if ( helperid < incr )
num += iguana_helperB(coin,helperid,coin->bundles[hdrsi],convertflag); {
} for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
while ( (n= iguana_convertfinished(coin)) < max ) num += iguana_helperB(coin,helperid,coin->bundles[hdrsi],convertflag);
{ }
//printf("helperid.%d convertfinished.%d vs max %d bundlescount.%d\n",helperid,n,max,coin->bundlescount); while ( (n= iguana_convertfinished(coin)) < max )
sleep(IGUANA_NUMHELPERS+3); {
//printf("helperid.%d convertfinished.%d vs max %d bundlescount.%d\n",helperid,n,max,coin->bundlescount);
sleep(IGUANA_NUMHELPERS+3);
}
} }
if ( helperid == 0 ) if ( helperid == 0 )
{ {
@ -691,7 +694,7 @@ void iguana_helper(void *arg)
if ( coin->firstRTheight == 0 ) if ( coin->firstRTheight == 0 )
{ {
if ( coin->spendvectorsaved == 1 ) 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 ) else if ( coin->spendvectorsaved > 1 && (coin->spendvalidated & (1 << helperid)) == 0 )
{ {
//printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); //printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid);

19
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; struct iguana_bundle *bp; int32_t hdrsi;
bundlei = (block->height % coin->chain->bundlesize); bundlei = (block->height % coin->chain->bundlesize);
hdrsi = (block->height / coin->chain->bundlesize);
if ( bundlei == 0 ) 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 ) 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 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] ) 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_blockunmark(coin,block,bp,bundlei,0);
iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2); 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) ) 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); //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); process_iguanablock(block->serdata,CHAINPARMS);
}*/ }*/
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block); 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); return(block);
} }
} }

15
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; i<m; i++)
{
if ( (bp= coin->bundles[(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->numremain = n;
coin->blocksrecv = numrecv; coin->blocksrecv = numrecv;
uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now(); uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now();

21
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) 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; struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && iter > 0 ) if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && iter > 0 )
return; 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); //printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS);
if ( iter == 0 ) 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 ) 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); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} }
#ifndef IGUANA_DISABLEPEERS #ifndef IGUANA_DISABLEPEERS
addr = &coin->peers->active[m++]; //if ( (rand() % 2) == 0 )
iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line)); {
//printf("call initpeer.(%s)\n",addr->ipaddr); addr = &coin->peers->active[m++];
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); 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 #endif
} }
iguana_possible_peer(coin,line);
} }
else 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 ) if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 )
lastbundle = hash2, lastheight = height; lastbundle = hash2, lastheight = height;
else if ( missing++ > coin->MAXBUNDLES && strcmp("BTC",coin->symbol) == 0 )
{
printf("missing.%d\n",missing);
break;
}
} }
} }
} }

2
iguana/iguana_payments.c

@ -381,7 +381,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
free(unspents); free(unspents);
return(0); 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 ( txobj != 0 && avail >= satoshis+txfee )
{ {
if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 ) if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num)) != 0 )

84
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_family = AF_INET;
saddr.sin_port = htons(port); saddr.sin_port = htons(port);
//#ifdef WIN32 //#ifdef WIN32
// saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1"); // saddr.sin_addr.s_addr = (uint32_t)calc_ipbits("127.0.0.1");
//#else //#else
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length); memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
expand_ipbits(checkipaddr,saddr.sin_addr.s_addr); expand_ipbits(checkipaddr,saddr.sin_addr.s_addr);
if ( strcmp(ipaddr,checkipaddr) != 0 ) if ( strcmp(ipaddr,checkipaddr) != 0 )
printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr); printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr);
//#endif //#endif
if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 ) if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 )
{ {
if ( errno != ETIMEDOUT ) 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_sec = 0;
timeout.tv_usec = 30000; timeout.tv_usec = 30000;
setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout)); 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; opt = 0;
getsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,&slen); 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); sleep(13);
//continue; //continue;
} }
if ( errno != ECONNRESET && errno != ENOTCONN && errno != ECONNREFUSED && errno != ETIMEDOUT && errno != EHOSTUNREACH ) 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); 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 #ifdef _WIN32
if ( (numsent= (int32_t)send(usock,serialized,remains,0)) < 0 ) if ( (numsent= (int32_t)send(usock,serialized,remains,0)) < 0 )
#else #else
if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 )
#endif #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); if ( errno == EAGAIN )
printf("bad errno.%d %s zombify.%p\n",errno,strerror(errno),&addr->dead); {
addr->dead = (uint32_t)time(NULL); addr->persistent_peer = 1;
return(-errno); //sleep(1);
} //else usleep(*sleeptimep), *sleeptimep *= 1.1; //continue;
} }
else if ( remains > 0 ) //if ( errno != EAGAIN && errno != EWOULDBLOCK )
{ {
remains -= numsent; 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);
serialized += numsent; printf("bad errno.%d %s zombify.%p\n",errno,strerror(errno),&addr->dead);
if ( remains > 0 ) addr->dead = (uint32_t)time(NULL);
printf("%s iguana sent.%d remains.%d of len.%d\n",addr->ipaddr,numsent,remains,len); 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; addr->totalsent += len;
if ( 0 && addr->basilisk != 0 ) if ( 0 && addr->basilisk != 0 )
@ -673,7 +681,7 @@ void _iguana_processmsg(struct supernet_info *myinfo,struct iguana_info *coin,in
} }
//addr->dead = 1; //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 #ifndef IGUANA_DEDICATED_THREADS
addr->dead = 1; addr->dead = 1;
#endif #endif
@ -874,7 +882,7 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA,stru
//else printf("connector null iA\n"); //else printf("connector null iA\n");
return(0); return(0);
} }
uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr) 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; 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 ) if ( (addr= iguana_peerslot(coin,(uint32_t)ipbits,0)) == 0 )
return((uint32_t)time(NULL)); return((uint32_t)time(NULL));
/*for (i=n=0; i<IGUANA_MAXPEERS; i++) /*for (i=n=0; i<IGUANA_MAXPEERS; i++)
{ {
if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 ) if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 )
return((uint32_t)time(NULL)); return((uint32_t)time(NULL));
else if ( coin->peers->active[i].ipaddr[0] != 0 ) else if ( coin->peers->active[i].ipaddr[0] != 0 )
n++; n++;
}*/ }*/
n = coin->peers->numranked; n = coin->peers->numranked;
if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers->numranked >= coin->MAXPEERS ) if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers->numranked >= coin->MAXPEERS )
return((uint32_t)time(NULL)); return((uint32_t)time(NULL));
@ -1184,11 +1192,11 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
iguana_memreset(mem[i]); iguana_memreset(mem[i]);
} }
#endif #endif
//addr->pubkey = GENESIS_PUBKEY; //addr->pubkey = GENESIS_PUBKEY;
ipbits = (uint32_t)addr->ipbits; ipbits = (uint32_t)addr->ipbits;
vcalc_sha256(0,addr->iphash.bytes,(uint8_t *)&ipbits,sizeof(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)); //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; bufsize = IGUANA_MAXPACKETSIZE;
if ( addr->blockspace == 0 ) if ( addr->blockspace == 0 )
addr->blockspace = mycalloc('r',1,bufsize + 8192); 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 ) if ( flag != 0 )
run = 0; run = 0;
/*else if ( 0 && addr->supernet != 0 && time(NULL) > lastping+SUPERNET_PINGGAP ) /*else if ( 0 && addr->supernet != 0 && time(NULL) > lastping+SUPERNET_PINGGAP )
{ {
iguana_send_supernet(addr,SUPERNET_GETPEERSTR,0); iguana_send_supernet(addr,SUPERNET_GETPEERSTR,0);
lastping = (uint32_t)time(NULL); lastping = (uint32_t)time(NULL);
}*/ }*/
if ( addr->persistent_peer != 0 ) if ( addr->persistent_peer != 0 )
{ {
if ( addr->usock < 0 || addr->dead != 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); iguana_iAkill(coin,addr,addr->dead != 0);
myfree(buf,bufsize); myfree(buf,bufsize);
if ( addr->filehash2 != 0 ) //if ( addr->filehash2 != 0 )
myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0; // myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0;
if ( 0 ) if ( 0 )
{ {
iguana_mempurge(&addr->RAWMEM); iguana_mempurge(&addr->RAWMEM);

74
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 ( block->mainchain != 0 && block->valid != 0 && block->txvalid != 0 )
{ {
/*if ( (bp= coin->bundles[block->bundlei]) != 0 ) /*if ( (bp= coin->bundles[block->bundlei]) != 0 )
{ {
bp->hashes[block->bundlei] = block->RO.hash2; bp->hashes[block->bundlei] = block->RO.hash2;
bp->blocks[block->bundlei] = block; bp->blocks[block->bundlei] = block;
}*/ }*/
return(0); 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; 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; 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,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 ) 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; txdata->zblock.fpos = 0;
req->datalen = txdata->datalen; req->datalen = txdata->datalen;
req->ipbits = txdata->zblock.fpipbits; req->ipbits = txdata->zblock.fpipbits;
} //else printf("cant save block\n"); } //else printf("cant save block\n");
} }
if ( txdata->zblock.fpos == 0 ) if ( txdata->zblock.fpos == 0 )
{ {
@ -523,7 +523,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
} }
req->addr = addr; 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 ) //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 ) if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
printf("%s Q.(%s)\n",coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2)); 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)); } 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; origtxdata->zblock.RO.recvlen = 0;
printf("gotblockM2: error finding block %s\n",bits256_str(str,origtxdata->zblock.RO.hash2)); printf("gotblockM2: error finding block %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return; return;
} else printf("getblockM autoextended.[%d]\n",bp->hdrsi); } //else printf("getblockM autoextended.[%d]\n",bp->hdrsi);
} }
} }
if ( bp == 0 ) if ( bp == 0 )
@ -973,7 +973,7 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
if ( 0 && coin->RTheight > 0 ) if ( 0 && coin->RTheight > 0 )
{ {
for (i=1; i<num; i++) for (i=1; i<num; i++)
iguana_sendblockreqPT(coin,0,0,-1,blockhashes[i],0); iguana_sendblockreqPT(coin,0,0,-1,blockhashes[i],0);
} }
} }
} }
@ -1239,7 +1239,7 @@ struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguan
else //if ( coin->RTheight > 0 && newheight == coin->RTheight ) else //if ( coin->RTheight > 0 && newheight == coin->RTheight )
{ {
//printf("newheight.%d is RTheight\n",newheight); //printf("newheight.%d is RTheight\n",newheight);
} }
} }
//if ( 0 && bits256_nonz(prevhash2) > 0 ) //if ( 0 && bits256_nonz(prevhash2) > 0 )
// iguana_patch(coin,block); // iguana_patch(coin,block);
@ -1388,13 +1388,13 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
if ( 0 && bp == coin->current ) 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); 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 != 0 && match >= coin->chain->bundlesize-1 )
{ {
if ( firstbp->queued == 0 ) if ( firstbp->queued == 0 )
{ {
//fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight); //fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight);
iguana_bundleQ(myinfo,coin,firstbp,1000); iguana_bundleQ(myinfo,coin,firstbp,1000);
} }
}*/ }*/
if ( firstbp != 0 && (addr= req->addr) != 0 && n >= coin->chain->bundlesize ) if ( firstbp != 0 && (addr= req->addr) != 0 && n >= coin->chain->bundlesize )
{ {
addr->RThashes[0] = firstbp->hashes[0]; 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); //printf("set block->blockhashes[%d]\n",num);
} }
/*if ( (addr= coin->peers->ranked[0]) != 0 ) /*if ( (addr= coin->peers->ranked[0]) != 0 )
{ {
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 ) if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 )
{ {
iguana_send(coin,addr,serialized,len); iguana_send(coin,addr,serialized,len);
//char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1])); //char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1]));
} }
}*/ }*/
iguana_blockQ("hdr1",coin,0,-1,blockhashes[1],1); iguana_blockQ("hdr1",coin,0,-1,blockhashes[1],1);
} }
else 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) ) 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++; 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 ) if ( _iguana_chainlink(myinfo,coin,block) == 0 )
{ {
next = block; next = block;
@ -1771,11 +1771,11 @@ int32_t iguana_reqblocks(struct supernet_info *myinfo,struct iguana_info *coin)
if ( (bp= coin->bundles[hdrsi]) != 0 ) if ( (bp= coin->bundles[hdrsi]) != 0 )
{ {
/*for (bundlei=0; bundlei<coin->chain->bundlesize; bundlei++) /*for (bundlei=0; bundlei<coin->chain->bundlesize; bundlei++)
if ( (block= bp->blocks[bundlei]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[bundlei]) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 ) 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); 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]); bp->blocks[bundlei] = iguana_blockfind("fixit",coin,bp->hashes[bundlei]);
}*/ }*/
bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize;
if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind("reqblocks",coin,bp->hashes[bundlei])) != 0 ) 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; myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0;
} }
/*else if ( req->type == 'Q' ) // quotes from inv /*else if ( req->type == 'Q' ) // quotes from inv
{ {
if ( (req= instantdex_recvquotes(coin,req,req->hashes,req->n)) != 0 ) if ( (req= instantdex_recvquotes(coin,req,req->hashes,req->n)) != 0 )
myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0;
}*/ }*/
else printf("iguana_updatebundles unknown type.%c\n",req->type);//, getchar(); else printf("iguana_updatebundles unknown type.%c\n",req->type);//, getchar();
//fprintf(stderr,"finished coin->recvQ\n"); //fprintf(stderr,"finished coin->recvQ\n");
if ( req != 0 ) 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) int32_t iguana_needhdrs(struct iguana_info *coin)
{ {
//if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize ) //if ( coin->longestchain == 0 || coin->blocks.hashblocks < coin->longestchain-coin->chain->bundlesize )
return(1); return(1);
//else return(0); //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); //printf("found valid [%d:%d] in blockQ\n",block!=0?block->hdrsi:-1,block!=0?block->bundlei:-1);
return(0); return(0);
} }
//lag = (priority == 0) ? IGUANA_DEFAULTLAG*3 : IGUANA_DEFAULTLAG; //lag = (priority == 0) ? IGUANA_DEFAULTLAG*3 : IGUANA_DEFAULTLAG;
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
block = iguana_blockfind("blockQ",coin,hash2); block = iguana_blockfind("blockQ",coin,hash2);
if ( priority != 0 || block == 0 )//|| iguana_blockstatus(coin,block) == 0 ) 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; coin->disableUTXO = 1;
//iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables //iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables
if ( iguana_balanceflush(myinfo,coin,coin->balanceflush) > 0 ) 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); //portable_mutex_unlock(&coin->RTmutex);
coin->disableUTXO = 0; coin->disableUTXO = 0;
fprintf(stderr,"%s back balanceflush\n",coin->symbol); fprintf(stderr,"%s back balanceflush\n",coin->symbol);

4
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); *txidp = bits256_doublesha256(txidstr,serialized,len);
if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 ) if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 )
{ {
//for (i=0; i<len; i++) for (i=0; i<len; i++)
// printf("%02x",serialized[i]); printf("%02x",serialized[i]);
char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid)); char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
return(-1); return(-1);
} }

42
iguana/iguana_unspents.c

@ -380,6 +380,33 @@ int32_t iguana_uheight(struct iguana_info *coin,int32_t bundleheight,struct igua
else return(bundleheight); 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]) 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; 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.vout = unspent->vout;
outpt.value = unspent->value; outpt.value = unspent->value;
outpt.hdrsi = unspent->height / coin->chain->bundlesize; 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 ) if ( array != 0 )
jaddi(array,iguana_RTunspentjson(myinfo,coin,outpt,txid,unspent->vout,unspent->value,0,rmd160,coinaddr,pubkey33,spentheight,remoteaddr)); jaddi(array,iguana_RTunspentjson(myinfo,coin,outpt,txid,unspent->vout,unspent->value,0,rmd160,coinaddr,pubkey33,spentheight,remoteaddr));
*depositsp += unspent->value; *depositsp += unspent->value;
@ -495,13 +529,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *
{ {
//printf("u%u ",unspentind); //printf("u%u ",unspentind);
deposits += U[unspentind].value; deposits += U[unspentind].value;
memset(&outpt,0,sizeof(outpt)); iguana_outpt_set(coin,&outpt,&U[unspentind],unspentind,lastpt.hdrsi,T[U[unspentind].txidind].txid,unspentind - T[U[unspentind].txidind].firstvout);
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;
RTspend = 0; RTspend = 0;
if ( iguana_RTspentflag(myinfo,coin,&RTspend,&spentheight,ramchain,outpt,lastheight,minconf,maxconf,U[unspentind].value) == 0 ) if ( iguana_RTspentflag(myinfo,coin,&RTspend,&spentheight,ramchain,outpt,lastheight,minconf,maxconf,U[unspentind].value) == 0 )
{ {

5
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) void iguana_exit(struct supernet_info *myinfo,struct iguana_bundle *bp)
{ {
static int exiting;
int32_t i,j,iter; struct iguana_info *coin,*tmp; int32_t i,j,iter; struct iguana_info *coin,*tmp;
if ( exiting != 0 )
while ( 1 )
sleep(1);
exiting = 1;
if ( myinfo == 0 ) if ( myinfo == 0 )
myinfo = SuperNET_MYINFO(0); myinfo = SuperNET_MYINFO(0);
printf("start EXIT\n"); printf("start EXIT\n");

1
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\"}}"

8
includes/iguana_defines.h

@ -58,16 +58,12 @@
#define IGUANA_MAXBUNDLES (50000000 / 500) #define IGUANA_MAXBUNDLES (50000000 / 500)
#define IGUANA_MINPEERS 64 #define IGUANA_MINPEERS 64
#define IGUANA_LOG2MAXPEERS 11 #define IGUANA_LOG2MAXPEERS 11 // cant exceed 13 bits as ramchain unspents has bitfield
#define IGUANA_LOG2PEERFILESIZE 23
#define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) #define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS)
#define IGUANA_LOG2PACKETSIZE 21
#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE) #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_RECENTPEER (3600 * 24 * 7)
#define IGUANA_PERMTHREAD 0 #define IGUANA_PERMTHREAD 0

10
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 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; 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 // 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_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 struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; }PACKEDSTRUCT; //firstunspentind,pubkeyoffset
@ -349,7 +349,7 @@ struct iguana_peer
struct msgcounts msgcounts; struct msgcounts msgcounts;
struct OS_memspace RAWMEM,TXDATA,HASHMEM; struct OS_memspace RAWMEM,TXDATA,HASHMEM;
struct iguana_ramchain ramchain; struct iguana_ramchain ramchain;
struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2; //struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2;
FILE *voutsfp,*vinsfp; FILE *voutsfp,*vinsfp;
uint8_t *blockspace;//[IGUANA_MAXPACKETSIZE + 8192]; uint8_t *blockspace;//[IGUANA_MAXPACKETSIZE + 8192];
#ifdef IGUANA_PEERALLOC #ifdef IGUANA_PEERALLOC
@ -391,7 +391,7 @@ struct iguana_bundlereq
{ {
struct queueitem DL; struct iguana_info *coin; int32_t type; struct queueitem DL; struct iguana_info *coin; int32_t type;
struct iguana_peer *addr; struct iguana_zblock *blocks; bits256 *hashes,txid; struct iguana_peer *addr; struct iguana_zblock *blocks; bits256 *hashes,txid;
struct iguana_txdatabits txdatabits; //struct iguana_txdatabits txdatabits;
struct iguana_msghdr H; struct iguana_msghdr H;
int32_t allocsize,datalen,n,recvlen,numtx; uint32_t ipbits; int32_t allocsize,datalen,n,recvlen,numtx; uint32_t ipbits;
struct iguana_zblock zblock; struct iguana_zblock zblock;

Loading…
Cancel
Save