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

Cleanup: Remove generics on Db #196

Merged
merged 1 commit into from
Aug 17, 2023
Merged
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
4 changes: 2 additions & 2 deletions firewood/examples/rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ fn main() {

struct RevisionTracker {
hashes: VecDeque<TrieHash>,
db: Db<SharedStore>,
db: Db,
}

impl RevisionTracker {
fn new(db: Db<SharedStore>) -> Self {
fn new(db: Db) -> Self {
Self {
hashes: VecDeque::new(),
db,
Expand Down
8 changes: 4 additions & 4 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,16 @@ pub struct DbRevInner<T> {

/// Firewood database handle.
#[derive(Debug)]
pub struct Db<S> {
pub struct Db {
inner: Arc<RwLock<DbInner>>,
revisions: Arc<Mutex<DbRevInner<S>>>,
revisions: Arc<Mutex<DbRevInner<SharedStore>>>,
payload_regn_nbit: u64,
metrics: Arc<DbMetrics>,
cfg: DbConfig,
}

// #[metered(registry = DbMetrics, visibility = pub)]
impl Db<SharedStore> {
impl Db {
const PARAM_SIZE: u64 = size_of::<DbParams>() as u64;

/// Open a database.
Expand Down Expand Up @@ -909,7 +909,7 @@ impl Db<SharedStore> {
}

#[metered(registry = DbMetrics, visibility = pub)]
impl<S: ShaleStore<Node> + Send + Sync> Db<S> {
impl Db {
/// Dump the Trie of the latest generic key-value storage.
pub fn kv_dump(&self, w: &mut dyn Write) -> Result<(), DbError> {
self.revisions.lock().base_revision.kv_dump(w)
Expand Down
13 changes: 5 additions & 8 deletions firewood/tests/db.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use firewood::{
db::{BatchOp, Db as PersistedDb, DbConfig, DbError, WalConfig},
merkle::{Node, TrieHash},
storage::StoreRevShared,
merkle::TrieHash,
};
use firewood_shale::compact::CompactSpace;

use std::{
collections::VecDeque,
fs::remove_dir_all,
Expand All @@ -22,9 +21,7 @@ macro_rules! kv_dump {
}};
}

type SharedStore = CompactSpace<Node, StoreRevShared>;

struct Db<'a, P: AsRef<Path> + ?Sized>(PersistedDb<SharedStore>, &'a P);
struct Db<'a, P: AsRef<Path> + ?Sized>(PersistedDb, &'a P);

impl<'a, P: AsRef<Path> + ?Sized> Db<'a, P> {
fn new(path: &'a P, cfg: &DbConfig) -> Result<Self, DbError> {
Expand Down Expand Up @@ -231,15 +228,15 @@ fn create_db_issue_proof() {
}

impl<P: AsRef<Path> + ?Sized> Deref for Db<'_, P> {
type Target = PersistedDb<SharedStore>;
type Target = PersistedDb;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<P: AsRef<Path> + ?Sized> DerefMut for Db<'_, P> {
fn deref_mut(&mut self) -> &mut PersistedDb<SharedStore> {
fn deref_mut(&mut self) -> &mut PersistedDb {
&mut self.0
}
}
Expand Down
Loading