Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bondcoder on June 24, 2019, 02:50:58 PM



Title: UTXO storing
Post by: bondcoder on June 24, 2019, 02:50:58 PM
I started my impementation of blockchain and I have question about UTXO storing. Do I need to store outputs after it was used? Or maybe I need to change them status on "used", or transfer into another collection (NoSQL )or table (relation)  of database?


Title: Re: UTXO storing
Post by: RHavar on June 24, 2019, 04:05:14 PM
You need to look at it in terms of operations you need to support. If you're doing your own validation, you need to be able to lookup any unspent utxo by (txid,vout). You also need to be sure it was only spent once.


There's probably a dozen decent ways to do this, so it's hard to advise you. One thing I'll mention though, that makes it tricky is you generally need to handle "reorgs" where the blockchain literally shifts under your feet.

Generally I've found the easiest way to work with something like the blockchain, is an append-only immutable database. And then you just  put indexes for all queries you need to do, to make it fast.

(And the one exception to "immutable" I like to make, is adding a field `isBest` for each block I have, which represents if it's in the most-proof-of-work chain, which makes queries a lot easier and faster)


Title: Re: UTXO storing
Post by: bondcoder on June 25, 2019, 06:59:44 AM
Thank you. I will use your advices in my implementation!