diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index f9a4145956..9250926e0c 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -239,7 +239,7 @@ impl Command { &self, config: &Config, db: &Arc>, - ) -> NetworkConfig>> { + ) -> NetworkConfig>>> { let peers_file = (!self.network.no_persist_peers).then_some(&self.network.peers_file); config.network_config( db.clone(), diff --git a/crates/staged-sync/src/config.rs b/crates/staged-sync/src/config.rs index 7c683f331d..297f8fc3d6 100644 --- a/crates/staged-sync/src/config.rs +++ b/crates/staged-sync/src/config.rs @@ -30,7 +30,7 @@ impl Config { /// Initializes network config from read data pub fn network_config( &self, - db: Arc, + db: DB, chain_spec: ChainSpec, disable_discovery: bool, bootnodes: Option>, diff --git a/crates/storage/db/src/abstraction/database.rs b/crates/storage/db/src/abstraction/database.rs index 7aff2d400e..4de1f4c540 100644 --- a/crates/storage/db/src/abstraction/database.rs +++ b/crates/storage/db/src/abstraction/database.rs @@ -3,6 +3,7 @@ use crate::{ transaction::{DbTx, DbTxMut}, Error, }; +use std::sync::Arc; /// Implements the GAT method from: /// . @@ -51,3 +52,35 @@ pub trait Database: for<'a> DatabaseGAT<'a> { Ok(res) } } + +// Generic over Arc +impl<'a, DB: Database> DatabaseGAT<'a> for Arc { + type TX = >::TX; + type TXMut = >::TXMut; +} + +impl Database for Arc { + fn tx(&self) -> Result<>::TX, Error> { + ::tx(self) + } + + fn tx_mut(&self) -> Result<>::TXMut, Error> { + ::tx_mut(self) + } +} + +// Generic over reference +impl<'a, DB: Database> DatabaseGAT<'a> for &DB { + type TX = >::TX; + type TXMut = >::TXMut; +} + +impl Database for &DB { + fn tx(&self) -> Result<>::TX, Error> { + ::tx(self) + } + + fn tx_mut(&self) -> Result<>::TXMut, Error> { + ::tx_mut(self) + } +} diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index 036738e157..d5ee4462ad 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -6,7 +6,6 @@ use reth_db::{ }; use reth_interfaces::Result; use reth_primitives::{rpc::BlockId, Block, BlockHash, BlockNumber, ChainInfo, Header, H256, U256}; -use std::sync::Arc; mod state; pub use state::{ @@ -20,19 +19,19 @@ pub use state::{ /// This provider implements most provider or provider factory traits. pub struct ShareableDatabase { /// Database - db: Arc, + db: DB, } impl ShareableDatabase { /// create new database provider - pub fn new(db: Arc) -> Self { + pub fn new(db: DB) -> Self { Self { db } } } -impl Clone for ShareableDatabase { +impl Clone for ShareableDatabase { fn clone(&self) -> Self { - Self { db: Arc::clone(&self.db) } + Self { db: self.db.clone() } } }