Skip to content

Commit

Permalink
feat(relayer): Introduce manual relayers (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mertwole authored Dec 17, 2024
1 parent f2ec2eb commit 851c56d
Show file tree
Hide file tree
Showing 13 changed files with 865 additions and 487 deletions.
103 changes: 103 additions & 0 deletions relayer/src/cli/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use clap::Args;

#[derive(Args)]
pub struct ProofStorageArgs {
/// Gear fee payer. If not set, proofs are saved to file system
#[arg(long = "gear-fee-payer", env = "GEAR_FEE_PAYER")]
pub gear_fee_payer: Option<String>,
}

#[derive(Args)]
pub struct GenesisConfigArgs {
/// Authority set hash used in genesis config
#[arg(long = "authority-set-hash", env = "GENESIS_CONFIG_AUTHORITY_SET_HASH")]
pub authority_set_hash: String,
/// Authority set id used in genesis config
#[arg(long = "authority-set-id", env = "GENESIS_CONFIG_AUTHORITY_SET_ID")]
pub authority_set_id: u64,
}

#[derive(Args)]
pub struct GearSignerArgs {
#[clap(flatten)]
pub common: GearArgs,

/// 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 = "gear-suri", env = "GEAR_SURI")]
pub suri: String,
}

#[derive(Args)]
pub struct GearArgs {
/// Domain of the Gear RPC endpoint
#[arg(
long = "gear-domain",
default_value = "ws://127.0.0.1",
env = "GEAR_DOMAIN"
)]
pub domain: String,

/// Port of the Gear RPC endpoint
#[arg(long = "gear-port", default_value = "9944", env = "GEAR_PORT")]
pub port: u16,

/// Retry count of the Gear RPC client
#[arg(
long = "gear-rpc-retries",
default_value = "3",
env = "GEAR_RPC_RETRIES"
)]
pub retries: u8,
}

#[derive(Args)]
pub struct EthereumSignerArgs {
#[clap(flatten)]
pub ethereum_args: EthereumArgs,

/// Private key for fee payer
#[arg(long = "eth-fee-payer", env = "ETH_FEE_PAYER")]
pub fee_payer: String,
}

#[derive(Args)]
pub struct EthereumArgs {
/// Address of the ethereum endpoint
#[arg(long = "ethereum-endpoint", env = "ETH_RPC")]
pub eth_endpoint: String,
/// Ethereum address of relayer contract
#[arg(long = "relayer-address", env = "ETH_RELAYER_ADDRESS")]
pub relayer_address: String,
/// Ethereum address of message queue contract
#[arg(long = "mq-address", env = "ETH_MESSAGE_QUEUE_ADDRESS")]
pub mq_address: String,
}

#[derive(Args)]
pub struct BeaconRpcArgs {
/// Address of the ethereum beacon RPC endpoint
#[arg(long = "ethereum-beacon-rpc", env = "ETH_BEACON_RPC")]
pub beacon_endpoint: String,

/// Timeout in seconds for requests to the ethereum beacon RPC
#[arg(
long = "ethereum-beacon-rpc-timeout",
env = "ETH_BEACON_RPC_TIMEOUT",
default_value = "10"
)]
pub beacon_timeout: Option<u64>,
}

#[derive(Args)]
pub struct PrometheusArgs {
/// Address of the prometheus endpoint
#[arg(
long = "prometheus-endpoint",
default_value = "0.0.0.0:9090",
env = "PROMETHEUS_ENDPOINT"
)]
pub endpoint: String,
}
210 changes: 210 additions & 0 deletions relayer/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
use clap::{Args, Parser, Subcommand};

mod common;

pub use common::{
BeaconRpcArgs, EthereumArgs, EthereumSignerArgs, GearArgs, GearSignerArgs, GenesisConfigArgs,
PrometheusArgs, ProofStorageArgs,
};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: CliCommands,
}

#[allow(clippy::enum_variant_names)]
#[derive(Subcommand)]
pub enum CliCommands {
/// Start core protocol gear to ethereum relayer
GearEthCore(GearEthCoreArgs),
/// Start core protocol ethereum to gear relayer
EthGearCore(EthGearCoreArgs),

/// Relay tokens from gear to ethereum
GearEthTokens(GearEthTokensArgs),
/// Relay tokens from ethereum to gear
EthGearTokens(EthGearTokensArgs),

/// Manually relay message from gear to ethereum
GearEthManual(GearEthManualArgs),
/// Manually relay message from ethereum to gear
EthGearManual(EthGearManualArgs),

/// Start kill switch relayer
KillSwitch(KillSwitchArgs),
}

#[derive(Args)]
pub struct GearEthCoreArgs {
#[clap(flatten)]
pub gear_args: GearArgs,
#[clap(flatten)]
pub ethereum_args: EthereumSignerArgs,
#[clap(flatten)]
pub genesis_config_args: GenesisConfigArgs,
#[clap(flatten)]
pub prometheus_args: PrometheusArgs,
#[clap(flatten)]
pub proof_storage_args: ProofStorageArgs,
}

