Skip to content

Commit

Permalink
Pass datadir absolute path to bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Aug 10, 2023
1 parent b152f9f commit 6ef5bae
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions gui/src/installer/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct DefineBitcoind {
}

pub struct StartInternalBitcoindStep {
conf_path: PathBuf,
bitcoind_datadir: PathBuf,
network: Network,
started: Option<Result<std::process::Child, std::io::Error>>,
exe_path: Option<PathBuf>,
Expand All @@ -92,7 +92,6 @@ pub struct InternalBitcoindNetworkConfig {
pub struct InternalBitcoindConfig {
#[cfg(unix)]
daemonwait: bool, // Used instead of `daemon` to ensure RPC server is running before exiting.
data_dir: PathBuf,
networks: HashMap<Network, InternalBitcoindNetworkConfig>,
}

Expand All @@ -119,12 +118,17 @@ impl std::fmt::Display for InternalBitcoindConfigError {
}
}

impl Default for InternalBitcoindConfig {
fn default() -> Self {
Self::new()
}
}

impl InternalBitcoindConfig {
pub fn new(data_dir: PathBuf) -> Self {
pub fn new() -> Self {
Self {
#[cfg(unix)]
daemonwait: true,
data_dir,
networks: HashMap::new(),
}
}
Expand All @@ -140,12 +144,6 @@ impl InternalBitcoindConfig {
.get("daemonwait")
.map(|v| v == "1")
.ok_or_else(|| InternalBitcoindConfigError::KeyNotFound("daemonwait".to_string()))?;
let data_dir = PathBuf::from_str(
gen_sec
.get("datadir")
.ok_or_else(|| InternalBitcoindConfigError::KeyNotFound("datadir".to_string()))?,
)
.map_err(|e| InternalBitcoindConfigError::CouldNotParseValue(e.to_string()))?;

let mut networks = HashMap::new();
for (maybe_sec, prop) in &conf_ini {
Expand Down Expand Up @@ -180,7 +178,6 @@ impl InternalBitcoindConfig {
Ok(Self {
#[cfg(unix)]
daemonwait,
data_dir,
networks,
})
}
Expand All @@ -199,9 +196,6 @@ impl InternalBitcoindConfig {
conf_ini
.with_general_section()
.set("daemonwait", if self.daemonwait { "1" } else { "0" });
conf_ini
.with_general_section()
.set("datadir", self.data_dir.to_string_lossy());

for (network, network_conf) in &self.networks {
conf_ini
Expand Down Expand Up @@ -367,7 +361,8 @@ impl Step for SelectBitcoindTypeStep {
conf
} else {
// TODO: Should the `else` only apply for "file not found" error?
InternalBitcoindConfig::new(internal_bitcoind_datadir(&ctx.data_dir))
// In case of error while parsing existing file, we may overwrite values from other networks by creating new config.
InternalBitcoindConfig::new()
};
// Insert entry for network if not present.
if conf.networks.get(&ctx.bitcoin_config.network).is_none() {
Expand Down Expand Up @@ -561,7 +556,7 @@ impl From<StartInternalBitcoindStep> for Box<dyn Step> {
impl StartInternalBitcoindStep {
pub fn new(liana_datadir: &PathBuf) -> Self {
Self {
conf_path: internal_bitcoind_config_path(liana_datadir),
bitcoind_datadir: internal_bitcoind_datadir(liana_datadir),
network: Network::Bitcoin,
started: None,
exe_path: None,
Expand All @@ -581,9 +576,13 @@ impl Step for StartInternalBitcoindStep {
match msg {
message::StartInternalBitcoindMsg::Start => {
if let Some(path) = &self.exe_path {
let datadir = self
.bitcoind_datadir
.canonicalize()
.expect("Failed to canonicalize bitcoind datadir path");
let args = vec![
format!("-chain={}", self.network.to_core_arg()),
format!("-conf={}", self.conf_path.to_string_lossy()),
format!("-chain={}", &self.network.to_core_arg()),
format!("-datadir={}", &datadir.to_string_lossy()),
];
let res = std::process::Command::new(path)
.args(&args)
Expand Down

0 comments on commit 6ef5bae

Please sign in to comment.