|
|
@ -517,9 +517,9 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre |
|
|
|
} |
|
|
|
if ( (spentbp= coin->bundles[hdrsi]) == 0 || hdrsi > spent_hdrsi ) |
|
|
|
printf("illegal hdrsi.%d when [%d] spentbp.%p\n",hdrsi,spent_hdrsi,spentbp);//, getchar();
|
|
|
|
else if ( unspentind == 0 || unspentind >= spentbp->ramchain.H.data->numunspents ) |
|
|
|
else if ( unspentind == 0 || unspentind >= ramchain->H.data->numunspents ) |
|
|
|
{ |
|
|
|
printf("illegal unspentind.%d vs max.%d spentbp.%p[%d]\n",unspentind,spentbp->ramchain.H.data->numunspents,spentbp,hdrsi); |
|
|
|
printf("illegal unspentind.%d vs max.%d spentbp.%p[%d]\n",unspentind,ramchain->H.data->numunspents,spentbp,hdrsi); |
|
|
|
exit(-1); |
|
|
|
} else return(spentbp); |
|
|
|
return(0); |
|
|
@ -1375,182 +1375,6 @@ int32_t iguana_volatileinit(struct iguana_info *coin) |
|
|
|
return(coin->balanceswritten); |
|
|
|
} |
|
|
|
|
|
|
|
void iguana_RTramchainfree(struct iguana_info *coin) |
|
|
|
{ |
|
|
|
iguana_utxoupdate(coin,-1,0,0,0,0,-1); // free hashtables
|
|
|
|
coin->RTheight = coin->balanceswritten * coin->chain->bundlesize; |
|
|
|
coin->RTgenesis = 0; |
|
|
|
iguana_ramchain_free(coin,&coin->RTramchain,1); |
|
|
|
//iguana_mempurge(&coin->RTHASHMEM);
|
|
|
|
} |
|
|
|
|
|
|
|
void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp) |
|
|
|
{ |
|
|
|
uint32_t i,changed = 0; struct iguana_ramchain *dest = &coin->RTramchain; struct iguana_blockRO *B; |
|
|
|
if ( dest->H.data != 0 ) |
|
|
|
{ |
|
|
|
i = 0; |
|
|
|
if ( coin->RTheight != bp->bundleheight + dest->H.data->numblocks ) |
|
|
|
changed++; |
|
|
|
else |
|
|
|
{ |
|
|
|
B = (void *)(long)((long)dest->H.data + dest->H.data->Boffset); |
|
|
|
for (i=0; i<dest->H.data->numblocks; i++) |
|
|
|
if ( bits256_cmp(B[i].hash2,bp->hashes[i]) != 0 ) |
|
|
|
{ |
|
|
|
char str[65],str2[65]; printf("mismatched hash2 at %d %s vs %s\n",bp->bundleheight+i,bits256_str(str,B[i].hash2),bits256_str(str2,bp->hashes[i])); |
|
|
|
changed++; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( changed != 0 ) |
|
|
|
{ |
|
|
|
printf("RTramchain changed %d bundlei.%d | coin->RTheight %d != %d bp->bundleheight + %d coin->RTramchain.H.data->numblocks\n",coin->RTheight,i,coin->RTheight,bp->bundleheight,dest->H.data->numblocks); |
|
|
|
//coin->RTheight = coin->balanceswritten * coin->chain->bundlesize;
|
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( coin->RTramchain.H.data == 0 ) |
|
|
|
{ |
|
|
|
printf("ALLOC RTramchain\n"); |
|
|
|
iguana_ramchainopen(coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]); |
|
|
|
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti; |
|
|
|
dest->externalind = dest->H.stacksize = 0; |
|
|
|
dest->H.scriptoffset = 1; |
|
|
|
//if ( coin->RTHASHMEM.ptr == 0 )
|
|
|
|
// iguana_meminit(&coin->RTHASHMEM,"RTHASH",0,1024L*1024L*1024L,0);
|
|
|
|
if ( coin->PREFETCHLAG != 0 ) |
|
|
|
{ |
|
|
|
iguana_ramchain_prefetch(coin,&coin->RTramchain,0); |
|
|
|
iguana_prefetch(coin,bp,coin->bundlescount,1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block) |
|
|
|
{ |
|
|
|
char fname[1024]; long filesize; int32_t err; void *ptr; |
|
|
|
if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 ) |
|
|
|
{ |
|
|
|
if ( iguana_mapchaininit(coin,R,bp,bundlei,block,ptr,filesize) == 0 ) |
|
|
|
{ |
|
|
|
if ( dest != 0 ) |
|
|
|
err = iguana_ramchain_iterate(coin,dest,R,bp,bundlei); |
|
|
|
else err = 0; |
|
|
|
if ( err != 0 || bits256_cmp(R->H.data->firsthash2,block->RO.hash2) != 0 ) |
|
|
|
{ |
|
|
|
char str[65]; |
|
|
|
printf("ERROR [%d:%d] %s vs ",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2)); |
|
|
|
printf("mapped.%s\n",bits256_str(str,R->H.data->firsthash2)); |
|
|
|
} else return(ptr); |
|
|
|
iguana_blockunmark(coin,block,bp,bundlei,1); |
|
|
|
} |
|
|
|
iguana_ramchain_free(coin,R,1); |
|
|
|
} |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_realtime_update(struct iguana_info *coin) |
|
|
|
{ |
|
|
|
double startmillis0; static double totalmillis0; static int32_t num0; |
|
|
|
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t starti,bundlei,i,n,flag=0; bits256 hash2; |
|
|
|
struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR; |
|
|
|
starti = coin->RTheight % coin->chain->bundlesize; |
|
|
|
if ( (bp= coin->current) != 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi == coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && (coin->RTheight < coin->blocks.hwmchain.height-3 || time(NULL) > bp->lastRT) )//&& coin->blocks.hwmchain.height >= coin->longestchain-1 && coin->RTramchain.H.data->numblocks < bp->n )
|
|
|
|
{ |
|
|
|
bp->lastRT = (uint32_t)time(NULL); |
|
|
|
iguana_RTramchainalloc(coin,bp); |
|
|
|
bp->isRT = 1; |
|
|
|
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height ) |
|
|
|
{ |
|
|
|
//printf("RT.%d vs hwm.%d starti.%d bp->n %d\n",coin->RTheight,coin->blocks.hwmchain.height,starti,bp->n);
|
|
|
|
dest = &coin->RTramchain; |
|
|
|
B = (void *)(long)((long)rdata + rdata->Boffset); |
|
|
|
bundlei = (coin->RTheight % coin->chain->bundlesize); |
|
|
|
if ( (block= bp->blocks[bundlei]) != 0 && bits256_nonz(block->RO.prev_block) != 0 ) |
|
|
|
{ |
|
|
|
iguana_blocksetcounters(coin,block,dest); |
|
|
|
startmillis0 = OS_milliseconds(); |
|
|
|
if ( iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 ) |
|
|
|
{ |
|
|
|
for (i=bundlei; i<bp->n; i++) |
|
|
|
{ |
|
|
|
block = iguana_bundleblock(coin,&hash2,bp,bundlei+i); |
|
|
|
if ( i == 0 || (bits256_nonz(hash2) != 0 && (block == 0 || block->txvalid == 0)) ) |
|
|
|
{ |
|
|
|
uint8_t serialized[512]; int32_t len; struct iguana_peer *addr; |
|
|
|
char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block); |
|
|
|
addr = coin->peers.ranked[rand() % 8]; |
|
|
|
if ( addr != 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 ) |
|
|
|
iguana_send(coin,addr,serialized,len); |
|
|
|
coin->RTgenesis = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
return(-1); |
|
|
|
} else iguana_ramchain_free(coin,&blockR,1); |
|
|
|
B[bundlei] = block->RO; |
|
|
|
totalmillis0 += (OS_milliseconds() - startmillis0); |
|
|
|
num0++; |
|
|
|
flag++; |
|
|
|
coin->blocks.RO[bp->bundleheight+bundlei] = block->RO; |
|
|
|
double startmillis = OS_milliseconds(); static double totalmillis; static int32_t num; |
|
|
|
/*if ( iguana_RTutxo(coin,bp,dest,bundlei) < 0 )
|
|
|
|
{ |
|
|
|
printf("RTutxo error -> RTramchainfree\n"); |
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
return(-1); |
|
|
|
}*/ |
|
|
|
totalmillis += (OS_milliseconds() - startmillis); |
|
|
|
num++; |
|
|
|
//printf("RTutxo.[%d] ave %.2f micros, total %.2f seconds\n",num,(totalmillis*1000.)/num,totalmillis/1000.);
|
|
|
|
//_iguana_chainlink(coin,block);
|
|
|
|
coin->RTheight++; |
|
|
|
printf(">>>> RT.%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); |
|
|
|
coin->RTramchain.H.data->numblocks = bundlei + 1; |
|
|
|
} else break; |
|
|
|
} |
|
|
|
} |
|
|
|
n = 0; |
|
|
|
if ( dest != 0 && flag != 0 && coin->RTheight >= coin->longestchain ) |
|
|
|
{ |
|
|
|
printf("ramchainiterate.[%d] ave %.2f micros, total %.2f seconds starti.%d num.%d\n",num0,(totalmillis0*1000.)/num0,totalmillis0/1000.,starti,coin->RTheight%bp->n); |
|
|
|
if ( iguana_spendvectors(coin,bp,dest,starti,coin->RTheight%bp->n,0) < 0 ) |
|
|
|
{ |
|
|
|
printf("RTutxo error -> RTramchainfree\n"); |
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("spendvectors calculated to %d\n",coin->RTheight); |
|
|
|
} |
|
|
|
while ( block != 0 ) |
|
|
|
{ |
|
|
|
if ( bits256_cmp(iguana_blockhash(coin,coin->RTheight-n-1),block->RO.hash2) != 0 ) |
|
|
|
{ |
|
|
|
printf("blockhash error at %d\n",coin->RTheight-n-1); |
|
|
|
break; |
|
|
|
} |
|
|
|
block = iguana_blockfind("RTupdate",coin,block->RO.prev_block); |
|
|
|
n++; |
|
|
|
if ( coin->RTgenesis != 0 && n >= bp->n ) |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( coin->RTgenesis == 0) |
|
|
|
{ |
|
|
|
if ( n == coin->RTheight ) |
|
|
|
{ |
|
|
|
printf("RTgenesis verified\n"); |
|
|
|
coin->RTgenesis = (uint32_t)time(NULL); |
|
|
|
} else printf("RTgenesis failed to verify\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( dest != 0 && flag != 0 ) |
|
|
|
printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); |
|
|
|
return(flag); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist) |
|
|
|
{ |
|
|
|
int32_t hdrsi,numpkinds,iter,numhdrsi,i,numunspents,err; struct iguana_bundle *bp; |
|
|
@ -1795,7 +1619,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin) |
|
|
|
return(n); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *spentbp) |
|
|
|
int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *spentbp,struct iguana_ramchain *ramchain) |
|
|
|
{ |
|
|
|
struct iguana_bundle *bp; int16_t spent_hdrsi; uint32_t numpkinds; struct iguana_unspent *spentU; struct iguana_spendvector *vec; int32_t i,converted,j,n = coin->bundlescount; |
|
|
|
if ( spentbp->converted != 0 ) |
|
|
@ -1805,9 +1629,9 @@ int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *s |
|
|
|
} |
|
|
|
spentbp->converted = 1; |
|
|
|
spent_hdrsi = spentbp->hdrsi; |
|
|
|
numpkinds = spentbp->ramchain.H.data->numpkinds; |
|
|
|
iguana_ramchain_prefetch(coin,&spentbp->ramchain,0); |
|
|
|
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset); |
|
|
|
numpkinds = ramchain->H.data->numpkinds; |
|
|
|
iguana_ramchain_prefetch(coin,ramchain,0); |
|
|
|
spentU = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Uoffset); |
|
|
|
for (i=converted=0; i<n; i++) |
|
|
|
{ |
|
|
|
if ( (bp= coin->bundles[i]) != 0 && bp->tmpspends != 0 && bp->numtmpspends > 0 ) |
|
|
@ -1841,13 +1665,13 @@ int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *s |
|
|
|
return(converted); |
|
|
|
} |
|
|
|
|
|
|
|
void iguana_convert(struct iguana_info *coin,struct iguana_bundle *bp) |
|
|
|
void iguana_convert(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain) |
|
|
|
{ |
|
|
|
static int64_t total,depth; |
|
|
|
int32_t i,n,m,converted; int64_t total_tmpspends; double startmillis = OS_milliseconds(); |
|
|
|
depth++; |
|
|
|
//printf("iguana_convert.[%d] depth.%d %u\n",bp->hdrsi,(int32_t)depth,bp->converted);
|
|
|
|
if ( (converted= iguana_spendvectorconvs(coin,bp)) < 0 ) |
|
|
|
if ( (converted= iguana_spendvectorconvs(coin,bp,ramchain)) < 0 ) |
|
|
|
printf("error ram balancecalc.[%d]\n",bp->hdrsi); |
|
|
|
else |
|
|
|
{ |
|
|
@ -1928,6 +1752,184 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int |
|
|
|
return(flag); |
|
|
|
} |
|
|
|
|
|
|
|
void iguana_RTramchainfree(struct iguana_info *coin) |
|
|
|
{ |
|
|
|
iguana_utxoupdate(coin,-1,0,0,0,0,-1); // free hashtables
|
|
|
|
coin->RTheight = coin->balanceswritten * coin->chain->bundlesize; |
|
|
|
coin->RTgenesis = 0; |
|
|
|
iguana_ramchain_free(coin,&coin->RTramchain,1); |
|
|
|
//iguana_mempurge(&coin->RTHASHMEM);
|
|
|
|
} |
|
|
|
|
|
|
|
void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp) |
|
|
|
{ |
|
|
|
uint32_t i,changed = 0; struct iguana_ramchain *dest = &coin->RTramchain; struct iguana_blockRO *B; |
|
|
|
if ( dest->H.data != 0 ) |
|
|
|
{ |
|
|
|
i = 0; |
|
|
|
if ( coin->RTheight != bp->bundleheight + dest->H.data->numblocks ) |
|
|
|
changed++; |
|
|
|
else |
|
|
|
{ |
|
|
|
B = (void *)(long)((long)dest->H.data + dest->H.data->Boffset); |
|
|
|
for (i=0; i<dest->H.data->numblocks; i++) |
|
|
|
if ( bits256_cmp(B[i].hash2,bp->hashes[i]) != 0 ) |
|
|
|
{ |
|
|
|
char str[65],str2[65]; printf("mismatched hash2 at %d %s vs %s\n",bp->bundleheight+i,bits256_str(str,B[i].hash2),bits256_str(str2,bp->hashes[i])); |
|
|
|
changed++; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( changed != 0 ) |
|
|
|
{ |
|
|
|
printf("RTramchain changed %d bundlei.%d | coin->RTheight %d != %d bp->bundleheight + %d coin->RTramchain.H.data->numblocks\n",coin->RTheight,i,coin->RTheight,bp->bundleheight,dest->H.data->numblocks); |
|
|
|
//coin->RTheight = coin->balanceswritten * coin->chain->bundlesize;
|
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( coin->RTramchain.H.data == 0 ) |
|
|
|
{ |
|
|
|
printf("ALLOC RTramchain\n"); |
|
|
|
iguana_ramchainopen(coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]); |
|
|
|
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti; |
|
|
|
dest->externalind = dest->H.stacksize = 0; |
|
|
|
dest->H.scriptoffset = 1; |
|
|
|
//if ( coin->RTHASHMEM.ptr == 0 )
|
|
|
|
// iguana_meminit(&coin->RTHASHMEM,"RTHASH",0,1024L*1024L*1024L,0);
|
|
|
|
if ( coin->PREFETCHLAG != 0 ) |
|
|
|
{ |
|
|
|
iguana_ramchain_prefetch(coin,&coin->RTramchain,0); |
|
|
|
iguana_prefetch(coin,bp,coin->bundlescount,1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block) |
|
|
|
{ |
|
|
|
char fname[1024]; long filesize; int32_t err; void *ptr; |
|
|
|
if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 ) |
|
|
|
{ |
|
|
|
if ( iguana_mapchaininit(coin,R,bp,bundlei,block,ptr,filesize) == 0 ) |
|
|
|
{ |
|
|
|
if ( dest != 0 ) |
|
|
|
err = iguana_ramchain_iterate(coin,dest,R,bp,bundlei); |
|
|
|
else err = 0; |
|
|
|
if ( err != 0 || bits256_cmp(R->H.data->firsthash2,block->RO.hash2) != 0 ) |
|
|
|
{ |
|
|
|
char str[65]; |
|
|
|
printf("ERROR [%d:%d] %s vs ",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2)); |
|
|
|
printf("mapped.%s\n",bits256_str(str,R->H.data->firsthash2)); |
|
|
|
} else return(ptr); |
|
|
|
iguana_blockunmark(coin,block,bp,bundlei,1); |
|
|
|
} |
|
|
|
iguana_ramchain_free(coin,R,1); |
|
|
|
} |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_realtime_update(struct iguana_info *coin) |
|
|
|
{ |
|
|
|
double startmillis0; static double totalmillis0; static int32_t num0; |
|
|
|
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t starti,bundlei,i,n,flag=0; bits256 hash2; |
|
|
|
struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR; |
|
|
|
starti = coin->RTheight % coin->chain->bundlesize; |
|
|
|
if ( (bp= coin->current) != 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi == coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && (coin->RTheight < coin->blocks.hwmchain.height-3 || time(NULL) > bp->lastRT) )//&& coin->blocks.hwmchain.height >= coin->longestchain-1 && coin->RTramchain.H.data->numblocks < bp->n )
|
|
|
|
{ |
|
|
|
bp->lastRT = (uint32_t)time(NULL); |
|
|
|
iguana_RTramchainalloc(coin,bp); |
|
|
|
bp->isRT = 1; |
|
|
|
while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height ) |
|
|
|
{ |
|
|
|
//printf("RT.%d vs hwm.%d starti.%d bp->n %d\n",coin->RTheight,coin->blocks.hwmchain.height,starti,bp->n);
|
|
|
|
dest = &coin->RTramchain; |
|
|
|
B = (void *)(long)((long)rdata + rdata->Boffset); |
|
|
|
bundlei = (coin->RTheight % coin->chain->bundlesize); |
|
|
|
if ( (block= bp->blocks[bundlei]) != 0 && bits256_nonz(block->RO.prev_block) != 0 ) |
|
|
|
{ |
|
|
|
iguana_blocksetcounters(coin,block,dest); |
|
|
|
startmillis0 = OS_milliseconds(); |
|
|
|
if ( iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 ) |
|
|
|
{ |
|
|
|
for (i=bundlei; i<bp->n; i++) |
|
|
|
{ |
|
|
|
block = iguana_bundleblock(coin,&hash2,bp,bundlei+i); |
|
|
|
if ( i == 0 || (bits256_nonz(hash2) != 0 && (block == 0 || block->txvalid == 0)) ) |
|
|
|
{ |
|
|
|
uint8_t serialized[512]; int32_t len; struct iguana_peer *addr; |
|
|
|
char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block); |
|
|
|
addr = coin->peers.ranked[rand() % 8]; |
|
|
|
if ( addr != 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 ) |
|
|
|
iguana_send(coin,addr,serialized,len); |
|
|
|
coin->RTgenesis = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
return(-1); |
|
|
|
} else iguana_ramchain_free(coin,&blockR,1); |
|
|
|
B[bundlei] = block->RO; |
|
|
|
totalmillis0 += (OS_milliseconds() - startmillis0); |
|
|
|
num0++; |
|
|
|
flag++; |
|
|
|
coin->blocks.RO[bp->bundleheight+bundlei] = block->RO; |
|
|
|
double startmillis = OS_milliseconds(); static double totalmillis; static int32_t num; |
|
|
|
/*if ( iguana_RTutxo(coin,bp,dest,bundlei) < 0 )
|
|
|
|
{ |
|
|
|
printf("RTutxo error -> RTramchainfree\n"); |
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
return(-1); |
|
|
|
}*/ |
|
|
|
totalmillis += (OS_milliseconds() - startmillis); |
|
|
|
num++; |
|
|
|
//printf("RTutxo.[%d] ave %.2f micros, total %.2f seconds\n",num,(totalmillis*1000.)/num,totalmillis/1000.);
|
|
|
|
//_iguana_chainlink(coin,block);
|
|
|
|
coin->RTheight++; |
|
|
|
printf(">>>> RT.%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); |
|
|
|
coin->RTramchain.H.data->numblocks = bundlei + 1; |
|
|
|
} else break; |
|
|
|
} |
|
|
|
} |
|
|
|
n = 0; |
|
|
|
if ( dest != 0 && flag != 0 && coin->RTheight >= coin->longestchain ) |
|
|
|
{ |
|
|
|
printf("ramchainiterate.[%d] ave %.2f micros, total %.2f seconds starti.%d num.%d\n",num0,(totalmillis0*1000.)/num0,totalmillis0/1000.,starti,coin->RTheight%bp->n); |
|
|
|
if ( iguana_spendvectors(coin,bp,dest,starti,coin->RTheight%bp->n,0) < 0 ) |
|
|
|
{ |
|
|
|
printf("RTutxo error -> RTramchainfree\n"); |
|
|
|
iguana_RTramchainfree(coin); |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("spendvectors calculated to %d\n",coin->RTheight); |
|
|
|
iguana_convert(coin,bp,dest); |
|
|
|
printf("spendvectors converted to %d\n",coin->RTheight); |
|
|
|
} |
|
|
|
while ( block != 0 ) |
|
|
|
{ |
|
|
|
if ( bits256_cmp(iguana_blockhash(coin,coin->RTheight-n-1),block->RO.hash2) != 0 ) |
|
|
|
{ |
|
|
|
printf("blockhash error at %d\n",coin->RTheight-n-1); |
|
|
|
break; |
|
|
|
} |
|
|
|
block = iguana_blockfind("RTupdate",coin,block->RO.prev_block); |
|
|
|
n++; |
|
|
|
if ( coin->RTgenesis != 0 && n >= bp->n ) |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( coin->RTgenesis == 0) |
|
|
|
{ |
|
|
|
if ( n == coin->RTheight ) |
|
|
|
{ |
|
|
|
printf("RTgenesis verified\n"); |
|
|
|
coin->RTgenesis = (uint32_t)time(NULL); |
|
|
|
} else printf("RTgenesis failed to verify\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( dest != 0 && flag != 0 ) |
|
|
|
printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); |
|
|
|
return(flag); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp) |
|
|
|
{ |
|
|
|
if ( bp->validated <= 1 ) |
|
|
|