Skip to content

Commit

Permalink
Add configurable HTTP request timeout to commit task
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed Mar 18, 2024
1 parent 83cceb5 commit cce7407
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
11 changes: 10 additions & 1 deletion sequencer/src/bin/commitment-task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use clap::Parser;
use contract_bindings::hot_shot::HotShot;
use ethers::{prelude::*, providers::Provider, signers::coins_bip39::English};
use futures::FutureExt;
use sequencer::hotshot_commitment::{run_hotshot_commitment_task, CommitmentTaskOptions};
use sequencer::{
hotshot_commitment::{run_hotshot_commitment_task, CommitmentTaskOptions},
options::parse_duration,
};
use std::io;
use std::sync::Arc;
use std::time::Duration;
use tide_disco::error::ServerError;
use tide_disco::Api;
use url::Url;
Expand Down Expand Up @@ -65,6 +69,10 @@ pub struct Options {
/// The server provides healthcheck and version endpoints.
#[clap(short, long, env = "ESPRESSO_COMMITMENT_TASK_PORT")]
pub port: Option<u16>,

/// Client-side timeout for HTTP requests.
#[clap(long, env = "ESPRESSO_COMMITMENT_TASK_REQUEST_TIMEOUT", value_parser = parse_duration, default_value = "5s")]
pub request_timeout: Duration,
}
#[async_std::main]
async fn main() {
Expand Down Expand Up @@ -122,6 +130,7 @@ async fn main() {
l1_provider: opt.l1_provider.clone(),
sequencer_mnemonic: opt.eth_mnemonic,
sequencer_account_index: opt.hotshot_account_index,
request_timeout: opt.request_timeout,
query_service_url: Some(opt.sequencer_url),
};
tracing::info!("Launching HotShot commitment task..");
Expand Down
19 changes: 6 additions & 13 deletions sequencer/src/hotshot_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::anyhow;
use async_std::{sync::Arc, task::sleep};
use async_trait::async_trait;
use clap::Parser;
use contract_bindings::hot_shot::{HotShot, Qc};
use ethers::prelude::*;
use futures::{
Expand All @@ -20,45 +19,37 @@ const RETRY_DELAY: Duration = Duration::from_secs(1);

type HotShotClient = surf_disco::Client<hotshot_query_service::Error>;

#[derive(Parser, Clone, Debug)]
pub struct CommitmentTaskOptions {
/// URL of layer 1 Ethereum JSON-RPC provider.
#[clap(long, env = "ESPRESSO_SEQUENCER_L1_PROVIDER")]
pub l1_provider: Url,

/// Chain ID for layer 1 Ethereum.
///
/// This can be specified explicitly as a sanity check. No transactions will be executed if the
/// RPC specified by `l1_provider` has a different chain ID. If not specified, the chain ID from
/// the RPC will be used.
#[clap(long, env = "ESPRESSO_SEQUENCER_L1_CHAIN_ID")]
pub l1_chain_id: Option<u64>,

/// Address of HotShot contract on layer 1.
#[clap(long, env = "ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS", default_value = None)]
pub hotshot_address: Address,

/// Mnemonic phrase for a funded wallet.
///
/// This is the wallet that will be used to send blocks sequenced by HotShot to the sequencer
/// contract. It must be funded with ETH on layer 1.
#[clap(long, env = "ESPRESSO_SEQUENCER_ETH_MNEMONIC", default_value = None)]
pub sequencer_mnemonic: String,

/// Index of a funded account derived from sequencer-mnemonic.
#[clap(
long,
env = "ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX",
default_value = "0"
)]
pub sequencer_account_index: u32,

/// URL of HotShot Query Service
///
/// Even though this is an Option type it *must* currently be set when
/// passing the options to `run_hotshot_commitment_task`.
#[clap(long, env = "ESPRESSO_SEQUENCER_QUERY_SERVICE_URL")]
pub query_service_url: Option<Url>,

/// Client-side timeout for HTTP requests.
pub request_timeout: Duration,
}

pub async fn run_hotshot_commitment_task(opt: &CommitmentTaskOptions) {
Expand All @@ -67,7 +58,9 @@ pub async fn run_hotshot_commitment_task(opt: &CommitmentTaskOptions) {
.clone()
.expect("query service URL must be specified");

let hotshot = HotShotClient::new(query_service_url);
let hotshot = HotShotClient::builder(query_service_url)
.set_timeout(Some(opt.request_timeout))
.build();
hotshot.connect(None).await;

// Connect to the layer one HotShot contract.
Expand Down

0 comments on commit cce7407

Please sign in to comment.