-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bootstrap relayer gadget * integrated the relayer gadget into the node * add example config and it works * fix the gmp linking * fix linking on macos with nix * improve the code * Update relayer to v0.5.6-dev
- Loading branch information
Showing
13 changed files
with
4,008 additions
and
701 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "webb-relayer-gadget" | ||
version = "0.0.1" | ||
authors = ["Webb Developers <[email protected]>", "Shady Khalifa <[email protected]>"] | ||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
tracing = { workspace = true } | ||
ethereum-types = { workspace = true } | ||
|
||
# Substrate | ||
sp-application-crypto = { workspace = true } | ||
sp-keystore = { workspace = true } | ||
sc-keystore = { workspace = true } | ||
|
||
# Relayer | ||
webb-relayer = { git = "https://github.com/webb-tools/relayer", tag = "v0.5.6-dev" } | ||
webb-relayer-context = { git = "https://github.com/webb-tools/relayer", tag = "v0.5.6-dev" } | ||
webb-relayer-config = { git = "https://github.com/webb-tools/relayer", tag = "v0.5.6-dev" } | ||
webb-relayer-store = { git = "https://github.com/webb-tools/relayer", tag = "v0.5.6-dev" } | ||
webb-relayer-types = { git = "https://github.com/webb-tools/relayer", tag = "v0.5.6-dev" } | ||
|
||
# DKG | ||
dkg-runtime-primitives = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "webb-relayer-gadget-cli" | ||
version = "0.0.1" | ||
authors = ["Webb Developers <[email protected]>", "Shady Khalifa <[email protected]>"] | ||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
clap = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::path::PathBuf; | ||
|
||
/// Cli tool to interact with Webb Relayer CLI | ||
#[derive(Debug, Clone, clap::Parser)] | ||
#[clap(next_help_heading = "Webb Relayer")] | ||
pub struct WebbRelayerCmd { | ||
/// Directory that contains configration files for the relayer. | ||
#[arg(long, value_name = "PATH")] | ||
pub relayer_config_dir: Option<PathBuf>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Configuration Examples | ||
|
||
This directory contains a very simple and minimal configuration for starting a Private Transaction Relayer over the Gorli Testnet. This configuration is used for testing and for demonstration purposes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
//! Webb Relayer Gadget | ||
//! | ||
//! Integrates the Webb Relayer into the Substrate Node. | ||
use dkg_runtime_primitives::crypto; | ||
use ethereum_types::Secret; | ||
use sc_keystore::LocalKeystore; | ||
use sp_application_crypto::{ecdsa, ByteArray, CryptoTypePublicPair, Pair}; | ||
use sp_keystore::SyncCryptoStore; | ||
use std::{net::SocketAddr, path::PathBuf, sync::Arc}; | ||
use webb_relayer::service; | ||
use webb_relayer_context::RelayerContext; | ||
|
||
/// Webb Relayer gadget initialization parameters. | ||
pub struct WebbRelayerParams { | ||
/// Concrete local key store | ||
pub local_keystore: Option<Arc<LocalKeystore>>, | ||
/// Configuration directory | ||
pub config_dir: Option<PathBuf>, | ||
/// Database path | ||
pub database_path: Option<PathBuf>, | ||
/// RPC HTTP address, `None` if disabled. | ||
pub rpc_http: Option<SocketAddr>, | ||
/// RPC WebSocket address, `None` if disabled. | ||
pub rpc_ws: Option<SocketAddr>, | ||
} | ||
|
||
pub async fn start_relayer_gadget(relayer_params: WebbRelayerParams) { | ||
let mut config = match relayer_params.config_dir.as_ref() { | ||
Some(p) => load_config(p).expect("failed to load relayer config"), | ||
None => { | ||
tracing::error!( | ||
target: "relayer-gadget", | ||
"Error: Not Starting Webb Relayer Gadget. No Config Directory Specified" | ||
); | ||
return | ||
}, | ||
}; | ||
|
||
post_process_config(&mut config, &relayer_params) | ||
.expect("failed to post process relayer config"); | ||
|
||
let store = create_store(relayer_params.database_path).expect("failed to create relayer store"); | ||
let ctx = RelayerContext::new(config, store.clone()).expect("failed to build relayer context"); | ||
|
||
// Start the web server: | ||
service::build_web_services(ctx.clone()) | ||
.await | ||
.expect("failed to build relayer web services"); | ||
service::ignite(ctx, Arc::new(store)) | ||
.await | ||
.expect("failed to ignite relayer services"); | ||
} | ||
|
||
/// Loads the configuration from the given directory. | ||
fn load_config( | ||
config_dir: &PathBuf, | ||
) -> Result<webb_relayer_config::WebbRelayerConfig, Box<dyn std::error::Error>> { | ||
if !config_dir.is_dir() { | ||
return Err("Config path is not a directory".into()) | ||
} | ||
|
||
Ok(webb_relayer_config::utils::load(config_dir)?) | ||
} | ||
|
||
/// Creates a database store for the relayer based on the configuration passed in. | ||
pub fn create_store( | ||
database_path: Option<PathBuf>, | ||
) -> Result<webb_relayer_store::SledStore, Box<dyn std::error::Error>> { | ||
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: &WebbRelayerParams, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
// Make sure governance relayer is always enabled | ||
config.features.governance_relay = true; | ||
let ecdsa_pair = get_ecdsa_pair(params.local_keystore.clone())?.ok_or("no ecdsa key found")?; | ||
let ecdsa_secret = ecdsa_pair.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: Option<Arc<LocalKeystore>>, | ||
) -> Result<Option<crypto::Pair>, Box<dyn std::error::Error>> { | ||
let local_key_store = local_keystore.expect("failed to get local keystore"); | ||
let ecdsa_public = local_key_store | ||
.keys(dkg_runtime_primitives::KEY_TYPE)? | ||
.into_iter() | ||
.find_map(|CryptoTypePublicPair(id, public_key)| { | ||
if id == ecdsa::CRYPTO_ID { | ||
crypto::Public::from_slice(&public_key).ok() | ||
} else { | ||
None | ||
} | ||
}) | ||
.ok_or("failed to get ecdsa public key")?; | ||
local_key_store.key_pair::<crypto::Pair>(&ecdsa_public).map_err(Into::into) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters