Skip to content

Commit

Permalink
Merge branch 'mikhail/celestia-mainnet-config' of https://github.com/…
Browse files Browse the repository at this point in the history
…movementlabsxyz/movement into mikhail/celestia-mainnet-config
  • Loading branch information
l-monninger committed Feb 22, 2025
2 parents 742e884 + 796fc4c commit fbc3175
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 107 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ hex = { version = "0.4.3", default-features = false, features = [
ics23 = { version = "0.11.0" }
k256 = { version = "0.13.3" }
keccak-hash = "0.10.0"
itertools = { version = "0.12.1", default-features = false }
itertools = { version = "0.13.0", default-features = false }
jmt = "0.9.0"
log = "0.4.21"
mirai-annotations = "1.10.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ services:
celestia light start
--core.ip rpc.celestia.pops.one
--p2p.network celestia
--node.store /.movement/celestia/movement/.celestia-light
--keyring.backend test
--keyring.keyname movement_celestia_light
--log.level WARN
environment:
- NODE_TYPE=light
- P2P_NETWORK=celestia
volumes:
- ${HOME}/.celestia-light/keys:/home/celestia/keys
- ${DOT_MOVEMENT_PATH}/celestia:/.movement/celestia
ports:
- 26658:26658
depends_on:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::ffi::OsStr;
use std::iter;

#[derive(Debug, Clone)]
pub struct Arabica;

Expand All @@ -8,15 +11,22 @@ 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> {
// celestia light start --core.ip validator-1.celestia-arabica-11.com --p2p.network arabica
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",
Expand All @@ -25,7 +35,11 @@ impl Arabica {
"arabica",
"--log.level",
"FATAL",
],
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{ffi::OsStr, iter};

#[derive(Debug, Clone)]
pub struct Mainnet;

Expand All @@ -8,13 +10,18 @@ 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> {
// celestia light start --core.ip rpc.celestia.pops.one --p2p.network celestia
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",
Expand All @@ -27,7 +34,11 @@ impl Mainnet {
"celestia",
"--log.level",
"FATAL",
],
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{ffi::OsStr, iter};

#[derive(Debug, Clone)]
pub struct Mocha;

Expand All @@ -8,13 +10,18 @@ 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> {
// celestia light start --core.ip validator-1.celestia-mocha-11.com --p2p.network mocha
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",
Expand All @@ -27,7 +34,11 @@ impl Mocha {
"mocha",
"--log.level",
"FATAL",
],
"--node.store",
]
.iter()
.map(AsRef::<OsStr>::as_ref)
.chain(iter::once(node_store_dir.as_ref())),
)
.await?;

Expand Down
34 changes: 14 additions & 20 deletions protocol-units/da/movement/protocol/setup/src/arabica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,24 @@ impl Arabica {
Ok(address.to_string())
}

pub async fn celestia_light_init(&self) -> Result<(), anyhow::Error> {
// celestia light init --p2p.network arabica
run_command(
"celestia",
&["light", "init", "--p2p.network", "arabica", "--keyring.backend", "test"],
)
.await?;

Ok(())
async fn celestia_light_init(
&self,
dot_movement: &DotMovement,
config: &Config,
) -> Result<(), anyhow::Error> {
common::celestia::celestia_light_init(dot_movement, config, "arabica").await
}

pub async fn get_da_block_height(&self) -> Result<u64, anyhow::Error> {
common::celestia::current_block_height("https://rpc.celestia-arabica-11.com").await
}

pub async fn get_auth_token(&self) -> Result<String, anyhow::Error> {
// celestia light auth admin --p2p.network arabica
let auth_token =
run_command("celestia", &["light", "auth", "admin", "--p2p.network", "arabica"])
.await?
.trim()
.to_string();

Ok(auth_token)
async fn get_auth_token(
&self,
dot_movement: &DotMovement,
config: &Config,
) -> Result<String, anyhow::Error> {
common::celestia::get_auth_token(dot_movement, config, "arabica").await
}

pub async fn setup_celestia(
Expand All @@ -91,14 +85,14 @@ impl Arabica {
let mut config = common::celestia::make_dirs(dot_movement.clone(), config).await?;

// celestia light init --p2p.network arabica
self.celestia_light_init().await?;
self.celestia_light_init(&dot_movement, &config).await?;

// get the arabica 11 address
let address = self.get_arabica_11_address().await?;
config.appd.celestia_validator_address.replace(address.clone());

// get the auth token
let auth_token = self.get_auth_token().await?;
let auth_token = self.get_auth_token(&dot_movement, &config).await?;
config.appd.celestia_auth_token.replace(auth_token.clone());

// get the initial block height
Expand Down
63 changes: 52 additions & 11 deletions protocol-units/da/movement/protocol/setup/src/common/celestia.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::common;
use anyhow::Context;
use celestia_types::nmt::Namespace;
use commander::run_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] {
let mut rng = rand::thread_rng();
rng.gen()
Expand All @@ -19,16 +24,16 @@ pub fn random_namespace() -> Namespace {
Namespace::new_v0(&random_10_bytes()).unwrap()
}

fn celestia_chain_dir(dot_movement: &DotMovement, config: &Config) -> PathBuf {
dot_movement.get_path().join("celestia").join(&config.appd.celestia_chain_id)
}

pub fn initialize_celestia_config(
dot_movement: DotMovement,
mut config: Config,
) -> Result<Config, anyhow::Error> {
// use the dot movement path to set up the celestia app and node paths
let dot_movement_path = dot_movement.get_path();

let celestia_chain_id = if config.celestia_force_new_chain {
if config.celestia_force_new_chain {
// if forced just replace the chain id with a random one

config.appd.celestia_chain_id = random_chain_id();
config.appd.celestia_namespace = random_namespace();
config.appd.celestia_chain_id.clone()
Expand All @@ -39,9 +44,7 @@ pub fn initialize_celestia_config(

// update the app path with the chain id
config.appd.celestia_path.replace(
dot_movement_path
.join("celestia")
.join(celestia_chain_id.clone())
celestia_chain_dir(&dot_movement, &config)
.join(".celestia-app")
.to_str()
.ok_or(anyhow::anyhow!("Failed to convert path to string."))?
Expand All @@ -50,9 +53,7 @@ pub fn initialize_celestia_config(

// update the node path with the chain id
config.bridge.celestia_bridge_path.replace(
dot_movement_path
.join("celestia")
.join(celestia_chain_id.clone())
celestia_chain_dir(&dot_movement, &config)
.join(".celestia-node")
.to_str()
.ok_or(anyhow::anyhow!("Failed to convert path to string."))?
Expand All @@ -62,6 +63,46 @@ pub fn initialize_celestia_config(
Ok(config)
}

pub async fn celestia_light_init(
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?;

Ok(())
}

pub async fn get_auth_token(
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();

Ok(auth_token)
}

pub async fn make_dirs(
_dot_movement: DotMovement,
config: Config,
Expand Down
Loading

0 comments on commit fbc3175

Please sign in to comment.