Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: dserrano5 on April 06, 2013, 08:54:49 PM



Title: My blockchain is b0rked, would like to repair it
Post by: dserrano5 on April 06, 2013, 08:54:49 PM
Some days ago I found this:

Code:
$ bitcoind getblockhash 3
0000000082b5015589a3fdf2d4baff403e6f0be035a5d9742c1cae6295464449
$ bitcoind getblock 0000000082b5015589a3fdf2d4baff403e6f0be035a5d9742c1cae6295464449
error: no response from server

debug.log:

Code:
2013-04-01 10:29:34 ThreadRPCServer method=getblock
2013-04-01 10:29:35 ERROR: CheckProofOfWork() : nBits below minimum work
2013-04-01 10:29:35 ERROR: CBlock::ReadFromDisk() : errors in block header

syslog:

Code:
[12:35:48] kernel: [616350.252104] bitcoin-rpchand[21782]: segfault at 10 ip 00000000005393a3 sp 00007f217a401e70 error 4 in bitcoind[400000+3cd000]

This happened with all blocks between 1 and 59571, inclusive. A couple of days later when examining my blk00000.dat I noticed that the genesis block was followed by a bunch of null bytes, until exactly the 16 MiB mark. The next magic value showed up not much later, followed by the block 59573. I assume that the data between 16 MiB and that point was part of the block 59572.

So I tried extracting the missing data from my copy of the bootstrap.dat but I only managed to completely break the blk00000.dat :). Then I took a peek to the blk00001.dat to look what was the first block there, and stored all previous blocks in the blk00000.dat.

Bitcoin starts and runs fine, but reading some blocks still kills the process, while reading some others returns garbage. I wrote a small blockchain parser and it seems to be sane; after all, the data came from the bootstrap.dat. So I'm not sure why bitcoin is dying on them (though I have some hypotheses).

I have another copy of the datadir handy, not to mention the bootstrap.dat itself, but I'd really like to repair this one. Does the .bitcoin/blocks/index directory have something to do? Can/should I remove it? Anything else worth a try?


Title: Re: My blockchain is b0rked, would like to repair it
Post by: grue on April 06, 2013, 11:34:10 PM
why not just delete everything except wallet.dat and bitcoin.conf (if you have it), and let the client redownload the blocks?


Title: Re: My blockchain is b0rked, would like to repair it
Post by: dserrano5 on April 07, 2013, 09:50:27 AM
why not just delete everything except wallet.dat and bitcoin.conf (if you have it), and let the client redownload the blocks?

I wouldn't learn anything by doing that.


Title: Re: My blockchain is b0rked, would like to repair it
Post by: MaGNeT on April 07, 2013, 10:50:46 AM
why not just delete everything except wallet.dat and bitcoin.conf (if you have it), and let the client redownload the blocks?

I wouldn't learn anything by doing that.

Yes you would.
You would learn it saves a lot of time and trouble  ;D