Title: Correct header data for block 1 Post by: MatthewLM on December 18, 2012, 10:11:06 PM Hello. I have some code that calculates a hash for a block. It was working perfectly sometime before, but now for some reason I cannot get a correct hash for block 1. I can calculate the correct hash for the genesis block, but not block 1. I've taken what I've thought is the correct header data for block 1 and I've tried to hash it manually using a technique that works for the genesis block and it seems that the header data is incorrect. Can anyone find a problem with this data? I might be going crazy as I can't find it:
Code: // VERSION Thanks. Title: Re: Correct header data for block 1 Post by: koin on December 18, 2012, 10:24:48 PM for some reason I cannot get a correct hash for block 1.. for block 1 or for the genesis block (block 0)? https://bitcointalk.org/index.php?topic=119530 Title: Re: Correct header data for block 1 Post by: MatthewLM on December 18, 2012, 10:28:22 PM Hi koin. I am referring to the block with the index 1, aka. the 2nd block.
http://blockexplorer.com/b/1 This is driving me slightly insane. :-) Title: Re: Correct header data for block 1 Post by: kjj on December 18, 2012, 10:31:49 PM Double check the endianness of your prevhash. In the genesis block, it is all zeros, meaning that you still get the right result even if you have it backwards.
Just a guess. Title: Re: Correct header data for block 1 Post by: MatthewLM on December 18, 2012, 10:33:33 PM Double check the endianness of your prevhash. In the genesis block, it is all zeros, meaning that you still get the right result even if you have it backwards. Just a guess. That's a good guess kjj. Unfortunately I tried reversing the previous block hash and it still failed. Title: Re: Correct header data for block 1 Post by: etotheipi on December 18, 2012, 11:54:54 PM Perhaps it's a single-bit error! I documented my experience with this here (https://bitcointalk.org/index.php?topic=44887.0). It was maddening, to be able to confirm 1.5 million tx hashes, and have exactly one fail. It took me a while, but I eventually narrowed it down. I was able to manually compare the tx from a different source to the one in my blkfile.
Title: Re: Correct header data for block 1 Post by: MatthewLM on December 19, 2012, 02:57:12 PM Thanks for the link Alan, as it's interesting.
But I did not obtain the block data from the block database from the satoshi client. I've created the data manually. It was working before, so at some point I accidentally changed something, I just do not know what. Does anyone know how to dump block byte data from the block database for the satoshi client? Doing that would be very useful to compare the data. As for bit errors, I've received mixed messages as to whether or not error correction is important at the application level. To be safe, in any case, I plan to implement some error correction to my database software. Before I do that I want to get the full validator unit tests working. The error correction will probably be something simple at first, such as hamming code. Title: Re: Correct header data for block 1 Post by: kjj on December 19, 2012, 03:25:02 PM Does anyone know how to dump block byte data from the block database for the satoshi client? https://bitcointalk.org/index.php?topic=119530.msg1291088#msg1291088 Title: Re: Correct header data for block 1 Post by: MatthewLM on December 19, 2012, 03:33:07 PM I managed to get a hex dump of the raw block data. The blockchain data storage is more simple than I thought it would be. The blocks are stored with the network identifier ("magic bytes") followed by the block length and then the block. This is the result:
Code: (null):cbitcoin matt$ hexdump -C -n 80 -s 301 /Users/matt/Library/Application\ Support/Bitcoin/blk0001.dat And indeed when I compared the data I saw there is one incorrect byte in the merkle root. I think I remember what I did. I replaced all the lowercase hexadecimal literals with uppercase ones and must have made this mistake and forgot about it. It works now. Does anyone know how to dump block byte data from the block database for the satoshi client? https://bitcointalk.org/index.php?topic=119530.msg1291088#msg1291088 Thanks, though I managed to figure it out. Title: Re: Correct header data for block 1 Post by: Peter Todd on December 19, 2012, 05:22:35 PM FWIW I wrote some Python code that recreates the raw hex block header, the part that is hashed to create a block hash, from the output of the RPC interface getblock:
Code: import struct Note the [::-1] to the byte order to change the endianness in a few places. |