From 34c6820cfdb87db9a3f08d627b999139cc911de5 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 4 Nov 2024 23:32:14 -0400 Subject: [PATCH] fix: merge issue --- .../src/validator_announce.rs | 3 +- .../chains/hyperlane-starknet/src/indexer.rs | 86 +++++++++++++------ .../hyperlane-base/src/settings/chains.rs | 6 +- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/rust/main/chains/hyperlane-cosmos/src/validator_announce.rs b/rust/main/chains/hyperlane-cosmos/src/validator_announce.rs index 4be64b6b6..d82b0e829 100644 --- a/rust/main/chains/hyperlane-cosmos/src/validator_announce.rs +++ b/rust/main/chains/hyperlane-cosmos/src/validator_announce.rs @@ -13,6 +13,7 @@ use crate::{ GetAnnounceStorageLocationsRequestInner, }, signers::Signer, + types::tx_response_to_outcome, ConnectionConf, CosmosProvider, }; @@ -107,7 +108,7 @@ impl ValidatorAnnounce for CosmosValidatorAnnounce { .wasm_send(announce_request, None) .await?; - Ok(response.try_into()?) + Ok(tx_response_to_outcome(response)?) } async fn announce_tokens_needed(&self, announcement: SignedType) -> Option { diff --git a/rust/main/chains/hyperlane-starknet/src/indexer.rs b/rust/main/chains/hyperlane-starknet/src/indexer.rs index 8946f94e9..f36883b22 100644 --- a/rust/main/chains/hyperlane-starknet/src/indexer.rs +++ b/rust/main/chains/hyperlane-starknet/src/indexer.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use hyperlane_core::{ ChainResult, ContractLocator, HyperlaneMessage, Indexed, Indexer, InterchainGasPayment, - LogMeta, MerkleTreeInsertion, SequenceAwareIndexer, H256, U256, + LogMeta, MerkleTreeInsertion, ReorgPeriod, SequenceAwareIndexer, H256, U256, }; use starknet::core::types::{ BlockId, BlockTag, EventFilter, FieldElement, MaybePendingBlockWithTxHashes, @@ -45,7 +45,7 @@ impl ParsedEvent { /// Starknet RPC Provider pub struct StarknetMailboxIndexer { contract: Arc>, - reorg_period: u32, + reorg_period: ReorgPeriod, } impl StarknetMailboxIndexer { @@ -53,7 +53,7 @@ impl StarknetMailboxIndexer { pub fn new( conf: ConnectionConf, locator: ContractLocator, - reorg_period: u32, + reorg_period: &ReorgPeriod, ) -> ChainResult { let rpc_client = AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(conf.url.clone()))); @@ -64,7 +64,7 @@ impl StarknetMailboxIndexer { Ok(Self { contract: Arc::new(contract), - reorg_period, + reorg_period: reorg_period.clone(), }) } @@ -100,16 +100,32 @@ impl StarknetMailboxIndexer { #[instrument(level = "debug", err, ret, skip(self))] async fn get_finalized_block_number(&self) -> ChainResult { - Ok( - self.contract - .provider - .block_number() - .await - .map_err(Into::::into)? - .saturating_sub(self.reorg_period as u64) - .try_into() - .unwrap(), // TODO: check if safe - ) + match self.reorg_period { + ReorgPeriod::None => Ok( + self.contract + .provider + .block_number() + .await + .map_err(Into::::into)? + .try_into() + .unwrap(), // TODO: check if safe + ), + ReorgPeriod::Blocks(reorg_period) => Ok( + self.contract + .provider + .block_number() + .await + .map_err(Into::::into)? + .saturating_sub(reorg_period.get() as u64) + .try_into() + .unwrap(), // TODO: check if safe + ), + ReorgPeriod::Tag(_) => { + Err(hyperlane_core::ChainCommunicationError::InvalidReorgPeriod( + self.reorg_period.clone(), + )) + } + } } } @@ -263,7 +279,7 @@ impl SequenceAwareIndexer for StarknetMailboxIndexer { /// Starknet RPC Provider pub struct StarknetMerkleTreeHookIndexer { contract: Arc>, - reorg_period: u32, + reorg_period: ReorgPeriod, } impl StarknetMerkleTreeHookIndexer { @@ -271,7 +287,7 @@ impl StarknetMerkleTreeHookIndexer { pub fn new( conf: ConnectionConf, locator: ContractLocator, - reorg_period: u32, + reorg_period: &ReorgPeriod, ) -> ChainResult { let rpc_client = AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(conf.url.clone()))); @@ -282,7 +298,7 @@ impl StarknetMerkleTreeHookIndexer { Ok(Self { contract: Arc::new(contract), - reorg_period, + reorg_period: reorg_period.clone(), }) } } @@ -347,16 +363,32 @@ impl Indexer for StarknetMerkleTreeHookIndexer { #[instrument(level = "debug", err, ret, skip(self))] async fn get_finalized_block_number(&self) -> ChainResult { - Ok( - self.contract - .provider - .block_number() - .await - .map_err(Into::::into)? - .saturating_sub(self.reorg_period as u64) - .try_into() - .unwrap(), // TODO: check if safe - ) + match self.reorg_period { + ReorgPeriod::None => Ok( + self.contract + .provider + .block_number() + .await + .map_err(Into::::into)? + .try_into() + .unwrap(), // TODO: check if safe + ), + ReorgPeriod::Blocks(reorg_period) => Ok( + self.contract + .provider + .block_number() + .await + .map_err(Into::::into)? + .saturating_sub(reorg_period.get() as u64) + .try_into() + .unwrap(), // TODO: check if safe + ), + ReorgPeriod::Tag(_) => { + Err(hyperlane_core::ChainCommunicationError::InvalidReorgPeriod( + self.reorg_period.clone(), + )) + } + } } } diff --git a/rust/main/hyperlane-base/src/settings/chains.rs b/rust/main/hyperlane-base/src/settings/chains.rs index 36ff9c730..b4cef616f 100644 --- a/rust/main/hyperlane-base/src/settings/chains.rs +++ b/rust/main/hyperlane-base/src/settings/chains.rs @@ -323,7 +323,7 @@ impl ChainConf { let indexer = Box::new(h_starknet::StarknetMailboxIndexer::new( conf.clone(), locator, - self.reorg_period, + &self.reorg_period, )?); Ok(indexer as Box>) } @@ -371,7 +371,7 @@ impl ChainConf { let indexer = Box::new(h_starknet::StarknetMailboxIndexer::new( conf.clone(), locator, - self.reorg_period, + &self.reorg_period, )?); Ok(indexer as Box>) @@ -517,7 +517,7 @@ impl ChainConf { let indexer = Box::new(h_starknet::StarknetMerkleTreeHookIndexer::new( conf.clone(), locator, - self.reorg_period, + &self.reorg_period, )?); Ok(indexer as Box>)