Skip to content

Commit

Permalink
refactor(input-reader): update state-fold use
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Oct 25, 2023
1 parent 52030b1 commit bf27f7c
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 431 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed timestamp in GraphQL API
- Fixed BigInt in GraphQL API
- 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

Expand Down
81 changes: 4 additions & 77 deletions offchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ members = [
"redacted",
"rollups-events",
"rollups-http-client",
"state-server",
"test-fixtures",
"types",
]
Expand Down
8 changes: 5 additions & 3 deletions offchain/eth-input-reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ async-trait.workspace = true
axum.workspace = true
backoff = { workspace = true, features = ["tokio"] }
clap = { workspace = true, features = ["derive", "env"] }
eth-state-client-lib.workspace = true
eth-state-fold-types = { workspace = true, features = ["ethers"] }
eth-tx-manager.workspace = true
eth-block-history.workspace = true
eth-state-fold.workspace = true
eth-state-fold-types.workspace = true
ethers.workspace = true
ethers-signers = { workspace = true, features = ["aws"] }
futures.workspace = true
hyper.workspace = true
Expand All @@ -46,3 +47,4 @@ redis.workspace = true
serial_test.workspace = true
testcontainers.workspace = true
tracing-test = { workspace = true, features = ["no-env-filter"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
70 changes: 38 additions & 32 deletions offchain/eth-input-reader/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use clap::Parser;
use eth_state_client_lib::config::{
Error as SCError, SCConfig, SCEnvCLIConfig,
};
use eth_tx_manager::{
config::{Error as TxError, TxEnvCLIConfig, TxManagerConfig},
Priority,
};
use eth_block_history::config::{BHConfig, BHEnvCLIConfig};
use eth_state_fold::config::{SFConfig, SFEnvCLIConfig};
use http_server::HttpServerConfig;
use log::{LogConfig, LogEnvCliConfig};
use snafu::{ResultExt, Snafu};
Expand All @@ -25,13 +20,16 @@ use types::deployment_files::{
#[command(about = "Configuration for rollups eth-input-reader")]
pub struct EthInputReaderEnvCLIConfig {
#[command(flatten)]
pub sc_config: SCEnvCLIConfig,
pub broker_config: BrokerCLIConfig,

#[command(flatten)]
pub sf_config: SFEnvCLIConfig,

#[command(flatten)]
pub tx_config: TxEnvCLIConfig,
pub bh_config: BHEnvCLIConfig,

#[command(flatten)]
pub broker_config: BrokerCLIConfig,
pub log_config: LogEnvCliConfig,

/// Path to file with deployment json of dapp
#[arg(long, env, default_value = "./dapp_deployment.json")]
Expand All @@ -41,31 +39,35 @@ pub struct EthInputReaderEnvCLIConfig {
#[arg(long, env, default_value = "./rollups_deployment.json")]
pub rd_rollups_deployment_file: PathBuf,

/// Duration of rollups epoch in seconds, for which eth-input-reader will make claims.
/// Duration of rollups epoch in seconds, for which eth-input-reader will read
#[arg(long, env, default_value = "604800")]
pub rd_epoch_duration: u64,

/// Chain ID
#[arg(long, env)]
pub chain_id: Option<u64>,

/// 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 log_config: LogConfig,

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,
Expand All @@ -83,6 +85,9 @@ pub enum Error {

#[snafu(display("Rollups json parse error"))]
RollupsJsonParseError { source: serde_json::Error },

#[snafu(display("Configuration missing chain_id"))]
MissingChainId,
}

#[derive(Debug)]
Expand All @@ -98,12 +103,12 @@ 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 bh_config = BHConfig::initialize(eth_input_reader_config.bh_config);

let tx_config =
TxManagerConfig::initialize(eth_input_reader_config.tx_config)
.context(TxManagerSnafu)?;
let log_config =
LogConfig::initialize(eth_input_reader_config.log_config);

let path = eth_input_reader_config.rd_dapp_deployment_file;
let dapp_deployment: DappDeployment = read_json(path)?;
Expand All @@ -115,19 +120,20 @@ 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,
log_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 {
Expand Down
13 changes: 10 additions & 3 deletions offchain/eth-input-reader/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Provider<RetryClient<Http>>>,
},

#[snafu(whatever, display("{message}"))]
Whatever {
Expand Down
Loading

0 comments on commit bf27f7c

Please sign in to comment.