Better validation of signers during config parsing (#2139)

### Description

This improves the validation during config parsing to ensure that all
the expected signers are configured which means the errors will have the
correct config path.

### Drive-by changes

Also updated the checks for missing chain configurations to be more
clear and use the chain config path rather than the config that
indicated the config was required and removes a now redundant check.

### Related issues

- Fixes #2101

### Backward compatibility

_Are these changes backward compatible?_

Yes

_Are there any infrastructure implications, e.g. changes that would
prohibit deploying older commits using this infra tooling?_

None


### Testing

_What kind of testing have these changes undergone?_

Manual
asaj/ci-try
Mattie Conover 2 years ago committed by GitHub
parent 669a610c16
commit 3e5b20c88e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      rust/agents/relayer/src/relayer.rs
  2. 35
      rust/agents/relayer/src/settings/mod.rs
  3. 15
      rust/agents/scraper/src/agent.rs
  4. 11
      rust/agents/validator/src/settings.rs
  5. 8
      rust/hyperlane-core/src/config.rs

@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use eyre::{ensure, Result}; use eyre::Result;
use tokio::sync::{ use tokio::sync::{
mpsc::{self, UnboundedReceiver, UnboundedSender}, mpsc::{self, UnboundedReceiver, UnboundedSender},
RwLock, RwLock,
@ -64,14 +64,6 @@ impl BaseAgent for Relayer {
let core = settings.build_hyperlane_core(metrics.clone()); let core = settings.build_hyperlane_core(metrics.clone());
let db = DB::from_path(&settings.db)?; let db = DB::from_path(&settings.db)?;
for dest_chain in &settings.destination_chains {
let Ok(cfg) = settings.chain_setup(dest_chain) else { continue };
ensure!(
cfg.signer.is_some(),
"Destination chain {dest_chain} does not have a configured signer"
)
}
// Use defined remote chains + the origin chain // Use defined remote chains + the origin chain
let domains = settings let domains = settings
.destination_chains .destination_chains

@ -273,24 +273,37 @@ impl FromRawConf<'_, RawRelayerSettings> for RelayerSettings {
.parse_config_with_filter::<Settings>(cwp, Some(&chain_filter)) .parse_config_with_filter::<Settings>(cwp, Some(&chain_filter))
.take_config_err(&mut err); .take_config_err(&mut err);
let destination_chains = if let Some(base) = &base { // validate all destination chains are present and get their HyperlaneDomain.
let destination_chains = base
.as_ref()
.map(|base| {
destination_chain_names destination_chain_names
.iter() .iter()
.filter_map(|destination| { .filter_map(|destination| {
base.lookup_domain(destination) base.lookup_domain(destination)
.take_err(&mut err, || cwp + "destinationchainnames") .context("Missing configuration for a destination chain")
.take_err(&mut err, || cwp + "chains" + destination)
}) })
.collect() .collect::<Vec<_>>()
} else { })
vec![] .unwrap_or_default();
};
let origin_chain = if let Some(base) = &base { if let Some(base) = &base {
for domain in destination_chains.iter() {
base.chain_setup(domain)
.unwrap()
.signer
.as_ref()
.ok_or_else(|| eyre!("Signer is required for destination chains"))
.take_err(&mut err, || cwp + "chains" + domain.name() + "signer");
}
}
let origin_chain = base.as_ref().and_then(|base| {
base.lookup_domain(&origin_chain_name) base.lookup_domain(&origin_chain_name)
.take_err(&mut err, || cwp + "originchainname") .context("Missing configuration for the origin chain")
} else { .take_err(&mut err, || cwp + "chains" + &origin_chain_name)
None });
};
err.into_result()?; err.into_result()?;
Ok(Self { Ok(Self {

@ -3,6 +3,7 @@ use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use eyre::{eyre, WrapErr}; use eyre::{eyre, WrapErr};
use itertools::Itertools;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tracing::{info_span, instrument::Instrumented, trace, Instrument}; use tracing::{info_span, instrument::Instrumented, trace, Instrument};
@ -67,17 +68,19 @@ impl FromRawConf<'_, RawScraperSettings> for ScraperSettings {
) )
.take_config_err(&mut err); .take_config_err(&mut err);
let chains_to_scrape = if let Some(base) = &base { let chains_to_scrape = base
.as_ref()
.map(|base| {
chains_to_scrape chains_to_scrape
.iter() .iter()
.filter_map(|chain| { .filter_map(|chain| {
base.lookup_domain(chain) base.lookup_domain(chain)
.take_err(&mut err, || cwp + "chainstoscrape") .context("Missing configuration for a chain in `chainstoscrape`")
.take_err(&mut err, || cwp + "chains" + chain)
}) })
.collect() .collect_vec()
} else { })
vec![] .unwrap_or_default();
};
err.into_result()?; err.into_result()?;
Ok(Self { Ok(Self {

@ -2,7 +2,7 @@
use std::time::Duration; use std::time::Duration;
use eyre::eyre; use eyre::{eyre, Context};
use hyperlane_base::{ use hyperlane_base::{
decl_settings, CheckpointSyncerConf, RawCheckpointSyncerConf, RawSignerConf, Settings, decl_settings, CheckpointSyncerConf, RawCheckpointSyncerConf, RawSignerConf, Settings,
@ -91,12 +91,11 @@ impl FromRawConf<'_, RawValidatorSettings> for ValidatorSettings {
) )
.take_config_err(&mut err); .take_config_err(&mut err);
let origin_chain = if let Some(base) = &base { let origin_chain = base.as_ref().and_then(|base| {
base.lookup_domain(&origin_chain_name) base.lookup_domain(&origin_chain_name)
.take_err(&mut err, || cwp + "originchainname") .context("Missing configuration for the origin chain")
} else { .take_err(&mut err, || cwp + "chains" + &origin_chain_name)
None });
};
err.into_result()?; err.into_result()?;
Ok(Self { Ok(Self {

@ -90,6 +90,14 @@ impl<S: Into<String>> Add<S> for &ConfigPath {
} }
} }
impl<S: Into<String>> Add<S> for ConfigPath {
type Output = ConfigPath;
fn add(self, rhs: S) -> Self::Output {
self.join(rhs)
}
}
impl Add<ConfigPath> for &ConfigPath { impl Add<ConfigPath> for &ConfigPath {
type Output = ConfigPath; type Output = ConfigPath;

Loading…
Cancel
Save