|
|
@ -184,37 +184,9 @@ int32_t iguana_savehdrs(struct iguana_info *coin) |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
if ( ramchain->debitsfileptr != 0 ) |
|
|
|
{ |
|
|
|
munmap(ramchain->debitsfileptr,ramchain->debitsfilesize); |
|
|
|
ramchain->debitsfileptr = 0; |
|
|
|
ramchain->debitsfilesize = 0; |
|
|
|
ramchain->A = 0; |
|
|
|
} |
|
|
|
if ( ramchain->lastspendsfileptr != 0 ) |
|
|
|
{ |
|
|
|
munmap(ramchain->lastspendsfileptr,ramchain->lastspendsfilesize); |
|
|
|
ramchain->lastspendsfileptr = 0; |
|
|
|
ramchain->lastspendsfilesize = 0; |
|
|
|
ramchain->Uextras = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
coin->balanceswritten = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) |
|
|
|
{ |
|
|
|
int32_t i,j,k,m,c,height,flag,bundlei,from_ro; char checkstr[1024],line[1024]; |
|
|
|
int32_t i,j,k,m,c,height,flag,bundlei; char checkstr[1024],line[1024]; |
|
|
|
struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,zero,lastbundle; |
|
|
|
struct iguana_block *block; |
|
|
|
memset(&zero,0,sizeof(zero)); |
|
|
@ -329,81 +301,7 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) |
|
|
|
if ( iter == 1 ) |
|
|
|
{ |
|
|
|
if ( coin->balanceswritten > 0 ) |
|
|
|
{ |
|
|
|
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 |
|
|
|
{ |
|
|
|
bits256 balancehash; struct iguana_utxo *Uptr; struct iguana_account *Aptr; struct sha256_vstate vstate; int32_t numpkinds,numunspents; uint32_t crc,filecrc; FILE *fp; char crcfname[512],str[65],str2[65]; |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
char buf[2048]; |
|
|
|
iguana_bundlestats(coin,buf); |
|
|
|
coin->balanceswritten = iguana_volatileinit(coin); |
|
|
|
if ( coin->balanceswritten > 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<coin->balanceswritten; i++) |
|
|
|