From efdab67a255ffdc1159b70f01ff6174b74876697 Mon Sep 17 00:00:00 2001 From: Chris Guida Date: Sat, 28 Sep 2024 19:14:29 -0600 Subject: [PATCH 1/2] better handling of cookie file on signet/mutinynet --- Cargo.lock | 63 +++++++++---------------------------------------- Cargo.toml | 2 +- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48fb625..20b92e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,7 +119,7 @@ version = "1.0.0-alpha.2" source = "git+https://github.com/chrisguida/bdk?rev=cc32e69a12b8c30e571e6261a8b99dec2cef6ff5#cc32e69a12b8c30e571e6261a8b99dec2cef6ff5" dependencies = [ "bdk_chain", - "bitcoin 0.30.2", + "bitcoin", "getrandom", "js-sys", "log", @@ -134,7 +134,7 @@ name = "bdk_chain" version = "0.6.0" source = "git+https://github.com/chrisguida/bdk?rev=cc32e69a12b8c30e571e6261a8b99dec2cef6ff5#cc32e69a12b8c30e571e6261a8b99dec2cef6ff5" dependencies = [ - "bitcoin 0.30.2", + "bitcoin", "miniscript", "serde", ] @@ -164,18 +164,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitcoin" -version = "0.29.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" -dependencies = [ - "bech32", - "bitcoin_hashes 0.11.0", - "secp256k1 0.24.3", - "serde", -] - [[package]] name = "bitcoin" version = "0.30.2" @@ -185,9 +173,9 @@ dependencies = [ "base64 0.13.1", "bech32", "bitcoin-private", - "bitcoin_hashes 0.12.0", + "bitcoin_hashes", "hex_lit", - "secp256k1 0.27.0", + "secp256k1", "serde", ] @@ -197,15 +185,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" -[[package]] -name = "bitcoin_hashes" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" -dependencies = [ - "serde", -] - [[package]] name = "bitcoin_hashes" version = "0.12.0" @@ -234,7 +213,7 @@ name = "bitcoincore-rpc-json" version = "0.17.0" source = "git+https://github.com/chrisguida/rust-bitcoincore-rpc?branch=feat/scanblocks#23927f3e8b3bd413e0bf8b7c42b9531345bdd1a3" dependencies = [ - "bitcoin 0.30.2", + "bitcoin", "bitcoin-private", "serde", "serde_json", @@ -333,12 +312,12 @@ dependencies = [ [[package]] name = "cln-rpc" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3b630e345cdfc6f64315414b50815a9eeabbf12438413798bf09e9e79be8b8" +checksum = "3374857a63bde21f5cc54ed3884476f3118dd5e26d792d16dfa21d8a4acb23e8" dependencies = [ "anyhow", - "bitcoin 0.29.2", + "bitcoin", "bytes", "futures-util", "hex", @@ -600,7 +579,7 @@ version = "10.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1eb102b66b2127a872dbcc73095b7b47aeb9d92f7b03c2b2298253ffc82c7594" dependencies = [ - "bitcoin 0.30.2", + "bitcoin", "bitcoin-private", "serde", ] @@ -770,38 +749,18 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "secp256k1" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" -dependencies = [ - "bitcoin_hashes 0.11.0", - "secp256k1-sys 0.6.1", - "serde", -] - [[package]] name = "secp256k1" version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" dependencies = [ - "bitcoin_hashes 0.12.0", + "bitcoin_hashes", "rand", - "secp256k1-sys 0.8.1", + "secp256k1-sys", "serde", ] -[[package]] -name = "secp256k1-sys" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" -dependencies = [ - "cc", -] - [[package]] name = "secp256k1-sys" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 8eca6d2..5a7762e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ clap = { version = "4.4.0", features = ["derive"] } cln-plugin = { git = "https://github.com/elementsproject/lightning", version = "0.1.4" } # cln-plugin = { path = "../../lightning/plugins" } # cln-plugin = { git = "https://github.com/chrisguida/lightning", version = "0.1.4", branch = "feat/cln-plugin-send-notifs" } -cln-rpc = "0.1.3" +cln-rpc = "0.2.0" home = "0.5.5" log = "0.4.18" serde = "1.0.159" diff --git a/src/main.rs b/src/main.rs index 0beb218..b069737 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,11 @@ extern crate serde_json; use bdk::chain::tx_graph::CanonicalTx; use bdk::chain::ConfirmationTimeAnchor; -use bitcoincore_rpc::Auth; +// use bitcoincore_rpc::Auth; +use bitcoincore_rpc::{Auth, Client, RpcApi}; use clap::error::ErrorKind; use clap::{CommandFactory, Parser, Subcommand}; -use cln_rpc::model::DatastoreMode; +use cln_rpc::model::requests::DatastoreMode; use cln_rpc::{ model::requests::{DatastoreRequest, ListdatastoreRequest}, ClnRpc, Request, Response, @@ -86,21 +87,24 @@ async fn main() -> Result<(), anyhow::Error> { } else { return Ok(()); }; - log::debug!( - "Configuration from CLN main daemon: {:?}", - configured_plugin.configuration() - ); - log::debug!( - "smaug_network = {:?}, cln_network = {}", - configured_plugin.option("smaug_network"), - configured_plugin.configuration().network - ); + let cln_network = configured_plugin.configuration().network.clone(); + if log::log_enabled!(log::Level::Debug) { + eprintln!( + "Configuration from CLN main daemon: {:?}", + configured_plugin.configuration() + ); + eprintln!( + "smaug_network = {:?}, cln_network = {}", + configured_plugin.option("smaug_network").unwrap().as_str(), + &cln_network, + ); + } let network = match configured_plugin.option("smaug_network") { Some(smaug_network) => match smaug_network.as_str() { Some(sn) => sn.to_owned(), - None => configured_plugin.configuration().network, + None => cln_network.clone(), }, - None => configured_plugin.configuration().network, + None => cln_network.clone(), }; let brpc_host = match configured_plugin.option("smaug_brpc_host") { Some(smaug_brpc_host) => match smaug_brpc_host.as_str() { @@ -144,23 +148,43 @@ async fn main() -> Result<(), anyhow::Error> { if let Auth::None = brpc_auth { if let Some(smaug_brpc_cookie_dir) = configured_plugin.option("smaug_brpc_cookie_dir") { if let Some(sbcd) = smaug_brpc_cookie_dir.as_str() { - brpc_auth = Auth::CookieFile(PathBuf::from(sbcd).join(".cookie")) + let cf_path = PathBuf::from(sbcd) + .join(".cookie"); + if !cf_path.exists() { + return Err(anyhow!("Nonexistent cookie file specified in smaug_brpc_cookie_dir: {}", cf_path.display())); + } + brpc_auth = Auth::CookieFile(PathBuf::from(sbcd).join(".cookie")); } else { - if network == "regtest" { - brpc_auth = Auth::CookieFile( - home_dir() - .expect("cannot determine home dir") - .join(".bitcoin/regtest") - .join(".cookie"), - ); + let cf_path = home_dir() + .expect("cannot determine home dir") + .join(format!(".bitcoin/{}", cln_network.clone())) + .join(".cookie"); + if cf_path.exists() { + brpc_auth = Auth::CookieFile(cf_path); } } } } if let Auth::None = brpc_auth { return Err(anyhow!("must specify either `smaug_bprc_cookie_dir` or `smaug_brpc_user` and `smaug_brpc_pass`")); + } else { + if log::log_enabled!(log::Level::Debug) { + eprintln!("using auth info: {:?}", brpc_auth); + } + let rpc_client = Client::new( + &format!("http://{}:{}", brpc_host.clone(), brpc_port.clone()), + brpc_auth.clone(), + )?; + + let _ = match rpc_client.get_connection_count() { + Ok(cc) => cc, + Err(e) => { + return Err(anyhow!("Cannot connect to bitcoind, ensure your `smaug_bprc_cookie_dir` or `smaug_brpc_user` and `smaug_brpc_pass` are correct + and that your node is active and accepting rpc connections")) + }, + }; } - log::trace!("using auth info: {:?}", brpc_auth); + let ln_dir: PathBuf = configured_plugin.configuration().lightning_dir.into(); // Create data dir if it does not exist fs::create_dir_all(ln_dir.join(SMAUG_DATADIR)).unwrap_or_else(|e| { From 81b21b6a5adf1e77a3334e693f21fcc738c77d55 Mon Sep 17 00:00:00 2001 From: Chris Guida Date: Tue, 1 Oct 2024 17:11:15 -0600 Subject: [PATCH 2/2] use default port for mutinynet and signet as well --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index b069737..d6428ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,11 +122,13 @@ async fn main() -> Result<(), anyhow::Error> { Some(sbp) => u16::try_from(sbp)?, None => match network.as_str() { "regtest" => 18443, + "signet" | "mutinynet" => 38332, _ => 8332, }, }, None => match network.as_str() { "regtest" => 18443, + "signet" | "mutinynet" => 38332, _ => 8332, }, };