Skip to content

Commit

Permalink
Refactor handling reorg period in Cosmos chain
Browse files Browse the repository at this point in the history
  • Loading branch information
apastushenka committed Oct 16, 2024
1 parent f768637 commit 762070f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rust/main/chains/hyperlane-cosmos/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ pub(crate) async fn get_block_height_for_lag(
provider: &WasmGrpcProvider,
lag: &ReorgPeriod,
) -> ChainResult<Option<u64>> {
let block_height = if !lag.is_none() {
let lag = lag.as_blocks()?;
let tip = provider.latest_block_height().await?;
let block_height = tip - lag as u64;
Some(block_height)
} else {
None
let block_height = match lag {
ReorgPeriod::Blocks(blocks) => {
let tip = provider.latest_block_height().await?;
let block_height = tip - blocks.get() as u64;
Some(block_height)
}
ReorgPeriod::None => None,
ReorgPeriod::Tag(_) => {
return Err(ChainCommunicationError::CustomError(
"Cosmos does not support reorg period as a tag".into(),
))
}
};

Ok(block_height)
Expand Down

0 comments on commit 762070f

Please sign in to comment.