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

Revertible store may not terminate while resetting #129

Closed
rnbguy opened this issue Sep 14, 2023 · 1 comment
Closed

Revertible store may not terminate while resetting #129

rnbguy opened this issue Sep 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@rnbguy
Copy link
Member

rnbguy commented Sep 14, 2023

When .reset() method is called on the revertible store, it calls the .set() or .delete() method for each logged operation.

while let Some(op) = self.op_log.pop() {
match op {
RevertOp::Delete(path) => self.delete(&path),
RevertOp::Set(path, value) => {
self.set(path, value).unwrap(); // safety - reset failures are unrecoverable
}
}
}

But the .set() may add a new operation to the op_log, and op_log may never be empty.

fn set(&mut self, path: Path, value: Vec<u8>) -> Result<Option<Vec<u8>>, Self::Error> {
let old_value = self.store.set(path.clone(), value)?;
match old_value {
// None implies this was an insert op, so we record the revert op as delete op
None => self.op_log.push(RevertOp::Delete(path)),
// Some old value implies this was an update op, so we record the revert op as a set op
// with the old value
Some(ref old_value) => self.op_log.push(RevertOp::Set(path, old_value.clone())),
}
Ok(old_value)
}

A sample test case demonstrating this.

let mut store = RevertibleStore::<InMemoryStore>::default();
store.set("into".to_owned().try_into()?, vec![1])?;
store.set("into".to_owned().try_into()?, vec![2])?;
store.reset(); // doesn't terminate
@rnbguy
Copy link
Member Author

rnbguy commented May 9, 2024

We will not fix this issue, as reverting requires rolling back to the previous root hash. However, while reverting the op_log, if the store adds a new key or deletes an old key - it arbitrarily reorganizes the tree.

Since it is a bug in the RevertibleStore, we will deprecate it in favor of InMemoryStore (which currently supports correct rollback) in #182.

@rnbguy rnbguy closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant