Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
75b2f188ff
  1. 52
      iguana/iguana_ramchain.c
  2. 41
      iguana/iguana_recv.c

52
iguana/iguana_ramchain.c

@ -1819,8 +1819,8 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block)
{
int32_t verifyflag = 0;
RAMCHAIN_DECLARE; 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,sigsize,subdir,firsti=1,err,flag,bundlei; uint32_t scriptspace,stackspace;
if ( block == 0 || bp == 0 || addr == 0 || (bundlei= block->bundlei) < 0 )
RAMCHAIN_DECLARE; 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,sigsize,subdir,firsti=1,err,flag,bundlei; uint32_t scriptspace,stackspace; struct iguana_blockRO RO;
if ( bp == 0 || addr == 0 || (bundlei= block->bundlei) < 0 )
{
printf("iguana_ramchain_data: null ptr %p %p %p\n",block,bp,addr);
return(-1);
@ -1834,12 +1834,23 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
addr->dirty[i] = 0;
if ( iguana_ramchain_init(fname,ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1,coin->chain->zcash) == 0 )
{
if ( block->fpipbits == 0 )
if ( block != 0 && block->fpipbits == 0 )
block->issued = block->RO.recvlen = 0, block->fpos = -1;
return(-1);
}
block->fpos = fpos = -1;
iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
if ( block != 0 )
{
RO = block->RO;
block->fpos = -1;
}
else
{
memset(&RO,0,sizeof(RO));
RO.hash2 = origtxdata->zblock.RO.hash2;
RO.prev_block = origtxdata->zblock.RO.prev_block;
}
fpos = -1;
iguana_ramchain_link(ramchain,origtxdata->zblock.RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
if ( (rdata= ramchain->H.data) != 0 )
{
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata);
@ -1849,12 +1860,16 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
//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;
if ( block != 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;
if ( block != 0 )
block->fpipbits = 1;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{
tx = &txarray[i];
@ -1877,7 +1892,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
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 = origtxdata->zblock.RO.prev_block;
rdata->scriptspace = scriptspace = ramchain->H.scriptoffset;
rdata->stackspace = stackspace = ramchain->H.stacksize;
iguana_ramchain_setsize(fname,ramchain,rdata,1,coin->chain->zcash);
@ -1885,18 +1900,21 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
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);
block->fpipbits = 0;
block->issued = 0;
block->RO.recvlen = 0;
if ( block != 0 )
{
block->fpipbits = 0;
block->issued = 0;
block->RO.recvlen = 0;
}
}
else
{
if ( (err= iguana_ramchain_verify(coin,ramchain)) == 0 )
{
iguana_blockzcopyRO(coin->chain->zcash,B,0,&block->RO,0);
iguana_blockzcopyRO(coin->chain->zcash,B,0,&RO,0);
rdata->scriptspace = ramchain->H.scriptoffset = scriptspace;
rdata->stackspace = ramchain->H.stacksize = stackspace;
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,(uint32_t)addr->ipbits,block->RO.hash2,block->RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
{
origtxdata->datalen = (int32_t)rdata->allocsize;
//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);
@ -1907,7 +1925,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
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,(uint32_t)addr->ipbits,block->RO.hash2,block->RO.prev_block,bundlei,fpos,1,0)) == 0 )
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(coin,fname,0,1,&R,0,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,fpos,1,0)) == 0 )
{
printf("delete unverified [%d:%d]\n",bp->hdrsi,bundlei);
iguana_ramchain_free(coin,&R,1);
@ -1920,7 +1938,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
bp->numspends += rdata->numspends;
//bp->rawscriptspace += rdata->scriptspace;
}
if ( fpos >= 0 )
if ( block != 0 && fpos >= 0 )
block->fpos = fpos, block->fpipbits = (uint32_t)addr->ipbits;
} else printf("save error\n");
}
@ -1931,7 +1949,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
}
}
}
if ( fpos < 0 )
if ( fpos < 0 && block != 0 )
iguana_blockunmark(coin,block,bp,bundlei,1);
//fprintf(stderr,"finished with hdrsi.%d ht.%d scripts.%u:%u\n",bp->hdrsi,bp->bundleheight,ramchain->H.scriptoffset,rdata->scriptspace);
ramchain->H.ROflag = 0;

41
iguana/iguana_recv.c

@ -789,43 +789,46 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
if ( block == 0 )
/*if ( block == 0 )
block = iguana_blockhashset("noblock",coin,bp->bundleheight+bundlei,origtxdata->zblock.RO.hash2,1);
if ( block->hdrsi != bp->hdrsi || block->bundlei != bundlei )
{
block->hdrsi = bp->hdrsi;
block->bundlei = bundlei;
}
if ( bp->blocks[bundlei] == 0 || bits256_nonz(bp->hashes[bundlei]) == 0 )
}*/
if ( (block= bp->blocks[bundlei]) == 0 || bits256_nonz(bp->hashes[bundlei]) == 0 )
{
//printf("SET [%d:%d]\n",bp->hdrsi,bundlei);
//iguana_hash2set(coin,"noblock",bp,bundlei,origtxdata->zblock.RO.hash2);
bp->hashes[bundlei] = origtxdata->zblock.RO.hash2;
if ( bp->speculative != 0 )
bp->speculative[bundlei] = bp->hashes[bundlei];
bp->blocks[bundlei] = block;
//bp->blocks[bundlei] = block;
}
numtx = origtxdata->zblock.RO.txn_count;
iguana_RTgotblock(coin,origtxdata->zblock.RO.hash2,data,&recvlen,&numtx);
//printf("getblockM update [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2));
block->txvalid = 1;
if ( block->fpipbits != 0 && block->fpos >= 0 )
if ( block != 0 )
{
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
char str[65],str2[65];
numredundant++, redundantsize += recvlen;
if ( time(NULL) > lastdisp+30 )
{
lastdisp = (uint32_t)time(NULL);
printf("%s have %d:%d at %d | %d blocks %s redundant xfers total %s %.2f%% wasted\n",coin->symbol,bp->hdrsi,bundlei,block->fpos,numredundant,mbstr(str,redundantsize),mbstr(str2,totalrecv),100.*redundantsize/totalrecv);
}
if ( bundlei > 1 )
block->txvalid = 1;
if ( block->fpipbits != 0 && block->fpos >= 0 )
{
// printf("DUP s.%d [%d:%d].(%s) %s n%d\n",numsaved,bp!=0?bp->hdrsi:-1,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks);
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
char str[65],str2[65];
numredundant++, redundantsize += recvlen;
if ( time(NULL) > lastdisp+30 )
{
lastdisp = (uint32_t)time(NULL);
printf("%s have %d:%d at %d | %d blocks %s redundant xfers total %s %.2f%% wasted\n",coin->symbol,bp->hdrsi,bundlei,block->fpos,numredundant,mbstr(str,redundantsize),mbstr(str2,totalrecv),100.*redundantsize/totalrecv);
}
if ( bundlei > 1 )
{
// printf("DUP s.%d [%d:%d].(%s) %s n%d\n",numsaved,bp!=0?bp->hdrsi:-1,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks);
}
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
}
txdata = origtxdata;
if ( iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block) >= 0 )

Loading…
Cancel
Save