Skip to content

Commit ceda768

Browse files
authored
fix: blockchain provider (#20)
1 parent dc3d42f commit ceda768

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

crates/rpc/src/ctx/full.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::{
44
eips::BlockId,
55
};
66
use reth::{
7-
providers::{ProviderFactory, ProviderResult},
7+
providers::{ProviderFactory, ProviderResult, providers::BlockchainProvider},
88
rpc::server_types::eth::{EthApiError, EthConfig},
99
tasks::{TaskExecutor, TaskSpawner},
1010
};
@@ -32,18 +32,30 @@ where
3232
Signet: Pnt,
3333
{
3434
/// Create a new `RpcCtx`.
35+
///
36+
/// ## WARNING
37+
///
38+
/// The [`BlockchainProvider`] passed in MUST be receiving updates from the
39+
/// node wrt canonical chain changes. Some task MUST be calling relevant
40+
/// [`CanonChainTracker`] methods on a clone of this [`BlockchainProvider`],
41+
///
42+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
43+
/// `safe,` finalized, etc will not work correctly.
44+
///
45+
/// [`CanonChainTracker`]: reth::providers::CanonChainTracker
3546
pub fn new<Tasks>(
3647
host: Host,
3748
constants: SignetSystemConstants,
3849
factory: ProviderFactory<Signet>,
50+
provider: BlockchainProvider<Signet>,
3951
eth_config: EthConfig,
4052
tx_cache: Option<TxCache>,
4153
spawner: Tasks,
4254
) -> ProviderResult<Self>
4355
where
4456
Tasks: TaskSpawner + Clone + 'static,
4557
{
46-
RpcCtxInner::new(host, constants, factory, eth_config, tx_cache, spawner)
58+
RpcCtxInner::new(host, constants, factory, provider, eth_config, tx_cache, spawner)
4759
.map(|inner| Self { inner: Arc::new(inner) })
4860
}
4961
}
@@ -87,18 +99,30 @@ where
8799
Signet: Pnt,
88100
{
89101
/// Create a new `RpcCtxInner`.
102+
///
103+
/// ## WARNING
104+
///
105+
/// The [`BlockchainProvider`] passed in MUST be receiving updates from the
106+
/// node wrt canonical chain changes. Some task MUST be calling relevant
107+
/// [`CanonChainTracker`] methods on a clone of this [`BlockchainProvider`],
108+
///
109+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
110+
/// `safe,` finalized, etc will not work correctly.
111+
///
112+
/// [`CanonChainTracker`]: reth::providers::CanonChainTracker
90113
pub fn new<Tasks>(
91114
host: Host,
92115
constants: SignetSystemConstants,
93116
factory: ProviderFactory<Signet>,
117+
provider: BlockchainProvider<Signet>,
94118
eth_config: EthConfig,
95119
tx_cache: Option<TxCache>,
96120
spawner: Tasks,
97121
) -> ProviderResult<Self>
98122
where
99123
Tasks: TaskSpawner + Clone + 'static,
100124
{
101-
SignetCtx::new(constants, factory, eth_config, tx_cache, spawner)
125+
SignetCtx::new(constants, factory, provider, eth_config, tx_cache, spawner)
102126
.map(|signet| Self { host, signet })
103127
}
104128

crates/rpc/src/ctx/signet.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,28 @@ where
9393
{
9494
/// Instantiate a new `SignetCtx`, spawning necessary tasks to keep the
9595
/// relevant caches up to date.
96+
///
97+
/// ## WARNING
98+
///
99+
/// The [`BlockchainProvider`] passed in MUST be receiving updates from the
100+
/// node wrt canonical chain changes. Some task MUST be calling relevant
101+
/// [`CanonChainTracker`] methods on a clone of this [`BlockchainProvider`],
102+
///
103+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
104+
/// `safe,` finalized, etc will not work correctly.
105+
///
106+
/// [`CanonChainTracker`]: reth::providers::CanonChainTracker
96107
pub fn new<Tasks>(
97108
constants: SignetSystemConstants,
98109
factory: ProviderFactory<Inner>,
110+
provider: BlockchainProvider<Inner>,
99111
eth_config: EthConfig,
100112
tx_cache: Option<TxCache>,
101113
spawner: Tasks,
102114
) -> ProviderResult<Self>
103115
where
104116
Tasks: TaskSpawner + Clone + 'static,
105117
{
106-
let provider = BlockchainProvider::new(factory.clone())?;
107-
108118
let cache = EthStateCache::spawn_with(provider.clone(), eth_config.cache, spawner.clone());
109119
let gas_oracle =
110120
GasPriceOracle::new(provider.clone(), eth_config.gas_oracle, cache.clone());

0 commit comments

Comments
 (0)