Skip to content

Commit

Permalink
Config parameter for celestia light node store directory (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev authored Feb 24, 2025
1 parent 209bf3a commit e82cbf6
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::ffi::OsStr;
use std::iter;
use commander::Command;

#[derive(Debug, Clone)]
pub struct Arabica;
Expand All @@ -11,37 +10,30 @@ impl Arabica {

pub async fn run(
&self,
dot_movement: dot_movement::DotMovement,
_dot_movement: dot_movement::DotMovement,
config: movement_da_util::config::Config,
) -> Result<(), anyhow::Error> {
let node_store_dir = dot_movement
.get_path()
.join("celestia")
.join(&config.appd.celestia_chain_id)
.join(".celestia-light");

commander::run_command(
"celestia",
[
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"validator-1.celestia-arabica-11.com",
"--p2p.network",
"arabica",
"--log.level",
"FATAL",
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;
let mut command = Command::new("celestia");
command.args([
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"validator-1.celestia-arabica-11.com",
"--p2p.network",
"arabica",
"--log.level",
"FATAL",
]);
if let Some(path) = &config.light.node_store {
command.arg("--node.store");
command.arg(path);
}
// FIXME: don't need to capture output
command.run_and_capture_output().await?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::OsStr, iter};
use commander::Command;

#[derive(Debug, Clone)]
pub struct Mainnet;
Expand All @@ -10,37 +10,30 @@ impl Mainnet {

pub async fn run(
&self,
dot_movement: dot_movement::DotMovement,
_dot_movement: dot_movement::DotMovement,
config: movement_da_util::config::Config,
) -> Result<(), anyhow::Error> {
let node_store_dir = dot_movement
.get_path()
.join("celestia")
.join(&config.appd.celestia_chain_id)
.join(".celestia-light");

commander::run_command(
let mut command = Command::new("celestia");
command.args([
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"rpc.celestia.pops.one",
"--p2p.network",
"celestia",
[
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"rpc.celestia.pops.one",
"--p2p.network",
"celestia",
"--log.level",
"FATAL",
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;
"--log.level",
"FATAL",
]);
if let Some(path) = &config.light.node_store {
command.arg("--node.store");
command.arg(path);
}
// FIXME: don't need to capture output
command.run_and_capture_output().await?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::OsStr, iter};
use commander::Command;

#[derive(Debug, Clone)]
pub struct Mocha;
Expand All @@ -10,37 +10,30 @@ impl Mocha {

pub async fn run(
&self,
dot_movement: dot_movement::DotMovement,
_dot_movement: dot_movement::DotMovement,
config: movement_da_util::config::Config,
) -> Result<(), anyhow::Error> {
let node_store_dir = dot_movement
.get_path()
.join("celestia")
.join(&config.appd.celestia_chain_id)
.join(".celestia-light");

commander::run_command(
"celestia",
[
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"rpc-mocha.pops.one",
"--p2p.network",
"mocha",
"--log.level",
"FATAL",
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;
let mut command = Command::new("celestia");
command.args([
"light",
"start",
"--keyring.backend",
"test",
"--keyring.keyname",
&config.light.key_name,
"--core.ip",
"rpc-mocha.pops.one",
"--p2p.network",
"mocha",
"--log.level",
"FATAL",
]);
if let Some(path) = &config.light.node_store {
command.arg("--node.store");
command.arg(path);
}
// FIXME: don't need to capture output
command.run_and_capture_output().await?;

Ok(())
}
Expand Down
49 changes: 24 additions & 25 deletions protocol-units/da/movement/protocol/setup/src/common/celestia.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::common;
use anyhow::Context;
use celestia_types::nmt::Namespace;
use commander::run_command;
use commander::Command;
use dot_movement::DotMovement;
use movement_da_util::config::Config;
use rand::Rng;
use tracing::info;

use std::ffi::OsStr;
use std::iter;
use std::path::PathBuf;

fn random_10_bytes() -> [u8; 10] {
Expand Down Expand Up @@ -42,6 +40,12 @@ pub fn initialize_celestia_config(
config.appd.celestia_chain_id.clone()
};

// set the node store directory accordingly to the chain id
config
.light
.node_store
.replace(celestia_chain_dir(&dot_movement, &config).join(".celestia-light"));

// update the app path with the chain id
config.appd.celestia_path.replace(
celestia_chain_dir(&dot_movement, &config)
Expand All @@ -64,41 +68,36 @@ pub fn initialize_celestia_config(
}

pub async fn celestia_light_init(
dot_movement: &DotMovement,
_dot_movement: &DotMovement,
config: &Config,
network: &str,
) -> Result<(), anyhow::Error> {
let node_store_dir = celestia_chain_dir(dot_movement, config).join(".celestia-light");
// celestia light init --p2p.network <network> --keyring.backend test --node_store <dir>
run_command(
"celestia",
["light", "init", "--p2p.network", network, "--keyring.backend", "test", "--node.store"]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;
let mut command = Command::new("celestia");
command.args(["light", "init", "--p2p.network", network, "--keyring.backend", "test"]);
if let Some(path) = &config.light.node_store {
command.arg("--node.store");
command.arg(path);
}
// FIXME: the output does not need to be captured
command.run_and_capture_output().await?;

Ok(())
}

pub async fn get_auth_token(
dot_movement: &DotMovement,
_dot_movement: &DotMovement,
config: &Config,
network: &str,
) -> Result<String, anyhow::Error> {
let node_store_dir = celestia_chain_dir(dot_movement, config).join(".celestia-light");
// celestia light auth admin --p2p.network mocha --node.store <dir>
let auth_token = run_command(
"celestia",
["light", "auth", "admin", "--p2p.network", network, "--node.store"]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?
.trim()
.to_string();
let mut command = Command::new("celestia");
command.args(["light", "auth", "admin", "--p2p.network", network]);
if let Some(path) = &config.light.node_store {
command.arg("--node.store");
command.arg(path);
}
let auth_token = command.run_and_capture_output().await?.trim().to_string();

Ok(auth_token)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use celestia_types::nmt::Namespace;
use godfig::env_default;

use std::env;
use std::path::PathBuf;

// The default hostname for the Celestia RPC
env_default!(
Expand Down Expand Up @@ -182,3 +183,7 @@ env_default!(
String,
"movement_celestia_light".into()
);

pub fn default_celestia_light_node_store() -> Option<PathBuf> {
std::env::var_os("CELESTIA_LIGHT_NODE_STORE").map(Into::into)
}
13 changes: 11 additions & 2 deletions protocol-units/da/movement/protocol/util/src/config/light.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
use super::default::default_celestia_light_node_key_name;
use super::default::{default_celestia_light_node_key_name, default_celestia_light_node_store};

use serde::{Deserialize, Serialize};

use std::path::PathBuf;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Config {
/// Name of the node's signing key in the keyring
#[serde(default = "default_celestia_light_node_key_name")]
pub key_name: String,
/// Path name of the node store directory
#[serde(default)]
pub node_store: Option<PathBuf>,
}

impl Default for Config {
fn default() -> Self {
Self { key_name: default_celestia_light_node_key_name() }
Self {
key_name: default_celestia_light_node_key_name(),
node_store: default_celestia_light_node_store(),
}
}
}
Loading

0 comments on commit e82cbf6

Please sign in to comment.