Why do we need CCoins in addition to CTransactions?

3

As per my understanding CTransactions represents the atomic unit in Bitcoin. It has the inputs CTxIn and outputs CTxOut.

Can any expert give the intuition of why we need CCoins in source code ? Why should we have a separate pruned class just for storing outputs ?

Prem Anand

Posted 2016-02-02T09:29:31.037

Reputation: 63

Answers

5

CCoins is an internal data structure, used to represented entries in the UTXO set while cached in memory (see CCoinsViewCache).

It is separate from CTransaction for efficiency and utility reasons. It lacks a vector for the output, saving space. It also has a much more efficient serialized form, allowing a more compact database on disk. Furthermore it has convenience methods that we wouldn't want in a base data type that's used everywhere. As CCoins is only used inside the consensus validation logic, it can be more specific.

Pieter Wuille

Posted 2016-02-02T09:29:31.037

Reputation: 54 032