Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: BoyFromDubai on February 09, 2023, 12:19:19 AM



Title: What data LevelDB stores?
Post by: BoyFromDubai on February 09, 2023, 12:19:19 AM
I know that LevelDB stores information about current UTXO in the whole network. But what data exactly in this database, that allows nodes create transactions? For example in a block the fields are: previous hash, timestamp, merkle root, nonce, difficulty and etc. But what are the fields in LevelDB?


Title: Re: What data LevelDB stores?
Post by: achow101 on February 09, 2023, 04:04:03 AM
It's a key-value store of outpoint to transaction output. Outpoints consist of the txid and output index, and transaction output is the amount in satoshis and the output script. These are the pieces from previous transactions that's needed to verify a transaction.


Title: Re: What data LevelDB stores?
Post by: Omair Amin on February 09, 2023, 08:30:30 AM
Some Bitcoin network implementations use LevelDB, a key-value store, to keep track of the outputs of unspent transactions (UTXOs). In LevelDB, the key-value pairs stand in for the UTXOs and the related data required to verify transactions and build new blocks.

The hash of the transaction that created the UTXO and the index of the output in that transaction are combined to create each key in the LevelDB database, which represents a UTXO. Each key's value consists of a binary representation of the output's script and its associated Bitcoin balance.



The set of unconfirmed transactions, the best known block header, and various metadata required to validate transactions and blocks are just a few examples of the additional data that LevelDB can hold in addition to the UTXO data regarding the health of the Bitcoin network.

It's crucial to note that since there is no set format for this data, the precise fields and structure of the data saved in LevelDB may differ between different Bitcoin protocol implementations.


Title: Re: What data LevelDB stores?
Post by: BoyFromDubai on February 09, 2023, 11:21:00 AM
But what kind of data about UTXO is stored in there? I've heard that it's like txid -> data about all UTXOs, but what kind of data? Saw that there are some bits that indicates if a vout is spent or not. And when all bits show that all vouts are spent, this pair txid -> vouts will be deleted


Title: Re: What data LevelDB stores?
Post by: ABCbits on February 09, 2023, 12:32:39 PM
The set of unconfirmed transactions, the best known block header, and various metadata required to validate transactions and blocks are just a few examples of the additional data that LevelDB can hold in addition to the UTXO data regarding the health of the Bitcoin network.

Bitcoin Core documentation doesn't mention mempool (on memory or dump file "mempool.dat") use LevelDB though[1].

But what kind of data about UTXO is stored in there? I've heard that it's like txid -> data about all UTXOs, but what kind of data? Saw that there are some bits that indicates if a vout is spent or not. And when all bits show that all vouts are spent, this pair txid -> vouts will be deleted

See https://bitcoin.stackexchange.com/a/29418 (https://bitcoin.stackexchange.com/a/29418).

[1] https://github.com/bitcoin/bitcoin/blob/v24.0.1/doc/files.md (https://github.com/bitcoin/bitcoin/blob/v24.0.1/doc/files.md)


Title: Re: What data LevelDB stores?
Post by: BoyFromDubai on February 09, 2023, 08:09:11 PM
See https://bitcoin.stackexchange.com/a/29418 (https://bitcoin.stackexchange.com/a/29418).



What do these letters at the beginning mean? 'c' + smth it means that a key consists of the letter c at the begging + smth?


Title: Re: What data LevelDB stores?
Post by: ABCbits on February 10, 2023, 11:15:50 AM
See https://bitcoin.stackexchange.com/a/29418 (https://bitcoin.stackexchange.com/a/29418).
What do these letters at the beginning mean? 'c' + smth it means that a key consists of the letter c at the begging + smth?

Correct. But if you decide to read LevelDB file directly, take note Bitcoin Core has obfuscation key[1] to prevent data corruption due to false positive from Anti virus[2].

[1] https://bitcoin.stackexchange.com/a/52167 (https://bitcoin.stackexchange.com/a/52167)
[2] https://github.com/bitcoin/bitcoin/issues/6613 (https://github.com/bitcoin/bitcoin/issues/6613)


Title: Re: What data LevelDB stores?
Post by: BoyFromDubai on April 09, 2023, 08:11:16 PM
Can one explain please what does "'C'+ 32-byte transaction hash + output index length + output index" mean? In this answer https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair/29418#29418
Firstly i decided, that hex C is stored in DB, but then I saw in there other letters, like T, or R, which are not hex numbers. So does that mean, that it's real letters, which are decoded in bytes via utf-8 for example?
And also it's not clear what output index length means. It means that if real vout index is 16 for example, then in bytes it's compared to '10' which has length of 2, and this output index length == '2' in bytes? And for vout 4096 for example hex representation is '1000', which has length of 4 bytes.
If so, then it's a bit strange. Is there any limit for the number of vouts per transaction, or I can send coins for a million users for example?