Title: How is UTXO currently stored in Bitcoin Core? Post by: jl2012 on May 09, 2015, 02:14:32 PM 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)? Title: Re: How is UTXO currently stored in Bitcoin Core? Post by: gmaxwell on May 09, 2015, 08:29:17 PM However, 35.86 bytes is merely enough for storing the size of scriptPubKey (1 bytes) + std P2PKH scriptPubKey (25 bytes) + value (8 bytes) 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).So where is the data for the 36 bytes outpoint (txid + index)? See the diagram at the top of coins.h. Title: Re: How is UTXO currently stored in Bitcoin Core? Post by: TierNolan on May 09, 2015, 09:17:26 PM The serialized size (https://github.com/bitcoin/bitcoin/blob/master/src/coins.h#L153) in CCoins doesn't include the txid hash. The database GetStats(...) (https://github.com/bitcoin/bitcoin/blob/687f10d9ec3548f13f929ca14cd813a0919639ec/src/txdb.cpp#L103) 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. |