From e9b2283789eb0d5b5a93fef2d93f66086ba1561d Mon Sep 17 00:00:00 2001 From: ImJeremyHe Date: Wed, 5 Jun 2024 17:40:26 +0800 Subject: [PATCH] Remove the commitment task in dev node --- sequencer/src/bin/espresso-dev-node.rs | 106 ++++--------------------- 1 file changed, 16 insertions(+), 90 deletions(-) diff --git a/sequencer/src/bin/espresso-dev-node.rs b/sequencer/src/bin/espresso-dev-node.rs index f6c98e1d24..e09bafc367 100644 --- a/sequencer/src/bin/espresso-dev-node.rs +++ b/sequencer/src/bin/espresso-dev-node.rs @@ -1,25 +1,15 @@ -use std::{io, time::Duration}; +use std::time::Duration; use async_compatibility_layer::logging::{setup_backtrace, setup_logging}; -use async_std::task::spawn; +use async_std::task::sleep; use clap::Parser; -use es_version::SEQUENCER_VERSION; -use ethers::types::Address; use futures::FutureExt; -use sequencer::{ - api::options, - api::test_helpers::TestNetwork, - hotshot_commitment::{run_hotshot_commitment_task, CommitmentTaskOptions}, - persistence, - testing::TestConfig, -}; +use sequencer::{api::options, api::test_helpers::TestNetwork, persistence, testing::TestConfig}; use sequencer_utils::{ - deployer::{deploy, Contract, Contracts}, + deployer::{deploy, Contracts}, AnvilOptions, }; -use tide_disco::{error::ServerError, Api}; use url::Url; -use vbs::version::StaticVersionType; #[derive(Clone, Debug, Parser)] struct Args { @@ -49,11 +39,6 @@ struct Args { /// Port that the HTTP API will use. #[clap(long, env = "ESPRESSO_SEQUENCER_API_PORT")] sequencer_api_port: u16, - /// If provided, the service will run a basic HTTP server on the given port. - /// - /// The server provides healthcheck and version endpoints. - #[clap(short, long, env = "ESPRESSO_COMMITMENT_TASK_PORT")] - commitment_task_port: u16, /// Port for connecting to the builder. #[clap(short, long, env = "ESPRESSO_BUILDER_PORT")] @@ -104,7 +89,7 @@ async fn main() -> anyhow::Result<()> { let light_client_genesis = network.light_client_genesis(); - let contracts = deploy( + let _contracts = deploy( url.clone(), cli_params.mnemonic.clone(), cli_params.account_index, @@ -115,62 +100,9 @@ async fn main() -> anyhow::Result<()> { ) .await?; - let hotshot_address = contracts - .get_contract_address(Contract::HotShot) - .expect("Cannot get the hotshot contract address"); - tracing::info!("hotshot address: {}", hotshot_address); - - tracing::info!("starting the commitment server"); - start_commitment_server( - cli_params.commitment_task_port, - hotshot_address, - SEQUENCER_VERSION, - ) - .unwrap(); - - let sequencer_url = - Url::parse(format!("http://localhost:{}", cli_params.sequencer_api_port).as_str()).unwrap(); - let commitment_task_options = CommitmentTaskOptions { - l1_provider: url, - l1_chain_id: None, - hotshot_address, - sequencer_mnemonic: cli_params.mnemonic, - sequencer_account_index: cli_params.account_index, - query_service_url: Some(sequencer_url), - request_timeout: Duration::from_secs(5), - delay: None, - }; - - tracing::info!("starting hotshot commitment task"); - run_hotshot_commitment_task::(&commitment_task_options).await; - - Ok(()) -} - -// Copied from `commitment_task::start_http_server`. -// TODO: Remove these redundant code -fn start_commitment_server( - port: u16, - hotshot_address: Address, - bind_version: Ver, -) -> io::Result<()> { - let mut app = tide_disco::App::<(), ServerError>::with_state(()); - let toml = toml::from_str::(include_str!("../../api/commitment_task.toml")) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - - let mut api = Api::<(), ServerError, Ver>::new(toml) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - - api.get("gethotshotcontract", move |_, _| { - async move { Ok(hotshot_address) }.boxed() - }) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - - app.register_module("api", api) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - - spawn(app.serve(format!("localhost:{port}"), bind_version)); - Ok(()) + loop { + sleep(Duration::from_secs(3600)).await + } } #[cfg(test)] @@ -214,7 +146,7 @@ mod tests { setup_logging(); setup_backtrace(); - let commitment_task_port = pick_unused_port().unwrap(); + let builder_port = pick_unused_port().unwrap(); let api_port = pick_unused_port().unwrap(); @@ -228,10 +160,7 @@ mod tests { .run() .unwrap() .command() - .env( - "ESPRESSO_COMMITMENT_TASK_PORT", - commitment_task_port.to_string(), - ) + .env("ESPRESSO_BUILDER_PORT", builder_port.to_string()) .env("ESPRESSO_SEQUENCER_API_PORT", api_port.to_string()) .env("ESPRESSO_SEQUENCER_POSTGRES_HOST", "localhost") .env( @@ -260,20 +189,17 @@ mod tests { .await .unwrap(); - let commitment_api_client: Client = Client::new( - format!("http://localhost:{commitment_task_port}/api") - .parse() - .unwrap(), - ); - commitment_api_client.connect(None).await; + let builder_api_client: Client = + Client::new(format!("http://localhost:{builder_port}").parse().unwrap()); + builder_api_client.connect(None).await; - let hotshot_contract = commitment_api_client - .get::("hotshot_contract") + let builder_address = builder_api_client + .get::("block_info/builderaddress") .send() .await .unwrap(); - assert!(!hotshot_contract.is_empty()); + assert!(!builder_address.is_empty()); let tx = Transaction::new(100.into(), vec![1, 2, 3]);