Bitcoin Forum
November 06, 2024, 03:20:39 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How is UTXO currently stored in Bitcoin Core?  (Read 772 times)
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1111


View Profile
May 09, 2015, 02:14:32 PM
 #1

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)?

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4270
Merit: 8805



View Profile WWW
May 09, 2015, 08:29:17 PM
 #2

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.
TierNolan
Legendary
*
Offline Offline

Activity: 1232
Merit: 1104


View Profile
May 09, 2015, 09:17:26 PM
 #3

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.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!