From 782f8014de4cde353441fc8885f6e14258d44ced Mon Sep 17 00:00:00 2001 From: Georgy Shepelev Date: Wed, 31 Jul 2024 17:08:35 +0400 Subject: [PATCH] merge checkpoints relayer into the single binary --- Cargo.lock | 27 ++-------- Cargo.toml | 1 - checkpoints-relayer/Cargo.toml | 23 --------- relayer/Cargo.toml | 4 ++ .../src/ethereum_checkpoints}/metrics.rs | 2 +- .../src/ethereum_checkpoints/mod.rs | 51 ++++--------------- .../src/ethereum_checkpoints}/replay_back.rs | 0 .../src/ethereum_checkpoints}/sync_update.rs | 0 .../src/ethereum_checkpoints}/tests/mod.rs | 2 +- .../sepolia-finality-update-5_254_112.json | 0 .../sepolia-finality-update-5_263_072.json | 0 .../src/ethereum_checkpoints}/utils/mod.rs | 0 .../utils/slots_batch.rs | 0 relayer/src/main.rs | 35 +++++++++++++ 14 files changed, 54 insertions(+), 91 deletions(-) delete mode 100644 checkpoints-relayer/Cargo.toml rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/metrics.rs (97%) rename checkpoints-relayer/src/main.rs => relayer/src/ethereum_checkpoints/mod.rs (80%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/replay_back.rs (100%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/sync_update.rs (100%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/tests/mod.rs (99%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/tests/sepolia-finality-update-5_254_112.json (100%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/tests/sepolia-finality-update-5_263_072.json (100%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/utils/mod.rs (100%) rename {checkpoints-relayer/src => relayer/src/ethereum_checkpoints}/utils/slots_batch.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 84ea050e..f63ea7e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1963,29 +1963,6 @@ dependencies = [ "tree_hash_derive", ] -[[package]] -name = "checkpoints-relayer" -version = "0.1.0" -dependencies = [ - "anyhow", - "ark-serialize 0.4.2", - "checkpoint_light_client", - "checkpoint_light_client-io", - "clap", - "futures", - "gclient", - "hex", - "log", - "parity-scale-codec", - "pretty_env_logger", - "prometheus", - "reqwest 0.11.27", - "serde", - "serde_json", - "tokio", - "utils-prometheus", -] - [[package]] name = "chrono" version = "0.4.38" @@ -8550,9 +8527,12 @@ name = "relayer" version = "0.1.0" dependencies = [ "anyhow", + "ark-serialize 0.4.2", "axum", "bridging_payment", "cgo_oligami", + "checkpoint_light_client", + "checkpoint_light_client-io", "clap", "dotenv", "ethereum-client", @@ -8573,6 +8553,7 @@ dependencies = [ "prometheus", "prover", "rand 0.8.5", + "reqwest 0.11.27", "serde", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 3159a93b..128d273b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ members = [ "gear-programs/*", "gear-programs/checkpoint-light-client/io", "utils-prometheus", - "checkpoints-relayer", ] resolver = "2" diff --git a/checkpoints-relayer/Cargo.toml b/checkpoints-relayer/Cargo.toml deleted file mode 100644 index 64ed4b7f..00000000 --- a/checkpoints-relayer/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "checkpoints-relayer" -version.workspace = true -edition.workspace = true - -[dependencies] -clap.workspace = true -tokio.workspace = true -checkpoint_light_client-io = { workspace = true, features = ["std"] } -checkpoint_light_client = { workspace = true, features = ["std"] } -parity-scale-codec.workspace = true -serde_json.workspace = true -serde = { workspace = true, features = ["std"] } -reqwest.workspace = true -anyhow.workspace = true -ark-serialize = { workspace = true, features = ["std"] } -log.workspace = true -pretty_env_logger.workspace = true -gclient.workspace = true -futures.workspace = true -hex = { workspace = true, features = ["std"] } -prometheus.workspace = true -utils-prometheus.workspace = true diff --git a/relayer/Cargo.toml b/relayer/Cargo.toml index cf671d10..bae262ac 100644 --- a/relayer/Cargo.toml +++ b/relayer/Cargo.toml @@ -11,7 +11,10 @@ gear-rpc-client.workspace = true prover.workspace = true anyhow.workspace = true +ark-serialize = { workspace = true, features = ["std"] } axum.workspace = true +checkpoint_light_client-io = { workspace = true, features = ["std"] } +checkpoint_light_client = { workspace = true, features = ["std"] } clap.workspace = true dotenv.workspace = true futures.workspace = true @@ -28,6 +31,7 @@ pretty_env_logger.workspace = true primitive-types = { workspace = true, features = ["std"] } prometheus.workspace = true rand.workspace = true +reqwest.workspace = true serde.workspace = true serde_json.workspace = true thiserror.workspace = true diff --git a/checkpoints-relayer/src/metrics.rs b/relayer/src/ethereum_checkpoints/metrics.rs similarity index 97% rename from checkpoints-relayer/src/metrics.rs rename to relayer/src/ethereum_checkpoints/metrics.rs index 5b2712e5..8f6eb861 100644 --- a/checkpoints-relayer/src/metrics.rs +++ b/relayer/src/ethereum_checkpoints/metrics.rs @@ -1,6 +1,6 @@ use super::*; use prometheus::{IntCounter, IntGauge}; -use utils_prometheus::{impl_metered_service, MetricsBuilder}; +use utils_prometheus::impl_metered_service; pub struct Message { pub slot: Slot, diff --git a/checkpoints-relayer/src/main.rs b/relayer/src/ethereum_checkpoints/mod.rs similarity index 80% rename from checkpoints-relayer/src/main.rs rename to relayer/src/ethereum_checkpoints/mod.rs index a419e290..59dda96b 100644 --- a/checkpoints-relayer/src/main.rs +++ b/relayer/src/ethereum_checkpoints/mod.rs @@ -1,9 +1,9 @@ +use super::*; use checkpoint_light_client_io::{ ethereum_common::{utils as eth_utils, SLOTS_PER_EPOCH}, tree_hash::Hash256, Handle, HandleResult, Slot, SyncCommitteeUpdate, G2, }; -use clap::Parser; use futures::{ future::{self, Either}, pin_mut, @@ -11,7 +11,6 @@ use futures::{ use gclient::{EventListener, EventProcessor, GearApi, WSAddress}; use metrics::Message as MetricMessage; use parity_scale_codec::Decode; -use pretty_env_logger::env_logger::fmt::TimestampPrecision; use reqwest::Client; use tokio::{ signal::unix::{self, SignalKind}, @@ -33,36 +32,6 @@ const SIZE_BATCH: u64 = 44 * SLOTS_PER_EPOCH; const COUNT_FAILURE: usize = 3; const DELAY_SECS_FINALITY_REQUEST: u64 = 30; -#[derive(Debug, Parser)] -struct Args { - /// Specify ProgramId of the Checkpoint-light-client program - #[arg(long)] - program_id: String, - - /// Specify an endpoint providing Beacon API - #[arg(long)] - beacon_endpoint: String, - - /// Domain of the VARA RPC endpoint - #[arg(long, default_value = "ws://127.0.0.1")] - vara_domain: String, - - /// Port of the VARA RPC endpoint - #[arg(long, default_value = "9944")] - vara_port: u16, - - /// Substrate URI that identifies a user by a mnemonic phrase or - /// provides default users from the keyring (e.g., "//Alice", "//Bob", - /// etc.). The password for URI should be specified in the same `suri`, - /// separated by the ':' char - #[arg(long, default_value = "//Alice")] - suri: String, - - /// Address of the prometheus endpoint - #[arg(long = "prometheus-endpoint", default_value = "http://127.0.0.1:9090")] - endpoint_prometheus: String, -} - enum Status { Ok, NotActual, @@ -73,13 +42,9 @@ enum Status { }, } -#[tokio::main] -async fn main() { - pretty_env_logger::formatted_builder() - .format_timestamp(Some(TimestampPrecision::Micros)) - .parse_default_env() - .init(); - +pub async fn relay( + args: RelayCheckpointsArgs, +) { log::info!("Started"); let Ok(mut signal_interrupt) = unix::signal(SignalKind::interrupt()) else { @@ -87,14 +52,16 @@ async fn main() { return; }; - let Args { + let RelayCheckpointsArgs { program_id, beacon_endpoint, vara_domain, vara_port, suri, - endpoint_prometheus, - } = Args::parse(); + prometheus_args: PrometheusArgs { + endpoint: endpoint_prometheus, + }, + } = args; let sender_metrics = metrics::spawn(endpoint_prometheus); diff --git a/checkpoints-relayer/src/replay_back.rs b/relayer/src/ethereum_checkpoints/replay_back.rs similarity index 100% rename from checkpoints-relayer/src/replay_back.rs rename to relayer/src/ethereum_checkpoints/replay_back.rs diff --git a/checkpoints-relayer/src/sync_update.rs b/relayer/src/ethereum_checkpoints/sync_update.rs similarity index 100% rename from checkpoints-relayer/src/sync_update.rs rename to relayer/src/ethereum_checkpoints/sync_update.rs diff --git a/checkpoints-relayer/src/tests/mod.rs b/relayer/src/ethereum_checkpoints/tests/mod.rs similarity index 99% rename from checkpoints-relayer/src/tests/mod.rs rename to relayer/src/ethereum_checkpoints/tests/mod.rs index 01a20bf6..6c4b4137 100644 --- a/checkpoints-relayer/src/tests/mod.rs +++ b/relayer/src/ethereum_checkpoints/tests/mod.rs @@ -1,4 +1,4 @@ -use crate::utils::{self, slots_batch, FinalityUpdateResponse}; +use super::utils::{self, slots_batch, FinalityUpdateResponse}; use checkpoint_light_client::WASM_BINARY; use checkpoint_light_client_io::{ ethereum_common::{ diff --git a/checkpoints-relayer/src/tests/sepolia-finality-update-5_254_112.json b/relayer/src/ethereum_checkpoints/tests/sepolia-finality-update-5_254_112.json similarity index 100% rename from checkpoints-relayer/src/tests/sepolia-finality-update-5_254_112.json rename to relayer/src/ethereum_checkpoints/tests/sepolia-finality-update-5_254_112.json diff --git a/checkpoints-relayer/src/tests/sepolia-finality-update-5_263_072.json b/relayer/src/ethereum_checkpoints/tests/sepolia-finality-update-5_263_072.json similarity index 100% rename from checkpoints-relayer/src/tests/sepolia-finality-update-5_263_072.json rename to relayer/src/ethereum_checkpoints/tests/sepolia-finality-update-5_263_072.json diff --git a/checkpoints-relayer/src/utils/mod.rs b/relayer/src/ethereum_checkpoints/utils/mod.rs similarity index 100% rename from checkpoints-relayer/src/utils/mod.rs rename to relayer/src/ethereum_checkpoints/utils/mod.rs diff --git a/checkpoints-relayer/src/utils/slots_batch.rs b/relayer/src/ethereum_checkpoints/utils/slots_batch.rs similarity index 100% rename from checkpoints-relayer/src/utils/slots_batch.rs rename to relayer/src/ethereum_checkpoints/utils/slots_batch.rs diff --git a/relayer/src/main.rs b/relayer/src/main.rs index 6abb31e8..cd838506 100644 --- a/relayer/src/main.rs +++ b/relayer/src/main.rs @@ -11,6 +11,7 @@ use prover::proving::GenesisConfig; use relay_merkle_roots::MerkleRootRelayer; use utils_prometheus::MetricsBuilder; +mod ethereum_checkpoints; mod message_relayer; mod proof_storage; mod prover_interface; @@ -45,6 +46,8 @@ enum CliCommands { /// Relay message to ethereum #[clap(visible_alias("rm"))] RelayMessages(RelayMessagesArgs), + /// Start service constantly relaying Ethereum checkpoints to the Vara program + RelayCheckpoints(RelayCheckpointsArgs), } #[derive(Args)] @@ -124,6 +127,35 @@ struct ProofStorageArgs { gear_fee_payer: Option, } +#[derive(Args)] +struct RelayCheckpointsArgs { + /// Specify ProgramId of the Checkpoint-light-client program + #[arg(long)] + program_id: String, + + /// Specify an endpoint providing Beacon API + #[arg(long)] + beacon_endpoint: String, + + /// Domain of the VARA RPC endpoint + #[arg(long, default_value = "ws://127.0.0.1")] + vara_domain: String, + + /// Port of the VARA RPC endpoint + #[arg(long, default_value = "9944")] + vara_port: u16, + + /// Substrate URI that identifies a user by a mnemonic phrase or + /// provides default users from the keyring (e.g., "//Alice", "//Bob", + /// etc.). The password for URI should be specified in the same `suri`, + /// separated by the ':' char + #[arg(long, default_value = "//Alice")] + suri: String, + + #[clap(flatten)] + prometheus_args: PrometheusArgs, +} + #[tokio::main] async fn main() { let _ = dotenv::dotenv(); @@ -136,6 +168,7 @@ async fn main() { .filter(Some("ethereum-client"), log::LevelFilter::Info) .filter(Some("metrics"), log::LevelFilter::Info) .format_timestamp(Some(TimestampPrecision::Seconds)) + .parse_default_env() .init(); let cli = Cli::parse(); @@ -201,6 +234,8 @@ async fn main() { relayer.run().await.unwrap(); } + + CliCommands::RelayCheckpoints(args) => ethereum_checkpoints::relay(args).await, }; }