Skip to content

Commit

Permalink
Add Ethereum bridge chain parameters + refactor runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Oct 14, 2022
1 parent 12ca4da commit 6953a81
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Configuration settings to do with the Ethereum bridge.
//! Runtime configuration for a validator node
#[allow(unused_imports)]
use namada::types::ethereum_events::EthereumEvent;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -28,7 +28,8 @@ pub enum Mode {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
/// The mode in which to run the Ethereum bridge
/// The mode in which to run the Ethereum node and oracle setup of this
/// validator
pub mode: Mode,
/// The Ethereum JSON-RPC endpoint that the Ethereum event oracle will use
/// to listen for events from the Ethereum bridge smart contracts
Expand Down
2 changes: 2 additions & 0 deletions apps/src/lib/config/ethereum_bridge/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod ledger;
pub mod params;
22 changes: 22 additions & 0 deletions apps/src/lib/config/ethereum_bridge/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Blockchain-level parameters for the configuration of the Ethereum bridge.
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config {
/// Minimum number of confirmations needed to trust an Ethereum branch.
/// This must be at least one.
pub min_confirmations: u64,
/// The addresses of the Ethereum contracts that need to be directly known
/// by validators
pub contract_addresses: Addresses,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Addresses {
/// The Ethereum address of the proxy contract e.g.
/// 0x6B175474E89094C44Da98b954EedeAC495271d0F
pub proxy: String,
/// The Ethereum address of the ERC20 contract that represents this chain's
/// native token e.g. 0x6B175474E89094C44Da98b954EedeAC495271d0F
pub native_erc20: String,
}
3 changes: 3 additions & 0 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod genesis_config {
EstablishedAccount, Genesis, ImplicitAccount, TokenAccount, Validator,
};
use crate::cli;
use crate::config::ethereum_bridge;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HexString(pub String);
Expand Down Expand Up @@ -121,6 +122,8 @@ pub mod genesis_config {
pub gov_params: GovernanceParamsConfig,
// Treasury parameters
pub treasury_params: TreasuryParamasConfig,
// Ethereum bridge config
pub ethereum_bridge_params: Option<ethereum_bridge::params::Config>,
// Wasm definitions
pub wasm: HashMap<String, WasmConfig>,
}
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Node and client configuration
pub mod ethereum;
pub mod ethereum_bridge;
pub mod genesis;
pub mod global;
pub mod utils;
Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct Ledger {
pub chain_id: ChainId,
pub shell: Shell,
pub tendermint: Tendermint,
pub ethereum: ethereum::Config,
pub ethereum_bridge: ethereum_bridge::ledger::Config,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -197,7 +197,7 @@ impl Ledger {
),
instrumentation_namespace: "anoman_tm".to_string(),
},
ethereum: ethereum::Config::default(),
ethereum_bridge: ethereum_bridge::ledger::Config::default(),
}
}

Expand Down
19 changes: 11 additions & 8 deletions apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tower::ServiceBuilder;
use self::abortable::AbortableSpawner;
use self::shims::abcipp_shim::AbciService;
use crate::config::utils::num_of_threads;
use crate::config::{ethereum, TendermintMode};
use crate::config::{ethereum_bridge, TendermintMode};
use crate::facade::tendermint_proto::abci::CheckTxType;
use crate::facade::tower_abci::{response, split, Server};
use crate::node::ledger::broadcaster::Broadcaster;
Expand Down Expand Up @@ -623,11 +623,13 @@ async fn start_ethereum_node(
return (eth_node, None, oracle);
}

let ethereum_url = config.ethereum.oracle_rpc_endpoint.clone();
let ethereum_url = config.ethereum_bridge.oracle_rpc_endpoint.clone();

// Boot up geth and wait for it to finish syncing
let start_managed_eth_node =
matches!(config.ethereum.mode, ethereum::Mode::Managed);
let start_managed_eth_node = matches!(
config.ethereum_bridge.mode,
ethereum_bridge::ledger::Mode::Managed
);
let (eth_node, abort_sender) =
ethereum_node::start(&ethereum_url, start_managed_eth_node)
.await
Expand Down Expand Up @@ -665,21 +667,22 @@ async fn start_ethereum_node(

// Start the oracle for listening to Ethereum events
let (eth_sender, eth_receiver) = mpsc::channel(ORACLE_CHANNEL_BUFFER_SIZE);
let oracle = match config.ethereum.mode {
ethereum::Mode::Managed | ethereum::Mode::Remote => {
let oracle = match config.ethereum_bridge.mode {
ethereum_bridge::ledger::Mode::Managed
| ethereum_bridge::ledger::Mode::Remote => {
ethereum_node::oracle::run_oracle(
ethereum_url,
eth_sender,
abort_sender,
)
}
ethereum::Mode::EventsEndpoint => {
ethereum_bridge::ledger::Mode::EventsEndpoint => {
ethereum_node::test_tools::events_endpoint::serve(
eth_sender,
abort_sender,
)
}
ethereum::Mode::Off => {
ethereum_bridge::ledger::Mode::Off => {
ethereum_node::test_tools::mock_oracle::run_oracle(
ethereum_url,
eth_sender,
Expand Down

0 comments on commit 6953a81

Please sign in to comment.