Author

Topic: How is UTXO currently stored in Bitcoin Core? (Read 764 times)

legendary
Activity: 1232
Merit: 1083
The serialized size in CCoins doesn't include the txid hash.  The database GetStats(...) method has to add 32 to account for the key.

The database is a map of {'c', uint256 txid} to {CCoins tx_coins}.  The 'c' prefix is used to indicate that the entry is a coins entry.
staff
Activity: 4172
Merit: 8419
However, 35.86 bytes is merely enough for storing the size of scriptPubKey (1 bytes) + std P2PKH scriptPubKey (25 bytes) + value (8 bytes)
So where is the data for the 36 bytes outpoint (txid + index)?
The representation is compressed.  The txid, height, version, and coinbase flag are _shared_ among all outputs for a transaction. The value and index are stored in variable length compressed representations, the scriptpubkey is stored in a templitized compressed representation (e.g. only encodes the the type and the  hash for p2sh/p2pkh outputs).

See the diagram at the top of coins.h.
legendary
Activity: 1792
Merit: 1087
I get the following gettxoutsetinfo output:

{
"height" : 355650,
"bestblock" : "00000000000000000fd87566bb5527cc1580f7c7c2afdde34797d3072f616d3e",
"transactions" : 5622974,
"txouts" : 19127223,
"bytes_serialized" : 685867123,
"hash_serialized" : "7aaaa95a2a74edf337a89d93907324d4bfb7abf423ee9a484caf3af6e506ad79",
"total_amount" : 14141114.77930497
}


So it's 685867123/19127223 = 35.86 bytes/txout

However, 35.86 bytes is merely enough for storing the size of scriptPubKey (1 bytes) + std P2PKH scriptPubKey (25 bytes) + value (8 bytes)

So where is the data for the 36 bytes outpoint (txid + index)?
Jump to: