Skip to content

refactor: use Url in the config #136

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

Merged
merged 2 commits into from
Aug 6, 2025
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
31 changes: 11 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,27 @@ pub struct BuilderConfig {
/// URL for Host RPC node.
#[from_env(
var = "HOST_RPC_URL",
desc = "URL for Host RPC node. This MUST be a valid HTTP or WS URL, starting with http://, https://, ws:// or wss://",
infallible
desc = "URL for Host RPC node. This MUST be a valid HTTP or WS URL, starting with http://, https://, ws:// or wss://"
)]
pub host_rpc_url: Cow<'static, str>,
pub host_rpc_url: url::Url,

/// URL for the Rollup RPC node.
#[from_env(
var = "ROLLUP_RPC_URL",
desc = "URL for Rollup RPC node. This MUST be a valid WS url starting with ws:// or wss://. Http providers are not supported.",
infallible
desc = "URL for Rollup RPC node. This MUST be a valid WS url starting with ws:// or wss://. Http providers are not supported."
)]
pub ru_rpc_url: Cow<'static, str>,
pub ru_rpc_url: url::Url,

/// URL of the tx pool to poll for incoming transactions.
#[from_env(
var = "TX_POOL_URL",
desc = "URL of the tx pool to poll for incoming transactions",
infallible
)]
pub tx_pool_url: Cow<'static, str>,
#[from_env(var = "TX_POOL_URL", desc = "URL of the tx pool to poll for incoming transactions")]
pub tx_pool_url: url::Url,

/// Additional RPC URLs to which the builder should broadcast transactions.
/// * Should not include the `HOST_RPC_URL` value, as that is already sent to by default.
/// * Setting this can incur `already known` errors.
#[from_env(
var = "TX_BROADCAST_URLS",
desc = "Additional RPC URLs to which the builder broadcasts transactions",
infallible,
optional
)]
pub tx_broadcast_urls: Vec<Cow<'static, str>>,
Expand Down Expand Up @@ -190,15 +183,13 @@ impl BuilderConfig {
tokio::sync::OnceCell::const_new();

ONCE.get_or_try_init(|| async {
let url = url::Url::parse(&self.ru_rpc_url)?;

let scheme = url.scheme();
let scheme = self.ru_rpc_url.scheme();
eyre::ensure!(
scheme == "ws" || scheme == "wss",
"Invalid Rollup RPC URL scheme: {scheme}. Expected ws:// or wss://"
);

RootProvider::connect_with(BuiltInConnectionString::Ws(url, None))
RootProvider::connect_with(BuiltInConnectionString::Ws(self.ru_rpc_url.clone(), None))
.await
.map_err(Into::into)
})
Expand All @@ -216,7 +207,7 @@ impl BuilderConfig {
.with_nonce_management(SimpleNonceManager::default())
.fetch_chain_id()
.wallet(EthereumWallet::from(builder_signer))
.connect(&self.host_rpc_url)
.connect(self.host_rpc_url.as_str())
.await
.map_err(Into::into)
}
Expand All @@ -225,8 +216,8 @@ impl BuilderConfig {
pub fn connect_additional_broadcast(&self) -> Vec<RootProvider> {
self.tx_broadcast_urls
.iter()
.map(|url_str| {
let url = url::Url::parse(url_str).expect("failed to parse URL");
.map(|url| {
let url = url.parse::<url::Url>().expect("Invalid URL in tx_broadcast_urls");
RootProvider::new_http(url)
})
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/cache/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl BundlePoller {

/// Fetches bundles from the transaction cache and returns them.
pub async fn check_bundle_cache(&mut self) -> eyre::Result<Vec<TxCacheBundle>> {
let bundle_url: Url = Url::parse(&self.config.tx_pool_url)?.join("bundles")?;
let bundle_url: Url = self.config.tx_pool_url.join("bundles")?;
let token =
self.token.secret().await.map_err(|e| eyre::eyre!("Failed to read token: {e}"))?;

Expand Down
2 changes: 1 addition & 1 deletion src/tasks/cache/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TxPoller {

/// Polls the transaction cache for transactions.
pub async fn check_tx_cache(&mut self) -> Result<Vec<TxEnvelope>, Error> {
let url: Url = Url::parse(&self.config.tx_pool_url)?.join("transactions")?;
let url: Url = self.config.tx_pool_url.join("transactions")?;
self.client
.get(url)
.send()
Expand Down
17 changes: 8 additions & 9 deletions src/tasks/submit/prep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use signet_constants::SignetSystemConstants;
use signet_sim::BuiltBlock;
use signet_types::{SignRequest, SignResponse};
use signet_zenith::BundleHelper;
use std::sync::OnceLock;
use tracing::Instrument;

/// Preparation logic for transactions issued to the host chain by the
Expand All @@ -35,8 +34,8 @@ pub struct SubmitPrep<'a> {
constants: SignetSystemConstants,

// Memoized quincey request and response
sig_request: OnceLock<SignRequest>,
quincey_resp: OnceLock<SignResponse>,
sig_request: std::sync::OnceLock<SignRequest>,
quincey_resp: tokio::sync::OnceCell<SignResponse>,
}

impl<'a> SubmitPrep<'a> {
Expand Down Expand Up @@ -78,12 +77,12 @@ impl<'a> SubmitPrep<'a> {

/// Get the quincey signature response for the block.
async fn quincey_resp(&self) -> eyre::Result<&SignResponse> {
if let Some(resp) = self.quincey_resp.get() {
return Ok(resp);
}

let sig = self.quincey.get_signature(self.sig_request()).await?;
Ok(self.quincey_resp.get_or_init(|| sig))
self.quincey_resp
.get_or_try_init(|| async {
let sig_request = self.sig_request();
self.quincey.get_signature(sig_request).await
})
.await
}

/// Get the signature components from the response.
Expand Down
6 changes: 3 additions & 3 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn setup_test_config() -> Result<BuilderConfig> {
let config = BuilderConfig {
host_chain_id: signet_constants::pecorino::HOST_CHAIN_ID,
ru_chain_id: signet_constants::pecorino::RU_CHAIN_ID,
host_rpc_url: "https://host-rpc.pecorino.signet.sh".into(),
ru_rpc_url: "https://rpc.pecorino.signet.sh".into(),
host_rpc_url: "https://host-rpc.pecorino.signet.sh".parse().unwrap(),
ru_rpc_url: "https://rpc.pecorino.signet.sh".parse().unwrap(),
tx_broadcast_urls: vec!["http://localhost:9000".into()],
zenith_address: Address::default(),
quincey_url: "http://localhost:8080".into(),
Expand All @@ -31,7 +31,7 @@ pub fn setup_test_config() -> Result<BuilderConfig> {
builder_key: "0000000000000000000000000000000000000000000000000000000000000000".into(),
builder_rewards_address: Address::default(),
rollup_block_gas_limit: 3_000_000_000,
tx_pool_url: "http://localhost:9000/".into(),
tx_pool_url: "http://localhost:9000/".parse().unwrap(),
oauth: OAuthConfig {
oauth_client_id: "some_client_id".into(),
oauth_client_secret: "some_client_secret".into(),
Expand Down
Loading