3

The IDs of the unspent transactions are stored in the UTXO database. I assume that it's generated like this by the client:

for block in blocks:
    for transaction in block:
        utxo.remove(transaction.input)
        utxo.add(transaction)

However, I have some doubts: What else is stored in the UTXO database? Does it store the actual amount of unspent coins for each transaction (which would seem necessary for the verification of the uncomfirmed transactions)?

4

The UTXO database starts empty and then is updated while the blockchain is parsed in the manner that you described. Only, there can be more than one input and more than one output for a transaction, so I'd put it like this:

for block in blocks:
    for transaction in block:
        for(input in transaction):
            utxoset.remove(input)
        for(output in transaction):
            utxoset.add(output)

Obviously, the block is checked for validity and therefore we know that the inputs and outputs are legit.

The UTXO set then stores the UTXOs referenced by outpoints as key, where an outpoint consists of:

  • TXID: Unique hash identifier of the transaction that created the output
  • index: the position of the output in the transaction's output list

And the information stored in the Transaction Outputs is:

  • value: number of satoshis the output is good for
  • pubkey script: the conditions the output can be spent under

Finally, for each block undo data is generated, in the case that a reorganization occurs.

  • 1
    For a userA, if we want to see userA's total balance (sum of all UTXO), do we need to iterate from head block to the tail and check all UTXOs which is linked to userA? or utxoset provides us a faster/efficient way? @Murch♦ – alper Jan 3 '18 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy