When exactly an entry is added to the set of unspent transactions outputs?
When exactly an entry is removed from the set of unspent transactions outputs?
The answer to these questions is that there is no singular set of unspent transaction outputs. There are multiple versions that are maintained and/or implied for different purposes.
1) There is the UTXO set defined by the on-disk LevelDB database. This only changes after a flush (see further).
2) There is the UTXO set defined by the in-memory cache (the
pcoinsTip object). It represents the state of the network at the current best block, but does not include the effect of any unconfirmed transactions. Whenever the number of changes in this cache grows too big (see
-dbcache) it gets flushed to disk.
3) There is the UTXO set defined by the memory pool. It consists of the UTXO set defined in 2, plus all outputs created by unconfirmed transactions, minus all outputs spent by unconfirmed transactions. This changes every time the mempool changes. Note that this UTXO set is nowhere materialized explicitly - it's just defined by what is in the cache (see 2) and unconfirmed transactions in the mempool.
Whats' the difference between validating a transaction that is validated in block (case of a relayed block) and a transaction that is validated standalone (case of a relayed transaction).
From the top of my head:
- Only consensus rules are validated, not policy/standardness rules
- All scripts are validated in parallel (on multiple CPU cores)
- The changes are flushed to
pcoinsTip (and possibly to disk)