From ce5a4be316bfb7a92dc4c4636fa452bd4d1ff5a6 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Krieger Date: Fri, 18 Aug 2023 17:40:47 -0300 Subject: [PATCH] refactor(input-reader): update state-fold use --- CHANGELOG.md | 5 + docker-bake.hcl | 10 +- docker-bake.override.hcl | 4 - offchain/Cargo.lock | 79 +---------- offchain/Cargo.toml | 1 - offchain/Dockerfile | 10 -- offchain/eth-input-reader/Cargo.toml | 7 +- offchain/eth-input-reader/src/config.rs | 62 ++++----- offchain/eth-input-reader/src/error.rs | 13 +- .../eth-input-reader/src/eth_input_reader.rs | 67 +++++---- .../eth-input-reader/src/machine/driver.rs | 3 +- offchain/eth-input-reader/src/setup.rs | 130 +++++++++++------- offchain/state-server/Cargo.toml | 24 ---- offchain/state-server/README.md | 5 - offchain/state-server/src/error.rs | 28 ---- offchain/state-server/src/lib.rs | 119 ---------------- offchain/state-server/src/main.rs | 22 --- 17 files changed, 177 insertions(+), 412 deletions(-) delete mode 100644 offchain/state-server/Cargo.toml delete mode 100644 offchain/state-server/README.md delete mode 100644 offchain/state-server/src/error.rs delete mode 100644 offchain/state-server/src/lib.rs delete mode 100644 offchain/state-server/src/main.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 300bbad4e..d88fb58cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,14 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added authority claimer service to support reader mode +- Added `CHAIN_ID` environment variable to `eth-input-reader` ### Changed - Renamed `dispatcher` service to `eth-input-reader` +- Replaced the state-server with the state-fold library in the `eth-input-reader` +- Moved `SF_*` and `BH_*` environment variables from `state-server` config to the `eth-input-reader` ### Removed +- Removed the state-server from the node - Removed claiming functionality from `eth-input-reader` +- Removed `SS_MAX_DECODING_MESSAGE_SIZE` environment variable from eth-input-reader because it doesn't use gRPC anymore ## [1.0.0] 2023-08-22 diff --git a/docker-bake.hcl b/docker-bake.hcl index 9180678d4..f3a397a8b 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -11,8 +11,7 @@ group "default" { "hardhat", "host-runner", "inspect-server", - "indexer", - "state-server" + "indexer" ] } @@ -23,13 +22,6 @@ target "deps" { context = "." } -target "state-server" { - inherits = ["docker-metadata-action", "docker-platforms"] - dockerfile = "offchain/Dockerfile" - target = "state_server" - context = "." -} - target "eth-input-reader" { inherits = ["docker-metadata-action", "docker-platforms"] dockerfile = "offchain/Dockerfile" diff --git a/docker-bake.override.hcl b/docker-bake.override.hcl index 3f3aee7b6..035d3ae7d 100644 --- a/docker-bake.override.hcl +++ b/docker-bake.override.hcl @@ -7,10 +7,6 @@ variable "DOCKER_ORGANIZATION" { default = "cartesi" } -target "state-server" { - tags = ["${DOCKER_ORGANIZATION}/rollups-state-server:${TAG}"] -} - target "eth-input-reader" { tags = ["${DOCKER_ORGANIZATION}/rollups-eth-input-reader:${TAG}"] } diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index 514223b10..207a30f90 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -1642,9 +1642,10 @@ dependencies = [ "backoff", "clap", "contracts", - "eth-state-client-lib", + "eth-block-history", + "eth-state-fold", "eth-state-fold-types", - "eth-tx-manager", + "ethers", "ethers-signers", "futures", "http-server", @@ -1694,24 +1695,6 @@ dependencies = [ "uuid 0.8.2", ] -[[package]] -name = "eth-state-client-lib" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b7d6b6315771fab8783b4aefdd034e887c2e688ac0357dc1007b97b49e4296" -dependencies = [ - "async-trait", - "clap", - "eth-state-fold-types", - "eth-state-server-common", - "serde", - "serde_json", - "snafu", - "tokio", - "tokio-stream", - "tonic", -] - [[package]] name = "eth-state-fold" version = "0.7.1" @@ -1745,44 +1728,6 @@ dependencies = [ "toml 0.5.11", ] -[[package]] -name = "eth-state-server-common" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4953e04ab2e41d45722a21e92d066f03111a8ab81ec765ae6b4873ee77040c43" -dependencies = [ - "anyhow", - "eth-state-fold-types", - "prost", - "serde", - "serde_json", - "snafu", - "tonic", - "tonic-build", -] - -[[package]] -name = "eth-state-server-lib" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819fa6c22d25963976ebf2ae1db3c1c5489bb951b847ee21d85481097ead2190" -dependencies = [ - "clap", - "eth-block-history", - "eth-state-fold", - "eth-state-fold-types", - "eth-state-server-common", - "futures", - "serde", - "serde_json", - "snafu", - "tokio", - "tokio-stream", - "tonic", - "tonic-health", - "tracing", -] - [[package]] name = "eth-tx-manager" version = "0.10.1" @@ -4879,24 +4824,6 @@ dependencies = [ "der", ] -[[package]] -name = "state-server" -version = "1.1.0" -dependencies = [ - "eth-block-history", - "eth-state-fold", - "eth-state-fold-types", - "eth-state-server-lib", - "serde", - "snafu", - "tokio", - "tonic", - "tracing", - "tracing-subscriber", - "types", - "url", -] - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index 0dd4ed3af..119373077 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -15,7 +15,6 @@ members = [ "redacted", "rollups-events", "rollups-http-client", - "state-server", "test-fixtures", "types", ] diff --git a/offchain/Dockerfile b/offchain/Dockerfile index 0cf704976..57693b040 100644 --- a/offchain/Dockerfile +++ b/offchain/Dockerfile @@ -43,16 +43,6 @@ WORKDIR /var/opt/cartesi ENV PATH="/opt/cartesi/bin:${PATH}" ## runtimes -FROM runtime AS state_server -RUN <, + + /// Depth on the blockchain the reader will be listening to + #[arg(long, env, default_value = "7")] + pub subscription_depth: usize, } #[derive(Clone, Debug)] pub struct EthInputReaderConfig { - pub sc_config: SCConfig, - pub tx_config: TxManagerConfig, pub broker_config: BrokerConfig, + pub sf_config: SFConfig, + pub bh_config: BHConfig, pub dapp_deployment: DappDeployment, pub rollups_deployment: RollupsDeployment, pub epoch_duration: u64, - pub priority: Priority, + pub chain_id: u64, + pub subscription_depth: usize, } #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("StateClient configuration error: {}", source))] - StateClientError { source: SCError }, - - #[snafu(display("TxManager configuration error: {}", source))] - TxManagerError { source: TxError }, - #[snafu(display("Json read file error ({})", path.display()))] JsonReadFileError { path: PathBuf, @@ -82,6 +80,9 @@ pub enum Error { #[snafu(display("Rollups json parse error"))] RollupsJsonParseError { source: serde_json::Error }, + + #[snafu(display("Configuration missing chain_id"))] + MissingChainId, } #[derive(Debug)] @@ -97,12 +98,9 @@ impl Config { "eth_input_reader", ); - let sc_config = SCConfig::initialize(eth_input_reader_config.sc_config) - .context(StateClientSnafu)?; + let sf_config = SFConfig::initialize(eth_input_reader_config.sf_config); - let tx_config = - TxManagerConfig::initialize(eth_input_reader_config.tx_config) - .context(TxManagerSnafu)?; + let bh_config = BHConfig::initialize(eth_input_reader_config.bh_config); let path = eth_input_reader_config.rd_dapp_deployment_file; let dapp_deployment: DappDeployment = read_json(path)?; @@ -114,19 +112,19 @@ impl Config { let broker_config = BrokerConfig::from(eth_input_reader_config.broker_config); - assert!( - sc_config.default_confirmations < tx_config.default_confirmations, - "`state-client confirmations` has to be less than `tx-manager confirmations,`" - ); + let chain_id = eth_input_reader_config + .chain_id + .ok_or(Error::MissingChainId)?; let eth_input_reader_config = EthInputReaderConfig { - sc_config, - tx_config, broker_config, + sf_config, + bh_config, dapp_deployment, rollups_deployment, epoch_duration: eth_input_reader_config.rd_epoch_duration, - priority: Priority::Normal, + chain_id, + subscription_depth: eth_input_reader_config.subscription_depth, }; Ok(Config { diff --git a/offchain/eth-input-reader/src/error.rs b/offchain/eth-input-reader/src/error.rs index ffc9a0848..5026314fb 100644 --- a/offchain/eth-input-reader/src/error.rs +++ b/offchain/eth-input-reader/src/error.rs @@ -2,10 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 (see LICENSE) use axum::http::uri::InvalidUri; -use eth_state_client_lib::error::StateServerError; +use ethers::providers::{Http, Provider, RetryClient}; use snafu::Snafu; use std::net::AddrParseError; use tonic::transport::Error as TonicError; +use url::ParseError; use crate::machine; @@ -29,8 +30,14 @@ pub enum EthInputReaderError { #[snafu(display("connection error"))] ConnectError { source: TonicError }, - #[snafu(display("state server error"))] - StateServerError { source: StateServerError }, + #[snafu(display("parser error"))] + ParseError { source: ParseError }, + + #[snafu(display("parser error"))] + BlockArchiveError { + source: + eth_block_history::BlockArchiveError>>, + }, #[snafu(whatever, display("{message}"))] Whatever { diff --git a/offchain/eth-input-reader/src/eth_input_reader.rs b/offchain/eth-input-reader/src/eth_input_reader.rs index 2d1a03628..b9376b461 100644 --- a/offchain/eth-input-reader/src/eth_input_reader.rs +++ b/offchain/eth-input-reader/src/eth_input_reader.rs @@ -1,22 +1,27 @@ // (c) Cartesi and individual authors (see AUTHORS) // SPDX-License-Identifier: Apache-2.0 (see LICENSE) -use eth_state_client_lib::StateServer; +use eth_state_fold::{Foldable, StateFoldEnvironment}; use eth_state_fold_types::{Block, BlockStreamItem}; use rollups_events::{Address, DAppMetadata}; +use std::sync::{Arc, Mutex}; use tokio_stream::StreamExt; use tracing::{error, info, instrument, trace, warn}; use types::foldables::authority::rollups::{RollupsInitialState, RollupsState}; +use types::UserData; use crate::{ config::EthInputReaderConfig, - error::{BrokerSnafu, EthInputReaderError, StateServerSnafu}, + error::{BrokerSnafu, EthInputReaderError}, machine::{ driver::MachineDriver, rollups_broker::BrokerFacade, BrokerReceive, BrokerSend, Context, }, metrics::EthInputReaderMetrics, - setup::{create_block_subscription, create_context, create_state_server}, + setup::{ + create_block_subscriber, create_context, create_env, create_provider, + create_subscription, InputProvider, + }, }; use snafu::{whatever, ResultExt}; @@ -29,17 +34,21 @@ pub async fn start( info!("Setting up eth-input-reader with config: {:?}", config); let dapp_metadata = DAppMetadata { - chain_id: config.tx_config.chain_id, + chain_id: config.chain_id, dapp_address: Address::new(config.dapp_deployment.dapp_address.into()), }; - trace!("Creating state-server connection"); - let state_server = create_state_server(&config.sc_config).await?; + trace!("Creating provider"); + let provider = create_provider(&config).await?; + + trace!("Creating block-subscriber"); + let block_subscriber = + create_block_subscriber(&config, Arc::clone(&provider)).await?; trace!("Starting block subscription with confirmations"); - let mut block_subscription = create_block_subscription( - &state_server, - config.sc_config.default_confirmations, + let mut block_subscription = create_subscription( + Arc::clone(&block_subscriber), + config.subscription_depth, ) .await?; @@ -49,10 +58,23 @@ pub async fn start( .await .context(BrokerSnafu)?; + trace!("Creating env"); + let env = create_env( + &config, + Arc::clone(&provider), + Arc::clone(&block_subscriber.block_archive), + ) + .await?; + trace!("Creating context"); - let mut context = - create_context(&config, &state_server, &broker, dapp_metadata, metrics) - .await?; + let mut context = create_context( + &config, + Arc::clone(&block_subscriber), + &broker, + dapp_metadata, + metrics, + ) + .await?; trace!("Creating machine driver and blockchain driver"); let mut machine_driver = @@ -75,8 +97,8 @@ pub async fn start( b.parent_hash ); process_block( + &Arc::clone(&env), &b, - &state_server, &initial_state, &mut context, &mut machine_driver, @@ -114,24 +136,21 @@ pub async fn start( #[instrument(level = "trace", skip_all)] #[allow(clippy::too_many_arguments)] async fn process_block( + env: &Arc>>, block: &Block, - - state_server: &impl StateServer< - InitialState = RollupsInitialState, - State = RollupsState, - >, initial_state: &RollupsInitialState, - context: &mut Context, machine_driver: &mut MachineDriver, - broker: &(impl BrokerSend + BrokerReceive), ) -> Result<(), EthInputReaderError> { trace!("Querying rollup state"); - let state = state_server - .query_state(initial_state, block.hash) - .await - .context(StateServerSnafu)?; + let state = RollupsState::get_state_for_block( + &Arc::new(initial_state.to_owned()), + block, + env, + ) + .await + .expect("should get state"); // Drive machine trace!("Reacting to state with `machine_driver`"); diff --git a/offchain/eth-input-reader/src/machine/driver.rs b/offchain/eth-input-reader/src/machine/driver.rs index 475db5f25..0f9ba551b 100644 --- a/offchain/eth-input-reader/src/machine/driver.rs +++ b/offchain/eth-input-reader/src/machine/driver.rs @@ -5,7 +5,8 @@ use super::Context; use super::{rollups_broker::BrokerFacadeError, BrokerSend}; -use eth_state_fold_types::{ethereum_types::Address, Block}; +use eth_state_fold_types::Block; +use ethers::types::Address; use types::foldables::input_box::{DAppInputBox, Input, InputBox}; use tracing::{debug, instrument, trace}; diff --git a/offchain/eth-input-reader/src/setup.rs b/offchain/eth-input-reader/src/setup.rs index 4fb3d6966..fb6832073 100644 --- a/offchain/eth-input-reader/src/setup.rs +++ b/offchain/eth-input-reader/src/setup.rs @@ -1,88 +1,116 @@ // (c) Cartesi and individual authors (see AUTHORS) // SPDX-License-Identifier: Apache-2.0 (see LICENSE) -use eth_state_client_lib::{ - config::SCConfig, error::StateServerError, BlockServer, - GrpcStateFoldClient, StateServer, -}; +use eth_block_history::{BlockArchive, BlockSubscriber, SubscriptionError}; +use eth_state_fold::StateFoldEnvironment; use eth_state_fold_types::BlockStreamItem; +use ethers::providers::{ + Http, HttpRateLimitRetryPolicy, Provider, RetryClient, +}; use rollups_events::DAppMetadata; use snafu::ResultExt; -use tokio_stream::{Stream, StreamExt}; -use tonic::transport::Channel; -use types::foldables::authority::{RollupsInitialState, RollupsState}; +use std::sync::{Arc, Mutex}; +use tokio_stream::Stream; +use types::UserData; +use url::Url; +use crate::error::{BlockArchiveSnafu, ParseSnafu}; use crate::{ config::EthInputReaderConfig, - error::{ - BrokerSnafu, ChannelSnafu, ConnectSnafu, EthInputReaderError, - StateServerSnafu, - }, + error::{BrokerSnafu, EthInputReaderError}, machine::{BrokerStatus, Context}, metrics::EthInputReaderMetrics, }; -const BUFFER_LEN: usize = 256; +/// Maximum events allowed to be in a single provider response. If response +/// event number reaches over this number, the request must be split into +/// sub-ranges retried on each of them separately. +/// +/// Motivation for this configuration parameter mainly comes from Alchemy +/// as past a certain limit it responds with invalid data. +pub const MAXIMUM_EVENTS_PER_RESPONSE: usize = 10000; -pub async fn create_state_server( - config: &SCConfig, -) -> Result< - impl StateServer - + BlockServer, - EthInputReaderError, -> { - let channel = Channel::from_shared(config.grpc_endpoint.to_owned()) - .context(ChannelSnafu)? - .connect() - .await - .context(ConnectSnafu)?; +pub type InputProvider = Provider>; + +pub async fn create_provider( + config: &EthInputReaderConfig, +) -> Result, EthInputReaderError> { + let http = Http::new( + Url::parse(&config.bh_config.http_endpoint).context(ParseSnafu)?, + ); + + let retry_client = + RetryClient::new(http, Box::new(HttpRateLimitRetryPolicy), 10, 1000); + + let provider = Provider::new(retry_client); - Ok(GrpcStateFoldClient::new_from_channel(channel)) + Ok(Arc::new(provider)) } -pub async fn create_block_subscription( - client: &impl BlockServer, - confirmations: usize, +pub async fn create_block_subscriber( + config: &EthInputReaderConfig, + provider: Arc, +) -> Result>, EthInputReaderError> { + Ok(Arc::new( + BlockSubscriber::start( + Arc::clone(&provider), + config.bh_config.ws_endpoint.to_owned(), + config.bh_config.block_timeout, + config.bh_config.max_depth, + ) + .await + .context(BlockArchiveSnafu)?, + )) +} + +pub async fn create_subscription( + block_subscriber: Arc>, + subscription_depth: usize, ) -> Result< - impl Stream> - + Send + impl Stream>> + std::marker::Unpin, EthInputReaderError, > { - let s = client - .subscribe_blocks(confirmations) + Ok(block_subscriber + .subscribe_new_blocks_at_depth(subscription_depth) .await - .context(StateServerSnafu)?; - - let s = { - use futures::StreamExt; - s.ready_chunks(BUFFER_LEN) - }; + .context(BlockArchiveSnafu)?) +} - let s = s.filter_map( - |mut x| { - if x.len() == BUFFER_LEN { - None - } else { - x.pop() - } - }, +pub async fn create_env( + config: &EthInputReaderConfig, + provider: Arc, + block_archive: Arc>, +) -> Result< + Arc>>, + EthInputReaderError, +> { + let env = StateFoldEnvironment::new( + provider, + Some(block_archive), + config.sf_config.safety_margin, + config.sf_config.genesis_block, + config.sf_config.query_limit_error_codes.clone(), + config.sf_config.concurrent_events_fetch, + MAXIMUM_EVENTS_PER_RESPONSE, + Mutex::new(UserData::default()), ); - Ok(s) + Ok(Arc::new(env)) } pub async fn create_context( config: &EthInputReaderConfig, - block_server: &impl BlockServer, + block_subscriber: Arc>, broker: &impl BrokerStatus, dapp_metadata: DAppMetadata, metrics: EthInputReaderMetrics, ) -> Result { - let genesis_timestamp: u64 = block_server - .query_block(config.dapp_deployment.deploy_block_hash) + let genesis_timestamp: u64 = block_subscriber + .block_archive + .block_with_hash(&config.dapp_deployment.deploy_block_hash) .await - .context(StateServerSnafu)? + .context(BlockArchiveSnafu)? .timestamp .as_u64(); let epoch_length = config.epoch_duration; diff --git a/offchain/state-server/Cargo.toml b/offchain/state-server/Cargo.toml deleted file mode 100644 index 2c7bfe02c..000000000 --- a/offchain/state-server/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "state-server" -edition.workspace = true -license.workspace = true -version.workspace = true - -[[bin]] -name = "cartesi-rollups-state-server" -path = "src/main.rs" - -[dependencies] -types = { path = "../types" } - -eth-block-history.workspace = true -eth-state-fold-types.workspace = true -eth-state-fold.workspace = true -eth-state-server-lib.workspace = true -serde.workspace = true -snafu.workspace = true -tokio = { workspace = true, features = ["macros", "sync", "rt-multi-thread"] } -tonic.workspace = true -tracing-subscriber = { workspace = true, features = ["env-filter"] } -tracing.workspace = true -url.workspace = true diff --git a/offchain/state-server/README.md b/offchain/state-server/README.md deleted file mode 100644 index bd0598c10..000000000 --- a/offchain/state-server/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# State-fold server - -Service based on the [State-fold library](https://github.com/cartesi/state-fold) used to: - -- Detect state changes in the blockchain to generate rollups input events to be processed by the Cartesi Node. diff --git a/offchain/state-server/src/error.rs b/offchain/state-server/src/error.rs deleted file mode 100644 index 0dc5b9414..000000000 --- a/offchain/state-server/src/error.rs +++ /dev/null @@ -1,28 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -use eth_block_history::BlockArchiveError; -use eth_state_fold_types::ethers::providers::{Http, RetryClient}; -use snafu::Snafu; -use tonic::transport::Error as TonicError; -use url::ParseError; - -#[derive(Debug, Snafu)] -#[snafu(visibility(pub(crate)))] -#[allow(clippy::enum_variant_names)] -pub enum StateServerError { - #[snafu(display("tonic error"))] - TonicError { source: TonicError }, - - #[snafu(display("parser error"))] - ParserError { source: ParseError }, - - #[snafu(display("block archive error"))] - BlockArchiveError { - source: BlockArchiveError< - eth_state_fold_types::ethers::providers::Provider< - RetryClient, - >, - >, - }, -} diff --git a/offchain/state-server/src/lib.rs b/offchain/state-server/src/lib.rs deleted file mode 100644 index 1a4dbfc48..000000000 --- a/offchain/state-server/src/lib.rs +++ /dev/null @@ -1,119 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -use eth_state_fold::{Foldable, StateFoldEnvironment}; -use eth_state_fold_types::ethers::providers::{ - Http, HttpRateLimitRetryPolicy, Provider, RetryClient, -}; -use eth_state_server_lib::{ - config, - grpc_server::StateServer, - utils::{start_server, wait_for_signal}, -}; -use snafu::ResultExt; -use std::sync::{Arc, Mutex}; -use tokio::sync::oneshot; -use types::UserData; -use url::Url; - -use crate::error::{ - BlockArchiveSnafu, ParserSnafu, StateServerError, TonicSnafu, -}; - -mod error; - -const MAX_RETRIES: u32 = 10; -const INITIAL_BACKOFF: u64 = 1000; - -#[tracing::instrument(level = "trace")] -pub async fn run_server> + 'static>( - config: config::StateServerConfig, -) -> Result<(), StateServerError> -where - ::InitialState: serde::de::DeserializeOwned, - F: serde::ser::Serialize, -{ - tracing::trace!("Starting rollups state-server with config `{:?}`", config); - - let provider = create_provider(&config)?; - let block_subscriber = - create_block_subscriber(&config, Arc::clone(&provider)).await?; - let env = create_env( - &config, - Arc::clone(&provider), - Arc::clone(&block_subscriber.block_archive), - )?; - - let server = StateServer::<_, _, F>::new(block_subscriber, env); - - let server_address = config.server_address; - let (shutdown_tx, shutdown_rx) = oneshot::channel(); - - tokio::spawn(async { wait_for_signal(shutdown_tx).await }); - - start_server(server_address, server, shutdown_rx) - .await - .context(TonicSnafu) -} - -type ServerProvider = Provider>; - -fn create_provider( - config: &config::StateServerConfig, -) -> Result, StateServerError> { - let http = Http::new( - Url::parse(&config.block_history.http_endpoint).context(ParserSnafu)?, - ); - - let retry_client = RetryClient::new( - http, - Box::new(HttpRateLimitRetryPolicy), - MAX_RETRIES, - INITIAL_BACKOFF, - ); - - let provider = Provider::new(retry_client); - - Ok(Arc::new(provider)) -} - -fn create_env( - config: &config::StateServerConfig, - provider: Arc, - block_archive: Arc>, -) -> Result< - Arc>>, - StateServerError, -> { - let env = StateFoldEnvironment::new( - provider, - Some(block_archive), - config.state_fold.safety_margin, - config.state_fold.genesis_block, - config.state_fold.query_limit_error_codes.clone(), - config.state_fold.concurrent_events_fetch, - 10000, - Mutex::new(UserData::default()), - ); - - Ok(Arc::new(env)) -} - -async fn create_block_subscriber( - config: &config::StateServerConfig, - provider: Arc, -) -> Result< - Arc>, - StateServerError, -> { - let block_subscriber = eth_block_history::BlockSubscriber::start( - Arc::clone(&provider), - config.block_history.ws_endpoint.to_owned(), - config.block_history.block_timeout, - config.block_history.max_depth, - ) - .await - .context(BlockArchiveSnafu)?; - - Ok(Arc::new(block_subscriber)) -} diff --git a/offchain/state-server/src/main.rs b/offchain/state-server/src/main.rs deleted file mode 100644 index cd6216f7a..000000000 --- a/offchain/state-server/src/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -use eth_state_server_lib::config::StateServerConfig; -use tracing_subscriber::filter::{EnvFilter, LevelFilter}; -use types::foldables::authority::rollups::RollupsState; - -#[tokio::main] -async fn main() -> Result<(), Box> { - let filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - tracing_subscriber::fmt().with_env_filter(filter).init(); - - let config = StateServerConfig::initialize_from_args()?; - - tracing::info!(?config, "starting state server"); - - state_server::run_server::(config) - .await - .map_err(|e| e.into()) -}