rchain / rchip-proposals

Where RChain improvement proposals can be submitted
Apache License 2.0
8 stars 5 forks source link

Export of REV vault state (REV balances) #41

Open tgrospic opened 3 years ago

tgrospic commented 3 years ago

Overview

The purpose of this RCHIP is to specify the export process from on-chain REV vault contract to get the full list of REV balances. This export is needed for two planned hard forks: Hard Fork 1 and [Hard Fork 2] (not published yet).

Specification

REV vault contract keeps the record of all REV addresses and their current balance. It uses implementation of TreeHashMap with keys as hashed REV addresses and vaults as values.

Traversing of all records in REV vault is implemented in Scala to achieve much better speed than directly in Rholang. The main code is in RhoTrieTraverser and executable entry point is in StateBalanceMain with hard coded unforgeable name of vault map (TreeHashMap) where REV vaults are stored in REV vault contract.

Validation

Validation of the whole export process can be done with the prepared scripts and configurations in repository tgrospic/rnode-rev-export-hard-fork-1.

The process has two steps:

  1. Download Last Finalized State (LFS) of the network on which snapshot (export of REV balances) for Hard Fork 1 is created.
  2. Run state-balance-main command to export REV balances in csv format.

Because exported csv file contain hashed REV addresses we are using data from transaction server to read mapping between hash value and REV address. Because this file can be validated by it own and export requires replay of all blocks as input to transaction server, this file will be provided as part of the specification.

More information can be found in the PR#3411 where is the source code for the export process.