-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow packet clearing to be done through event relayer (#535)
* Simplify trait bounds for QueryCosmosPacketAcknowledgements * Remove height returned from PacketCommitmentsQuerier * Remove height argument from query_send_packets_from_sequences * Remove height argument in ack clearing * Remove height argument in PacketRelayer * Simplify trait bounds * Implement BlockEventsQuerier * Implement RelayWithPolledEvents * Add BlockEventsQuerier middleware * Use RelayWithPolledEvents to implement AutoRelayer * Implement AutoRelayStartingCurrentHeight * Implement HasBiRelayAt for CosmosRelayDriver * Initial clearing test is working * Full IBC transfer is working * Clean up constraints * Try running only clearing test * Abort background relayer on drop * Separate out IBC transfer and packet clearing tests * Keep drop handle in local variable
- Loading branch information
1 parent
063c43f
commit 9865ee3
Showing
41 changed files
with
713 additions
and
198 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
crates/chain/chain-components/src/impls/queries/block_events.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use alloc::vec::Vec; | ||
use core::marker::PhantomData; | ||
use core::time::Duration; | ||
|
||
use cgp::prelude::*; | ||
use hermes_chain_type_components::traits::types::event::HasEventType; | ||
use hermes_chain_type_components::traits::types::height::HasHeightType; | ||
use hermes_runtime_components::traits::runtime::HasRuntime; | ||
use hermes_runtime_components::traits::sleep::CanSleep; | ||
|
||
use crate::traits::queries::block_events::{BlockEventsQuerier, BlockEventsQuerierComponent}; | ||
use crate::traits::queries::chain_status::CanQueryChainHeight; | ||
|
||
pub struct WaitBlockHeightAndQueryEvents<InQuerier>(pub PhantomData<InQuerier>); | ||
|
||
#[cgp_provider(BlockEventsQuerierComponent)] | ||
impl<Chain, InQuerier> BlockEventsQuerier<Chain> for WaitBlockHeightAndQueryEvents<InQuerier> | ||
where | ||
Chain: HasRuntime + HasEventType + CanQueryChainHeight, | ||
InQuerier: BlockEventsQuerier<Chain>, | ||
Chain::Runtime: CanSleep, | ||
{ | ||
async fn query_block_events( | ||
chain: &Chain, | ||
height: &Chain::Height, | ||
) -> Result<Vec<Chain::Event>, Chain::Error> { | ||
let runtime = chain.runtime(); | ||
|
||
loop { | ||
let current_height = chain.query_chain_height().await?; | ||
if ¤t_height >= height { | ||
break; | ||
} else { | ||
runtime.sleep(Duration::from_millis(200)).await; | ||
} | ||
} | ||
|
||
InQuerier::query_block_events(chain, height).await | ||
} | ||
} | ||
|
||
pub struct RetryQueryBlockEvents<const MAX_RETRIES: usize, InQuerier>(pub PhantomData<InQuerier>); | ||
|
||
#[cgp_provider(BlockEventsQuerierComponent)] | ||
impl<Chain, InQuerier, const MAX_RETRIES: usize> BlockEventsQuerier<Chain> | ||
for RetryQueryBlockEvents<MAX_RETRIES, InQuerier> | ||
where | ||
Chain: HasRuntime + HasHeightType + HasEventType + HasAsyncErrorType, | ||
InQuerier: BlockEventsQuerier<Chain>, | ||
Chain::Runtime: CanSleep, | ||
{ | ||
async fn query_block_events( | ||
chain: &Chain, | ||
height: &Chain::Height, | ||
) -> Result<Vec<Chain::Event>, Chain::Error> { | ||
let runtime = chain.runtime(); | ||
let mut sleep_time = Duration::from_millis(500); | ||
|
||
for _ in 0..MAX_RETRIES { | ||
let res = InQuerier::query_block_events(chain, height).await; | ||
if let Ok(events) = res { | ||
return Ok(events); | ||
} | ||
|
||
runtime.sleep(sleep_time).await; | ||
sleep_time *= 2; | ||
} | ||
|
||
InQuerier::query_block_events(chain, height).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
crates/chain/chain-components/src/traits/queries/block_events.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use alloc::vec::Vec; | ||
|
||
use cgp::prelude::*; | ||
use hermes_chain_type_components::traits::types::event::HasEventType; | ||
use hermes_chain_type_components::traits::types::height::HasHeightType; | ||
|
||
#[cgp_component { | ||
provider: BlockEventsQuerier, | ||
context: Chain, | ||
}] | ||
#[async_trait] | ||
pub trait CanQueryBlockEvents: HasHeightType + HasEventType + HasAsyncErrorType { | ||
async fn query_block_events( | ||
&self, | ||
height: &Self::Height, | ||
) -> Result<Vec<Self::Event>, Self::Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.