Skip to content

Commit

Permalink
Accept extra_args on node restart
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Jan 20, 2025
1 parent af85eae commit 7a08605
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::{Duration, Instant},
};

use anyhow::{anyhow, bail, Context};
use anyhow::{bail, Context};
use async_trait::async_trait;
use bitcoin::Address;
use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi};
Expand Down Expand Up @@ -283,7 +283,11 @@ impl Restart for BitcoinNode {
}
}

async fn start(&mut self, config: Option<Self::Config>) -> Result<()> {
async fn start(
&mut self,
config: Option<Self::Config>,
_extra_args: Option<Vec<String>>,
) -> Result<()> {
if let Some(config) = config {
self.config = config;
}
Expand Down
3 changes: 1 addition & 2 deletions src/config/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::{env, path::PathBuf, time::Duration};

use tempfile::TempDir;

use crate::utils::generate_test_id;

use super::CitreaMode;
use crate::utils::generate_test_id;

#[derive(Clone, Default)]
pub struct TestCaseEnv {
Expand Down
13 changes: 9 additions & 4 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ where
})
}

fn spawn(config: &C) -> Result<SpawnOutput> {
fn spawn(config: &C, extra_args: Option<Vec<String>>) -> Result<SpawnOutput> {
let citrea = get_citrea_path()?;

let kind = C::node_kind();
Expand All @@ -145,6 +145,7 @@ where

Command::new(citrea)
.args(get_citrea_args(config))
.args(extra_args.unwrap_or_default())
.envs(config.env())
.stdout(Stdio::from(stdout_file))
.stderr(Stdio::from(stderr_file))
Expand Down Expand Up @@ -191,7 +192,7 @@ where
async fn spawn(config: &Self::Config, docker: &Arc<Option<DockerEnv>>) -> Result<SpawnOutput> {
match docker.as_ref() {
Some(docker) if docker.citrea() => docker.spawn(config.to_owned().into()).await,
_ => Self::spawn(config),
_ => Self::spawn(config, None),
}
}

Expand Down Expand Up @@ -251,7 +252,11 @@ where
Ok(())
}

async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()> {
async fn start(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()> {
let config = self.config_mut();

if let Some(new_config) = new_config {
Expand All @@ -272,7 +277,7 @@ where
copy_directory(old_dir, &new_dir)?;
config.set_dir(new_dir);

*self.spawn_output() = Self::spawn(config)?;
*self.spawn_output() = Self::spawn(config, extra_args)?;
self.wait_for_ready(None).await
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,19 @@ pub trait NodeT: Send {
#[async_trait]
pub trait Restart: NodeT + Send {
async fn wait_until_stopped(&mut self) -> Result<()>;
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()>;
async fn start(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()>;

// Default implementation to support waiting for node to be fully shutdown and brough back up with new config.
async fn restart(&mut self, new_config: Option<Self::Config>) -> Result<()> {
async fn restart(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()> {
self.wait_until_stopped().await?;
self.start(new_config).await
self.start(new_config, extra_args).await
}
}
2 changes: 1 addition & 1 deletion tests/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl TestCase for RestartBitcoinTest {
assert_eq!(info.txindex, None);

// Restart node with txindex
da.restart(Some(new_conf)).await?;
da.restart(Some(new_conf), None).await?;

let block_after = da.get_block_count().await?;
let info = da.get_index_info().await?;
Expand Down

0 comments on commit 7a08605

Please sign in to comment.