-
Notifications
You must be signed in to change notification settings - Fork 38
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
Define basic interfaces for using Merkle tree #39
Conversation
_x: PhantomData<S>, | ||
} | ||
|
||
impl<S: KVStorage> MerkleTree<S> { |
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.
Maybe we need a sort of contain(value) -> bool
method?
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.
no, for the same reason with get()
.
merkle-tree/src/lib.rs
Outdated
|
||
/// A state machine that interpret the given storage as a Merkle tree rooted by a specific key. | ||
/// | ||
/// Note that there is no `get()` method as leaf nodes (which the user of this struct would like to read) |
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.
I don't understand this part. Isn't it that the MerkleTree
is an upper-level abstraction upon KVstorage
? In that case, I believe get()
method is still needed unless our PBC code holds both KVstorage
and MerkleTree
.
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.
No it's not. MerkleTree is just one way of interpreting the given storage. We still need to access to the underlying storage for the following cases.
- We need to access to entries that are not part of the Merkle tree. (e.g., past blocks)
- We need to use the 'checkpoint' functionalities provided by the storage.
That makes it natural not to provideget()
method that would just invoke anotherget()
of the underlying storage.
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.
I add a commit about this. Please check a6d9a65
|
||
/// TODO: Provide error types. | ||
/// | ||
/// Note: This trait is quite subject to change. | ||
#[async_trait] | ||
pub trait KVStore { | ||
pub trait KVStorage { |
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.
We need contain()
here?
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.
fixed.
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.
checked
simperby/src/lib.rs
Outdated
@@ -16,7 +16,7 @@ pub trait BlockExecutor { | |||
type Transaction; | |||
async fn execute( | |||
&self, | |||
store: &mut dyn KVStore, | |||
store: &mut dyn KVStorage, |
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.
it's better to change from "store" to "storage"
kv-storage/src/lib.rs
Outdated
/// Retrieves the value associated with the key. If not exists, it will return `None`. | ||
async fn get(&self, key: Hash256) -> Result<Option<Vec<u8>>, Error>; | ||
/// Checks whether the given item exists in the storage. | ||
async fn contain(&self, key: Hash256) -> Result<(), Error>; |
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.
how contain fn notify its result?
I thk, contain(val) -> bool is better.
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.
@Milchstra3e Same as get
i.e., Ok(())
if exists, Error
if
- not exists
- DB error
Error variants will be added later.
kv-storage/src/lib.rs
Outdated
/// Removes a key-value pair from the storage. If not exists, it will fail. | ||
async fn remove(&mut self, key: Hash256) -> Result<(), Error>; | ||
/// Retrieves the value associated with the key. If not exists, it will return `None`. | ||
async fn get(&self, key: Hash256) -> Result<Option<Vec<u8>>, Error>; |
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.
get
returns None
if the item of the given key doesn't exist, while contain
returns Err
in the same case.
That might be confusing.
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.
fixed.
merkle-tree/src/lib.rs
Outdated
unimplemented!() | ||
} | ||
|
||
/// Returns a reference to the underlting storage. |
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.
typo
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.
fixed
/// Records the current state to the persistent storage. | ||
async fn commit_checkpoint(&mut self) -> Result<(), Error>; | ||
/// Reverts all the changes made since the last checkpoint. | ||
async fn revert_to_latest_checkpoint(&mut self) -> Result<(), Error>; |
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.
Can we commit checkpoint two times in a row and then revert to latest two times?
In other words, will the commits stack up if we call commit_checkpoint
multiple times?
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.
stated.
No description provided.