<p>The next input for this particular output is a "marker" that this output is already spent</p>

CC BY-SA 3.0
2014-06-30T15:27:22.547Z
So when I, as a miner node, try to verify a transaction, I need to look through the entire block chain to see if any of the transaction's output have been used as an input already? Is that the only way to check that an output has been "marked" as spent?
feralin
CC BY-SA 3.0
2014-06-30T17:32:13.930Z
@feralin thats the way how its done and its the only way if you want to do it on your own
Dennis Kriechel
CC BY-SA 3.0
2014-06-30T18:14:55.440Z
@Recall so there is nothing in the transaction data that says that a certain output has been spent?
feralin
CC BY-SA 3.0
2014-06-30T18:16:09.397Z
No its not, a transaction output cant be modified so there cant be a flag or something else to mark it
Dennis Kriechel
CC BY-SA 3.0
2014-06-30T15:25:30.190Z
2014-06-30T15:25:30.190Z
amaclin
<p>Every full Bitcoin node maintains a database of which unspent outputs are left. </p>

<p>When verifying a transaction, all its inputs are fetched from the database. If one is missing, validation fails. Among the data retrieved is the value of those unspent outputs, and their script (od address), which define the conditions under which the output can be spent. This information is necessary to validate whether the spending transaction has the correct signatures and does not create more bitcoin than it consumes.</p>

<p>If all validation of all transactions in a block succeed, the consumed inputs are removed from the database, and all outputs of those transactions added as fresh unspent outputs in the database, allowing them to be spent by future blocks.</p>

<p>As this database only contains outputs (so no signatures, for example), and even only the unspent ones, it is much smaller than the entire blockchain (some 450 MB as of juli 2014). So, no, we don't go scan through the entire blockchain to know whether outputs are not double-spent - we keep a separate database with just the data we need from it for validation.</p>

CC BY-SA 3.0
2014-07-02T15:49:42.010Z
This answer goes more into detail than the previous one, so I'm accepting this one instead. Thanks!
feralin
CC BY-SA 3.0
2018-02-05T18:12:14.480Z
I get it about only spending one, but this transaction confuses me, which appears to reduce the balance of an address twice on separate occasions (this is the tipjar for bitref.com FYI) https://blockchain.info/address/38Ee9XUoHp6usVRDKNTdUvS1EUsca3Sb6L?sort=0
Dean Radcliffe
CC BY-SA 3.0
2018-02-05T18:43:39.437Z
Block explorers will confuse you. Addresses don't hold a balance. There are only outputs. Each output has an address an and amount. Transaction inputs spend *one specific* previous output completely.
Pieter Wuille
CC BY-SA 3.0
2014-07-02T05:45:39.063Z
2014-07-02T05:45:39.063Z
Pieter Wuille
<p>The <a href="https://bitcoin.org/en/developer-guide#block-chain-overview" rel="noreferrer">Bitcoin developer guide</a> states that </p>

<blockquote>
  <p>each output of a particular transaction can only be used as an input once in the block chain. Any subsequent reference is a forbidden double spend—an attempt to spend the same satoshis twice.</p>
</blockquote>

<p>So how does a Bitcoin network node actually mark a transaction's output as spent? I imagine it would need to be irreversible, so that other nodes cannot revert the "spent" marker, but I cannot think of a way that Bitcoin could ensure that.</p>

<p>Where in the standard Bitcoin code does this marking occur, and how does it occur?</p>

<transactions><doublespend><utxo>
How is a Transaction Output Marked as Spent?
feralin
# How is a Transaction Output Marked as Spent?

(Asked by: username_0 on 2014-06-30)

The [Bitcoin developer guide](https://bitcoin.org/en/developer-guide#block-chain-overview) states that

> each output of a particular transaction can only be used as an input once in the block chain. Any subsequent reference is a forbidden double spend—an attempt to spend the same satoshis twice.

So how does a Bitcoin network node actually mark a transaction's output as spent? I imagine it would need to be irreversible, so that other nodes cannot revert the "spent" marker, but I cannot think of a way that Bitcoin could ensure that.

Where in the standard Bitcoin code does this marking occur, and how does it occur?

**Tags:** transactions, doublespend, utxo


---

## 2 answers

### Answer by username_3 on 2014-07-02. Score: 15 | Accepted answer

Every full Bitcoin node maintains a database of which unspent outputs are left.

When verifying a transaction, all its inputs are fetched from the database. If one is missing, validation fails. Among the data retrieved is the value of those unspent outputs, and their script (od address), which define the conditions under which the output can be spent. This information is necessary to validate whether the spending transaction has the correct signatures and does not create more bitcoin than it consumes.

If all validation of all transactions in a block succeed, the consumed inputs are removed from the database, and all outputs of those transactions added as fresh unspent outputs in the database, allowing them to be spent by future blocks.

As this database only contains outputs (so no signatures, for example), and even only the unspent ones, it is much smaller than the entire blockchain (some 450 MB as of juli 2014). So, no, we don't go scan through the entire blockchain to know whether outputs are not double-spent - we keep a separate database with just the data we need from it for validation.

> **Comments:**
> **username_0**: This answer goes more into detail than the previous one, so I'm accepting this one instead. Thanks!  
> **username_4**: I get it about only spending one, but this transaction confuses me, which appears to reduce the balance of an address twice on separate occasions (this is the tipjar for bitref.com FYI) https://blockchain.info/address/38Ee9XUoHp6usVRDKNTdUvS1EUsca3Sb6L?sort=0  
> **username_3**: Block explorers will confuse you. Addresses don't hold a balance. There are only outputs. Each output has an address an and amount. Transaction inputs spend *one specific* previous output completely.  

---

### Answer by username_1 on 2014-06-30. Score: 4

The next input for this particular output is a "marker" that this output is already spent

> **Comments:**
> **username_0**: So when I, as a miner node, try to verify a transaction, I need to look through the entire block chain to see if any of the transaction's output have been used as an input already? Is that the only way to check that an output has been "marked" as spent?  
> **username_2**: @username_0 thats the way how its done and its the only way if you want to do it on your own  
> **username_0**: @Recall so there is nothing in the transaction data that says that a certain output has been spent?  
> **username_2**: No its not, a transaction output cant be modified so there cant be a flag or something else to mark it  

---

