Skip to content

Commit

Permalink
Prevent mutations to DbRev<SharedStore> (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Feb 27, 2024
1 parent 6639e34 commit 8ca1081
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,6 @@ impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> {
.key_value_iter_from_key(self.header.kv_root, start_key)
}

fn flush_dirty(&mut self) -> Option<()> {
self.header.flush_dirty();
self.merkle.flush_dirty()?;
Some(())
}

fn borrow_split(&mut self) -> (&mut shale::Obj<DbHeader>, &mut Merkle<S, Bincode>) {
(&mut self.header, &mut self.merkle)
}

/// Get root hash of the generic key-value storage.
pub fn kv_root_hash(&self) -> Result<TrieHash, DbError> {
self.merkle
Expand Down Expand Up @@ -398,6 +388,23 @@ impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> {
}
}

impl DbRev<MutStore> {
fn borrow_split(
&mut self,
) -> (
&mut shale::Obj<DbHeader>,
&mut Merkle<CompactSpace<Node, StoreRevMut>, Bincode>,
) {
(&mut self.header, &mut self.merkle)
}

fn flush_dirty(&mut self) -> Option<()> {
self.header.flush_dirty();
self.merkle.flush_dirty()?;
Some(())
}
}

impl From<DbRev<MutStore>> for DbRev<SharedStore> {
fn from(value: DbRev<MutStore>) -> Self {
DbRev {
Expand Down

0 comments on commit 8ca1081

Please sign in to comment.