My computer crashed the other day and it messed up a block. I had to rerun bitcoind with -reindex to fix it. Now I'm trying to figure out how to intentionally corrupt the chain or database for testing. Just cutting the power doesn't seem to do the trick... is there a good method to create a corrupted database? I'm on Ubuntu, direct connected.
How to Create a Corrupted Blockchain Database for Testing?
5 replies 295 views
Following up on that, I tried renaming blocks in the blocks and chainstate folders. Got a startup error from that. So, if anyone wants to create a corrupt database for testing, looks like that method works.
But why would you wanna corrupt the db? In my experience, corruption usually happens during syncing, not after. Most cases I've seen involve power outages or using the wrong format like FAT32. That can mess things up big time. RAM issues can also cause problems.
Thanks for the reply! So, I had a sudden power cut while loading the blockchain. When I rebooted, bitcoind wouldn’t start. I'm thinking of writing a script to check if my local blockchain data is intact at startup. If it’s not, I wanna run bitcoind with -reindex. I already have a script that checks if bitcoind fails to start.
Dude, simulating a power outage is risky! You might fry your motherboard or something. Better to just force-kill the bitcoind process instead. Use Task Manager or send a SIGKILL on Linux or Mac, that’s way safer for testing.
When you launch Bitcoin Core, it checks the recent blocks. You might just need to edit the blk*dat or rev*dat files to simulate corruption. I think that might work, but I haven’t tried it on my own setup.