Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State export & import #2052

Closed
Tracked by #2007
cwgoes opened this issue Oct 26, 2023 · 3 comments
Closed
Tracked by #2007

State export & import #2052

cwgoes opened this issue Oct 26, 2023 · 3 comments
Assignees

Comments

@cwgoes
Copy link
Collaborator

cwgoes commented Oct 26, 2023

We need the ability to export and import state to and from a genesis file (collection of TOML files). This may be useful in case Namada needs to perform an irregular state-modifying upgrade where specific data structures kept in state must be manually modified or where the keyspace layout needs to change. This requires:

  • each validity predicate can export its state to and import its state from part of the genesis file (e.g. MASP - commitments, nullifiers, notes, etc.; governance - proposals, delegates, etc.)
  • the ledger can export its state to and import its state from part of the genesis file (e.g. replay protection, other system-level key/value state pairs)

The export and import functions should be inverses; i.e., when we export state and reimport it on a different node, we get exactly the same state. This can be tested by hashing the entire storage, exporting it, importing it, re-hashing the storage on the new node, and checking that the hash matches the original. It's important that we're able to take the state export and start up a new chain (with the export as genesis), we should test this flow as well.

We should be able to use Serde for JSON serialization & deserialization, so this shouldn't require too much more than paired import / export functions for all VPs and other parts of state, where:

  • the import function takes a bunch of structs (deserialized from JSON) and writes them to the appropriate DB keys
  • the export function reads all relevant DB keys into structs and serializes them to JSON (which can be imported)

We'll also need a namada export <filename> command (no special import command should be required, just the usual genesis start).

This work may have conflicts with ongoing genesis flow refactors by @batconjurer; we should communicate with him.

@adrianbrink
Copy link
Member

We should be able to test this on a testnet quite easily.

Run a chain with 4 validators and 2 nodes. Let the chain run for 1000 blocks. Stop 1 validator and 1 node. The chain continues. Export the state on 1 validator and 1 node. Clean the data directories of the 1 validator and 1 node. Import the state into the validator and node. Both should continue where they had exported it.

@cwgoes
Copy link
Collaborator Author

cwgoes commented Oct 30, 2023

Agreed with @sug0 to start with a simpler version that does not serialize/deserialize everything to JSON, but just add an import DB command to mirror the dump DB command, and write a simple demo of exporting & importing state, including performing some simple modification.

@cwgoes
Copy link
Collaborator Author

cwgoes commented Nov 11, 2023

Done by #2092 #2835. Needs to be tested.

@cwgoes cwgoes closed this as completed Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants