doc/state.md
Read this in other languages: Korean, 日本語, 简体中文.
The full state of a Grin chain consists of all the following data:
In addition, all headers in the chain are required to anchor the above state with a valid proof of work (the state corresponds to the most worked chain). We note that once each range proof is validated and the sum of all kernels commitment is computed, range proofs and kernels are not strictly necessary for a node to function anymore.
With a full Grin state, we can validate the following:
The data used to produce the hashes for leaf nodes in each MMR (in addition to their position is the following:
Note that all outputs, range proofs and kernels are added in their respective MMRs in the order they occur in each block (recall that block data is required to be sorted).
As outputs get spent, both their commitment and range proof data can be removed. In addition, the corresponding output and range proof MMRs can be pruned.
Data storage for outputs, range proofs and kernels in Grin is simple: a plain append-only file that's memory-mapped for data access. As outputs get spent, a remove log maintains which positions can be removed. Those positions nicely match MMR node positions as they're all inserted in the same order. When the remove log gets large, corresponding files can be occasionally compacted by rewriting them without the removed pieces (also append-only) and the remove log can be emptied. As for MMRs, we need to add a little more complexity.