Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
e42d98918a
  1. 37
      deprecated/obsolete.h
  2. 2
      iguana/iguana777.c
  3. 4
      iguana/iguana777.h
  4. 2
      iguana/iguana_exchanges.c
  5. 13
      iguana/iguana_peers.c
  6. 178
      iguana/iguana_ramchain.c
  7. 84
      iguana/iguana_recv.c

37
deprecated/obsolete.h

@ -17312,6 +17312,43 @@ len = 0;
} }
return(i); return(i);
} }
//printf("mapped Soffset.%ld\n",(long)mapchain->data->Soffset);
/*iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
if ( 1 ) // unix issues?
{
if ( (err= iguana_ramchain_cmp(ramchain,mapchain,0)) != 0 )
fpos = -1, printf("error.%d comparing ramchains\n",err);
else
{
ptr = mapchain->fileptr; fsize = mapchain->filesize;
mapchain->fileptr = 0, mapchain->filesize = 0;
iguana_ramchain_free(coin,mapchain,1);
memset(&R,0,sizeof(R));
R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize;
iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
}
}
if ( (err= iguana_ramchain_cmp(ramchain,&R,0)) != 0 )
{
fpos = -1;
block->issued = 0;
block->RO.recvlen = 0;
printf("error.%d comparing REMAP ramchains\n",err);
}
else
{
iguana_ramchain_extras(coin,&R,0,0);
if ( (err= iguana_ramchain_iterate(coin,0,&R,bp,bundlei)) != 0 )
printf("err.%d iterate ",err);
//printf("SUCCESS REMAP\n");
bp->numtxids += rdata->numtxids;
bp->numunspents += rdata->numunspents;
bp->numspends += rdata->numspends;
//bp->rawscriptspace += rdata->scriptspace;
}
iguana_ramchain_free(coin,&R,1);
if ( err != 0 )
iguana_blockunmark(coin,block,bp,bundlei,1);*/
#endif #endif
#endif #endif

2
iguana/iguana777.c

@ -854,7 +854,7 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi
#ifdef __PNACL__ #ifdef __PNACL__
coin->startPEND = coin->endPEND = 1; coin->startPEND = coin->endPEND = 1;
#endif #endif
coin->enableCACHE = 0;//(strcmp("BTC",coin->symbol) != 0); coin->enableCACHE = (strcmp("BTCD",coin->symbol) == 0);
if ( jobj(json,"cache") != 0 ) if ( jobj(json,"cache") != 0 )
coin->enableCACHE = juint(json,"cache"); coin->enableCACHE = juint(json,"cache");
if ( (coin->polltimeout= juint(json,"poll")) <= 0 ) if ( (coin->polltimeout= juint(json,"poll")) <= 0 )

4
iguana/iguana777.h

@ -532,8 +532,8 @@ struct iguana_bundlereq
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;
uint8_t copyflag,*serializeddata;
struct iguana_zblock zblock; struct iguana_zblock zblock;
uint8_t copyflag,serializeddata[];
}; };
struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; }; struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; };
@ -1053,7 +1053,7 @@ int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coi
struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *encodedhash,int32_t n); struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *encodedhash,int32_t n);
struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson); struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson);
int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin); int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin);
struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,int32_t datalen); struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,uint8_t *data,int32_t datalen);
void instantdex_FSMinit(); void instantdex_FSMinit();
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins);
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf); char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf);

2
iguana/iguana_exchanges.c

@ -875,7 +875,7 @@ void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256
{ {
struct iguana_bundlereq *req; struct exchange_info *exchange = exchanges777_find("bitcoin"); struct iguana_bundlereq *req; struct exchange_info *exchange = exchanges777_find("bitcoin");
//printf("got %d quotes from %s\n",n,addr->ipaddr); //printf("got %d quotes from %s\n",n,addr->ipaddr);
req = iguana_bundlereq(coin,addr,'Q',0); req = iguana_bundlereq(coin,addr,'Q',0,0);
req->hashes = quotes, req->n = n; req->hashes = quotes, req->n = n;
queue_enqueue("recvQ",&exchange->recvQ,&req->DL,0); queue_enqueue("recvQ",&exchange->recvQ,&req->DL,0);
} }

13
iguana/iguana_peers.c

