thehubbleproject / hubble-contracts

Hubble optimistic rollup
https://thehubbleproject.github.io/docs/
MIT License
133 stars 28 forks source link

update root of the dbTree when restoring from DB #623

Open kautukkundan opened 3 years ago

kautukkundan commented 3 years ago

Problem

this._root = this.zeros[0] works when we have an empty tree. But we will have a problem once we have new leaves in the tree and have a non-empty tree root in DB.

When we restart the client and read the root() from the DBTree, we expect to read the non-empty tree root in DB. But here the cached root still returns the empty tree root.

_Originally posted by @ChihChengLiang in https://github.com/thehubbleproject/hubble-contracts/pull/619#discussion_r668678148_

Solution

Need to come up with a restoreFromDB function which updates the tree root when the node is restarted. The tree root is already stored in the db and is accessible via getNode(0,0). Rest of the nodes need not be touched.