Skip to content

Commit fdaa818

Browse files
authored
Allow start_chain to return multiple child processes (#591)
* Allow start_chain to return multiple child processes * Debug log command when starting child process
1 parent cc0d85a commit fdaa818

File tree

15 files changed

+78
-37
lines changed

15 files changed

+78
-37
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/cli-components/src/impls/commands/bootstrap/chain.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,27 @@ where
8080
)
8181
.await;
8282

83-
let m_chain_process = chain_driver.take_chain_process();
83+
let chain_processes = chain_driver.take_chain_process();
8484

85-
if let Some(chain_process) = m_chain_process {
86-
app.log(&format!("running chain {} running in the background. Press Ctrl+C to stop then chain...", chain_driver.chain().chain_id()), &LevelInfo).await;
85+
if !chain_processes.is_empty() {
86+
app.log(
87+
&format!(
88+
"running chain {} in the background. Press Ctrl+C to stop then chain...",
89+
chain_driver.chain().chain_id()
90+
),
91+
&LevelInfo,
92+
)
93+
.await;
8794

88-
Runtime::wait_child_process(chain_process)
89-
.await
90-
.map_err(|e| {
91-
App::wrap_error(App::raise_error(e), "chain process exited with error")
92-
})?;
95+
for chain_process in chain_processes {
96+
Runtime::wait_child_process(chain_process)
97+
.await
98+
.map_err(|e| {
99+
App::wrap_error(App::raise_error(e), "chain process exited with error")
100+
})?;
101+
}
93102

94-
app.log("chain process exited with no error", &LevelInfo)
103+
app.log("chain processes exited with no error", &LevelInfo)
95104
.await;
96105
}
97106

crates/cosmos/cosmos-integration-tests/src/contexts/chain_driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use toml::to_string_pretty;
5959
pub struct CosmosChainDriver {
6060
pub chain: CosmosChain,
6161
pub chain_command_path: PathBuf,
62-
pub chain_process: Option<Child>,
62+
pub chain_processes: Vec<Child>,
6363
pub chain_node_config: CosmosChainNodeConfig,
6464
pub genesis_config: CosmosGenesisConfig,
6565
pub validator_wallet: CosmosTestWallet,
@@ -158,8 +158,8 @@ impl ChainCommandPathGetter<CosmosChainDriver> for CosmosChainDriverComponents {
158158

159159
#[cgp_provider(ChainProcessTakerComponent)]
160160
impl ChainProcessTaker<CosmosChainDriver> for CosmosChainDriverComponents {
161-
fn take_chain_process(chain_driver: &mut CosmosChainDriver) -> Option<Child> {
162-
chain_driver.chain_process.take()
161+
fn take_chain_process(chain_driver: &mut CosmosChainDriver) -> Vec<Child> {
162+
core::mem::take(&mut chain_driver.chain_processes)
163163
}
164164
}
165165

crates/cosmos/cosmos-integration-tests/src/impls/bootstrap/build_cosmos_chain_driver.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ use tokio::process::Child;
2525
use crate::contexts::chain_driver::CosmosChainDriver;
2626
use crate::traits::bootstrap::build_chain::CanBuildChainWithNodeConfig;
2727

28-
pub struct BuildCosmosChainDriver;
29-
30-
#[cgp_provider(ChainDriverBuilderComponent)]
28+
#[cgp_new_provider(ChainDriverBuilderComponent)]
3129
impl<Bootstrap, Runtime> ChainDriverBuilder<Bootstrap> for BuildCosmosChainDriver
3230
where
3331
Bootstrap: HasChainDriverType<ChainDriver = CosmosChainDriver>
@@ -47,7 +45,7 @@ where
4745
genesis_config: CosmosGenesisConfig,
4846
chain_node_config: CosmosChainNodeConfig,
4947
wallets: BTreeMap<String, CosmosTestWallet>,
50-
chain_process: Child,
48+
chain_processes: Vec<Child>,
5149
) -> Result<CosmosChainDriver, Bootstrap::Error> {
5250
let validator_wallet = wallets
5351
.get("validator")
@@ -96,7 +94,7 @@ where
9694
chain_command_path,
9795
chain_node_config,
9896
genesis_config,
99-
chain_process: Some(chain_process),
97+
chain_processes,
10098
validator_wallet,
10199
relayer_wallet,
102100
user_wallet_a,

crates/cosmos/cosmos-test-components/src/bootstrap/impls/chain/bootstrap_chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use hermes_test_components::chain_driver::traits::types::chain::HasChainType;
1313
use hermes_test_components::driver::traits::types::chain_driver::HasChainDriverType;
1414

1515
use crate::bootstrap::traits::chain::build_chain_driver::CanBuildChainDriver;
16-
use crate::bootstrap::traits::chain::start_chain::CanStartChainFullNode;
16+
use crate::bootstrap::traits::chain::start_chain::CanStartChainFullNodes;
1717
use crate::bootstrap::traits::generator::generate_chain_id::CanGenerateChainId;
1818
use crate::bootstrap::traits::generator::generate_wallet_config::CanGenerateWalletConfigs;
1919
use crate::bootstrap::traits::genesis::add_genesis_wallet::CanAddWalletToGenesis;
@@ -40,7 +40,7 @@ where
4040
+ CanAddWalletToGenesis
4141
+ CanCollectGenesisTransactions
4242
+ CanInitChainNodeConfig
43-
+ CanStartChainFullNode
43+
+ CanStartChainFullNodes
4444
+ CanBuildChainDriver,
4545
Runtime: HasFilePathType + HasChildProcessType + HasAsyncErrorType,
4646
Chain: HasChainIdType + HasWalletType,
@@ -92,7 +92,7 @@ where
9292

9393
// Start the chain full node in the background, and return the child process handle
9494
let chain_process = bootstrap
95-
.start_chain_full_node(&chain_home_dir, &chain_config, &genesis_config)
95+
.start_chain_full_nodes(&chain_home_dir, &chain_config, &genesis_config)
9696
.await?;
9797

9898
// Build the chain context from the bootstrap parameters

crates/cosmos/cosmos-test-components/src/bootstrap/impls/chain/build_wait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
genesis_config: Bootstrap::ChainGenesisConfig,
3636
chain_node_config: Bootstrap::ChainNodeConfig,
3737
wallets: BTreeMap<String, Wallet<Bootstrap::Chain>>,
38-
chain_process: ChildProcessOf<Bootstrap::Runtime>,
38+
chain_process: Vec<ChildProcessOf<Bootstrap::Runtime>>,
3939
) -> Result<ChainDriver, Bootstrap::Error> {
4040
let chain_driver = InBuilder::build_chain_driver(
4141
bootstrap,

crates/cosmos/cosmos-test-components/src/bootstrap/impls/chain/start_chain.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use crate::bootstrap::traits::types::genesis_config::HasChainGenesisConfigType;
1212
use crate::bootstrap::types::chain_node_config::CosmosChainNodeConfig;
1313
use crate::bootstrap::types::genesis_config::CosmosGenesisConfig;
1414

15-
pub struct StartCosmosChain;
16-
17-
#[cgp_provider(ChainFullNodeStarterComponent)]
15+
#[cgp_new_provider(ChainFullNodeStarterComponent)]
1816
impl<Bootstrap, Runtime> ChainFullNodeStarter<Bootstrap> for StartCosmosChain
1917
where
2018
Bootstrap: HasRuntime<Runtime = Runtime>
@@ -25,12 +23,12 @@ where
2523
+ CanRaiseAsyncError<Runtime::Error>,
2624
Runtime: HasFilePathType + CanStartChildProcess,
2725
{
28-
async fn start_chain_full_node(
26+
async fn start_chain_full_nodes(
2927
bootstrap: &Bootstrap,
3028
chain_home_dir: &Runtime::FilePath,
3129
chain_config: &CosmosChainNodeConfig,
3230
_chain_genesis_config: &CosmosGenesisConfig,
33-
) -> Result<Runtime::ChildProcess, Bootstrap::Error> {
31+
) -> Result<Vec<Runtime::ChildProcess>, Bootstrap::Error> {
3432
let chain_command = bootstrap.chain_command_path();
3533

3634
let args = [
@@ -69,6 +67,6 @@ where
6967
.await
7068
.map_err(Bootstrap::raise_error)?;
7169

72-
Ok(child_process)
70+
Ok(vec![child_process])
7371
}
7472
}

crates/cosmos/cosmos-test-components/src/bootstrap/traits/chain/build_chain_driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub trait CanBuildChainDriver:
2828
genesis_config: Self::ChainGenesisConfig,
2929
chain_node_config: Self::ChainNodeConfig,
3030
wallets: BTreeMap<String, Wallet<Self::Chain>>,
31-
chain_process: ChildProcessOf<Self::Runtime>,
31+
chain_processes: Vec<ChildProcessOf<Self::Runtime>>,
3232
) -> Result<Self::ChainDriver, Self::Error>;
3333
}

crates/cosmos/cosmos-test-components/src/bootstrap/traits/chain/start_chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ use crate::bootstrap::traits::types::genesis_config::HasChainGenesisConfigType;
1111
context: Bootstrap,
1212
}]
1313
#[async_trait]
14-
pub trait CanStartChainFullNode:
14+
pub trait CanStartChainFullNodes:
1515
HasChainNodeConfigType
1616
+ HasChainGenesisConfigType
1717
+ HasRuntime<Runtime: HasChildProcessType + HasFilePathType>
1818
+ HasAsyncErrorType
1919
{
20-
async fn start_chain_full_node(
20+
async fn start_chain_full_nodes(
2121
&self,
2222
chain_home_dir: &FilePathOf<Self::Runtime>,
2323
chain_node_config: &Self::ChainNodeConfig,
2424
chain_genesis_config: &Self::ChainGenesisConfig,
25-
) -> Result<ChildProcessOf<Self::Runtime>, Self::Error>;
25+
) -> Result<Vec<ChildProcessOf<Self::Runtime>>, Self::Error>;
2626
}

crates/runtime/runtime/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ cgp = { workspace = true }
1616
hermes-runtime-components = { workspace = true }
1717
hermes-async-runtime-components = { workspace = true }
1818
hermes-tokio-runtime-components = { workspace = true }
19+
hermes-logging-components = { workspace = true }
20+
hermes-tracing-logging-components = { workspace = true }
1921

20-
tokio = { workspace = true }
22+
tokio = { workspace = true }

0 commit comments

Comments
 (0)