Skip to content

Commit

Permalink
merge checkpoints relayer into the single binary
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep committed Jul 31, 2024
1 parent bc140cc commit 782f801
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 91 deletions.
27 changes: 4 additions & 23 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ members = [
"gear-programs/*",
"gear-programs/checkpoint-light-client/io",
"utils-prometheus",
"checkpoints-relayer",
]

resolver = "2"
Expand Down
23 changes: 0 additions & 23 deletions checkpoints-relayer/Cargo.toml

This file was deleted.

4 changes: 4 additions & 0 deletions relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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,
};
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},
Expand All @@ -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,
Expand All @@ -73,28 +42,26 @@ 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 {
log::error!("Failed to set SIGINT handler");
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);

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -124,6 +127,35 @@ struct ProofStorageArgs {
gear_fee_payer: Option<String>,
}

#[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();
Expand All @@ -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();
Expand Down Expand Up @@ -201,6 +234,8 @@ async fn main() {

relayer.run().await.unwrap();
}

CliCommands::RelayCheckpoints(args) => ethereum_checkpoints::relay(args).await,
};
}

Expand Down

0 comments on commit 782f801

Please sign in to comment.