-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for chain to start up in Cosmos Bootstrap (#492)
* Add CanWaitChainStartup trait to ChainDriver * Simplify wiring of LegacyCosmosSdkBootstrapComponents * Implement CanWaitChainStartup for CosmosChainDriver * Call chain_driver.wait_chain_startup() inside bootstrap * Revert "Call chain_driver.wait_chain_startup() inside bootstrap" This reverts commit 4a0e246. * Use BuildAndWaitChainDriver inside Cosmos bootstrap
- Loading branch information
1 parent
ec5f5b0
commit e7bbfad
Showing
16 changed files
with
158 additions
and
37 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
crates/cosmos/cosmos-test-components/src/bootstrap/impls/chain/build_wait.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,53 @@ | ||
use core::marker::PhantomData; | ||
use std::collections::BTreeMap; | ||
|
||
use cgp::prelude::CanRaiseError; | ||
use hermes_runtime_components::traits::os::child_process::{ChildProcessOf, HasChildProcessType}; | ||
use hermes_runtime_components::traits::runtime::HasRuntimeType; | ||
use hermes_test_components::chain::traits::types::wallet::{HasWalletType, Wallet}; | ||
use hermes_test_components::chain_driver::traits::types::chain::HasChainType; | ||
use hermes_test_components::chain_driver::traits::wait::CanWaitChainStartup; | ||
use hermes_test_components::driver::traits::types::chain_driver::HasChainDriverType; | ||
|
||
use crate::bootstrap::traits::chain::build_chain_driver::ChainDriverBuilder; | ||
use crate::bootstrap::traits::types::chain_node_config::HasChainNodeConfigType; | ||
use crate::bootstrap::traits::types::genesis_config::HasChainGenesisConfigType; | ||
|
||
pub struct BuildAndWaitChainDriver<InBuilder>(pub PhantomData<InBuilder>); | ||
|
||
impl<Bootstrap, ChainDriver, InBuilder> ChainDriverBuilder<Bootstrap> | ||
for BuildAndWaitChainDriver<InBuilder> | ||
where | ||
Bootstrap: HasRuntimeType<Runtime: HasChildProcessType> | ||
+ HasChainType<Chain: HasWalletType> | ||
+ HasChainDriverType<ChainDriver = ChainDriver> | ||
+ HasChainGenesisConfigType | ||
+ HasChainNodeConfigType | ||
+ CanRaiseError<ChainDriver::Error>, | ||
InBuilder: ChainDriverBuilder<Bootstrap>, | ||
ChainDriver: CanWaitChainStartup, | ||
{ | ||
async fn build_chain_driver( | ||
bootstrap: &Bootstrap, | ||
genesis_config: Bootstrap::ChainGenesisConfig, | ||
chain_node_config: Bootstrap::ChainNodeConfig, | ||
wallets: BTreeMap<String, Wallet<Bootstrap::Chain>>, | ||
chain_process: ChildProcessOf<Bootstrap::Runtime>, | ||
) -> Result<ChainDriver, Bootstrap::Error> { | ||
let chain_driver = InBuilder::build_chain_driver( | ||
bootstrap, | ||
genesis_config, | ||
chain_node_config, | ||
wallets, | ||
chain_process, | ||
) | ||
.await?; | ||
|
||
chain_driver | ||
.wait_chain_startup() | ||
.await | ||
.map_err(Bootstrap::raise_error)?; | ||
|
||
Ok(chain_driver) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
crates/cosmos/cosmos-test-components/src/bootstrap/impls/chain/mod.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod bootstrap_chain; | ||
pub mod build_wait; | ||
pub mod start_chain; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod wait; |
49 changes: 49 additions & 0 deletions
49
crates/test/test-components/src/chain_driver/impls/wait.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,49 @@ | ||
use core::time::Duration; | ||
|
||
use cgp::prelude::*; | ||
use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainHeight; | ||
use hermes_relayer_components::chain::traits::types::height::HasHeightFields; | ||
use hermes_runtime_components::traits::runtime::HasRuntime; | ||
use hermes_runtime_components::traits::sleep::CanSleep; | ||
|
||
use crate::chain_driver::traits::types::chain::HasChain; | ||
use crate::chain_driver::traits::wait::ChainStartupWaiter; | ||
|
||
pub struct WaitChainReachHeight<const H: u64>; | ||
|
||
impl<ChainDriver, Chain, const H: u64> ChainStartupWaiter<ChainDriver> for WaitChainReachHeight<H> | ||
where | ||
ChainDriver: | ||
HasChain<Chain = Chain> + HasRuntime<Runtime: CanSleep> + CanRaiseError<&'static str>, | ||
Chain: CanQueryChainHeight + HasHeightFields, | ||
{ | ||
async fn wait_chain_startup(chain_driver: &ChainDriver) -> Result<(), ChainDriver::Error> { | ||
let runtime = chain_driver.runtime(); | ||
let chain = chain_driver.chain(); | ||
|
||
for _ in 0..10 { | ||
if let Ok(height) = chain.query_chain_height().await { | ||
if Chain::revision_height(&height) >= H { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
runtime.sleep(Duration::from_millis(500)).await; | ||
} | ||
|
||
Err(ChainDriver::raise_error( | ||
"chain did not progress to target height within 5 seconds", | ||
)) | ||
} | ||
} | ||
|
||
pub struct NoWaitChainStartup; | ||
|
||
impl<ChainDriver> ChainStartupWaiter<ChainDriver> for NoWaitChainStartup | ||
where | ||
ChainDriver: Async + HasErrorType, | ||
{ | ||
async fn wait_chain_startup(_chain_driver: &ChainDriver) -> Result<(), ChainDriver::Error> { | ||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod impls; | ||
pub mod traits; |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod chain_process; | |
pub mod config; | ||
pub mod fields; | ||
pub mod types; | ||
pub mod wait; |
10 changes: 10 additions & 0 deletions
10
crates/test/test-components/src/chain_driver/traits/wait.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,10 @@ | ||
use cgp::prelude::*; | ||
|
||
#[cgp_component { | ||
context: ChainDriver, | ||
provider: ChainStartupWaiter, | ||
}] | ||
#[async_trait] | ||
pub trait CanWaitChainStartup: Async + HasErrorType { | ||
async fn wait_chain_startup(&self) -> Result<(), Self::Error>; | ||
} |