-
Notifications
You must be signed in to change notification settings - Fork 151
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
Introduce the KVDB to phala runtime #749
Conversation
…tate storage into db
@@ -52,6 +51,7 @@ members = [ | |||
"crates/phala-async-executor", | |||
"crates/phala-allocator", | |||
"crates/pink", | |||
"crates/pkvdb", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation
@@ -5,4 +5,4 @@ edition = "2018" | |||
description = "Platform abstraction layer for Phactory Runtime" | |||
|
|||
[dependencies] | |||
anyhow = "1.0.43" | |||
anyhow = "1.0.43" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this change
@@ -2,7 +2,7 @@ use super::*; | |||
|
|||
// For bin_api | |||
impl<Platform: pal::Platform + Serialize + DeserializeOwned> Phactory<Platform> { | |||
fn get_info_json(&self) -> Result<Value, Value> { | |||
fn get_info_json(&mut self) -> Result<Value, Value> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks not good to turn this top level state into mut
.
use std::{io::Write, marker::PhantomData}; | ||
use std::{path::Path, str}; | ||
use std::{marker::PhantomData}; | ||
use std::{ str}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt
@@ -74,7 +74,7 @@ mod types; | |||
|
|||
// TODO: Completely remove the reference to Phala/Khala runtime. Instead we can create a minimal | |||
// runtime definition locally. | |||
type RuntimeHasher = <chain::Runtime as frame_system::Config>::Hashing; | |||
pub(crate) type RuntimeHasher = <chain::Runtime as frame_system::Config>::Hashing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it available in sub mods without the pub(crate)
?
|
||
impl<H: Hasher> Default for PhalaTrieStorage<H> { | ||
fn default() -> Self { | ||
Self::Empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where the Empty is used? Is it possible to remove this variant?
{ | ||
fn from(v: Vec<u8>) -> Self { | ||
let (rc, val) = v.split_at(4); | ||
let value = T::from(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still double allocation
db: Arc<Mutex<DB>>, | ||
pink_overlay: Arc<Mutex<MemoryDB<H>>>, | ||
sync_overlay: Arc<Mutex<MemoryDB<H>>>, | ||
raw_map: BTreeMap<Vec<u8>, Vec<u8>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one overlay(the raw_map) here should be enough. pink/sync are user logic.
sync_overlay: Arc<Mutex<MemoryDB<H>>>, | ||
raw_map: BTreeMap<Vec<u8>, Vec<u8>>, | ||
pub pink_root: Option<H::Out>, | ||
pub sync_root: Option<H::Out>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root should be tracked by user, don't put them in this low level DB layer.
} | ||
} | ||
|
||
impl<H: Hasher> HashDB<H, DBValue> for TrieEssenceStorage<H> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many impl HashDB for ...
. Can we reduce some of them?
Closed. The work is continued in #928 |
This PR is targetd to replace phactory and pink MemoryDB into underlying KVDB.
Currenly, Pink and Phactory both use the MemoryDB, Morever after a specificed interval, Phactory will take a checkpoint not only over it's RuntimeState but the Pink storage. Unfortunatly, just replace the Pink storage could cause the whole system into inconsistence. For example:
Assume that, Phactory is now sync
100th
block from pherry and Pink is working on99th
block, if we just simply commit the transaction in Pink into the underlying storage, when the phactory crash now, Phactory checkpoint maybe at59th
block. When phala restart, from59th
block to99
block storage changes is duplicated,Implementation Details
firstly we should introduce the KVDB as a crate to support base semantics used for both
Pink
andPhactory
.Pink
is just need aTrieBackend
. So simplly wraps the underlying storage asTrieBackendStorage
makes thing sound. And forPhactory
it just needs theRawDB
interface notHashDB
. Due to this, we should introduce another interface over pkvdb to supply theRawDB
interface.And then, commit all transaction both
Pink
changes andPhactory
checkpoint per block makes thing sound.