Skip to content

Commit

Permalink
Remove get_revision configuration option (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Aug 15, 2023
1 parent e257247 commit 450f382
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion firewood/examples/rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl RevisionTracker {

fn get_revision(&self, index: usize) -> Revision<SharedStore> {
self.db
.get_revision(&self.hashes[index], None)
.get_revision(&self.hashes[index])
.unwrap_or_else(|| panic!("revision-{index} should exist"))
}
}
Expand Down
4 changes: 2 additions & 2 deletions firewood/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::io::Write;

use crate::db::{DbError, DbRevConfig};
use crate::db::DbError;
use crate::merkle::TrieHash;
#[cfg(feature = "proof")]
use crate::{merkle::MerkleError, proof::Proof};
Expand All @@ -14,7 +14,7 @@ pub type Nonce = u64;

#[async_trait]
pub trait Db<R: Revision> {
async fn get_revision(&self, root_hash: TrieHash, cfg: Option<DbRevConfig>) -> Option<R>;
async fn get_revision(&self, root_hash: TrieHash) -> Option<R>;
}

#[async_trait]
Expand Down
10 changes: 2 additions & 8 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,7 @@ impl Db<SharedStore> {
///
/// If no revision with matching root hash found, returns None.
// #[measure([HitCount])]
pub fn get_revision(
&self,
root_hash: &TrieHash,
cfg: Option<DbRevConfig>,
) -> Option<Revision<SharedStore>> {
pub fn get_revision(&self, root_hash: &TrieHash) -> Option<Revision<SharedStore>> {
let mut revisions = self.revisions.lock();
let inner_lock = self.inner.read();

Expand Down Expand Up @@ -883,8 +879,6 @@ impl Db<SharedStore> {
// Release the lock after we find the revision
drop(inner_lock);

let cfg = cfg.as_ref().unwrap_or(&self.cfg.rev);

let db_header_ref = Db::get_db_header_ref(&space.merkle.meta).unwrap();

let merkle_payload_header_ref =
Expand All @@ -906,7 +900,7 @@ impl Db<SharedStore> {
(space.blob.meta.clone(), space.blob.payload.clone()),
self.payload_regn_nbit,
0,
cfg,
&self.cfg.rev,
)
.unwrap(),
}
Expand Down
9 changes: 2 additions & 7 deletions firewood/src/service/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{path::Path, thread};
use tokio::sync::{mpsc, oneshot};

use crate::api::Revision;
use crate::db::DbRevConfig;

use crate::{
db::{DbConfig, DbError},
merkle::TrieHash,
Expand Down Expand Up @@ -181,15 +181,10 @@ impl crate::api::Db<RevisionHandle> for Connection
where
tokio::sync::mpsc::Sender<Request>: From<tokio::sync::mpsc::Sender<Request>>,
{
async fn get_revision(
&self,
root_hash: TrieHash,
cfg: Option<DbRevConfig>,
) -> Option<RevisionHandle> {
async fn get_revision(&self, root_hash: TrieHash) -> Option<RevisionHandle> {
let (send, recv) = oneshot::channel();
let msg = Request::NewRevision {
root_hash,
cfg,
respond_to: send,
};
self.sender
Expand Down
6 changes: 1 addition & 5 deletions firewood/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

use tokio::sync::{mpsc, oneshot};

use crate::{
db::{DbError, DbRevConfig},
merkle::TrieHash,
};
use crate::{db::DbError, merkle::TrieHash};

mod client;
mod server;
Expand All @@ -25,7 +22,6 @@ pub struct RevisionHandle {
pub enum Request {
NewRevision {
root_hash: TrieHash,
cfg: Option<DbRevConfig>,
respond_to: oneshot::Sender<Option<RevId>>,
},

Expand Down
3 changes: 1 addition & 2 deletions firewood/src/service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ impl FirewoodService {
match msg {
Request::NewRevision {
root_hash,
cfg,
respond_to,
} => {
let id: RevId = lastid.fetch_add(1, Ordering::Relaxed);
let msg = match db.get_revision(&root_hash, cfg) {
let msg = match db.get_revision(&root_hash) {
Some(rev) => {
revs.insert(id, rev);
Some(id)
Expand Down
6 changes: 3 additions & 3 deletions firewood/tests/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn test_revisions() {
dumped
.iter()
.zip(hashes.iter().cloned())
.map(|(data, hash)| (data, db.get_revision(&hash, None).unwrap()))
.map(|(data, hash)| (data, db.get_revision(&hash).unwrap()))
.map(|(data, rev)| (data, kv_dump!(rev)))
.for_each(|(b, a)| {
if &a != b {
Expand All @@ -144,7 +144,7 @@ fn test_revisions() {
dumped
.iter()
.zip(hashes.iter().cloned())
.map(|(data, hash)| (data, db.get_revision(&hash, None).unwrap()))
.map(|(data, hash)| (data, db.get_revision(&hash).unwrap()))
.map(|(data, rev)| (data, kv_dump!(rev)))
.for_each(|(previous_dump, after_reopen_dump)| {
if &after_reopen_dump != previous_dump {
Expand Down Expand Up @@ -208,7 +208,7 @@ fn create_db_issue_proof() {
let proposal = db.new_proposal(batch).unwrap();
proposal.commit().unwrap();

let rev = db.get_revision(&root_hash, None).unwrap();
let rev = db.get_revision(&root_hash).unwrap();
let key = "doe".as_bytes();
let root_hash = rev.kv_root_hash();

Expand Down

0 comments on commit 450f382

Please sign in to comment.