Skip to content

Commit 8136497

Browse files
committed
fix: simplify provider connection
1 parent 8b264b9 commit 8136497

File tree

3 files changed

+26
-65
lines changed

3 files changed

+26
-65
lines changed

bin/builder.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ async fn main() -> eyre::Result<()> {
2323
let constants = config.load_pecorino_constants();
2424
let authenticator = Authenticator::new(&config)?;
2525

26-
let (host_provider, ru_provider, sequencer_signer) = tokio::try_join!(
27-
config.connect_host_provider(),
28-
config.connect_ru_provider(),
29-
config.connect_sequencer_signer(),
30-
)?;
26+
let (host_provider, sequencer_signer) =
27+
tokio::try_join!(config.connect_host_provider(), config.connect_sequencer_signer(),)?;
28+
let ru_provider = config.connect_ru_provider();
3129

3230
let zenith = config.connect_zenith(host_provider.clone());
3331

src/config.rs

+22-59
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv};
1818
use oauth2::url;
1919
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig, SignetSystemConstants};
2020
use signet_zenith::Zenith;
21-
use std::{borrow::Cow, num};
21+
use std::borrow::Cow;
2222

2323
/// Configuration for a builder running a specific rollup on a specific host
2424
/// chain.
@@ -142,39 +142,6 @@ pub struct BuilderConfig {
142142
pub slot_calculator: SlotCalculator,
143143
}
144144

145-
/// Error loading the configuration.
146-
#[derive(Debug, thiserror::Error)]
147-
pub enum ConfigError {
148-
/// Error loading from environment variable
149-
#[error("missing or non-unicode environment variable: {0}")]
150-
Var(String),
151-
/// Error parsing environment variable
152-
#[error("failed to parse environment variable: {0}")]
153-
Parse(#[from] num::ParseIntError),
154-
/// Error parsing boolean environment variable
155-
#[error("failed to parse boolean environment variable")]
156-
ParseBool,
157-
/// Error parsing hex from environment variable
158-
#[error("failed to parse hex: {0}")]
159-
Hex(#[from] hex::FromHexError),
160-
/// Error connecting to the provider
161-
#[error("failed to connect to provider: {0}")]
162-
Provider(#[from] alloy::transports::TransportError),
163-
/// Error connecting to the signer
164-
#[error("failed to connect to signer: {0}")]
165-
Signer(#[from] SignerError),
166-
/// I/O error
167-
#[error("I/O error: {0}")]
168-
Io(#[from] std::io::Error),
169-
}
170-
171-
impl ConfigError {
172-
/// Missing or non-unicode env var.
173-
pub fn missing(s: &str) -> Self {
174-
ConfigError::Var(s.to_string())
175-
}
176-
}
177-
178145
/// Type alias for the provider used to build and submit blocks to the host.
179146
pub type HostProvider = FillProvider<
180147
JoinFill<
@@ -196,51 +163,47 @@ pub type ZenithInstance<P = HostProvider> = Zenith::ZenithInstance<(), P, alloy:
196163

197164
impl BuilderConfig {
198165
/// Connect to the Builder signer.
199-
pub async fn connect_builder_signer(&self) -> Result<LocalOrAws, ConfigError> {
200-
LocalOrAws::load(&self.builder_key, Some(self.host_chain_id)).await.map_err(Into::into)
166+
pub async fn connect_builder_signer(&self) -> Result<LocalOrAws, SignerError> {
167+
LocalOrAws::load(&self.builder_key, Some(self.host_chain_id)).await
201168
}
202169

203170
/// Connect to the Sequencer signer.
204-
pub async fn connect_sequencer_signer(&self) -> Result<Option<LocalOrAws>, ConfigError> {
205-
match &self.sequencer_key {
206-
Some(sequencer_key) => LocalOrAws::load(sequencer_key, Some(self.host_chain_id))
171+
pub async fn connect_sequencer_signer(&self) -> eyre::Result<Option<LocalOrAws>> {
172+
if let Some(sequencer_key) = &self.sequencer_key {
173+
LocalOrAws::load(sequencer_key, Some(self.host_chain_id))
207174
.await
208175
.map_err(Into::into)
209-
.map(Some),
210-
None => Ok(None),
176+
.map(Some)
177+
} else {
178+
Ok(None)
211179
}
212180
}
213181

214182
/// Connect to the Rollup rpc provider.
215-
pub async fn connect_ru_provider(&self) -> Result<RootProvider<Ethereum>, ConfigError> {
183+
pub fn connect_ru_provider(&self) -> RootProvider<Ethereum> {
216184
let url = url::Url::parse(&self.ru_rpc_url).expect("failed to parse URL");
217-
let provider = RootProvider::<Ethereum>::new_http(url);
218-
Ok(provider)
185+
RootProvider::<Ethereum>::new_http(url)
219186
}
220187

221188
/// Connect to the Host rpc provider.
222-
pub async fn connect_host_provider(&self) -> Result<HostProvider, ConfigError> {
189+
pub async fn connect_host_provider(&self) -> eyre::Result<HostProvider> {
223190
let builder_signer = self.connect_builder_signer().await?;
224-
let provider = ProviderBuilder::new()
191+
ProviderBuilder::new()
225192
.wallet(EthereumWallet::from(builder_signer))
226193
.connect(&self.host_rpc_url)
227194
.await
228-
.map_err(ConfigError::Provider)?;
229-
230-
Ok(provider)
195+
.map_err(Into::into)
231196
}
232197

233198
/// Connect additional broadcast providers.
234-
pub async fn connect_additional_broadcast(&self) -> Result<Vec<RootProvider>, ConfigError> {
235-
let mut providers: Vec<RootProvider> = Vec::with_capacity(self.tx_broadcast_urls.len());
236-
237-
for url_str in self.tx_broadcast_urls.iter() {
238-
let url = url::Url::parse(url_str).expect("failed to parse URL");
239-
let provider = RootProvider::new_http(url);
240-
providers.push(provider);
241-
}
242-
243-
Ok(providers)
199+
pub fn connect_additional_broadcast(&self) -> Vec<RootProvider> {
200+
self.tx_broadcast_urls
201+
.iter()
202+
.map(|url_str| {
203+
let url = url::Url::parse(url_str).expect("failed to parse URL");
204+
RootProvider::new_http(url)
205+
})
206+
.collect::<Vec<_>>()
244207
}
245208

246209
/// Connect to the Zenith instance, using the specified provider.

src/tasks/submit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl SubmitTask {
206206
let fut = spawn_provider_send!(&self.host_provider, &tx);
207207

208208
// Spawn send_tx futures for all additional broadcast host_providers
209-
for host_provider in self.config.connect_additional_broadcast().await? {
209+
for host_provider in self.config.connect_additional_broadcast() {
210210
spawn_provider_send!(&host_provider, &tx);
211211
}
212212

0 commit comments

Comments
 (0)