paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.81k stars 1.07k forks source link

Initialize database with `ProviderFactory` #3579

Open shekhirin opened 1 year ago

shekhirin commented 1 year ago

Describe the feature

We use a bunch of helpers for initializing/opening a database throughout the codebase: https://github.com/paradigmxyz/reth/blob/9821311585f62ed868b1df2e9516f94d51527f26/crates/storage/db/src/lib.rs#L108 https://github.com/paradigmxyz/reth/blob/9821311585f62ed868b1df2e9516f94d51527f26/crates/storage/db/src/lib.rs#L136 https://github.com/paradigmxyz/reth/blob/9821311585f62ed868b1df2e9516f94d51527f26/crates/storage/db/src/lib.rs#L150

Such free floating functions is not the best experience, so we can migrate to using ProviderFactory instead: https://github.com/paradigmxyz/reth/blob/9821311585f62ed868b1df2e9516f94d51527f26/crates/storage/provider/src/providers/database/mod.rs#L59-L73


Things to keep in mind:

  1. We still need to be able to set the LogLevel
  2. CLI tools use Database::view and Database::update which aren't available if initialized through ProviderFactory. We need to figure it out.

Additional context

https://github.com/paradigmxyz/reth/pull/3524#issuecomment-1618116522

cjeva10 commented 1 year ago

I'm trying to understand what's going on here. When the cli executes reth node we're calling init_db so this seems like a place to use ProviderFactory.

The issue is we need to use db on subsequent function calls such as init_genesis or start_metrics_endpoint. How can we do that with ProviderFactory without changing all those function signatures as well? Is that the plan here?

https://github.com/paradigmxyz/reth/blob/9821311585f62ed868b1df2e9516f94d51527f26/bin/reth/src/node/mod.rs#L172-L179

onbjerg commented 1 year ago

Another thing to keep in mind is that we want MDBX to leak as little as possible so a potential database switch later would just be implementing the database traits, so the solution should still retain the generic DB param

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 14 days with no activity.

nkysg commented 3 weeks ago

Does this still need to work?