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

Define basic interfaces for using Merkle tree #39

Merged
merged 11 commits into from
Aug 12, 2022
Merged

Conversation

junha1
Copy link
Member

@junha1 junha1 commented Aug 8, 2022

No description provided.

common/src/lib.rs Outdated Show resolved Hide resolved
_x: PhantomData<S>,
}

impl<S: KVStorage> MerkleTree<S> {
Copy link

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?

Copy link
Member Author

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().


/// 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)
Copy link

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.

Copy link
Member Author

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.

  1. We need to access to entries that are not part of the Merkle tree. (e.g., past blocks)
  2. We need to use the 'checkpoint' functionalities provided by the storage.
    That makes it natural not to provide get() method that would just invoke another get() of the underlying storage.

Copy link
Member Author

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 {
Copy link

Choose a reason for hiding this comment

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

We need contain() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

Milchstra3e
Milchstra3e previously approved these changes Aug 9, 2022
Copy link
Contributor

@Milchstra3e Milchstra3e left a comment

Choose a reason for hiding this comment

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

checked

@@ -16,7 +16,7 @@ pub trait BlockExecutor {
type Transaction;
async fn execute(
&self,
store: &mut dyn KVStore,
store: &mut dyn KVStorage,
Copy link
Contributor

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"

/// 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>;
Copy link
Contributor

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.

Copy link
Member Author

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

  1. not exists
  2. DB error
    Error variants will be added later.

/// 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>;
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

unimplemented!()
}

/// Returns a reference to the underlting storage.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Copy link
Member Author

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>;
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

stated.

posgnu
posgnu previously approved these changes Aug 10, 2022
@junha1 junha1 merged commit 5e6eb33 into postech-dao:main Aug 12, 2022
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.

None yet

5 participants