@ -550,7 +550,14 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
coin->totalrecv += len, coin->totalpackets++; coin->totalrecv += len, coin->totalpackets++;
//printf("next iter.(%s) numreferrals.%d numpings.%d\n",addr->ipaddr,addr->numreferrals,addr->numpings); //printf("next iter.(%s) numreferrals.%d numpings.%d\n",addr->ipaddr,addr->numreferrals,addr->numpings);
} }
} else printf("header error from %s\n",addr->ipaddr); }
else
{
int z;
for (z=0; z<sizeof(*H); z++)
printf("%02x",((uint8_t *)H)[z]);
printf(" header error from %s len %d crc.%08x\n",addr->ipaddr,len,calc_crc32(0,buf,len));
}
} }
void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen) void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen)
@ -1106,11 +1113,11 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
run = 0; run = 0;
while ( addr->usock >= 0 && addr->dead == 0 && coin->peers->shuttingdown == 0 ) while ( addr->usock >= 0 && addr->dead == 0 && coin->peers->shuttingdown == 0 )
{ {
if ( 0 && (req= queue_dequeue(&coin->cacheQ,0)) != 0 ) if ( (req= queue_dequeue(&coin->cacheQ,0)) != 0 )
{ {
if ( req->datalen != 0 ) if ( req->datalen != 0 )
{ {
//char str[65]; printf("CACHE.%p parse[%d] %s %s\n",req,req->recvlen,req->H.command,bits256_str(str,req->block.RO.hash2)); //char str[65]; printf("CACHE.%p parse[%d] %s %s\n",req,req->recvlen,req->H.command,bits256_str(str,req->zblock.RO.hash2));
iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen); iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen);
} else printf("CACHE error no datalen\n"); } else printf("CACHE error no datalen\n");
coin->cachefreed++; coin->cachefreed++;

178
iguana/iguana_ramchain.c

@ -1815,8 +1815,6 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
static uint64_t totalrecv; static uint64_t totalrecv;
int32_t verifyflag = 0; int32_t verifyflag = 0;
RAMCHAIN_DECLARE; uint32_t addr_ipbits; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,msize,sigsize,subdir,firsti=1,err,flag,bundlei = -2; bits256 merkle_root; struct iguana_bundle *bp = 0; struct iguana_block *block; uint32_t scriptspace,stackspace; RAMCHAIN_DECLARE; uint32_t addr_ipbits; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,msize,sigsize,subdir,firsti=1,err,flag,bundlei = -2; bits256 merkle_root; struct iguana_bundle *bp = 0; struct iguana_block *block; uint32_t scriptspace,stackspace;
if ( (rdata= ramchain->H.data) == 0 )
return(-1);
totalrecv += recvlen; totalrecv += recvlen;
#ifdef __PNACL__ #ifdef __PNACL__
//verifyflag = 1; //verifyflag = 1;
@ -1899,129 +1897,95 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
} }
block->fpos = fpos = -1; block->fpos = fpos = -1;
iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0); iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata); if ( (rdata= ramchain->H.data) != 0 )
subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR;
char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,subdir), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/%d/%d",GLOBAL_TMPDIR,coin->symbol,subdir,bp->bundleheight), OS_ensure_directory(dirname);
//printf("Kspace.%p bp.[%d:%d] <- scriptspace.%d expanded.%d\n",Kspace,bp->hdrsi,bundlei,scriptspace,ramchain->expanded);
if ( T == 0 || U == 0 || S == 0 || B == 0 )
{
block->issued = 0;
block->RO.recvlen = 0;
printf("fatal error getting txdataptrs %p %p %p %p\n",T,U,S,B);
return(-1);
}
block->fpipbits = 1;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{ {
tx = &txarray[i]; _iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata);
iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,bundlei); subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR;
for (j=0; j<tx->tx_out; j++) char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,subdir), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/%d/%d",GLOBAL_TMPDIR,coin->symbol,subdir,bp->bundleheight), OS_ensure_directory(dirname);
//printf("Kspace.%p bp.[%d:%d] <- scriptspace.%d expanded.%d\n",Kspace,bp->hdrsi,bundlei,scriptspace,ramchain->expanded);
if ( T == 0 || U == 0 || S == 0 || B == 0 )
{
block->issued = 0;
block->RO.recvlen = 0;
printf("fatal error getting txdataptrs %p %p %p %p\n",T,U,S,B);
return(-1);
}
block->fpipbits = 1;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{ {
memset(rmd160,0,sizeof(rmd160)); tx = &txarray[i];
//printf("i.%d j.%d pkscriptlen.%d\n",i,j,tx->vouts[j].pk_scriptlen); iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,bundlei);
iguana_ramchain_addunspent20(coin,addr,RAMCHAIN_ARG,tx->vouts[j].value,tx->vouts[j].pk_script,tx->vouts[j].pk_scriptlen,tx->txid,j,-1,bp,rmd160); for (j=0; j<tx->tx_out; j++)
{
memset(rmd160,0,sizeof(rmd160));
//printf("i.%d j.%d pkscriptlen.%d\n",i,j,tx->vouts[j].pk_scriptlen);
iguana_ramchain_addunspent20(coin,addr,RAMCHAIN_ARG,tx->vouts[j].value,tx->vouts[j].pk_script,tx->vouts[j].pk_scriptlen,tx->txid,j,-1,bp,rmd160);
}
ramchain->H.spendind += tx->tx_in;
} }
ramchain->H.spendind += tx->tx_in; //printf("scriptoffset.%d after %d txids\n",ramchain->H.scriptoffset,txn_count);
} ramchain->H.txidind = ramchain->H.spendind = rdata->firsti;
//printf("scriptoffset.%d after %d txids\n",ramchain->H.scriptoffset,txn_count); for (i=0; i<txn_count; i++,ramchain->H.txidind++)
ramchain->H.txidind = ramchain->H.spendind = rdata->firsti;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{
tx = &txarray[i];
for (j=0; j<tx->tx_in; j++)
{ {
iguana_ramchain_addspend256(coin,addr,RAMCHAIN_ARG,tx->vins[j].prev_hash,tx->vins[j].prev_vout,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->vins[j].sequence,bp);//,bp->hdrsi,bundlei); tx = &txarray[i];
for (j=0; j<tx->tx_in; j++)
{
iguana_ramchain_addspend256(coin,addr,RAMCHAIN_ARG,tx->vins[j].prev_hash,tx->vins[j].prev_vout,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->vins[j].sequence,bp);//,bp->hdrsi,bundlei);
}
} }
} rdata->prevhash2 = block->RO.prev_block;
rdata->prevhash2 = block->RO.prev_block; rdata->scriptspace = scriptspace = ramchain->H.scriptoffset;
rdata->scriptspace = scriptspace = ramchain->H.scriptoffset; rdata->stackspace = stackspace = ramchain->H.stacksize;
rdata->stackspace = stackspace = ramchain->H.stacksize; iguana_ramchain_setsize(fname,ramchain,rdata,1,coin->chain->zcash);
iguana_ramchain_setsize(fname,ramchain,rdata,1,coin->chain->zcash); flag = 0;
flag = 0; if ( ramchain->H.txidind != rdata->numtxids || ramchain->H.unspentind != rdata->numunspents || ramchain->H.spendind != rdata->numspends )
if ( ramchain->H.txidind != rdata->numtxids || ramchain->H.unspentind != rdata->numunspents || ramchain->H.spendind != rdata->numspends ) {
{ printf("error creating PT ramchain.[%d:%d] ramchain->txidind %d != %d ramchain->data->numtxids || ramchain->unspentind %d != %d ramchain->data->numunspents || ramchain->spendind %d != %d ramchain->data->numspends space.(%d v %d)\n",bp->hdrsi,bp->bundleheight,ramchain->H.txidind,rdata->numtxids,ramchain->H.unspentind,rdata->numunspents,ramchain->H.spendind,rdata->numspends,ramchain->H.scriptoffset,rdata->scriptspace);
printf("error creating PT ramchain.[%d:%d] ramchain->txidind %d != %d ramchain->data->numtxids || ramchain->unspentind %d != %d ramchain->data->numunspents || ramchain->spendind %d != %d ramchain->data->numspends space.(%d v %d)\n",bp->hdrsi,bp->bundleheight,ramchain->H.txidind,rdata->numtxids,ramchain->H.unspentind,rdata->numunspents,ramchain->H.spendind,rdata->numspends,ramchain->H.scriptoffset,rdata->scriptspace); block->fpipbits = 0;
block->fpipbits = 0; block->issued = 0;
block->issued = 0; block->RO.recvlen = 0;
block->RO.recvlen = 0; }
} else
else
{
if ( (err= iguana_ramchain_verify(coin,ramchain)) == 0 )
{ {
iguana_blockzcopyRO(coin->chain->zcash,B,0,&block->RO,0); if ( (err= iguana_ramchain_verify(coin,ramchain)) == 0 )
rdata->scriptspace = ramchain->H.scriptoffset = scriptspace;
rdata->stackspace = ramchain->H.stacksize = stackspace;
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
{ {
origtxdata->datalen = (int32_t)rdata->allocsize; iguana_blockzcopyRO(coin->chain->zcash,B,0,&block->RO,0);
//char str[65]; printf("saved.%s [%d:%d] fpos.%d datalen.%d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,bundlei,fpos,origtxdata->datalen); rdata->scriptspace = ramchain->H.scriptoffset = scriptspace;
ramchain->H.ROflag = 0; rdata->stackspace = ramchain->H.stacksize = stackspace;
flag = 1; if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
if ( addr->dirty[0] != 0 && addr->voutsfp != 0 )
fflush(addr->voutsfp);
if ( addr->dirty[1] != 0 && addr->vinsfp != 0 )
fflush(addr->vinsfp);
memset(&R,0,sizeof(R));
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(coin,fname,0,1,&R,0,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,fpos,1,0)) == 0 )
{ {
printf("delete unverified [%d:%d]\n",bp->hdrsi,bundlei); origtxdata->datalen = (int32_t)rdata->allocsize;
iguana_ramchain_free(coin,&R,1); //char str[65]; printf("saved.%s [%d:%d] fpos.%d datalen.%d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,bundlei,fpos,origtxdata->datalen);
fpos = -1; ramchain->H.ROflag = 0;
//printf("mapped Soffset.%ld\n",(long)mapchain->data->Soffset); flag = 1;
/*iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1); if ( addr->dirty[0] != 0 && addr->voutsfp != 0 )
if ( 1 ) // unix issues? fflush(addr->voutsfp);
{ if ( addr->dirty[1] != 0 && addr->vinsfp != 0 )
if ( (err= iguana_ramchain_cmp(ramchain,mapchain,0)) != 0 ) fflush(addr->vinsfp);
fpos = -1, printf("error.%d comparing ramchains\n",err); memset(&R,0,sizeof(R));
else if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(coin,fname,0,1,&R,0,addr_ipbits,block->RO.hash2,block->RO.prev_block,bundlei,fpos,1,0)) == 0 )
{
ptr = mapchain->fileptr; fsize = mapchain->filesize;
mapchain->fileptr = 0, mapchain->filesize = 0;
iguana_ramchain_free(coin,mapchain,1);
memset(&R,0,sizeof(R));
R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize;
iguana_ramchain_link(&R,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
}
}
if ( (err= iguana_ramchain_cmp(ramchain,&R,0)) != 0 )
{ {
printf("delete unverified [%d:%d]\n",bp->hdrsi,bundlei);
iguana_ramchain_free(coin,&R,1);
fpos = -1; fpos = -1;
block->issued = 0;
block->RO.recvlen = 0;
printf("error.%d comparing REMAP ramchains\n",err);
} }
else else
{ {
iguana_ramchain_extras(coin,&R,0,0);
if ( (err= iguana_ramchain_iterate(coin,0,&R,bp,bundlei)) != 0 )
printf("err.%d iterate ",err);
//printf("SUCCESS REMAP\n");
bp->numtxids += rdata->numtxids; bp->numtxids += rdata->numtxids;
bp->numunspents += rdata->numunspents; bp->numunspents += rdata->numunspents;
bp->numspends += rdata->numspends; bp->numspends += rdata->numspends;
//bp->rawscriptspace += rdata->scriptspace; //bp->rawscriptspace += rdata->scriptspace;
} }
iguana_ramchain_free(coin,&R,1); if ( fpos >= 0 )
if ( err != 0 ) block->fpos = fpos, block->fpipbits = addr_ipbits;
iguana_blockunmark(coin,block,bp,bundlei,1);*/ } else printf("save error\n");
} }
else else
{ {
bp->numtxids += rdata->numtxids; printf("ramchain verification error.%d hdrsi.%d bundlei.%d n.%d\n",err,bp->hdrsi,bundlei,bp->n);
bp->numunspents += rdata->numunspents; fpos = -1;
bp->numspends += rdata->numspends; }
//bp->rawscriptspace += rdata->scriptspace;
}
if ( fpos >= 0 )
block->fpos = fpos, block->fpipbits = addr_ipbits;
} else printf("save error\n");
}
else
{
printf("ramchain verification error.%d hdrsi.%d bundlei.%d n.%d\n",err,bp->hdrsi,bundlei,bp->n);
fpos = -1;
} }
} }
if ( fpos < 0 ) if ( fpos < 0 )

