Skip to content

Commit

Permalink
update coreln config and better handling missing files (#90)
Browse files Browse the repository at this point in the history
* fixes outdated coreln config and adds --developer flag for while it runs
* rewrite coreln visualization to use the rest server that comes with the coreln node instead of c-lightning-REST
* better handles missing folders/files
  • Loading branch information
tee8z authored Oct 22, 2024
1 parent 0a98d06 commit 8856828
Show file tree
Hide file tree
Showing 24 changed files with 566 additions and 306 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions doppler/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USERID=1000
GROUPID=1000
6 changes: 6 additions & 0 deletions doppler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
/data
/scripts
doppler.db
doppler-cluster.yaml
/ui_config
2 changes: 1 addition & 1 deletion doppler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "doppler"
version = "0.3.1"
version = "0.3.2"
repository = "https://github.com/tee8z/doppler.git"

[package.metadata.dist]
Expand Down
11 changes: 4 additions & 7 deletions doppler/config/regtest/cln.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@

## Load your plugins from a directory
#plugin-dir=/path/to/your/.lightning/plugins

## Load plugins individually
plugin=/opt/c-lightning-rest/plugin.js
rest-port=8080
rest-docport=4001
rest-protocol=https
clnrest-host=0.0.0.0
clnrest-port=8080
clnrest-protocol=https
## Set the network for Core Lightning to sync to, Bitcoin Mainnet for most users
## Not required if the config file is in a network directory
network=regtest
Expand All @@ -116,4 +113,4 @@ rpc-file-mode=0660

dev-fast-gossip
experimental-dual-fund
large-channels
large-channels
9 changes: 4 additions & 5 deletions doppler/config/signet/cln.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@
#plugin-dir=/path/to/your/.lightning/plugins

## Load plugins individually
plugin=/opt/c-lightning-rest/plugin.js
rest-port=8080
rest-docport=4001
rest-protocol=https
clnrest-host=0.0.0.0
clnrest-port=8080
clnrest-protocol=https
## Set the network for Core Lightning to sync to, Bitcoin Mainnet for most users
## Not required if the config file is in a network directory
network=signet
Expand All @@ -116,4 +115,4 @@ rpc-file-mode=0660

dev-fast-gossip
experimental-dual-fund
large-channels
large-channels
48 changes: 35 additions & 13 deletions doppler/src/cln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub struct Cln {
pub container_name: String,
pub name: String,
pub pubkey: Option<String>,
pub rune: Option<String>,
pub alias: String,
pub grpc_port: String,
pub p2p_port: String,
pub rpc_server: String,
pub rest_port: String,
pub macaroon_path: String,
pub server_url: String,
pub path_vol: String,
pub bitcoind_node_container_name: String,
Expand All @@ -50,6 +50,12 @@ impl Cln {
) -> Result<String, Error> {
get_peers_short_channel_id(self, options, node_command, "source")
}

pub fn add_rune(&mut self, options: &Options) -> Result<(), Error> {
let rune = get_rune(self, options)?;
self.rune = Some(rune);
Ok(())
}
}

impl L2Node for Cln {
Expand Down Expand Up @@ -178,7 +184,7 @@ pub fn build_cln(
// Passing these args on the command line is unavoidable due to how the docker image is setup
let command = Command::Simple(
format!(
"--network={} --lightning-dir=/home/clightning",
"--network={} --lightning-dir=/home/clightning --developer",
options.network
)
.to_string(),
Expand All @@ -199,10 +205,7 @@ pub fn build_cln(
]),
env_file: Some(EnvFile::Simple(".env".to_owned())),
command: Some(command),
volumes: Volumes::Simple(vec![
format!("{}:/home/clightning:rw", cln_conf.path_vol),
format!("{}/certs:/opt/c-lightning-rest/certs:rw", cln_conf.path_vol),
]),
volumes: Volumes::Simple(vec![format!("{}:/home/clightning:rw", cln_conf.path_vol)]),
networks: Networks::Simple(vec![NETWORK.to_owned()]),
..Default::default()
};
Expand All @@ -211,11 +214,8 @@ pub fn build_cln(
.insert(cln_conf.container_name.clone(), Some(cln));
cln_conf.server_url = format!("https://localhost:{}", rest_port.to_string());
info!(
"connect to {} via rest using {} with access macaroons at {} and via rpc using localhost:{} ",
cln_conf.container_name,
cln_conf.server_url,
cln_conf.macaroon_path,
grpc_port,
"connect to {} via rest using {} and via rpc using localhost:{} ",
cln_conf.container_name, cln_conf.server_url, grpc_port,
);
cln_conf.grpc_port = grpc_port.to_string();
cln_conf.rest_port = rest_port.to_string();
Expand Down Expand Up @@ -275,7 +275,7 @@ pub fn build_and_save_config(
pubkey: None,
server_url: format!("http://{}:10000", container_name),
path_vol: full_path.clone(),
macaroon_path: format!("{}/certs/access.macaroon", full_path),
rune: None,
rpc_server: format!("{}:10000", container_name),
grpc_port: "10000".to_owned(),
p2p_port: "9735".to_owned(),
Expand Down Expand Up @@ -378,13 +378,13 @@ fn load_config(
alias: name.to_owned(),
container_name: container_name.to_owned(),
pubkey: None,
rune: None,
rpc_server: format!("{}:10000", container_name),
server_url: format!("https://{}:8080", container_name),
path_vol: full_path.to_owned(),
grpc_port: "10000".to_owned(),
p2p_port: "9735".to_owned(),
rest_port: "8080".to_owned(),
macaroon_path: format!("{}/certs/access.macaroon", full_path),
bitcoind_node_container_name: bitcoind_service,
network,
})
Expand Down Expand Up @@ -798,3 +798,25 @@ fn get_rhash(node: &Cln, options: &Options) -> Result<String, Error> {
}
Ok(found_rhash.unwrap())
}

fn get_rune(node: &Cln, options: &Options) -> Result<String, Error> {
let network: String = format!("--network={}", options.network);
let compose_path = options.compose_path.as_ref().unwrap();

let commands = vec![
"-f",
compose_path,
"exec",
node.get_container_name(),
"lightning-cli",
"--lightning-dir=/home/clightning",
&network,
"createrune",
];
let output = run_command(options, "createrune".to_owned(), commands)?;
let found_rune: Option<String> = node.get_property("rune", output);
if found_rune.is_none() {
error!("no rune found");
}
Ok(found_rune.unwrap())
}
1 change: 1 addition & 0 deletions doppler/src/conf_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ impl Options {

for coreln in self.cln_nodes.iter_mut() {
coreln.add_pubkey(&options_clone);
coreln.add_rune(&options_clone)?;
}
Ok(())
}
Expand Down
16 changes: 11 additions & 5 deletions doppler/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::{
};
use anyhow::{anyhow, Error};
use log::{debug, error, info};
use std::fs::{File, OpenOptions};
use std::fs::{self, File, OpenOptions};
use std::io::Write;
use std::os::unix::prelude::PermissionsExt;
use std::path::Path;
use std::process::{Command, Output};
use std::str::from_utf8;
use std::thread;
Expand All @@ -24,7 +25,9 @@ pub fn load_options_from_external_nodes(
options.load_lnds()?;
debug!("loaded lnds");
let network = options.external_nodes.clone().unwrap()[0].network.clone();

create_ui_config_files(&options, &network)?;

Ok(())
}

Expand Down Expand Up @@ -94,8 +97,6 @@ pub fn run_cluster(options: &mut Options, compose_path: &str) -> Result<(), Erro
debug!("saved cluster config");

start_docker_compose(options)?;
create_ui_config_files(options, &options.network)?;

debug!("started cluster");
//simple wait for docker-compose to spin up
thread::sleep(Duration::from_secs(6));
Expand All @@ -104,8 +105,10 @@ pub fn run_cluster(options: &mut Options, compose_path: &str) -> Result<(), Erro
mine_initial_blocks(options)?;
}
setup_l2_nodes(options)?;
create_ui_config_files(options, &options.network)
.map_err(|e| anyhow!("error creating ui config: {}", e))?;
if options.aliases && options.external_nodes.is_none() {
update_bash_alias(options)?;
update_bash_alias(options).map_err(|e| anyhow!("error creating alias: {}", e))?;
}

Ok(())
Expand Down Expand Up @@ -230,6 +233,9 @@ fn update_bash_alias(options: &Options) -> Result<(), Error> {
});
let script_path = "scripts/aliases.sh";
let full_path = get_absolute_path(script_path)?;
if let Some(parent) = Path::new(&full_path).parent() {
fs::create_dir_all(parent)?;
}
let mut file: File = OpenOptions::new()
.read(true)
.write(true)
Expand All @@ -255,7 +261,7 @@ pub fn update_bash_alias_external(options: &Options) -> Result<(), Error> {
{name}() {{
lncli --network={network} --macaroonpath={macaroon_path} --rpcserver={rpcserver} --tlscertpath="" "$@"
}}
"#,
"#,
name=lnd.node_alias, network=lnd.network, macaroon_path=lnd.macaroon_path, rpcserver=lnd.api_endpoint));
script_content.push('\n');
});
Expand Down
1 change: 1 addition & 0 deletions doppler/src/lnd_actions/lnd_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ impl LndCli {
];

