Skip to content

Commit

Permalink
Remove unconstrained generic in `ProviderFactory::new_with_database_p…
Browse files Browse the repository at this point in the history
…ath` (#6869)
  • Loading branch information
makcandrov authored Feb 29, 2024
1 parent f829633 commit 70d786a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions crates/storage/provider/src/providers/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ impl<DB> ProviderFactory<DB> {
Self { db, chain_spec, snapshot_provider: None }
}

/// Create new database provider by passing a path. [`ProviderFactory`] will own the database
/// instance.
pub fn new_with_database_path<P: AsRef<Path>>(
path: P,
chain_spec: Arc<ChainSpec>,
args: DatabaseArguments,
) -> RethResult<ProviderFactory<DatabaseEnv>> {
Ok(ProviderFactory::<DatabaseEnv> {
db: init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?,
chain_spec,
snapshot_provider: None,
})
}

/// Database provider that comes with a shared snapshot provider.
pub fn with_snapshots(
mut self,
Expand All @@ -97,6 +83,22 @@ impl<DB> ProviderFactory<DB> {
}
}

impl ProviderFactory<DatabaseEnv> {
/// Create new database provider by passing a path. [`ProviderFactory`] will own the database
/// instance.
pub fn new_with_database_path<P: AsRef<Path>>(
path: P,
chain_spec: Arc<ChainSpec>,
args: DatabaseArguments,
) -> RethResult<Self> {
Ok(ProviderFactory::<DatabaseEnv> {
db: init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?,
chain_spec,
snapshot_provider: None,
})
}
}

impl<DB: Database> ProviderFactory<DB> {
/// Returns a provider with a created `DbTx` inside, which allows fetching data from the
/// database using different types of providers. Example: [`HeaderProvider`]
Expand Down Expand Up @@ -534,7 +536,7 @@ mod tests {
use alloy_rlp::Decodable;
use assert_matches::assert_matches;
use rand::Rng;
use reth_db::{tables, test_utils::ERROR_TEMPDIR, transaction::DbTxMut, DatabaseEnv};
use reth_db::{tables, test_utils::ERROR_TEMPDIR, transaction::DbTxMut};
use reth_interfaces::{
provider::ProviderError,
test_utils::{
Expand Down Expand Up @@ -578,7 +580,7 @@ mod tests {
#[test]
fn provider_factory_with_database_path() {
let chain_spec = ChainSpecBuilder::mainnet().build();
let factory = ProviderFactory::<DatabaseEnv>::new_with_database_path(
let factory = ProviderFactory::new_with_database_path(
tempfile::TempDir::new().expect(ERROR_TEMPDIR).into_path(),
Arc::new(chain_spec),
Default::default(),
Expand Down

0 comments on commit 70d786a

Please sign in to comment.