diff --git a/rust/main/agents/validator/src/settings.rs b/rust/main/agents/validator/src/settings.rs index 3d1245df1c..d464be5a92 100644 --- a/rust/main/agents/validator/src/settings.rs +++ b/rust/main/agents/validator/src/settings.rs @@ -125,7 +125,7 @@ impl FromRawConf for ValidatorSettings { .get_opt_key("blocks") .get_opt_key("reorgPeriod") .parse_value("Invalid reorgPeriod") - .unwrap_or(ReorgPeriod::from_number(1)); + .unwrap_or(ReorgPeriod::from_blocks(1)); cfg_unwrap_all!(cwp, err: [base, origin_chain, validator, checkpoint_syncer]); diff --git a/rust/main/agents/validator/src/submit.rs b/rust/main/agents/validator/src/submit.rs index 16629e3aca..5248ab7a35 100644 --- a/rust/main/agents/validator/src/submit.rs +++ b/rust/main/agents/validator/src/submit.rs @@ -617,7 +617,7 @@ mod test { &expected_local_merkle_tree, &mock_onchain_merkle_tree_clone, unix_timestamp, - ReorgPeriod::from_number(expected_reorg_period), + ReorgPeriod::from_blocks(expected_reorg_period), ); Ok(()) }); @@ -625,7 +625,7 @@ mod test { // instantiate the validator submitter let validator_submitter = ValidatorSubmitter::new( Duration::from_secs(1), - ReorgPeriod::from_number(expected_reorg_period), + ReorgPeriod::from_blocks(expected_reorg_period), Arc::new(mock_merkle_tree_hook), dummy_singleton_handle(), Arc::new(mock_checkpoint_syncer), diff --git a/rust/main/chains/hyperlane-cosmos/src/utils.rs b/rust/main/chains/hyperlane-cosmos/src/utils.rs index 91c5e96253..31213dd306 100644 --- a/rust/main/chains/hyperlane-cosmos/src/utils.rs +++ b/rust/main/chains/hyperlane-cosmos/src/utils.rs @@ -32,7 +32,7 @@ pub(crate) async fn get_block_height_for_lag( lag: &ReorgPeriod, ) -> ChainResult> { let block_height = if !lag.is_none() { - let lag = lag.as_number()?; + let lag = lag.as_blocks()?; let tip = provider.latest_block_height().await?; let block_height = tip - lag as u64; Some(block_height) diff --git a/rust/main/hyperlane-base/src/settings/chains.rs b/rust/main/hyperlane-base/src/settings/chains.rs index a665aa9d14..0e08b2d156 100644 --- a/rust/main/hyperlane-base/src/settings/chains.rs +++ b/rust/main/hyperlane-base/src/settings/chains.rs @@ -289,7 +289,7 @@ impl ChainConf { } ChainConnectionConf::Cosmos(conf) => { let signer = self.cosmos_signer().await.context(ctx)?; - let reorg_period = self.reorg_period.as_number().context(ctx)?; + let reorg_period = self.reorg_period.as_blocks().context(ctx)?; let indexer = Box::new(h_cosmos::CosmosMailboxDispatchIndexer::new( conf.clone(), locator, @@ -329,7 +329,7 @@ impl ChainConf { } ChainConnectionConf::Cosmos(conf) => { let signer = self.cosmos_signer().await.context(ctx)?; - let reorg_period = self.reorg_period.as_number().context(ctx)?; + let reorg_period = self.reorg_period.as_blocks().context(ctx)?; let indexer = Box::new(h_cosmos::CosmosMailboxDeliveryIndexer::new( conf.clone(), locator, @@ -412,7 +412,7 @@ impl ChainConf { Ok(indexer as Box>) } ChainConnectionConf::Cosmos(conf) => { - let reorg_period = self.reorg_period.as_number().context(ctx)?; + let reorg_period = self.reorg_period.as_blocks().context(ctx)?; let indexer = Box::new(h_cosmos::CosmosInterchainGasPaymasterIndexer::new( conf.clone(), locator, @@ -455,7 +455,7 @@ impl ChainConf { } ChainConnectionConf::Cosmos(conf) => { let signer = self.cosmos_signer().await.context(ctx)?; - let reorg_period = self.reorg_period.as_number().context(ctx)?; + let reorg_period = self.reorg_period.as_blocks().context(ctx)?; let indexer = Box::new(h_cosmos::CosmosMerkleTreeHookIndexer::new( conf.clone(), locator, diff --git a/rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs b/rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs index 7276d662b4..3434a7168a 100644 --- a/rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs +++ b/rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs @@ -209,7 +209,7 @@ mod test { .unwrap(); let dummy_checkpoint_index = 56; let unix_timestamp = 1620000000; - let reorg_period = ReorgPeriod::from_number(5); + let reorg_period = ReorgPeriod::from_blocks(5); let dummy_reorg_event = ReorgEvent { local_merkle_root: dummy_local_merkle_root, canonical_merkle_root: dummy_canonical_merkle_root, diff --git a/rust/main/hyperlane-base/src/settings/parser/mod.rs b/rust/main/hyperlane-base/src/settings/parser/mod.rs index 2b62910e96..7c608427bb 100644 --- a/rust/main/hyperlane-base/src/settings/parser/mod.rs +++ b/rust/main/hyperlane-base/src/settings/parser/mod.rs @@ -137,7 +137,7 @@ fn parse_chain( .get_opt_key("blocks") .get_key("reorgPeriod") .parse_value("Invalid reorgPeriod") - .unwrap_or(ReorgPeriod::from_number(1)); + .unwrap_or(ReorgPeriod::from_blocks(1)); let rpcs = parse_base_and_override_urls(&chain, "rpcUrls", "customRpcUrls", "http", &mut err); diff --git a/rust/main/hyperlane-core/src/chain.rs b/rust/main/hyperlane-core/src/chain.rs index 8772b9c787..042249686a 100644 --- a/rust/main/hyperlane-core/src/chain.rs +++ b/rust/main/hyperlane-core/src/chain.rs @@ -51,13 +51,13 @@ pub enum ReorgPeriod { } impl ReorgPeriod { - pub fn from_number(number: u32) -> Self { - NonZeroU32::try_from(number) + pub fn from_blocks(blocks: u32) -> Self { + NonZeroU32::try_from(blocks) .map(ReorgPeriod::Blocks) .unwrap_or(ReorgPeriod::None) } - pub fn as_number(&self) -> Result { + pub fn as_blocks(&self) -> Result { match self { ReorgPeriod::None => Ok(0), ReorgPeriod::Blocks(blocks) => Ok(blocks.get()), @@ -101,7 +101,7 @@ impl<'de> Deserialize<'de> for ReorgPeriod { fn visit_u64(self, v: u64) -> Result { let v = v.try_into().map_err(de::Error::custom)?; - Ok(ReorgPeriod::from_number(v)) + Ok(ReorgPeriod::from_blocks(v)) } fn visit_str(self, v: &str) -> Result {