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

pruntime: Optional use RocksDB/redb as trie state backend #1265

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

kvinwang
Copy link
Collaborator

@kvinwang kvinwang commented May 11, 2023

Description

This PR moves the chain storage and phat contract storage onto Gramine's encrypted file system.

Prior to this, we used an in-memory im::OrdMap as the storage backend. However, with the growing amount of on-chain data and the number of phat contracts, memory storage would quickly become unsustainable. Therefore, we considered moving the data into the file system to solve the problem of memory explosion. In this PR, we use Gramine's encrypted file system to store RocksDB as the storage backend. The modification is based on the existing software architecture and is implemented by changing the internal implementation of phala_trie_storage::TrieStorage.

In order to be compatible with the previous pruntime checkpoint, RocksDB is used only as a cache. That is to say, when pruntime takes snapshots, it will dump all the contents of RocksDB into the snapshot, and when pruntime starts, it will delete the RocksDB used last time and rebuild a new RocksDB instance from the snapshot.

To enable RocksDB, run pruntime with --db=rocksdb:

./pruntime --db=rocksdb

What have been tested

After the modification, the following compatibility tests were made:

  • Checkpoint loading matrix
    Saved from MemoryDB Saved from RocksDB
    Load to MemoryDB
    Load to RocksDB
  • Make sure the checkpoint is compatible with older pruntime versions.
  • Regression test for load_proof.
  • Test with contracts.
  • The encryption block size is 4096.

Overhead

I attempted to synchronize Khala blocks. It took twice as long compared to using a memory database
image

Merging

Because this PR may affect the stability of pRuntime, let's not merge it for the time being, we need a lot of testing on some test networks to ensure its stability.

@kvinwang kvinwang mentioned this pull request May 11, 2023
@kvinwang kvinwang force-pushed the kvdb2 branch 2 times, most recently from a9261b2 to 936ed73 Compare May 16, 2023 06:28
@kvinwang kvinwang changed the title RocksDB as trie state backend pruntime: RocksDB as trie state backend May 16, 2023
@kvinwang kvinwang marked this pull request as ready for review May 16, 2023 08:06
@h4x3rotab
Copy link
Contributor

Sorry. Didn't get time to review it. Will do this week.

@kvinwang kvinwang changed the title pruntime: RocksDB as trie state backend pruntime: Optional use RocksDB/redb as trie state backend Jul 7, 2023
@kvinwang kvinwang marked this pull request as draft July 7, 2023 02:24
@kvinwang kvinwang marked this pull request as ready for review July 7, 2023 04:31
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