Bitcoin Forum
May 22, 2024, 08:59:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Tracking unspent outputs  (Read 167 times)
unsigned_long_long (OP)
Jr. Member
*
Offline Offline

Activity: 39
Merit: 6


View Profile
December 26, 2020, 11:27:59 PM
 #1

I have a question for anybody familiar with the Bitcoin codebase. I'm interested in how spent/unspent outputs are tracked to prevent double spends, specifically I just want to know what data structures are used for checking if a output is spent or not (i.e. to prevent double spends). I know this could be done with a hash table or bloom filter.

I took a quick look through the codebase, I would have expected it to be https://github.com/bitcoin/bitcoin/blob/master/src/txdb.h#L59 although this HaveCoin seems to check the existence of the coin - not if it's spent or not.

It would take me a long time to read through the code and figure this out so I'm hoping somebody who already knows the answer can help me.

Thanks in advance.  Smiley
NotATether
Legendary
*
Offline Offline

Activity: 1610
Merit: 6753


bitcoincleanup.com / bitmixlist.org


View Profile WWW
December 27, 2020, 09:48:17 AM
 #2

The HaveCoin method really does check if a coin is unspent. If you look in the base class CCoinsView https://github.com/bitcoin/bitcoin/blob/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/src/coins.h#L189-L190 , that's where it's mentioned. The implementation is defined in coins.cpp and it just calls the IsSpent() method of each Coin class. And that method checks if the output contained in it has been set to null.

IsSpent code is located at https://github.com/bitcoin/bitcoin/blob/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/src/coins.h#L76-L78

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!