From c33862b155616bf55866c7793a68f7b8d07fa214 Mon Sep 17 00:00:00 2001 From: James Hiew Date: Tue, 30 Aug 2022 16:41:07 +0100 Subject: [PATCH 1/2] Add config for Ethereum interop --- apps/src/lib/config/ethereum.rs | 19 +++++++++++++++++++ apps/src/lib/config/mod.rs | 13 +++---------- apps/src/lib/node/ledger/mod.rs | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 apps/src/lib/config/ethereum.rs diff --git a/apps/src/lib/config/ethereum.rs b/apps/src/lib/config/ethereum.rs new file mode 100644 index 0000000000..7f4e9fafe5 --- /dev/null +++ b/apps/src/lib/config/ethereum.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +/// Default [Ethereum JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) endpoint used by the oracle +pub const DEFAULT_ORACLE_RPC_ENDPOINT: &str = "http://127.0.0.1:8545"; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Config { + /// The Ethereum JSON-RPC endpoint that the Ethereum event oracle will use + /// to listen for events from the Ethereum bridge smart contracts + pub oracle_rpc_endpoint: String, +} + +impl Default for Config { + fn default() -> Self { + Self { + oracle_rpc_endpoint: DEFAULT_ORACLE_RPC_ENDPOINT.to_owned(), + } + } +} diff --git a/apps/src/lib/config/mod.rs b/apps/src/lib/config/mod.rs index edf13cbeff..35ddc76842 100644 --- a/apps/src/lib/config/mod.rs +++ b/apps/src/lib/config/mod.rs @@ -1,5 +1,6 @@ //! Node and client configuration +pub mod ethereum; pub mod genesis; pub mod global; pub mod utils; @@ -38,8 +39,6 @@ pub const FILENAME: &str = "config.toml"; pub const TENDERMINT_DIR: &str = "tendermint"; /// Chain-specific Anoma DB. Nested in chain dirs. pub const DB_DIR: &str = "db"; -/// Websocket address for Ethereum fullnode RPC -pub const ETHEREUM_URL: &str = "http://127.0.0.1:8545"; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Config { @@ -84,6 +83,7 @@ pub struct Ledger { pub chain_id: ChainId, pub shell: Shell, pub tendermint: Tendermint, + pub ethereum: ethereum::Config, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -103,8 +103,6 @@ pub struct Shell { db_dir: PathBuf, /// Use the [`Ledger::tendermint_dir()`] method to read the value. tendermint_dir: PathBuf, - /// Use the [`Ledger::ethereum_url()`] method to read the value. - ethereum_url: String, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -176,7 +174,6 @@ impl Ledger { tx_wasm_compilation_cache_bytes: None, db_dir: DB_DIR.into(), tendermint_dir: TENDERMINT_DIR.into(), - ethereum_url: ETHEREUM_URL.into(), }, tendermint: Tendermint { rpc_address: SocketAddr::new( @@ -200,6 +197,7 @@ impl Ledger { ), instrumentation_namespace: "anoman_tm".to_string(), }, + ethereum: ethereum::Config::default(), } } @@ -217,11 +215,6 @@ impl Ledger { pub fn tendermint_dir(&self) -> PathBuf { self.shell.tendermint_dir(&self.chain_id) } - - /// Get the websocket url for the Ethereum fullnode - pub fn ethereum_url(&self) -> String { - self.shell.ethereum_url.clone() - } } impl Shell { diff --git a/apps/src/lib/node/ledger/mod.rs b/apps/src/lib/node/ledger/mod.rs index b1c0d4f2e6..16896fa143 100644 --- a/apps/src/lib/node/ledger/mod.rs +++ b/apps/src/lib/node/ledger/mod.rs @@ -305,7 +305,7 @@ async fn run_aux(config: config::Ledger, wasm_dir: PathBuf) { let (broadcaster_sender, broadcaster_receiver) = tokio::sync::mpsc::unbounded_channel(); - let ethereum_url = config.ethereum_url(); + let ethereum_url = config.ethereum.oracle_rpc_endpoint.clone(); let (ethereum_node, oracle, broadcaster) = if matches!( config.tendermint.tendermint_mode, TendermintMode::Validator From 956ee9c4af00fb68ef82fc13d1bdeff4ad7358d6 Mon Sep 17 00:00:00 2001 From: James Hiew Date: Fri, 2 Sep 2022 10:09:15 +0100 Subject: [PATCH 2/2] Log the Ethereum endpoint being used in more places --- apps/src/lib/node/ledger/ethereum_node/mod.rs | 4 +++- apps/src/lib/node/ledger/ethereum_node/oracle.rs | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/src/lib/node/ledger/ethereum_node/mod.rs b/apps/src/lib/node/ledger/ethereum_node/mod.rs index 39b6d282af..3ded71765b 100644 --- a/apps/src/lib/node/ledger/ethereum_node/mod.rs +++ b/apps/src/lib/node/ledger/ethereum_node/mod.rs @@ -141,15 +141,17 @@ pub mod eth_fullnode { let client = Web3::new(url, CLIENT_TIMEOUT); const SLEEP_DUR: Duration = Duration::from_secs(1); + tracing::info!(?url, "Checking Geth status"); loop { if let Ok(false) = client.eth_syncing().await { - tracing::info!("Finished syncing"); + tracing::info!(?url, "Finished syncing"); break; } if let Err(error) = client.eth_syncing().await { // This is very noisy and usually not interesting. // Still can be very useful tracing::debug!( + ?url, ?error, "Couldn't check Geth sync status" ); diff --git a/apps/src/lib/node/ledger/ethereum_node/oracle.rs b/apps/src/lib/node/ledger/ethereum_node/oracle.rs index 144f89a7af..2ed1944e25 100644 --- a/apps/src/lib/node/ledger/ethereum_node/oracle.rs +++ b/apps/src/lib/node/ledger/ethereum_node/oracle.rs @@ -101,12 +101,16 @@ pub mod oracle_process { rt.block_on(async move { LocalSet::new() .run_until(async move { - tracing::info!("Ethereum event oracle is starting"); + tracing::info!( + ?url, + "Ethereum event oracle is starting" + ); let oracle = Oracle::new(&url, sender, abort_sender); run_oracle_aux(oracle).await; tracing::info!( + ?url, "Ethereum event oracle is no longer running" ); })