From 5d8a2e568cf5a9611c902541ef6966005715bf62 Mon Sep 17 00:00:00 2001 From: Mattie Conover Date: Tue, 8 Aug 2023 10:23:11 -0700 Subject: [PATCH] Validator announce signers (#2617) ### Description This handles a bug where we did not default the chain signer to the validator signature for EVM chains and also handles the case where we might try to announce without setting a chain signer for other chains. ### Drive-by changes Not really a change but I looked into #2457 and I noticed the validators already check that signers are set for all destination chains so I think the error was just for validators which this PR fixes. ### Related issues - Fixes #2458 - Fixes #2457 ### Backward compatibility Yes ### Testing Unit Tests --- rust/agents/validator/src/settings.rs | 25 ++++++++++++++++++++----- rust/agents/validator/src/validator.rs | 8 ++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/rust/agents/validator/src/settings.rs b/rust/agents/validator/src/settings.rs index ffb3906f8..fe659e312 100644 --- a/rust/agents/validator/src/settings.rs +++ b/rust/agents/validator/src/settings.rs @@ -10,7 +10,7 @@ use hyperlane_base::{ SignerConf, }; use hyperlane_core::config::*; -use hyperlane_core::HyperlaneDomain; +use hyperlane_core::{HyperlaneDomain, HyperlaneDomainProtocol}; decl_settings!(Validator, Parsed { @@ -54,7 +54,7 @@ impl FromRawConf<'_, RawValidatorSettings> for ValidatorSettings { let validator = raw .validator - .parse_config(&cwp.join("validator")) + .parse_config::(&cwp.join("validator")) .take_config_err(&mut err); let checkpoint_syncer = raw @@ -112,11 +112,26 @@ impl FromRawConf<'_, RawValidatorSettings> for ValidatorSettings { }); err.into_result()?; + + let mut base = base.unwrap(); + let origin_chain = origin_chain.unwrap(); + let validator = validator.unwrap(); + + if origin_chain.domain_protocol() == HyperlaneDomainProtocol::Ethereum { + // if an EVM chain we can assume the chain signer is the validator signer when not + // specified + base.chains + .get_mut(origin_chain.name()) + .unwrap() + .signer + .get_or_insert_with(|| validator.clone()); + } + Ok(Self { - base: base.unwrap(), + base, db, - origin_chain: origin_chain.unwrap(), - validator: validator.unwrap(), + origin_chain, + validator, checkpoint_syncer: checkpoint_syncer.unwrap(), reorg_period: reorg_period.unwrap(), interval, diff --git a/rust/agents/validator/src/validator.rs b/rust/agents/validator/src/validator.rs index 5960ab00a..7d302c085 100644 --- a/rust/agents/validator/src/validator.rs +++ b/rust/agents/validator/src/validator.rs @@ -226,6 +226,14 @@ impl Validator { } async fn announce(&self) -> Result<()> { + if self.core.settings.chains[self.origin_chain.name()] + .signer + .is_none() + { + warn!(origin_chain=%self.origin_chain, "Cannot announce validator without a signer; make sure a signer is set for the origin chain"); + return Ok(()); + } + // Sign and post the validator announcement let announcement = Announcement { validator: self.signer.eth_address(),