Skip to content

Commit

Permalink
Rename ReorgPeriod::from_number and ReorgPeriod::as_number
Browse files Browse the repository at this point in the history
  • Loading branch information
apastushenka committed Oct 15, 2024
1 parent 219d7ca commit f768637
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rust/main/agents/validator/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl FromRawConf<RawValidatorSettings> 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]);

Expand Down
4 changes: 2 additions & 2 deletions rust/main/agents/validator/src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,15 @@ 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(())
});

// 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),
Expand Down
2 changes: 1 addition & 1 deletion rust/main/chains/hyperlane-cosmos/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) async fn get_block_height_for_lag(
lag: &ReorgPeriod,
) -> ChainResult<Option<u64>> {
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)
Expand Down
8 changes: 4 additions & 4 deletions rust/main/hyperlane-base/src/settings/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -412,7 +412,7 @@ impl ChainConf {
Ok(indexer as Box<dyn SequenceAwareIndexer<InterchainGasPayment>>)
}
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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rust/main/hyperlane-base/src/settings/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions rust/main/hyperlane-core/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, Report> {
pub fn as_blocks(&self) -> Result<u32, Report> {
match self {
ReorgPeriod::None => Ok(0),
ReorgPeriod::Blocks(blocks) => Ok(blocks.get()),
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'de> Deserialize<'de> for ReorgPeriod {

fn visit_u64<E: de::Error>(self, v: u64) -> Result<Self::Value, E> {
let v = v.try_into().map_err(de::Error::custom)?;
Ok(ReorgPeriod::from_number(v))
Ok(ReorgPeriod::from_blocks(v))
}

fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
Expand Down

0 comments on commit f768637

Please sign in to comment.