<p>Looks for pcoinsTip->Flush(), which batch updates the underlying database CCoinsView.</p>

<p>It is not called for every update as that would require many writes. The way it is implemented now means many outputs can be added and marked spent entirely without needing to hit disk. The result is a disk database that is slightly out of data with the memory version, which means more work to redo when a node crashes, but this case is rare, and having faster block relay is more important.</p>

CC BY-SA 3.0
2014-03-31T08:46:08.007Z
2014-03-31T11:58:52.853Z
2014-03-31T11:58:52.853Z
Pieter Wuille
<p>The logic of this function is quite simple:
1, mark inputs spent
   Call coins.Spend()
2, add new outputs to database.
   Call inputs.SetCoins()</p>

<p>My question is in step1, it invalidate the old output because it has been spent.</p>

<p>But in function coins.Spend(), I only found it kick out the spent output, I didn't find  where the function update the database. If the old output is kicked, the database should also be updated, but coins.Spend() is only update the memory data structure.</p>

<transactions>
A question about CTransaction::UpdateCoins() in 0.8.6
onlycoin
# A question about CTransaction::UpdateCoins() in 0.8.6

(Asked by: username_0 on 2014-03-31)

The logic of this function is quite simple:
1, mark inputs spent
Call coins.Spend()
2, add new outputs to database.
Call inputs.SetCoins()

My question is in step1, it invalidate the old output because it has been spent.

But in function coins.Spend(), I only found it kick out the spent output, I didn't find where the function update the database. If the old output is kicked, the database should also be updated, but coins.Spend() is only update the memory data structure.

**Tags:** transactions


---

## 1 answers

### Answer by username_1 on 2014-03-31. Score: 1

Looks for pcoinsTip->Flush(), which batch updates the underlying database CCoinsView.

It is not called for every update as that would require many writes. The way it is implemented now means many outputs can be added and marked spent entirely without needing to hit disk. The result is a disk database that is slightly out of data with the memory version, which means more work to redo when a node crashes, but this case is rare, and having faster block relay is more important.


---

