• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

bitcoin core development – What is the data format layout for txindex LevelDB values?

Moussa by Moussa
February 15, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


The keys I understand, t + 32-byte hash.

But my problem are the values. I understand from sources such as What are the keys used in the blockchain levelDB (ie what are the key:value pairs)? that the values should encode three values: dat file number, block offset, and tx offset within block.

But I’ve noticed that each value has a different sizes between 5 and 10 on the first thousand entries, so I’m not sure how to decode the values into those three fields. Are those fields simply 3 varint values?

Here’s my Plyvel code that prints out the lengths using plyvel==1.5.1, Bitcoin Core v26.0.0 on Ubuntu 23.10:

#!/usr/bin/env python3

import struct

import plyvel

def decode_varint(data):
    """
    https://github.com/alecalve/python-bitcoin-blockchain-parser/blob/c06f420995b345c9a193c8be6e0916eb70335863/blockchain_parser/utils.py#L41
    """
    assert(len(data) > 0)
    size = int(data[0])
    assert(size <= 255)

    if size < 253:
        return size, 1

    if size == 253:
        format_ = '<H'
    elif size == 254:
        format_ = '<I'
    elif size == 255:
        format_ = '<Q'
    else:
        # Should never be reached
        assert 0, "unknown format_ for size : %s" % size

    size = struct.calcsize(format_)
    return struct.unpack(format_, data[1:size+1])[0], size + 1

ldb = plyvel.DB('/home/ciro/snap/bitcoin-core/common/.bitcoin/indexes/txindex/', compression=None)
i = 0
for key, value in ldb:
    if key[0:1] == b't':
        txid = bytes(reversed(key[1:])).hex()
        print(i)
        print(txid)
        print(len(value))
        print(value.hex(' '))
        value = bytes(reversed(value))
        file, off = decode_varint(value)
        blk_off, off = decode_varint(value[off:])
        tx_off, off = decode_varint(value[off:])
        print((txid, file, blk_off, tx_off))
        print()
        i += 1

but it eventually blows up at:

131344
ec4de461b0dd1350b7596f95c0d7576aa825214d9af0e8c54de567ab0ce70800
7
42 ff c0 43 8b 94 35
Traceback (most recent call last):
  File "/home/ciro/bak/git/bitcoin-strings-with-txids/./tmp.py", line 39, in <module>
    blk_off, off = decode_varint(value[off:])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ciro/bak/git/bitcoin-strings-with-txids/./tmp.py", line 29, in decode_varint
    return struct.unpack(format_, data[1:size+1])[0], size + 1
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 8 bytes

So I wonder if I guessed the format wrong, or if it’s just a bug in my code.

Comparing to: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer I would decode:

42 ff c0 43 8b 94 35

manually as:

  • 42
  • ff: expect 8 bytes next
    • c0 43 8b 94 35: only 5 bytes left, blowup

I also tried to inverse value:

value = bytes(reversed(value))

but then it blows up very early, definitely wrong.

I also tried to ignore the error to see if there are others, but there were hundreds them, so something is definitely wrong with my method.

Related:



Source link

Related articles

Metaplanet Buys 1,111 Bitcoin, Robert Kiyosaki Sees BTC Crash

US Spot Bitcoin ETFs Push Inflows Streak To 15 Days

July 1, 2025

Bloomberg Analysts Predict 95% Chance of Solana, Litecoin, XRP ETF Approvals in 2025

July 1, 2025
Share76Tweet47

Related Posts

Metaplanet Buys 1,111 Bitcoin, Robert Kiyosaki Sees BTC Crash

US Spot Bitcoin ETFs Push Inflows Streak To 15 Days

by Moussa
July 1, 2025
0

Join Our Telegram channel to stay up to date on breaking news coverage Spot Bitcoin ETFs (exchange-traded funds) extended their...

Bloomberg Analysts Predict 95% Chance of Solana, Litecoin, XRP ETF Approvals in 2025

by Moussa
July 1, 2025
0

Leading Bloomberg ETF analysts Eric Balchunas and James Seyffart think that the odds of the US Securities and Exchange Commission...

Bitcoin To $1 Million? ‘Rich Dad’ Kiyosaki Says He’s Ready

Bitcoin To $1 Million? ‘Rich Dad’ Kiyosaki Says He’s Ready

by Moussa
July 1, 2025
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure Robert Kiyosaki, the author behind Rich Dad...

GameStop Inspired a Lingerie MMA League to Buy Bitcoin: SUBBD Token Soars?

GameStop Inspired a Lingerie MMA League to Buy Bitcoin: SUBBD Token Soars?

by Moussa
July 1, 2025
0

Reason to trust Strict editorial policy that focuses on accuracy, relevance, and impartiality Created by industry experts and meticulously reviewed...

How Institutional Flows and Market Cycles Are Shifting

How Institutional Flows and Market Cycles Are Shifting

by Moussa
July 1, 2025
0

Bitcoin Magazine How Institutional Flows and Market Cycles Are Shifting Year-to-date, bitcoin returns are flat — at negative 0.4%. This...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwdG5wLXN1YnNjcmlwdGlvbiUyMiUzRSUwQSUzQ2Zvcm0lMjBtZXRob2QlM0QlMjJwb3N0JTIyJTIwYWN0aW9uJTNEJTIyaHR0cHMlM0ElMkYlMkZhcHByb3gub3JnJTJGJTNGbmElM0RzJTIyJTNFJTBBJTBBJTNDaW5wdXQlMjB0eXBlJTNEJTIyaGlkZGVuJTIyJTIwbmFtZSUzRCUyMm5sY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GFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News