how to create a corrupted database or block

5 replies 82 views
cybergasFull Member
Posts: 93 · Reputation: 505
#1Jun 27, 2021, 10:00 PM
So, I had this problem before where my computer crashed and it messed up a block. To fix it, I just ran bitcoind with the -reindex option to sort out the block issue. Now, I'm curious about how to check if the chain or database is corrupted at startup and I'm trying to simulate a corrupted database. I've been testing ways to cause a corrupted state, but just cutting off the power doesn’t seem to do the trick. I think the power outage needs to happen at a specific point during chain maintenance. Is there a reliable method to create a corrupted database for testing? I'm running Ubuntu and connected directly.
6 Reply Quote Share
cybergasFull Member
Posts: 93 · Reputation: 505
#2Jun 30, 2021, 08:56 AM
Just a follow on:  I just started renaming blocks in blocks, chainstate and received the startup error: So if you want to create a corruption in db for testing, this works
4 Reply Quote Share
SwiftMinerSenior Member
Posts: 259 · Reputation: 1036
#3Jun 30, 2021, 03:00 PM
Firstly Op if I may ask , why are you trying to corrupt the drive? Probably it may exist, but I haven't really come across a drive corruption after the device have been successfully synced with the block chain. Majority of the cases I have come across especially on this forum are those where the drive got corrupt during the process of syncing with the block chain. Sometimes as a result of power outage and sometimes because the block chain was synced to a drive with the wrong format like FAT32 which sometimes has issues when the file load is huge. RAM also has a huge role to play when it comes to computation during the syncronisation process which will attribute how long it will take before the sync is completed.
4 Reply Quote Share
cybergasFull Member
Posts: 93 · Reputation: 505
#4Jul 2, 2021, 11:06 PM
Thanks for asking.  Basically the other day when initially loading the blockchain there was a sudden power outage.  When the system came back up the bitcoind errored out.  Eventually my plan is to have a script which checks if the blockchain (local data stored on my system) is intact (this will run as a ExecStartPre in systemd), and then if not have a systemd process which will in those cases run the bitcoind with the -reindex option.  I already have a simple script which checks if the bitcoind is unable to start and will then hook it up to systemd process which runs with the -reindex in those cases.
4 Reply Quote Share
LuckyCoinLegendary
Posts: 832 · Reputation: 4795
#5Jul 3, 2021, 05:09 AM
You shouldn't try to simulate a power outage as that can actually damage your motherboard. What would be better for testing purposes would be to force-kill the bitcoind process -  either by Task Manager or by sending SIGKILL (not sigterm) to it on Linux or Max.
0 Reply Quote Share
hash_bossLegendary
Posts: 1166 · Reputation: 5261
#6Jul 3, 2021, 09:04 AM
Bitcoin Core check recent block when you open it. So you probably just need to edit recently created blk*dat or rev*dat files to achieve that goal. I said probably since i didn't try it on my own Bitcoin Core files.
4 Reply Quote Share
?Reply
Sign in to reply to this topic

Related topics