// Used for amp payments
#[allow(unused_assignments)]
let mut subcommand = String::from("");
if let Some(command) = node_command.subcommand.clone() {
subcommand = command;
Expand Down
2 changes: 1 addition & 1 deletion doppler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Cli {
app_sub_commands: Option<AppSubCommands>,

/// Path to ui config file, used to connect to the nodes via the browser
#[arg(short, long, default_value = "./doppler_ui/ui_config/info.conf")]
#[arg(short, long, default_value = "./ui_config/info.conf.ini")]
ui_config_path: String,
}

Expand Down
8 changes: 6 additions & 2 deletions doppler/src/visualizer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use anyhow::{Error, Result};
use std::{
fs::File,
fs::{self, File},
io::{LineWriter, Write},
path::Path,
};

use crate::{get_absolute_path, Options};

pub fn create_ui_config_files(options: &Options, network: &str) -> Result<(), Error> {
let config_absolute_path = get_absolute_path(&options.ui_config_path)?;
if let Some(parent) = Path::new(&config_absolute_path).parent() {
fs::create_dir_all(parent)?;
}
let node_config_file = File::create(config_absolute_path)?;
let mut node_config = LineWriter::new(node_config_file);
for node in options.lnd_nodes.clone() {
Expand All @@ -27,7 +31,7 @@ pub fn create_ui_config_files(options: &Options, network: &str) -> Result<(), Er

for node in options.cln_nodes.clone() {
let header = format!("[{}] \n", node.alias);
let macaroon = format!("ACCESS_MACAROON_PATH={} \n", node.macaroon_path);
let macaroon = format!("RUNE={} \n", node.rune.unwrap_or_default());
let api_endpoint = format!("API_ENDPOINT={} \n", node.server_url);
let network = format!("NETWORK={} \n", network);
let node_type = format!("TYPE={} \n", "coreln");
Expand Down
1 change: 1 addition & 0 deletions doppler_ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/scripts
17 changes: 15 additions & 2 deletions doppler_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
cd /.doppler/<release tag> && node ./build
```

- Run from "./doppler/doppler_ui" in the git repo:
- Run from "./doppler/doppler_ui" in the git repo (not recommended for non-developers):
```
UI_CONFIG_PATH=./ui_config npm run build
UI_CONFIG_PATH=./ui_config npm run dev
```
- make sure to update `./ui_config/server.conf` to have correct path to doppler binary and full path to working directory
```
dopplerBinaryPath = /$HOME/doppler/target/distrib/doppler-x86_64-unknown-linux-gnu/doppler
currentWorkingDirectory = /$HOME/doppler/doppler_ui
```
- NOTE: you may need to copy the ./doppler/config into ./doppler_ui/, that's how to handle the following error if seen in the doppler logs from the UI:
```
thread 'main' panicked at doppler/src/bitcoind.rs:116:61:
called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
4 changes: 2 additions & 2 deletions doppler_ui/package-lock.json

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

2 changes: 1 addition & 1 deletion doppler_ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doppler",
"version": "0.3.1",
"version": "0.3.2",
"repository": "github:tee8z/doppler",
"bin": {
"doppler_ui": "build/index.js"
Expand Down
Loading

0 comments on commit 8856828

Please sign in to comment.