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

feat: basic persistent storage #8

Merged
merged 2 commits into from
Oct 3, 2023
Merged

feat: basic persistent storage #8

merged 2 commits into from
Oct 3, 2023

Conversation

zeapoz
Copy link
Member

@zeapoz zeapoz commented Oct 2, 2023

Allows for the restoration of the state when the tool was last used.

  • Implements basic persistent storage:
    • A new StateSnapshot struct that stores:
      • The latest L1 block number that was processed.
      • The latest L2 block number that was processed.
      • The mappings of index to key values.
  • Rename of state.rs -> types.rs.

Note: this PR does not implement graceful shutdown, so the snapshot file can in rare instances get out of sync with the local database.

@zeapoz zeapoz requested a review from tuommaki October 2, 2023 15:03
@zeapoz zeapoz self-assigned this Oct 2, 2023
Copy link
Collaborator

@tuommaki tuommaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍


/// Struct containing the fields used for restoring the tree state.
#[derive(Serialize, Deserialize)]
pub struct StateSnapshot {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for the future: Could we store the latest root hash here as well and use that to verify that tree & index key map are in sync?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

Comment on lines +13 to +14
/// The latest l1 block number that was processed.
pub current_l1_block_number: u64,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized something: When we import state from other sources (e.g. file), there's no such thing as L1 block number, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be the case, I'm not sure what the file format would look like at this point so I can't really answer that. Either way though, I think we can defer this issue to a later PR, what do you say?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely. I'm actually working on async L1Fetcher right now, based on your code here, so hence the thought. Let's see how this gets shape 🙂

@zeapoz zeapoz force-pushed the feat/persistent-storage branch from d26d3b6 to 720a1b5 Compare October 3, 2023 10:59
@zeapoz zeapoz merged commit 422b073 into main Oct 3, 2023
4 checks passed
@zeapoz zeapoz deleted the feat/persistent-storage branch October 3, 2023 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants