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

feat(provider): use NodeTypes on DatabaseProvider instead #12166

Merged
merged 1 commit into from
Oct 29, 2024
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
6 changes: 3 additions & 3 deletions crates/stages/stages/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use criterion::{criterion_main, measurement::WallTime, BenchmarkGroup, Criterion};
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
use reth_chainspec::ChainSpec;
use reth_config::config::{EtlConfig, TransactionLookupConfig};
use reth_db::{test_utils::TempDatabase, Database, DatabaseEnv};

use alloy_primitives::BlockNumber;
use reth_provider::{DatabaseProvider, DatabaseProviderFactory};
use reth_provider::{test_utils::MockNodeTypesWithDB, DatabaseProvider, DatabaseProviderFactory};
use reth_stages::{
stages::{MerkleStage, SenderRecoveryStage, TransactionLookupStage},
test_utils::TestStageDB,
Expand Down Expand Up @@ -148,7 +147,8 @@ fn measure_stage<F, S>(
block_interval: RangeInclusive<BlockNumber>,
label: String,
) where
S: Clone + Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, ChainSpec>>,
S: Clone
+ Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, MockNodeTypesWithDB>>,
F: Fn(S, &TestStageDB, StageRange),
{
let stage_range = (
Expand Down
11 changes: 7 additions & 4 deletions crates/stages/stages/benches/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#![allow(unreachable_pub)]
use alloy_primitives::{Address, Sealable, B256, U256};
use itertools::concat;
use reth_chainspec::ChainSpec;
use reth_db::{tables, test_utils::TempDatabase, Database, DatabaseEnv};
use reth_db_api::{
cursor::DbCursorRO,
transaction::{DbTx, DbTxMut},
};
use reth_primitives::{Account, SealedBlock, SealedHeader};
use reth_provider::{DatabaseProvider, DatabaseProviderFactory, TrieWriter};
use reth_provider::{
test_utils::MockNodeTypesWithDB, DatabaseProvider, DatabaseProviderFactory, TrieWriter,
};
use reth_stages::{
stages::{AccountHashingStage, StorageHashingStage},
test_utils::{StorageKind, TestStageDB},
Expand All @@ -31,7 +32,8 @@ use reth_trie_db::DatabaseStateRoot;
pub(crate) type StageRange = (ExecInput, UnwindInput);

pub(crate) fn stage_unwind<
S: Clone + Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, ChainSpec>>,
S: Clone
+ Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, MockNodeTypesWithDB>>,
>(
stage: S,
db: &TestStageDB,
Expand Down Expand Up @@ -63,7 +65,8 @@ pub(crate) fn stage_unwind<

pub(crate) fn unwind_hashes<S>(stage: S, db: &TestStageDB, range: StageRange)
where
S: Clone + Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, ChainSpec>>,
S: Clone
+ Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, MockNodeTypesWithDB>>,
{
let (input, unwind) = range;

Expand Down
7 changes: 2 additions & 5 deletions crates/stages/stages/src/stages/hashing_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ impl AccountHashingStage {
///
/// Proceeds to go to the `BlockTransitionIndex` end, go back `transitions` and change the
/// account state in the `AccountChangeSets` table.
pub fn seed<
Tx: DbTx + DbTxMut + 'static,
Spec: Send + Sync + 'static + reth_chainspec::EthereumHardforks,
>(
provider: &reth_provider::DatabaseProvider<Tx, Spec>,
pub fn seed<Tx: DbTx + DbTxMut + 'static, N: reth_provider::providers::ProviderNodeTypes>(
provider: &reth_provider::DatabaseProvider<Tx, N>,
opts: SeedOpts,
) -> Result<Vec<(alloy_primitives::Address, reth_primitives::Account)>, StageError> {
use alloy_primitives::U256;
Expand Down
5 changes: 2 additions & 3 deletions crates/stages/stages/src/test_utils/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::TestStageDB;
use reth_chainspec::ChainSpec;
use reth_db::{test_utils::TempDatabase, Database, DatabaseEnv};
use reth_provider::{DatabaseProvider, ProviderError};
use reth_provider::{test_utils::MockNodeTypesWithDB, DatabaseProvider, ProviderError};
use reth_stages_api::{
ExecInput, ExecOutput, Stage, StageError, StageExt, UnwindInput, UnwindOutput,
};
Expand All @@ -20,7 +19,7 @@ pub(crate) enum TestRunnerError {

/// A generic test runner for stages.
pub(crate) trait StageTestRunner {
type S: Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, ChainSpec>>
type S: Stage<DatabaseProvider<<TempDatabase<DatabaseEnv> as Database>::TXMut, MockNodeTypesWithDB>>
+ 'static;

/// Return a reference to the database.
Expand Down
8 changes: 4 additions & 4 deletions crates/storage/provider/src/providers/consistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
) -> ProviderResult<Vec<T>>
where
F: FnOnce(
&DatabaseProviderRO<N::DB, N::ChainSpec>,
&DatabaseProviderRO<N::DB, N>,
RangeInclusive<BlockNumber>,
&mut P,
) -> ProviderResult<Vec<T>>,
Expand Down Expand Up @@ -413,7 +413,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
) -> ProviderResult<Vec<R>>
where
S: FnOnce(
&DatabaseProviderRO<N::DB, N::ChainSpec>,
&DatabaseProviderRO<N::DB, N>,
RangeInclusive<TxNumber>,
) -> ProviderResult<Vec<R>>,
M: Fn(RangeInclusive<usize>, &BlockState) -> ProviderResult<Vec<R>>,
Expand Down Expand Up @@ -511,7 +511,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
fetch_from_block_state: M,
) -> ProviderResult<Option<R>>
where
S: FnOnce(&DatabaseProviderRO<N::DB, N::ChainSpec>) -> ProviderResult<Option<R>>,
S: FnOnce(&DatabaseProviderRO<N::DB, N>) -> ProviderResult<Option<R>>,
M: Fn(usize, TxNumber, &BlockState) -> ProviderResult<Option<R>>,
{
let in_mem_chain = self.head_block.iter().flat_map(|b| b.chain()).collect::<Vec<_>>();
Expand Down Expand Up @@ -578,7 +578,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
fetch_from_block_state: M,
) -> ProviderResult<R>
where
S: FnOnce(&DatabaseProviderRO<N::DB, N::ChainSpec>) -> ProviderResult<R>,
S: FnOnce(&DatabaseProviderRO<N::DB, N>) -> ProviderResult<R>,
M: Fn(&BlockState) -> ProviderResult<R>,
{
if let Some(Some(block_state)) = self.head_block.as_ref().map(|b| b.block_on_chain(id)) {
Expand Down
8 changes: 4 additions & 4 deletions crates/storage/provider/src/providers/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<N: ProviderNodeTypes> ProviderFactory<N> {
/// This sets the [`PruneModes`] to [`None`], because they should only be relevant for writing
/// data.
#[track_caller]
pub fn provider(&self) -> ProviderResult<DatabaseProviderRO<N::DB, N::ChainSpec>> {
pub fn provider(&self) -> ProviderResult<DatabaseProviderRO<N::DB, N>> {
Ok(DatabaseProvider::new(
self.db.tx()?,
self.chain_spec.clone(),
Expand All @@ -144,7 +144,7 @@ impl<N: ProviderNodeTypes> ProviderFactory<N> {
/// [`BlockHashReader`]. This may fail if the inner read/write database transaction fails to
/// open.
#[track_caller]
pub fn provider_rw(&self) -> ProviderResult<DatabaseProviderRW<N::DB, N::ChainSpec>> {
pub fn provider_rw(&self) -> ProviderResult<DatabaseProviderRW<N::DB, N>> {
Ok(DatabaseProviderRW(DatabaseProvider::new_rw(
self.db.tx_mut()?,
self.chain_spec.clone(),
Expand Down Expand Up @@ -186,8 +186,8 @@ impl<N: ProviderNodeTypes> ProviderFactory<N> {

impl<N: ProviderNodeTypes> DatabaseProviderFactory for ProviderFactory<N> {
type DB = N::DB;
type Provider = DatabaseProvider<<N::DB as Database>::TX, N::ChainSpec>;
type ProviderRW = DatabaseProvider<<N::DB as Database>::TXMut, N::ChainSpec>;
type Provider = DatabaseProvider<<N::DB as Database>::TX, N>;
type ProviderRW = DatabaseProvider<<N::DB as Database>::TXMut, N>;

fn database_provider_ro(&self) -> ProviderResult<Self::Provider> {
self.provider()
Expand Down
Loading
Loading