|
@ -601,10 +601,13 @@ int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int3 |
|
|
return(-errs); |
|
|
return(-errs); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void iguana_purgevolatiles(struct iguana_info *coin,struct iguana_ramchain *ramchain) |
|
|
void iguana_purgevolatiles(struct iguana_info *coin,struct iguana_ramchain *ramchain) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if ( ramchain->allocatedA != 0 && ramchain->A != 0 ) |
|
|
|
|
|
free(ramchain->A); |
|
|
ramchain->A = 0; |
|
|
ramchain->A = 0; |
|
|
|
|
|
if ( ramchain->allocatedU != 0 && ramchain->Uextras != 0 ) |
|
|
|
|
|
free(ramchain->Uextras); |
|
|
ramchain->Uextras = 0; |
|
|
ramchain->Uextras = 0; |
|
|
if ( ramchain->debitsfileptr != 0 ) |
|
|
if ( ramchain->debitsfileptr != 0 ) |
|
|
{ |
|
|
{ |
|
@ -694,6 +697,101 @@ void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramch |
|
|
} else printf("illegal ramchain.%p\n",ramchain); |
|
|
} else printf("illegal ramchain.%p\n",ramchain); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void iguana_truncatebalances(struct iguana_info *coin) |
|
|
|
|
|
{ |
|
|
|
|
|
int32_t i; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; |
|
|
|
|
|
for (i=0; i<coin->balanceswritten; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (bp= coin->bundles[i]) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
bp->balancefinish = 0; |
|
|
|
|
|
ramchain = &bp->ramchain; |
|
|
|
|
|
iguana_purgevolatiles(coin,ramchain); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
coin->balanceswritten = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t iguana_volatileinit(struct iguana_info *coin) |
|
|
|
|
|
{ |
|
|
|
|
|
bits256 balancehash; struct iguana_utxo *Uptr; struct iguana_account *Aptr; |
|
|
|
|
|
struct sha256_vstate vstate; int32_t i,from_ro,numpkinds,numunspents; struct iguana_bundle *bp; |
|
|
|
|
|
uint32_t crc,filecrc; FILE *fp; char crcfname[512],str[65],str2[65],buf[2048]; |
|
|
|
|
|
from_ro = 1; |
|
|
|
|
|
for (i=0; i<coin->balanceswritten; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish <= 1 || bp->utxofinish <= 1 ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("hdrsi.[%d] emitfinish.%u utxofinish.%u\n",i,bp->emitfinish,bp->utxofinish); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
if ( bp->ramchain.from_ro == 0 || bp->ramchain.from_roX == 0 || bp->ramchain.from_roA == 0 || bp->ramchain.from_roU == 0 ) |
|
|
|
|
|
from_ro = 0; |
|
|
|
|
|
} |
|
|
|
|
|
if ( i != coin->balanceswritten ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("TRUNCATE balances written.%d -> %d\n",coin->balanceswritten,i); |
|
|
|
|
|
iguana_truncatebalances(coin); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
vupdate_sha256(balancehash.bytes,&vstate,0,0); |
|
|
|
|
|
filecrc = 0; |
|
|
|
|
|
sprintf(crcfname,"DB/%s/balancecrc.%d",coin->symbol,coin->balanceswritten); |
|
|
|
|
|
if ( (fp= fopen(crcfname,"rb")) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( fread(&filecrc,1,sizeof(filecrc),fp) != sizeof(filecrc) ) |
|
|
|
|
|
filecrc = 0; |
|
|
|
|
|
else if ( fread(&balancehash,1,sizeof(balancehash),fp) != sizeof(balancehash) ) |
|
|
|
|
|
filecrc = 0; |
|
|
|
|
|
else if ( memcmp(&balancehash,&coin->balancehash,sizeof(balancehash)) != 0 ) |
|
|
|
|
|
filecrc = 0; |
|
|
|
|
|
fclose(fp); |
|
|
|
|
|
} |
|
|
|
|
|
if ( filecrc != 0 ) |
|
|
|
|
|
printf("have filecrc.%08x for %s milli.%.0f\n",filecrc,bits256_str(str,balancehash),OS_milliseconds()); |
|
|
|
|
|
if ( from_ro == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( filecrc == 0 ) |
|
|
|
|
|
vupdate_sha256(balancehash.bytes,&vstate,0,0); |
|
|
|
|
|
for (i=crc=0; i<coin->balanceswritten; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
numpkinds = numunspents = 0; |
|
|
|
|
|
Aptr = 0, Uptr = 0; |
|
|
|
|
|
if ( (bp= coin->bundles[i]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A) != 0 && (Uptr= bp->ramchain.Uextras) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( filecrc == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr)*numpkinds); |
|
|
|
|
|
vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr)*numunspents); |
|
|
|
|
|
} |
|
|
|
|
|
crc = calc_crc32(crc,(void *)Aptr,(int32_t)(sizeof(*Aptr) * numpkinds)); |
|
|
|
|
|
crc = calc_crc32(crc,(void *)Uptr,(int32_t)(sizeof(*Uptr) * numunspents)); |
|
|
|
|
|
} else printf("missing hdrs.[%d] data.%p num.(%u %d) %p %p\n",i,bp->ramchain.H.data,numpkinds,numunspents,Aptr,Uptr); |
|
|
|
|
|
} |
|
|
|
|
|
} else crc = filecrc; |
|
|
|
|
|
printf("millis %.0f from_ro.%d written.%d crc.%08x/%08x balancehash.(%s) vs (%s)\n",OS_milliseconds(),from_ro,coin->balanceswritten,crc,filecrc,bits256_str(str,balancehash),bits256_str(str2,coin->balancehash)); |
|
|
|
|
|
if ( (filecrc != 0 && filecrc != crc) || memcmp(balancehash.bytes,coin->balancehash.bytes,sizeof(balancehash)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("balancehash or crc mismatch\n"); |
|
|
|
|
|
iguana_truncatebalances(coin); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
printf("MATCHED balancehash numhdrsi.%d crc.%08x\n",coin->balanceswritten,crc); |
|
|
|
|
|
if ( (fp= fopen(crcfname,"wb")) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( fwrite(&crc,1,sizeof(crc),fp) != sizeof(crc) || fwrite(&balancehash,1,sizeof(balancehash),fp) != sizeof(balancehash) ) |
|
|
|
|
|
printf("error writing.(%s)\n",crcfname); |
|
|
|
|
|
fclose(fp); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
coin->RTheight = coin->balanceswritten * coin->chain->bundlesize; |
|
|
|
|
|
iguana_bundlestats(coin,buf); |
|
|
|
|
|
return(coin->balanceswritten); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist) |
|
|
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist) |
|
|
{ |
|
|
{ |
|
|
int32_t hdrsi,numpkinds,iter,numhdrsi,numunspents,err; struct iguana_bundle *bp; |
|
|
int32_t hdrsi,numpkinds,iter,numhdrsi,numunspents,err; struct iguana_bundle *bp; |
|
@ -812,6 +910,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu |
|
|
printf("error mapping bundle.[%d]\n",hdrsi); |
|
|
printf("error mapping bundle.[%d]\n",hdrsi); |
|
|
} |
|
|
} |
|
|
char str[65]; printf("BALANCES WRITTEN for %d bundles %s\n",coin->balanceswritten,bits256_str(str,coin->balancehash)); |
|
|
char str[65]; printf("BALANCES WRITTEN for %d bundles %s\n",coin->balanceswritten,bits256_str(str,coin->balancehash)); |
|
|
|
|
|
coin->balanceswritten = iguana_volatileinit(coin); |
|
|
return(coin->balanceswritten); |
|
|
return(coin->balanceswritten); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|