#[derive(Args)]
pub struct EthGearCoreArgs {
/// ProgramId of the checkpoint-light-client program
#[arg(long, env = "CHECKPOINT_LIGHT_CLIENT_ADDRESS")]
pub program_id: String,
#[clap(flatten)]
pub beacon_args: BeaconRpcArgs,
#[clap(flatten)]
pub gear_args: GearSignerArgs,
#[clap(flatten)]
pub prometheus_args: PrometheusArgs,
}

#[derive(Args)]
pub struct GearEthTokensArgs {
#[clap(subcommand)]
pub command: GearEthTokensCommands,

/// Block number to start relaying from. If not specified equals to the latest finalized block
#[arg(long = "from-block")]
pub from_block: Option<u32>,

#[clap(flatten)]
pub gear_args: GearArgs,
#[clap(flatten)]
pub ethereum_args: EthereumSignerArgs,
#[clap(flatten)]
pub prometheus_args: PrometheusArgs,
}

#[derive(Subcommand)]
pub enum GearEthTokensCommands {
/// Relay all the messages
AllTokenTransfers,
/// Relay only messages sent through bridging-payment
PaidTokenTransfers {
/// Address of the bridging-payment program
#[arg(long = "bridging-payment-address", env = "BRIDGING_PAYMENT_ADDRESS")]
bridging_payment_address: String,
},
}

#[derive(Args)]
pub struct EthGearTokensArgs {
#[command(subcommand)]
pub command: EthGearTokensCommands,

/// Address of the checkpoint-light-client program on gear
#[arg(
long = "checkpoint-light-client-address",
env = "CHECKPOINT_LIGHT_CLIENT_ADDRESS"
)]
pub checkpoint_light_client_address: String,

#[arg(long = "historical-proxy-address", env = "HISTORICAL_PROXY_ADDRESS")]
pub historical_proxy_address: String,

#[arg(long = "vft-manager-address", env = "VFT_MANAGER_ADDRESS")]
pub vft_manager_address: String,

#[clap(flatten)]
pub gear_args: GearSignerArgs,
#[clap(flatten)]
pub ethereum_args: EthereumArgs,
#[clap(flatten)]
pub beacon_rpc: BeaconRpcArgs,
#[clap(flatten)]
pub prometheus_args: PrometheusArgs,
}

#[derive(Subcommand)]
pub enum EthGearTokensCommands {
/// Relay all the transactions
AllTokenTransfers {
/// Address of the ERC20Manager contract on ethereum
#[arg(long = "erc20-manager-address", env = "ERC20_MANAGER_ADDRESS")]
erc20_manager_address: String,
},
/// Relay only transactions sent to BridgingPayment
PaidTokenTransfers {
/// Address of the BridgingPayment contract on ethereum
#[arg(long = "bridging-payment-address", env = "BRIDGING_PAYMENT_ADDRESS")]
bridging_payment_address: String,
},
}

#[derive(Args)]
pub struct GearEthManualArgs {
/// Nonce of the target message
#[arg(long = "message-nonce", short = 'n')]
pub nonce: String,

/// Block where target message was sent
#[arg(long = "message-block", short = 'b')]
pub block: u32,

/// Ethereum block number to start listening for merkle roots from. If not specified equals to the latest finalized block
#[arg(long = "from-eth-block")]
pub from_eth_block: Option<u64>,

#[clap(flatten)]
pub gear_args: GearArgs,
#[clap(flatten)]
pub ethereum_args: EthereumSignerArgs,
}

#[derive(Args)]
pub struct EthGearManualArgs {
/// Transaction hash of the target message
#[arg(long = "tx-hash", short = 't')]
pub tx_hash: String,

/// Ethereum slot containing target message
#[arg(long = "slot", short = 's')]
pub slot: u64,

/// ProgramId of the checkpoint-light-client program
#[arg(long = "checkpoint-light-client")]
pub checkpoint_light_client: String,

/// ProgramId of the historical-proxy program
#[arg(long = "historical-proxy")]
pub historical_proxy: String,

/// ProgramId of the program that will receive target message
#[arg(long = "receiver-program")]
pub receiver_program: String,

/// Route of the function that will be called on receiver-program
#[arg(long = "receiver-route")]
pub receiver_route: String,

#[clap(flatten)]
pub gear_args: GearSignerArgs,
#[clap(flatten)]
pub ethereum_args: EthereumArgs,
#[clap(flatten)]
pub beacon_args: BeaconRpcArgs,
}

#[derive(Args)]
pub struct KillSwitchArgs {
/// Eth block number to start kill switch relayer read events from. If not specified equals to the latest finalized block
#[arg(long = "from-eth-block")]
pub from_eth_block: Option<u64>,

#[clap(flatten)]
pub gear_args: GearArgs,
#[clap(flatten)]
pub ethereum_args: EthereumSignerArgs,
#[clap(flatten)]
pub genesis_config_args: GenesisConfigArgs,
#[clap(flatten)]
pub prometheus_args: PrometheusArgs,
#[clap(flatten)]
pub proof_storage_args: ProofStorageArgs,
}
Loading

0 comments on commit 851c56d

Please sign in to comment.