84
iguana/iguana_recv.c

@ -20,18 +20,20 @@
static int32_t numDuplicates,numAfteremit; static int32_t numDuplicates,numAfteremit;
static int64_t sizeDuplicates,sizeAfteremit; static int64_t sizeDuplicates,sizeAfteremit;
struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,int32_t datalen) struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,uint8_t *data,int32_t datalen)
{ {
struct iguana_bundlereq *req; int32_t allocsize,bsize; struct iguana_bundlereq *req; int32_t allocsize;
bsize = (int32_t)(sizeof(struct iguana_block) + coin->chain->zcash*sizeof(struct iguana_zcashRO)); if ( data == 0 )
allocsize = (uint32_t)sizeof(*req) + datalen + bsize; datalen = 0;
allocsize = (uint32_t)sizeof(*req) + datalen;
req = mycalloc(type,1,allocsize); req = mycalloc(type,1,allocsize);
req->allocsize = allocsize; req->allocsize = allocsize;
req->datalen = datalen; req->datalen = datalen;
req->addr = addr; req->addr = addr;
req->coin = coin; req->coin = coin;
req->type = type; req->type = type;
req->serializeddata = (void *)((long)req + bsize); if ( data != 0 && datalen > 0 )
memcpy(req->serializeddata,data,datalen);
return(req); return(req);
} }
@ -158,7 +160,7 @@ void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,st
{ {
struct iguana_bundlereq *req; struct iguana_bundlereq *req;
char str[65]; printf("%s unconfirmed.%s\n",addr->ipaddr,bits256_str(str,tx->txid)); char str[65]; printf("%s unconfirmed.%s\n",addr->ipaddr,bits256_str(str,tx->txid));
req = iguana_bundlereq(coin,addr,'U',datalen); req = iguana_bundlereq(coin,addr,'U',data,datalen);
req->datalen = datalen; req->datalen = datalen;
req->txid = tx->txid; req->txid = tx->txid;
memcpy(req->serializeddata,data,datalen); memcpy(req->serializeddata,data,datalen);
@ -366,7 +368,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
//iguana_blast(coin,addr); //iguana_blast(coin,addr);
} }
} }
copyflag = 0;//(coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0); copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
bp = 0, bundlei = -2; bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2); bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2);
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n ) if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
@ -384,7 +386,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
bp->dirty++; bp->dirty++;
if ( bundlei >= 0 && block != 0 ) if ( bundlei >= 0 && block != 0 )
{ {
if ( iguana_blockstatus(coin,block) != 0 && block->txvalid != 0 ) if ( block->fpipbits != 0 && block->txvalid != 0 )
{ {
numDuplicates++; numDuplicates++;
sizeDuplicates += recvlen; sizeDuplicates += recvlen;
@ -402,14 +404,8 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
if ( 0 && bp == coin->current ) if ( 0 && bp == coin->current )
printf("recv [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2)); printf("recv [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
} }
block->RO = origtxdata->zblock.RO; iguana_blockzcopyRO(coin->chain->zcash,&block->RO,0,&origtxdata->zblock.RO,0);
block->txvalid = 1; block->txvalid = 1;
/*if ( block->serdata == 0 )
{
block->serdata = malloc(recvlen);
memcpy(block->serdata,data,recvlen);
}*/
//printf("update prev for [%d:%d]\n",bp->hdrsi,bundlei);
} }
} }
else else
@ -432,20 +428,27 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
} }
} }
} }
if ( copyflag != 0 && recvlen != 0 && (bp == 0 || bundlei < 0 || ((block= bp->blocks[bundlei]) != 0 && iguana_blockstatus(coin,block) == 0)) ) block = 0;
if ( copyflag != 0 && recvlen != 0 && (bp == 0 || bundlei < 0 || ((block= bp->blocks[bundlei]) != 0 && block->fpipbits == 0 && block->req == 0)) )
{ {
req = iguana_bundlereq(coin,addr,'B',copyflag * recvlen); struct iguana_msghdr checkH;
req = iguana_bundlereq(coin,addr,'B',data,copyflag * recvlen);
req->copyflag = 1; req->copyflag = 1;
printf("copy %p serialized[%d]\n",req,req->recvlen); req->H = *H;
memcpy(req->serializeddata,data,recvlen); if ( 0 && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
{
int z;
for (z=0; z<sizeof(checkH); z++)
printf("%02x",((uint8_t *)&checkH)[z]);
printf(" req->H datalen.%d crc.%08x error\n",recvlen,calc_crc32(0,data,recvlen));
}
} }
else else
{ {
copyflag = 0; copyflag = 0;
req = iguana_bundlereq(coin,addr,'B',0); req = iguana_bundlereq(coin,addr,'B',0,0);
} }
req->recvlen = recvlen; req->recvlen = recvlen;
req->H = *H;
if ( bits256_cmp(origtxdata->zblock.RO.hash2,coin->APIblockhash) == 0 ) if ( bits256_cmp(origtxdata->zblock.RO.hash2,coin->APIblockhash) == 0 )
{ {
printf("MATCHED APIblockhash\n"); printf("MATCHED APIblockhash\n");
@ -494,7 +497,7 @@ void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256
{ {
struct iguana_bundlereq *req; struct iguana_bundlereq *req;
//printf("got %d txids from %s\n",n,addr->ipaddr); //printf("got %d txids from %s\n",n,addr->ipaddr);
req = iguana_bundlereq(coin,addr,'T',0); req = iguana_bundlereq(coin,addr,'T',0,0);
req->hashes = txids, req->n = n; req->hashes = txids, req->n = n;
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
} }
@ -526,7 +529,7 @@ void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct
addr->numRThashes = num; addr->numRThashes = num;
} }
} }
req = iguana_bundlereq(coin,addr,'H',0); req = iguana_bundlereq(coin,addr,'H',0,0);
req->blocks = zblocks, req->n = n; req->blocks = zblocks, req->n = n;
HDRnet++; HDRnet++;
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
@ -547,7 +550,7 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
addr->numRThashes = num; addr->numRThashes = num;
} }
} }
req = iguana_bundlereq(coin,addr,'S',0); req = iguana_bundlereq(coin,addr,'S',0,0);
req->hashes = blockhashes, req->n = n; req->hashes = blockhashes, req->n = n;
char str[65]; char str[65];
if ( 0 && n > 2 && addr != 0 ) if ( 0 && n > 2 && addr != 0 )
@ -1045,6 +1048,23 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
} }
} }
} }
else if ( req->copyflag != 0 )
{
if ( bp == 0 && (block == 0 || block->queued == 0))
{
//fprintf(stderr,"req.%p copyflag.%d data %d %d\n",req,req->copyflag,req->recvlen,recvlen);
coin->numcached++;
if ( block != 0 )
block->queued = 1;
queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0);
return(0);
}
else if ( block != 0 && block->req == 0 )
{
block->req = req;
req = 0;
} //else printf("already have cache entry.(%s)\n",bits256_str(str,origblock->RO.hash2));
}
if ( block != 0 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 ) if ( block != 0 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 )
{ {
int32_t i,numsaved = 0; struct iguana_block *tmpblock; static int32_t numrecv; int32_t i,numsaved = 0; struct iguana_block *tmpblock; static int32_t numrecv;
@ -1084,22 +1104,6 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,block,(struct iguana_block *)origblock); iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,block,(struct iguana_block *)origblock);
if ( block->lag != 0 && block->issued != 0 ) if ( block->lag != 0 && block->issued != 0 )
block->lag = (uint32_t)time(NULL) - block->issued; block->lag = (uint32_t)time(NULL) - block->issued;
if ( req->copyflag != 0 )
{
if ( block->queued == 0 && bp != 0 )
{
char str[65]; fprintf(stderr,"req.%p %s copyflag.%d %d data %d %d\n",req,bits256_str(str,block->RO.hash2),req->copyflag,block->height,req->recvlen,recvlen);
coin->numcached++;
block->queued = 1;
queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0);
return(0);
}
else if ( block->req == 0 )
{
block->req = req;
req = 0;
} //else printf("already have cache entry.(%s)\n",bits256_str(str,origblock->RO.hash2));
}
//printf("datalen.%d ipbits.%x\n",datalen,req->ipbits); //printf("datalen.%d ipbits.%x\n",datalen,req->ipbits);
} else printf("cant create origblock.%p block.%p bp.%p bundlei.%d\n",origblock,block,bp,bundlei); } else printf("cant create origblock.%p block.%p bp.%p bundlei.%d\n",origblock,block,bp,bundlei);
return(req); return(req);

Loading…
Cancel
Save