feat(rln): close db connection before dropping rln object (#187)

This commit is contained in:
Aaryamann Challani
2023-07-25 15:22:55 +05:30
committed by GitHub
parent c6b7a8c0a4
commit 23d2331b78
9 changed files with 42 additions and 3 deletions

View File

@@ -101,6 +101,10 @@ where
})
}
fn close_db_connection(&mut self) -> Result<()> {
Ok(())
}
// Returns the depth of the tree
fn depth(&self) -> usize {
self.depth

View File

@@ -65,6 +65,7 @@ pub trait ZerokitMerkleTree {
fn verify(&self, leaf: &FrOf<Self::Hasher>, witness: &Self::Proof) -> Result<bool>;
fn set_metadata(&mut self, metadata: &[u8]) -> Result<()>;
fn metadata(&self) -> Result<Vec<u8>>;
fn close_db_connection(&mut self) -> Result<()>;
}
pub trait ZerokitMerkleProof {

View File

@@ -83,6 +83,10 @@ where
})
}
fn close_db_connection(&mut self) -> Result<()> {
Ok(())
}
// Returns the depth of the tree
fn depth(&self) -> usize {
self.depth

View File

@@ -45,6 +45,15 @@ impl Database for SledDB {
Ok(SledDB(db))
}
fn close(&mut self) -> PmtreeResult<()> {
let _ = self.0.flush().map_err(|_| {
PmtreeErrorKind::DatabaseError(DatabaseErrorKind::CustomError(
"Cannot flush database".to_string(),
))
})?;
Ok(())
}
fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>> {
match self.0.get(key) {
Ok(value) => Ok(value.map(|val| val.to_vec())),