tenthirtyone / blocktools

Block Parser for Bitcoin
142 stars 73 forks source link

Using blocktools with regtest #11

Open datGryphon opened 6 years ago

datGryphon commented 6 years ago

Hi,

I wanted to say thanks for the work you've done so far, this a really great tool that has helped me gain a lot of insight about the structure of the block data stored locally on disk. However, I'm currently working on a project where I want to scan .dat files for orphaned blocks that I purposely generate in regtest mode, but the parser does not like the mostly empty block contents. Particularly the transactions which have no transaction scripts.

I have tried a little bit to modify the code to fix the errors I've encountered but i can only get the first block after the genesis block to parse correctly. I was hoping that maybe you had some insight about how I could adjust the tool to let me parse these nearly empty blocks correctly or where I could go to find more information about the format of .dat files produced by bitcoin. Attached below is the .dat file I've been working with. The first block after the genesis block should be the orphan block. There should be 3 additional blocks after that in the file.

Thank you, Caleb

blk00000.dat.zip

datGryphon commented 6 years ago

Hey,

Wanted to leave you an update. I'll attach below a snapshot of my modified version of your repo. There's one commit in there which should document the changes I made.

Basically all I did was modify the init in the block class so that when the magic number matches the one used by btc core in regest mode, the block header info is read in as normal and then instead of processing the transactions of the block: I read in self.blocksize worth of bytes then seek back the same distance, then look through the bytes i read to see if the magic number appears again, if so I seek to that point and return so the next block parses correctly, otherwise i set self.continueParsing to false.

Since all I want to do is look for forks, this serves my purpose because I can check for duplicate previous block hashes.

I also changed the main parsing loop in sight.py to change the output to better suit my needs but you can just ignore that.

Thanks again for this great program, Caleb

PS: I had to remove everything by the python source to get the filesize under 10Megs. Use the blk.dat I provided previously to test.

modified_blocktools.zip