Skip to content

Commit

Permalink
Improve diamond proxy addr getter
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Aug 8, 2024
1 parent 262a071 commit a48f918
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
23 changes: 10 additions & 13 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,13 +1311,18 @@ impl ExternalNodeConfig<()> {
let remote = RemoteENConfig::fetch(main_node_client)
.await
.context("Unable to fetch required config values from the main node")?;
let remote_diamond_proxy_addr = remote.diamond_proxy_addr;
if let Some(local_diamond_proxy_addr) = self.optional.contracts_diamond_proxy_addr {
let remote_diamond_proxy_addr = remote.diamond_proxy_addr;
anyhow::ensure!(
local_diamond_proxy_addr == remote_diamond_proxy_addr,
"Diamond proxy address {local_diamond_proxy_addr:?} specified in config doesn't match one returned \
by main node ({remote_diamond_proxy_addr:?})"
);
} else {
tracing::info!(
"Diamond proxy address is not specified in config; will use address \
returned by main node: {remote_diamond_proxy_addr:?}"
);
}
Ok(ExternalNodeConfig {
required: self.required,
Expand Down Expand Up @@ -1355,18 +1360,10 @@ impl ExternalNodeConfig {
/// If local configuration contains the address, it will be checked against the one returned by the main node.
/// Otherwise, the remote value will be used. However, using remote value has trust implications for the main
/// node so relying on it solely is not recommended.
pub fn diamond_proxy_address(&self) -> anyhow::Result<Address> {
let remote_diamond_proxy_addr = self.remote.diamond_proxy_addr;
let diamond_proxy_addr = if let Some(addr) = self.optional.contracts_diamond_proxy_addr {
addr
} else {
tracing::info!(
"Diamond proxy address is not specified in config; will use address \
returned by main node: {remote_diamond_proxy_addr:?}"
);
remote_diamond_proxy_addr
};
Ok(diamond_proxy_addr)
pub fn diamond_proxy_address(&self) -> Address {
self.optional
.contracts_diamond_proxy_addr
.unwrap_or(self.remote.diamond_proxy_addr)
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl ExternalNodeBuilder {

fn add_l1_batch_commitment_mode_validation_layer(mut self) -> anyhow::Result<Self> {
let layer = L1BatchCommitmentModeValidationLayer::new(
self.config.diamond_proxy_address()?,
self.config.diamond_proxy_address(),
self.config.optional.l1_batch_commit_data_generator_mode,
);
self.node.add_layer(layer);
Expand All @@ -279,7 +279,7 @@ impl ExternalNodeBuilder {
fn add_consistency_checker_layer(mut self) -> anyhow::Result<Self> {
let max_batches_to_recheck = 10; // TODO (BFT-97): Make it a part of a proper EN config
let layer = ConsistencyCheckerLayer::new(
self.config.diamond_proxy_address()?,
self.config.diamond_proxy_address(),
max_batches_to_recheck,
self.config.optional.l1_batch_commit_data_generator_mode,
);
Expand All @@ -306,7 +306,7 @@ impl ExternalNodeBuilder {
}

fn add_tree_data_fetcher_layer(mut self) -> anyhow::Result<Self> {
let layer = TreeDataFetcherLayer::new(self.config.diamond_proxy_address()?);
let layer = TreeDataFetcherLayer::new(self.config.diamond_proxy_address());
self.node.add_layer(layer);
Ok(self)
}
Expand Down
8 changes: 4 additions & 4 deletions core/bin/external_node/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn external_node_basics(components_str: &'static str) {

let expected_health_components = utils::expected_health_components(&env.components);
let l2_client = utils::mock_l2_client(&env);
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address().unwrap());
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address());

let node_handle = tokio::task::spawn_blocking(move || {
std::thread::spawn(move || {
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn node_reacts_to_stop_signal_during_initial_reorg_detection() {
let (env, env_handles) = utils::TestEnvironment::with_genesis_block("core").await;

let l2_client = utils::mock_l2_client_hanging();
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address().unwrap());
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address());

let mut node_handle = tokio::task::spawn_blocking(move || {
std::thread::spawn(move || {
Expand Down Expand Up @@ -132,7 +132,7 @@ async fn running_tree_without_core_is_not_allowed() {
let (env, _env_handles) = utils::TestEnvironment::with_genesis_block("tree").await;

let l2_client = utils::mock_l2_client(&env);
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address().unwrap());
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address());

let node_handle = tokio::task::spawn_blocking(move || {
std::thread::spawn(move || {
Expand Down Expand Up @@ -169,7 +169,7 @@ async fn running_tree_api_without_tree_is_not_allowed() {
let (env, _env_handles) = utils::TestEnvironment::with_genesis_block("core,tree_api").await;

let l2_client = utils::mock_l2_client(&env);
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address().unwrap());
let eth_client = utils::mock_eth_client(env.config.diamond_proxy_address());

let node_handle = tokio::task::spawn_blocking(move || {
std::thread::spawn(move || {
Expand Down

0 comments on commit a48f918

Please sign in to comment.