Skip to content

Commit c8deba9

Browse files
committed
refactors the rollup provider type
- refactors the rollup provider type from a FillProvider to a RootProvider - defines the alloy database provider type around this - updates relevant connection functions to use the new RuProvider type - renames Provider to HostProvider - renames WalletlessProvider to RuProvider
1 parent 79977bd commit c8deba9

File tree

6 files changed

+40
-69
lines changed

6 files changed

+40
-69
lines changed

bin/submit_transaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy::{
66
signers::aws::AwsSigner,
77
};
88
use aws_config::BehaviorVersion;
9-
use builder::config::{Provider, load_address, load_string, load_u64, load_url};
9+
use builder::config::{HostProvider, load_address, load_string, load_u64, load_url};
1010
use init4_bin_base::{
1111
deps::metrics::{counter, histogram},
1212
init4,
@@ -30,7 +30,7 @@ async fn main() {
3030
}
3131
}
3232

33-
async fn send_transaction(provider: Provider, recipient_address: Address) {
33+
async fn send_transaction(provider: HostProvider, recipient_address: Address) {
3434
// construct simple transaction to send ETH to a recipient
3535
let tx = TransactionRequest::default()
3636
.with_from(provider.default_signer_address())
@@ -67,7 +67,7 @@ async fn send_transaction(provider: Provider, recipient_address: Address) {
6767
histogram!("txn_submitter.tx_mine_time").record(mine_time as f64);
6868
}
6969

70-
async fn connect_from_config() -> (Provider, Address, u64) {
70+
async fn connect_from_config() -> (HostProvider, Address, u64) {
7171
// load signer config values from .env
7272
let rpc_url = load_url("RPC_URL").unwrap();
7373
let chain_id = load_u64("CHAIN_ID").unwrap();

src/config.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use alloy::{
1111
},
1212
};
1313
use eyre::Result;
14+
use oauth2::url;
1415
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig, SignetSystemConstants};
1516
use signet_zenith::Zenith;
1617
use std::{borrow::Cow, env, num, str::FromStr};
@@ -135,8 +136,8 @@ impl ConfigError {
135136
}
136137
}
137138

138-
/// Type alias for the provider used in the builder.
139-
pub type Provider = FillProvider<
139+
/// Type alias for the provider used to build and submit blocks to the host.
140+
pub type HostProvider = FillProvider<
140141
JoinFill<
141142
JoinFill<
142143
Identity,
@@ -148,18 +149,11 @@ pub type Provider = FillProvider<
148149
Ethereum,
149150
>;
150151

151-
/// Type alias for the provider used in the builder, without a wallet.
152-
pub type WalletlessProvider = FillProvider<
153-
JoinFill<
154-
Identity,
155-
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
156-
>,
157-
RootProvider,
158-
Ethereum,
159-
>;
152+
/// Type alias for the provider used to simulate against rollup state.
153+
pub type RuProvider = RootProvider<Ethereum>;
160154

161155
/// A [`Zenith`] contract instance using [`Provider`] as the provider.
162-
pub type ZenithInstance<P = Provider> = Zenith::ZenithInstance<(), P, alloy::network::Ethereum>;
156+
pub type ZenithInstance<P = HostProvider> = Zenith::ZenithInstance<(), P, alloy::network::Ethereum>;
163157

164158
impl BuilderConfig {
165159
/// Load the builder configuration from environment variables.
@@ -217,17 +211,14 @@ impl BuilderConfig {
217211
}
218212

219213
/// Connect to the Rollup rpc provider.
220-
pub async fn connect_ru_provider(&self) -> Result<WalletlessProvider, ConfigError> {
221-
let provider = ProviderBuilder::new()
222-
.connect(&self.ru_rpc_url)
223-
.await
224-
.map_err(ConfigError::Provider)?;
225-
214+
pub async fn connect_ru_provider(&self) -> Result<RootProvider<Ethereum>, ConfigError> {
215+
let url = url::Url::parse(&self.ru_rpc_url).expect("failed to parse URL");
216+
let provider = RootProvider::<Ethereum>::new_http(url);
226217
Ok(provider)
227218
}
228219

229220
/// Connect to the Host rpc provider.
230-
pub async fn connect_host_provider(&self) -> Result<Provider, ConfigError> {
221+
pub async fn connect_host_provider(&self) -> Result<HostProvider, ConfigError> {
231222
let builder_signer = self.connect_builder_signer().await?;
232223
let provider = ProviderBuilder::new()
233224
.wallet(EthereumWallet::from(builder_signer))
@@ -239,22 +230,20 @@ impl BuilderConfig {
239230
}
240231

241232
/// Connect additional broadcast providers.
242-
pub async fn connect_additional_broadcast(
243-
&self,
244-
) -> Result<Vec<WalletlessProvider>, ConfigError> {
245-
let mut providers: Vec<WalletlessProvider> =
246-
Vec::with_capacity(self.tx_broadcast_urls.len());
247-
for url in self.tx_broadcast_urls.iter() {
248-
let provider =
249-
ProviderBuilder::new().connect(url).await.map_err(ConfigError::Provider)?;
233+
pub async fn connect_additional_broadcast(&self) -> Result<Vec<RootProvider>, ConfigError> {
234+
let mut providers: Vec<RootProvider> = Vec::with_capacity(self.tx_broadcast_urls.len());
250235

236+
for url_str in self.tx_broadcast_urls.iter() {
237+
let url = url::Url::parse(url_str).expect("failed to parse URL");
238+
let provider = RootProvider::new_http(url);
251239
providers.push(provider);
252240
}
241+
253242
Ok(providers)
254243
}
255244

256245
/// Connect to the Zenith instance, using the specified provider.
257-
pub const fn connect_zenith(&self, provider: Provider) -> ZenithInstance {
246+
pub const fn connect_zenith(&self, provider: HostProvider) -> ZenithInstance {
258247
Zenith::new(self.zenith_address, provider)
259248
}
260249

src/tasks/block.rs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::{
2-
config::{BuilderConfig, WalletlessProvider},
2+
config::{BuilderConfig, RuProvider},
33
tasks::bundler::Bundle,
44
};
55
use alloy::{
66
consensus::TxEnvelope,
77
eips::{BlockId, BlockNumberOrTag::Latest},
8+
network::Ethereum,
89
providers::Provider,
910
};
1011
use signet_sim::{BlockBuild, BuiltBlock, SimCache};
@@ -42,11 +43,13 @@ pub struct Simulator {
4243
/// Configuration for the builder.
4344
pub config: BuilderConfig,
4445
/// A provider that cannot sign transactions, used for interacting with the rollup.
45-
pub ru_provider: WalletlessProvider,
46+
pub ru_provider: RuProvider,
4647
/// The slot calculator for determining when to wake up and build blocks.
4748
pub slot_calculator: SlotCalculator,
4849
}
4950

51+
type AlloyDatabaseProvider = WrapDatabaseAsync<AlloyDB<Ethereum, RuProvider>>;
52+
5053
impl Simulator {
5154
/// Creates a new `Simulator` instance.
5255
///
@@ -61,7 +64,7 @@ impl Simulator {
6164
/// A new `Simulator` instance.
6265
pub fn new(
6366
config: &BuilderConfig,
64-
ru_provider: WalletlessProvider,
67+
ru_provider: RuProvider,
6568
slot_calculator: SlotCalculator,
6669
) -> Self {
6770
Self { config: config.clone(), ru_provider, slot_calculator }
@@ -276,18 +279,20 @@ impl Simulator {
276279
/// # Returns
277280
///
278281
/// An `Option` containing the wrapped database or `None` if an error occurs.
279-
async fn create_db(&self) -> Option<WrapAlloyDatabaseAsync> {
282+
async fn create_db(&self) -> Option<AlloyDatabaseProvider> {
280283
let latest = match self.ru_provider.get_block_number().await {
281284
Ok(block_number) => block_number,
282285
Err(e) => {
283286
tracing::error!(error = %e, "failed to get latest block number");
284287
return None;
285288
}
286289
};
287-
let alloy_db = AlloyDB::new(self.ru_provider.clone(), BlockId::from(latest));
288-
let wrapped_db = WrapDatabaseAsync::new(alloy_db).unwrap_or_else(|| {
289-
panic!("failed to acquire async alloy_db; check which runtime you're using")
290-
});
290+
let alloy_db: AlloyDB<Ethereum, RuProvider> =
291+
AlloyDB::new(self.ru_provider.clone(), BlockId::from(latest));
292+
let wrapped_db: WrapDatabaseAsync<AlloyDB<Ethereum, RuProvider>> =
293+
WrapDatabaseAsync::new(alloy_db).unwrap_or_else(|| {
294+
panic!("failed to acquire async alloy_db; check which runtime you're using")
295+
});
291296
Some(wrapped_db)
292297
}
293298
}
@@ -329,29 +334,6 @@ async fn cache_updater(
329334
}
330335
}
331336

332-
/// The wrapped alloy database type that is compatible with `Db` and `DatabaseRef`.
333-
type WrapAlloyDatabaseAsync = WrapDatabaseAsync<
334-
AlloyDB<
335-
alloy::network::Ethereum,
336-
alloy::providers::fillers::FillProvider<
337-
alloy::providers::fillers::JoinFill<
338-
alloy::providers::Identity,
339-
alloy::providers::fillers::JoinFill<
340-
alloy::providers::fillers::GasFiller,
341-
alloy::providers::fillers::JoinFill<
342-
alloy::providers::fillers::BlobGasFiller,
343-
alloy::providers::fillers::JoinFill<
344-
alloy::providers::fillers::NonceFiller,
345-
alloy::providers::fillers::ChainIdFiller,
346-
>,
347-
>,
348-
>,
349-
>,
350-
alloy::providers::RootProvider,
351-
>,
352-
>,
353-
>;
354-
355337
/// Configuration struct for Pecorino network values.
356338
#[derive(Debug, Clone)]
357339
pub struct PecorinoCfg {}

src/tasks/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::Provider;
1+
use crate::config::HostProvider;
22
use alloy::{primitives::TxHash, providers::Provider as _};
33
use init4_bin_base::deps::metrics::{counter, histogram};
44
use std::time::Instant;
@@ -9,7 +9,7 @@ use tracing::{debug, error};
99
#[derive(Debug, Clone)]
1010
pub struct MetricsTask {
1111
/// Ethereum Provider
12-
pub host_provider: Provider,
12+
pub host_provider: HostProvider,
1313
}
1414

1515
impl MetricsTask {

src/tasks/submit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
config::{Provider, ZenithInstance},
2+
config::{HostProvider, ZenithInstance},
33
signer::LocalOrAws,
44
utils::extract_signature_components,
55
};
@@ -58,7 +58,7 @@ pub enum ControlFlow {
5858
#[derive(Debug, Clone)]
5959
pub struct SubmitTask {
6060
/// Ethereum Provider
61-
pub host_provider: Provider,
61+
pub host_provider: HostProvider,
6262
/// Zenith
6363
pub zenith: ZenithInstance,
6464
/// Reqwest

tests/block_builder_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[cfg(test)]
33
mod tests {
44
use alloy::{
5-
node_bindings::Anvil, primitives::U256, providers::ProviderBuilder,
5+
network::Ethereum, node_bindings::Anvil, primitives::U256, providers::RootProvider,
66
signers::local::PrivateKeySigner,
77
};
88
use builder::{
@@ -41,7 +41,7 @@ mod tests {
4141
let test_key_1 = PrivateKeySigner::from_signing_key(keys[1].clone().into());
4242

4343
// Create a rollup provider
44-
let ru_provider = ProviderBuilder::new().on_http(anvil_instance.endpoint_url());
44+
let ru_provider = RootProvider::<Ethereum>::new_http(anvil_instance.endpoint_url());
4545

4646
// Create a block builder with a slot calculator for testing
4747
let now = SystemTime::now()
@@ -100,7 +100,7 @@ mod tests {
100100
let (block_sender, mut block_receiver) = unbounded_channel();
101101

102102
// Create a rollup provider
103-
let ru_provider = ProviderBuilder::new().on_http(anvil_instance.endpoint_url());
103+
let ru_provider = RootProvider::<Ethereum>::new_http(anvil_instance.endpoint_url());
104104

105105
// Create a builder with a test slot calculator
106106
let slot_calculator = SlotCalculator::new(

0 commit comments

Comments
 (0)