Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/rust/snippets/getting_started.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn create_seed() -> Vec<u8> {
let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();

//Show seed phrase to user
let _phrase = m.word_iter().fold("".to_string(), |c, n| c + " " + n);
let _phrase = m.words().fold("".to_string(), |c, n| c + " " + n);

const EMPTY_PASSPHRASE: &str = "";
let seed = &m.to_seed(EMPTY_PASSPHRASE)[0..32]; // Only need the first 32 bytes
Expand Down
27 changes: 17 additions & 10 deletions libs/gl-client/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,16 @@ impl Signer {
/// requests from it. The requests are then verified and processed
/// using the `Hsmd`.
pub async fn run_once(&self, node_uri: Uri) -> Result<(), Error> {
debug!("Connecting to node at {}", node_uri);
info!("Connecting to node at {}", node_uri);

let tls_config = if node_uri.host().unwrap_or_default().contains("blckstrm") {
self.tls.inner.clone()
} else {
self.tls.inner.clone().domain_name("localhost")
};

let c = Endpoint::from_shared(node_uri.to_string())?
.tls_config(self.tls.inner.clone().domain_name("localhost"))?
.tls_config(tls_config)?
.tcp_keepalive(Some(crate::TCP_KEEPALIVE))
.http2_keep_alive_interval(crate::TCP_KEEPALIVE)
.keep_alive_timeout(crate::TCP_KEEPALIVE_TIMEOUT)
Expand Down Expand Up @@ -725,7 +732,7 @@ impl Signer {
&self,
scheduler_uri: String,
) -> Result<SchedulerClient<tonic::transport::channel::Channel>> {
debug!("Connecting to scheduler at {scheduler_uri}");
info!("Connecting to scheduler at {scheduler_uri}");

let channel = Endpoint::from_shared(scheduler_uri.clone())?
.tls_config(self.tls.inner.clone())?
Expand All @@ -740,7 +747,7 @@ impl Signer {
// If it fails due to connection error, sleep and retry. Re-throw all other errors.
loop {
#[allow(deprecated)]
let maybe_upgrade_res = scheduler
let res = scheduler
.maybe_upgrade(UpgradeRequest {
initmsg: self.init.clone(),
signer_version: self.version().to_owned(),
Expand All @@ -752,19 +759,19 @@ impl Signer {
})
.await;

if let Err(err_status) = maybe_upgrade_res {
match err_status.code() {
match res {
Err(e) => match e.code() {
Code::Unavailable => {
debug!("Cannot connect to scheduler, sleeping and retrying");
sleep(Duration::from_secs(3)).await;
continue;
}
_ => {
return Err(Error::Upgrade(err_status))?;
}
_ => Err(Error::Upgrade(e))?,
},
Ok(r) => {
debug!("Server reports version {}", r.into_inner().old_version)
}
}

break;
}
Ok(scheduler)
Expand Down
13 changes: 7 additions & 6 deletions libs/gl-plugin/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static LIMITER: OnceCell<RateLimiter<NotKeyed, InMemoryState, MonotonicClock>> =
OnceCell::const_new();

static RPC_CLIENT: OnceCell<Arc<Mutex<cln_rpc::ClnRpc>>> = OnceCell::const_new();
static RPC_POLL_INTERVAL: Duration = Duration::from_millis(500);


pub async fn get_rpc<P: AsRef<Path>>(path: P) -> Arc<Mutex<cln_rpc::ClnRpc>> {
RPC_CLIENT
Expand All @@ -42,12 +44,9 @@ pub async fn get_rpc<P: AsRef<Path>>(path: P) -> Arc<Mutex<cln_rpc::ClnRpc>> {
debug!("Connected to lightning-rpc.");
return Arc::new(Mutex::new(client));
}
Err(e) => {
debug!(
"Failed to connect to lightning-rpc: {:?}. Retrying in 50m...",
e
);
tokio::time::sleep(Duration::from_millis(50)).await;
Err(_) => {
debug!("Failed to connect to lightning-rpc. Retrying in {RPC_POLL_INTERVAL:?}...");
tokio::time::sleep(RPC_POLL_INTERVAL).await;
continue;
}
}
Expand Down Expand Up @@ -369,6 +368,7 @@ impl Node for PluginNodeServer {
req.request.signer_state.len()
);

eprintln!("WIRE: plugin -> signer: {:?}", req);
if let Err(e) = tx.send(Ok(req.request)).await {
warn!("Error streaming request {:?} to hsm_id={}", e, hsm_id);
break;
Expand All @@ -393,6 +393,7 @@ impl Node for PluginNodeServer {
log::warn!("The above error was returned instead of a response.");
return Ok(Response::new(pb::Empty::default()));
}
eprintln!("WIRE: signer -> plugin: {:?}", req);

// Create a state from the key-value-version tuples. Need to
// convert here, since `pb` is duplicated in the two different
Expand Down
17 changes: 11 additions & 6 deletions libs/gl-signerproxy/src/hsmproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::pb::{hsm_client::HsmClient, Empty, HsmRequest, HsmRequestContext};
use crate::wire::{DaemonConnection, Message};
use anyhow::{anyhow, Context};
use anyhow::{Error, Result};
use log::{debug, error, info, warn};
use log::{error, info, warn};
use std::convert::TryFrom;
use std::env;
use std::os::unix::io::{AsRawFd, FromRawFd};
Expand Down Expand Up @@ -70,12 +70,12 @@ async fn process_requests(
if let Ok(msg) = conn.read().await {
match msg.msgtype() {
9 => {
debug!("Got a message from node: {:?}", &msg.body);
eprintln!("Got a message from node: {:?}", &msg.body);
// This requests a new client fd with a given context,
// handle it locally, and defer the creation of the client
// fd on the server side until we need it.
let ctx = HsmRequestContext::from_client_hsmfd_msg(&msg)?;
debug!("Got a request for a new client fd. Context: {:?}", ctx);
eprintln!("Got a request for a new client fd. Context: {:?}", ctx);

let (local, remote) = UnixStream::pair()?;
let local = NodeConnection {
Expand Down Expand Up @@ -103,15 +103,20 @@ async fn process_requests(
signer_state: Vec::new(),
});
let start_time = tokio::time::Instant::now();
debug!("Got a message from node: {:?}", &req);
eprintln!(
"WIRE: lightningd -> hsmd: Got a message from node: {:?}",
&req
);
eprintln!("WIRE: hsmd -> plugin: Forwarding: {:?}", &req);
let res = server.request(req).await?.into_inner();
let msg = Message::from_raw(res.raw);
let delta = start_time.elapsed();
debug!(
"Got respone from hsmd: {:?} after {}ms",
eprintln!(
"WIRE: plugin -> hsmd: Got respone from hsmd: {:?} after {}ms",
&msg,
delta.as_millis()
);
eprintln!("WIRE: hsmd -> lightningd: {:?}", &msg);
conn.write(msg).await?
}
}
Expand Down
Loading