From cb2c939005126ee62e832860f09bb8c14409d2bd Mon Sep 17 00:00:00 2001 From: Salman Pathan Date: Wed, 13 Sep 2023 00:28:59 +0530 Subject: [PATCH] Code cleanup and update metadata (#64) --- README.md | 1 - gadget/cli/src/lib.rs | 10 ++--- gadget/config/README.md | 3 -- gadget/config/simple.toml | 42 -------------------- gadget/src/lib.rs | 82 +-------------------------------------- node/src/cli.rs | 2 +- node/src/service.rs | 10 +---- 7 files changed, 6 insertions(+), 144 deletions(-) delete mode 100644 gadget/config/README.md delete mode 100644 gadget/config/simple.toml diff --git a/README.md b/README.md index 5850be46..2a58b824 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ cargo build --release -p node-template ./target/release/node-template --tmp --chain local --alice \ --rpc-cors all --rpc-external --rpc-methods=unsafe \ --port 30433 \ - --relayer-config-dir=./gadget/config \ --light-client-init-pallet-config-path=./crates/eth2-pallet-init/config.toml \ --light-client-relay-config-path=./eth2substrate-block-relay-rs/config.toml --rpc-port 9444 diff --git a/gadget/cli/src/lib.rs b/gadget/cli/src/lib.rs index 57321cfc..744dc4ee 100644 --- a/gadget/cli/src/lib.rs +++ b/gadget/cli/src/lib.rs @@ -1,13 +1,9 @@ use std::path::PathBuf; -/// Cli tool to interact with Webb Relayer CLI +/// Cli tool to interact with Webb Light Client Relayer CLI #[derive(Debug, Clone, clap::Parser)] -#[clap(next_help_heading = "Webb Relayer")] -pub struct RelayerCmd { - /// Directory that contains configration files for the relayer. - #[arg(long, value_name = "PATH")] - pub relayer_config_dir: Option, - +#[clap(next_help_heading = "Webb Light Client Relayer")] +pub struct LightClientRelayerCmd { /// Light client relayer configuration directory. #[arg(long, value_name = "PATH")] pub light_client_relay_config_path: Option, diff --git a/gadget/config/README.md b/gadget/config/README.md deleted file mode 100644 index b1c137cf..00000000 --- a/gadget/config/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Configuration Examples - -This directory contains a very simple and minimal configuration for starting an Event Watching Relayer over the Goerli Testnet. This configuration is used for testing and for demonstration purposes. diff --git a/gadget/config/simple.toml b/gadget/config/simple.toml deleted file mode 100644 index be90b75b..00000000 --- a/gadget/config/simple.toml +++ /dev/null @@ -1,42 +0,0 @@ -port = 9955 - -# Controls what features are enabled in the relayer system -[features] -# if you are an authority, this always true. -governance-relay = true -data-query = true -private-tx-relay = true - -[evm.goerli] -name = "goerli" -http-endpoint = "https://rpc.ankr.com/eth_goerli" -ws-endpoint = "wss://rpc.ankr.com/eth_goerli" -chain-id = 5 -enabled = true -block-confirmations = 2 -# The private key of the account that will be used to sign transactions -# If not set, we will use the Keystore to get the ECDSA private key. -# private-key = "$PRIVATE_KEY" - -[[evm.goerli.contracts]] -contract = "VAnchor" -address = "0x38e7aa90c77f86747fab355eecaa0c2e4c3a463d" -deployed-at = 8703495 -events-watcher = { enabled = true, polling-interval = 15000 } -proposal-signing-backend = { type = "DKGNode", chain-id = 0 } - -[substrate.internal] -name = "internal" -chain-id = 0 -http-endpoint = "http://localhost:9933" -ws-endpoint = "ws://localhost:9944" -suri = "//Alice" -enabled = true - -[[substrate.internal.pallets]] -pallet = "DKG" -events-watcher = { enabled = true, polling-interval = 3000, print-progress-interval = 30000 } - -[[substrate.internal.pallets]] -pallet = "DKGProposalHandler" -events-watcher = { enabled = true, polling-interval = 3000, print-progress-interval = 30000 } diff --git a/gadget/src/lib.rs b/gadget/src/lib.rs index 75647058..e8b498a3 100644 --- a/gadget/src/lib.rs +++ b/gadget/src/lib.rs @@ -1,34 +1,19 @@ //! Webb Relayer Gadget //! //! Integrates the Webb Relayer into the Substrate Node. -#![allow(dead_code)] -use dkg_runtime_primitives::crypto; use eth2_pallet_init::{init_pallet, substrate_pallet_client::EthClientPallet}; use eth2_to_substrate_relay::eth2substrate_relay::Eth2SubstrateRelay; -use ethereum_types::Secret; -use sc_keystore::LocalKeystore; -use sp_core::crypto::{ByteArray, Pair}; -use sp_keystore::Keystore; -use std::{net::SocketAddr, path::PathBuf, sync::Arc}; +use std::path::PathBuf; use subxt::OnlineClient; use webb_proposals::TypedChainId; pub mod errors; -use errors::*; /// Webb Relayer gadget initialization parameters. pub struct Eth2LightClientParams { - /// Concrete local key store - pub local_keystore: Arc, - /// Event watching relayer configuration directory - pub ew_config_dir: Option, /// Light client relayer configuration path pub lc_relay_config_path: Option, /// Light client init pallet configuration path pub lc_init_config_path: Option, - /// Database path - pub database_path: Option, - /// RPC address, `None` if disabled. - pub rpc_addr: Option, /// Eth2 Chain Identifier pub eth2_chain_id: TypedChainId, } @@ -88,17 +73,6 @@ pub async fn start_gadget(relayer_params: Eth2LightClientParams) { relay.run(None).await; } -/// Loads the configuration from the given directory. -fn loads_event_listening_relayer_config( - config_dir: &PathBuf, -) -> anyhow::Result { - if !config_dir.is_dir() { - return Err(InvalidDirectory.into()) - } - - Ok(webb_relayer_config::utils::load(config_dir)?) -} - /// Loads the configuration for the light client fn loads_light_client_relayer_config( config_path: &PathBuf, @@ -112,57 +86,3 @@ fn loads_light_client_pallet_init_config( ) -> anyhow::Result { Ok(eth2_pallet_init::config::Config::load_from_toml(config_path.clone())) } - -/// Creates a database store for the relayer based on the configuration passed in. -pub fn create_store( - database_path: Option, -) -> anyhow::Result { - let db_path = match database_path { - Some(p) => p.join("relayerdb"), - None => { - tracing::debug!("Using temp dir for store"); - return webb_relayer_store::SledStore::temporary().map_err(Into::into) - }, - }; - - webb_relayer_store::SledStore::open(db_path).map_err(Into::into) -} - -/// Post process the relayer configuration. -/// -/// - if there is no signer for any EVM chain, set the signer to the ecdsa key from the -/// keystore. -/// - Ensures that governance relayer is always enabled. -fn post_process_config( - config: &mut webb_relayer_config::WebbRelayerConfig, - params: &Eth2LightClientParams, -) -> anyhow::Result<()> { - // Make sure governance relayer is always enabled - config.features.governance_relay = true; - let maybe_ecdsa_pair = get_ecdsa_pair(params.local_keystore.clone())?; - if maybe_ecdsa_pair.is_none() { - return Err(FailedToLoadKeys.into()) - } - let ecdsa_secret = maybe_ecdsa_pair.unwrap().to_raw_vec(); - // for each evm chain, if there is no signer, set the signer to the ecdsa key - for chain in config.evm.values_mut() { - if chain.private_key.is_none() { - chain.private_key = Some(Secret::from_slice(&ecdsa_secret).into()) - } - } - Ok(()) -} - -fn get_ecdsa_pair(local_keystore: Arc) -> anyhow::Result> { - let maybe_ecdsa_public = local_keystore - .ecdsa_public_keys(dkg_runtime_primitives::KEY_TYPE) - .into_iter() - .find_map(|public_key| crypto::Public::from_slice(&public_key.0).ok()); - - if maybe_ecdsa_public.is_none() { - return Err(FailedToLoadKeys.into()) - } - local_keystore - .key_pair::(&maybe_ecdsa_public.unwrap()) - .map_err(Into::into) -} diff --git a/node/src/cli.rs b/node/src/cli.rs index c0946c1b..12c26700 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -9,7 +9,7 @@ pub struct Cli { pub run: RunCmd, #[clap(flatten)] - pub relayer_cmd: pallet_eth2_light_client_relayer_gadget_cli::RelayerCmd, + pub relayer_cmd: pallet_eth2_light_client_relayer_gadget_cli::LightClientRelayerCmd, } #[derive(Debug, clap::Subcommand)] diff --git a/node/src/service.rs b/node/src/service.rs index cf6e1e13..60701095 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -142,7 +142,7 @@ pub fn new_partial( /// Builds a new service for a full client. pub fn new_full( config: Configuration, - relayer_cmd: pallet_eth2_light_client_relayer_gadget_cli::RelayerCmd, + relayer_cmd: pallet_eth2_light_client_relayer_gadget_cli::LightClientRelayerCmd, ) -> Result { let sc_service::PartialComponents { client, @@ -155,10 +155,6 @@ pub fn new_full( other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; - let rpc_addr = config.rpc_addr; - let database = &config.database; - let database_path = database.path().and_then(|path| path.parent()).map(|p| p.to_path_buf()); - let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( @@ -294,12 +290,8 @@ pub fn new_full( None, pallet_eth2_light_client_relayer_gadget::start_gadget( pallet_eth2_light_client_relayer_gadget::Eth2LightClientParams { - local_keystore: keystore_container.local_keystore(), - ew_config_dir: relayer_cmd.relayer_config_dir.clone(), lc_relay_config_path: relayer_cmd.light_client_relay_config_path.clone(), lc_init_config_path: relayer_cmd.light_client_init_pallet_config_path.clone(), - database_path: database_path.clone(), - rpc_addr, eth2_chain_id: TypedChainId::Evm(1), }, ),