hermeznetwork / hermez-node

Hermez node Go implementation
GNU Affero General Public License v3.0
61 stars 33 forks source link

Restore StateDB from SQL DB #923

Open arnaubennassar opened 3 years ago

arnaubennassar commented 3 years ago

Rationale

When facing some problems it's hard to restore the StateDB, unlike Postgres that have so many tooling around backup, recovering and related. Also the StateDB and SQL could end up in different states if something bad happens.

It would be very nice to be able to restore the StateDB from SQL.

Implementation

  1. Starting with an empty StateDB, add all the leafs into the MT using data from SQL DB aka historydb
  2. Build the MT Root, and check that it's valid against the SC, this way we can cryptographically verify that the StateDB is well synchronized.
Mikelle commented 3 years ago

Statedb is for saving accounts state and build merkle tree from it, it's the only thing, that is saved here. Statedb getting info from the ethereum events and updating merkle tree leafs block by block. BatchNums folders, which exist in statedb folder, it's a snapshot of the statedb for that particular batch. It exists for every batch, bcs it's needed for the reorg situation, so we can recreate current state. Important notice: if lose state db at some point, we can start node with a copy of last, current, BatchNumX folders.

We are putting this task on hold due to hard implementation and uncertain things. We can't restore db with the last state root, we have to add accounts to the statedb in the correct order and there can be a problem with the serialization order of the fields.