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. 45
      rust/agents/relayer/src/settings/mod.rs
  3. 25
      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 async_trait::async_trait;
use eyre::{ensure, Result};
use eyre::Result;
use tokio::sync::{
mpsc::{self, UnboundedReceiver, UnboundedSender},
RwLock,
@ -64,14 +64,6 @@ impl BaseAgent for Relayer {
let core = settings.build_hyperlane_core(metrics.clone());
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
let domains = settings
.destination_chains

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

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

@ -2,7 +2,7 @@
use std::time::Duration;
use eyre::eyre;
use eyre::{eyre, Context};
use hyperlane_base::{
decl_settings, CheckpointSyncerConf, RawCheckpointSyncerConf, RawSignerConf, Settings,
@ -91,12 +91,11 @@ impl FromRawConf<'_, RawValidatorSettings> for ValidatorSettings {
)
.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)
.take_err(&mut err, || cwp + "originchainname")
} else {
None
};
.context("Missing configuration for the origin chain")
.take_err(&mut err, || cwp + "chains" + &origin_chain_name)
});
err.into_result()?;
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 {
type Output = ConfigPath;

Loading…
Cancel
Save