Bitcoin

Chain Reconstruction – Invalid transaction when reading block from file `blk*.dat`.

The issue occurs at block 1,669,774 of the testnet (https://blockstream.info/testnet/block/0000000010001cebd3e4f2fe5f2e2cbbe35ba6457554d9e0e6eb100b6f91eaee).

To obtain a block, the key is read to retrieve the file and location. b<block_hash> It fetches from the leveldb database and then parses the blocks in the usual way. This works well for all blocks except this one, which returns a list of transactions for this block before reconstruction.

For example, a transaction list contains a hash. 6ef0f0d3fcf20aedefa37425ea93e69c7da4d04fd1ce983c5cba613630e775ca instead of hash f07b4eb879ead12e58742e322878310d4b5bcd48b25c1e4ab781 672a9f44a312.
bitcoin-cli getblock <hash> It returns me the correct list of transactions. (Using the correct hash in both cases, of course. 0000000010001cebd3e4f2fe5f2e2cbbe35ba6457554d9e0e6eb100b6f91eaee).

How do I get the correct version of the block? Thank you in advance!

Edit: Here is the function I use to get the file and location:

def read_raw_block(self, block_hash, only_header=False):
        block_key = bytes('b', 'utf-8') + binascii.unhexlify(inverse_hash(block_hash))
        block_data = self.blocks_leveldb.get(block_key)
        ds = BCDataStream()
        ds.write(block_data)

        version = ds.read_var_int()
        height = ds.read_var_int()
        status = ds.read_var_int()
        tx_count = ds.read_var_int()
        file_num = ds.read_var_int()
        block_pos_in_file = ds.read_var_int() - 8
        block_undo_pos_in_file = ds.read_var_int()
        block_header = ds.read_bytes(80)
        self.prepare_data_stream(file_num, block_pos_in_file)
        block = self.read_block(self.data_stream, only_header=only_header)
        block('block_index') = height
        return block

Solved: Segwit transaction. f07b4eb879ead12e58742e322878310d4b5bcd48b25c1e4ab781672a9f44a312 txid and 6ef0f0d3fcf20aedefa37425ea93e69c7da4d04fd1ce983c5cba613630e775ca It’s a hash!

Related Articles

Back to top button