gcarq / rusty-blockparser

Bitcoin Blockchain Parser written in Rust language
GNU General Public License v3.0
370 stars 145 forks source link

rusty-blockparser simplestats fails. LevelDB is parsing CURRENT.bak #93

Open cameronelliott opened 1 year ago

cameronelliott commented 1 year ago

Hi, thanks for making & sharing this project.

When running this: rusty-blockparser simplestats

I get this output: [22:55:17] INFO - main: Starting rusty-blockparser v0.10.0 ... [22:55:17] INFO - index: Reading index from /home/c/.bitcoin/blocks/index ... [22:55:17] ERROR - main: Cannot load blockchain data from: '/home/c/.bitcoin/blocks'. LevelDB: While parsing "CURRENT.bak": InvalidArgument: invalid file number for table or temp file

These are the files in /home/c/.bitcoin/blocks/index/: 000005.ldb 000367.ldb 000475.ldb 000480.ldb 000568.ldb 000573.ldb 000591.ldb 000596.ldb 000602.ldb CURRENT.bak 000363.ldb 000471.ldb 000476.ldb 000564.ldb 000569.ldb 000574.ldb 000592.ldb 000597.ldb 000604.ldb LOCK 000364.ldb 000472.ldb 000477.ldb 000565.ldb 000570.ldb 000588.ldb 000593.ldb 000598.ldb 000605.ldb LOG 000365.ldb 000473.ldb 000478.ldb 000566.ldb 000571.ldb 000589.ldb 000594.ldb 000599.ldb 000606.log LOG.old 000366.ldb 000474.ldb 000479.ldb 000567.ldb 000572.ldb 000590.ldb 000595.ldb 000600.ldb CURRENT MANIFEST-000607

My bitcoind version is bitcoin-24.0.1 I am running without pruning. (I have 500GB+ of data)

I am not sure what the issue is, maybe newer versions of Bitcoind are storing unexpected files in the index directory, they are incorrectly attempted to be parsed?

Thanks for any idea/suggestions.

cameronelliott commented 1 year ago

Removing CURRENT.bak fixes the issue, and allows simplestats to continue processing data. I guess a PR is needed to ignore CURRENT.bak

gcarq commented 1 year ago

Thanks for reporting this.

I guess a PR is needed to ignore CURRENT.bak

I think get_block_index might need some adaptions. rusty-leveldb expects a directory as argument, but it might be possible to pass a filename filter or some stricter sanity checks via Options.

gcarq commented 1 year ago

There seems to be no easy fix for this, except checking and deleting the file if present. As far as I can see a leveldb is composed of a whole directory and every file is part of it. It's not yet clear to me how this file has been created, I couldn't find much info in the bitcoin client.

Did you read that leveldb with some tool other than bitcoin-core?