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

Added RevertibleStorage to handle storage that does not need to be verified using Merkle Tries #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ impl ChangeBatch {
}

pub fn serialize<ID: Id>(&self, id: &ID) -> Vec<(Vec<u8>, &[u8])> {
let id = id.to_bytes();
self.0
.iter()
.flat_map(|(change_key, change)| {
let key_slice = change_key.as_slice();
let mut changes = Vec::new();

if let Some(old_value) = &change.old_value {
Expand All @@ -52,26 +50,12 @@ impl ChangeBatch {
return changes;
}
}
let key = [
id.as_slice(),
&[KEY_SEPARATOR],
key_slice,
&[change_key.into()],
&[OLD_VALUE],
]
.concat();
let key = key_old_value(id, change_key);
changes.push((key, old_value.as_slice()));
}

if let Some(new_value) = &change.new_value {
let key = [
id.as_slice(),
&[KEY_SEPARATOR],
key_slice,
&[change_key.into()],
&[NEW_VALUE],
]
.concat();
let key = key_new_value(id, change_key);
changes.push((key, new_value.as_slice()));
}
changes
Expand Down Expand Up @@ -137,3 +121,25 @@ where
}
}
}

pub fn key_old_value<ID: Id>(id: &ID, key: &TrieKey) -> Vec<u8> {
[
id.to_bytes().as_slice(),
&[KEY_SEPARATOR],
key.as_slice(),
&[key.into()],
&[OLD_VALUE],
]
.concat()
}

pub fn key_new_value<ID: Id>(id: &ID, key: &TrieKey) -> Vec<u8> {
[
id.to_bytes().as_slice(),
&[KEY_SEPARATOR],
key.as_slice(),
&[key.into()],
&[NEW_VALUE],
]
.concat()
}
6 changes: 6 additions & 0 deletions src/key_value_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ where
self.snap_counter += 1;
}

/// Retrieves a transactional state using the closest snapshot.
Trantorian1 marked this conversation as resolved.
Show resolved Hide resolved
///
/// > Note that if a snapshot does not exist for the exact commit id
/// > then changes will be iteratively reverted from the closest snapshot.
///
/// * `id`: transaction state will represent the state of the db at this change id
pub(crate) fn get_transaction(
&self,
id: ID,
Expand Down
Loading
Loading