Skip to content

Commit 4175f8c

Browse files
committed
fix: blockchain provider
1 parent dc3d42f commit 4175f8c

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

crates/rpc/src/ctx/full.rs

Lines changed: 31 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,32 @@ 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
40+
/// [`BlockchainProvider::set_canonical_head`],
41+
/// [`BlockchainProvider::set_safe`],
42+
/// [`BlockchainProvider::set_finalized`], and
43+
/// [`BlockchainProvider::on_forkchoice_update_received`] on a clone of
44+
/// this [`BlockchainProvider`].
45+
///
46+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
47+
/// `safe,` finalized, etc will not work correctly.
3548
pub fn new<Tasks>(
3649
host: Host,
3750
constants: SignetSystemConstants,
3851
factory: ProviderFactory<Signet>,
52+
provider: BlockchainProvider<Signet>,
3953
eth_config: EthConfig,
4054
tx_cache: Option<TxCache>,
4155
spawner: Tasks,
4256
) -> ProviderResult<Self>
4357
where
4458
Tasks: TaskSpawner + Clone + 'static,
4559
{
46-
RpcCtxInner::new(host, constants, factory, eth_config, tx_cache, spawner)
60+
RpcCtxInner::new(host, constants, factory, provider, eth_config, tx_cache, spawner)
4761
.map(|inner| Self { inner: Arc::new(inner) })
4862
}
4963
}
@@ -87,18 +101,32 @@ where
87101
Signet: Pnt,
88102
{
89103
/// Create a new `RpcCtxInner`.
104+
///
105+
/// ## WARNING
106+
///
107+
/// The [`BlockchainProvider`] passed in MUST be receiving updates from the
108+
/// node wrt canonical chain changes. Some task MUST be calling
109+
/// [`BlockchainProvider::set_canonical_head`],
110+
/// [`BlockchainProvider::set_safe`],
111+
/// [`BlockchainProvider::set_finalized`], and
112+
/// [`BlockchainProvider::on_forkchoice_update_received`] on a clone of
113+
/// this [`BlockchainProvider`].
114+
///
115+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
116+
/// `safe,` finalized, etc will not work correctly.
90117
pub fn new<Tasks>(
91118
host: Host,
92119
constants: SignetSystemConstants,
93120
factory: ProviderFactory<Signet>,
121+
provider: BlockchainProvider<Signet>,
94122
eth_config: EthConfig,
95123
tx_cache: Option<TxCache>,
96124
spawner: Tasks,
97125
) -> ProviderResult<Self>
98126
where
99127
Tasks: TaskSpawner + Clone + 'static,
100128
{
101-
SignetCtx::new(constants, factory, eth_config, tx_cache, spawner)
129+
SignetCtx::new(constants, factory, provider, eth_config, tx_cache, spawner)
102130
.map(|signet| Self { host, signet })
103131
}
104132

crates/rpc/src/ctx/signet.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,30 @@ 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
101+
/// [`BlockchainProvider::set_canonical_head`],
102+
/// [`BlockchainProvider::set_safe`],
103+
/// [`BlockchainProvider::set_finalized`], and
104+
/// [`BlockchainProvider::on_forkchoice_update_received`] on a clone of
105+
/// this [`BlockchainProvider`].
106+
///
107+
/// If this is not correctly set up, [`BlockId`] resolution for `latest`,
108+
/// `safe,` finalized, etc will not work correctly.
96109
pub fn new<Tasks>(
97110
constants: SignetSystemConstants,
98111
factory: ProviderFactory<Inner>,
112+
provider: BlockchainProvider<Inner>,
99113
eth_config: EthConfig,
100114
tx_cache: Option<TxCache>,
101115
spawner: Tasks,
102116
) -> ProviderResult<Self>
103117
where
104118
Tasks: TaskSpawner + Clone + 'static,
105119
{
106-
let provider = BlockchainProvider::new(factory.clone())?;
107-
108120
let cache = EthStateCache::spawn_with(provider.clone(), eth_config.cache, spawner.clone());
109121
let gas_oracle =
110122
GasPriceOracle::new(provider.clone(), eth_config.gas_oracle, cache.clone());

0 commit comments

Comments
 (0)