Skip to content

Commit

Permalink
Standardize terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Aug 3, 2022
1 parent a340131 commit 87ae736
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
2 changes: 1 addition & 1 deletion apps/src/lib/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub const TENDERMINT_DIR: &str = "tendermint";
pub const DB_DIR: &str = "db";
/// Relevant to validator nodes only. If provided, the ledger will monitor for
/// new Ethereum events via this endpoint rather than via a `geth` subprocess.
pub const ENV_VAR_ETHEREUM_ENDPOINT: &str = "ANOMA_ETHEREUM_ENDPOINT";
pub const ENV_VAR_ETHEREUM_URL: &str = "ANOMA_ETHEREUM_URL";
/// Websocket address for Ethereum fullnode RPC
pub const ETHEREUM_URL: &str = "http://127.0.0.1:8545";

Expand Down
104 changes: 51 additions & 53 deletions apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tower_abci_old::{response, split, Server};

use self::shims::abcipp_shim::AbciService;
use crate::config::utils::num_of_threads;
use crate::config::{TendermintMode, ENV_VAR_ETHEREUM_ENDPOINT};
use crate::config::{TendermintMode, ENV_VAR_ETHEREUM_URL};
use crate::node::ledger::broadcaster::Broadcaster;
use crate::node::ledger::shell::{Error, MempoolTxType, Shell};
use crate::node::ledger::shims::abcipp_shim::AbcippShim;
Expand Down Expand Up @@ -319,60 +319,58 @@ async fn run_aux(config: config::Ledger, wasm_dir: PathBuf) {
let abort_send_for_eth = abort_send.clone();
let (eth_abort_send, eth_abort_recv) =
tokio::sync::oneshot::channel::<tokio::sync::oneshot::Sender<()>>();
let ethereum_endpoint = std::env::var(ENV_VAR_ETHEREUM_ENDPOINT).ok();
let (ethereum_url, ethereum_node, abort_sender) =
match ethereum_endpoint {
Some(ethereum_endpoint) => {
tracing::info!(
%ethereum_endpoint,
"Ethereum endpoint provided in environment, will not start geth"
);
// we return a dummy join handle and sender, so we can share
// logic further down this function with how we'd normally
// handle a `geth` subprocess
let handle = tokio::spawn(async { Ok(()) });
let (abort_sender, _) = tokio::sync::oneshot::channel();
(ethereum_endpoint, handle, abort_sender)
}
None => {
let ethereum_url = config.ethereum_url();
tracing::info!(
%ethereum_url,
"No Ethereum URL provided in configuration, starting geth",
);
let url = ethereum_url.clone();
// boot up the ethereum node process
let (ethereum_node, abort_sender) = local
.run_until(async move {
EthereumNode::new(&url)
.await
.expect("Unable to start the Ethereum fullnode")
})
// we want any Ethereum endpoint set in the environment to override the
// one set in the config
let ethereum_url = std::env::var(ENV_VAR_ETHEREUM_URL).ok();
let (ethereum_url, ethereum_node, abort_sender) = match ethereum_url {
Some(ethereum_url) => {
tracing::info!(
%ethereum_url,
"Ethereum URL provided in environment, will not start geth"
);
// we return a dummy join handle and sender, so we can share
// logic further down this function with how we'd normally
// handle a `geth` subprocess
let handle = tokio::spawn(async { Ok(()) });
let (abort_sender, _) = tokio::sync::oneshot::channel();
(ethereum_url, handle, abort_sender)
}
None => {
let ethereum_url = config.ethereum_url();
tracing::info!(
%ethereum_url,
"No Ethereum URL provided in configuration, starting geth",
);
let url = ethereum_url.clone();
// boot up the ethereum node process
let (ethereum_node, abort_sender) = local
.run_until(async move {
EthereumNode::new(&url)
.await
.expect("Unable to start the Ethereum fullnode")
})
.await;

// run geth in the background
let handle = tokio::spawn(async move {
// On panic or exit, the `Drop` of `AbortSender` will
// send abort message
let aborter = Aborter {
sender: abort_send_for_eth,
who: "Ethereum",
};

let res = ethereum_node::run(ethereum_node, eth_abort_recv)
.map_err(Error::Ethereum)
.await;
tracing::info!("Ethereum fullnode is no longer running.");

// run geth in the background
let handle = tokio::spawn(async move {
// On panic or exit, the `Drop` of `AbortSender` will
// send abort message
let aborter = Aborter {
sender: abort_send_for_eth,
who: "Ethereum",
};

let res =
ethereum_node::run(ethereum_node, eth_abort_recv)
.map_err(Error::Ethereum)
.await;
tracing::info!(
"Ethereum fullnode is no longer running."
);

drop(aborter);
res
});
(ethereum_url, handle, abort_sender)
}
};
drop(aborter);
res
});
(ethereum_url, handle, abort_sender)
}
};

let (event_sender, event_receiver) = unbounded_channel();
let oracle = local.spawn_local(async move {
Expand Down

0 comments on commit 87ae736

Please sign in to comment.