Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Code cleanup and update metadata (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
salman01zp authored Sep 12, 2023
1 parent f9e77b5 commit cb2c939
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 144 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions gadget/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>,

#[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<PathBuf>,
Expand Down
3 changes: 0 additions & 3 deletions gadget/config/README.md

This file was deleted.

42 changes: 0 additions & 42 deletions gadget/config/simple.toml

This file was deleted.

82 changes: 1 addition & 81 deletions gadget/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<LocalKeystore>,
/// Event watching relayer configuration directory
pub ew_config_dir: Option<PathBuf>,
/// Light client relayer configuration path
pub lc_relay_config_path: Option<PathBuf>,
/// Light client init pallet configuration path
pub lc_init_config_path: Option<PathBuf>,
/// Database path
pub database_path: Option<PathBuf>,
/// RPC address, `None` if disabled.
pub rpc_addr: Option<SocketAddr>,
/// Eth2 Chain Identifier
pub eth2_chain_id: TypedChainId,
}
Expand Down Expand Up @@ -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<webb_relayer_config::WebbRelayerConfig> {
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,
Expand All @@ -112,57 +86,3 @@ fn loads_light_client_pallet_init_config(
) -> anyhow::Result<eth2_pallet_init::config::Config> {
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<PathBuf>,
) -> anyhow::Result<webb_relayer_store::SledStore> {
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<LocalKeystore>) -> anyhow::Result<Option<crypto::Pair>> {
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::<crypto::Pair>(&maybe_ecdsa_public.unwrap())
.map_err(Into::into)
}
2 changes: 1 addition & 1 deletion node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
10 changes: 1 addition & 9 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskManager, ServiceError> {
let sc_service::PartialComponents {
client,
Expand All @@ -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(
Expand Down Expand Up @@ -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),
},
),
Expand Down

0 comments on commit cb2c939

Please sign in to comment.