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 Sep 27, 2023
1 parent 9ed8c8e commit ce5a4be
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 412 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ group "default" {
"hardhat",
"host-runner",
"inspect-server",
"indexer",
"state-server"
"indexer"
]
}

Expand All @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions docker-bake.override.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]
}
Expand Down
79 changes: 3 additions & 76 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 @@ -15,7 +15,6 @@ members = [
"redacted",
"rollups-events",
"rollups-http-client",
"state-server",
"test-fixtures",
"types",
]
Expand Down
10 changes: 0 additions & 10 deletions offchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ WORKDIR /var/opt/cartesi
ENV PATH="/opt/cartesi/bin:${PATH}"

## runtimes
FROM runtime AS state_server
RUN <<EOF
apt-get update
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends ca-certificates
rm -rf /var/lib/apt/lists/*
EOF
COPY --from=builder /usr/src/app/offchain/target/release/cartesi-rollups-state-server /opt/cartesi/bin/cartesi-rollups-state-server
USER cartesi
ENTRYPOINT ["/opt/cartesi/bin/cartesi-rollups-state-server"]

FROM runtime AS indexer
RUN <<EOF
apt-get update
Expand Down
7 changes: 4 additions & 3 deletions offchain/eth-input-reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,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 Down
62 changes: 30 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 snafu::{ResultExt, Snafu};
use std::{fs::File, io::BufReader, path::PathBuf};
Expand All @@ -24,13 +19,13 @@ 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 tx_config: TxEnvCLIConfig,
pub sf_config: SFEnvCLIConfig,

#[command(flatten)]
pub broker_config: BrokerCLIConfig,
pub bh_config: BHEnvCLIConfig,

/// Path to file with deployment json of dapp
#[arg(long, env, default_value = "./dapp_deployment.json")]
Expand All @@ -40,31 +35,34 @@ 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 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 @@ -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)]
Expand All @@ -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)?;
Expand All @@ -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 {
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 ce5a4be

Please sign in to comment.