Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ impl LndkOnionMessenger {
}

// Create an onion messenger that depends on LND's signer client and consume related events.
let mut node_client = client.signer().clone();
let node_signer = LndNodeSigner::new(pubkey, &mut node_client);
let node_client = client.clone().signer_read_only();
let node_signer = LndNodeSigner::new(pubkey, node_client);
let messenger_utils = MessengerUtilities::new();
let network_graph = &NetworkGraph::new(network, &messenger_utils);
let message_router = &DefaultMessageRouter::new(network_graph, &messenger_utils);
Expand All @@ -229,10 +229,10 @@ impl LndkOnionMessenger {
IgnoringMessageHandler {},
);

let mut peers_client = client.lightning().clone();
let peers_client = client.lightning().clone();
self.run_onion_messenger(
peer_support,
&mut peers_client,
&peers_client,
onion_messenger,
network,
args.signals,
Expand Down
17 changes: 8 additions & 9 deletions src/lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use lightning::offers::invoice::UnsignedBolt12Invoice;
use lightning::offers::invoice_request::{InvoiceRequest, UnsignedInvoiceRequest};
use lightning::sign::{KeyMaterial, NodeSigner, Recipient};
use log::error;
use std::cell::RefCell;
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Display;
Expand Down Expand Up @@ -48,7 +47,7 @@ pub fn get_lnd_client(cfg: LndCfg) -> Result<Client, ConnectError> {
}

/// LndCfg specifies the configuration required to connect to LND's grpc client.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct LndCfg {
pub address: String,
pub creds: Creds,
Expand Down Expand Up @@ -233,23 +232,23 @@ pub fn has_build_tags(version: &Version, requirement: Option<BuildTagsRequiremen
}

/// LndNodeSigner provides signing operations using LND's signer subserver.
pub(crate) struct LndNodeSigner<'a> {
pub(crate) struct LndNodeSigner {
pubkey: PublicKey,
secp_ctx: Secp256k1<secp256k1::All>,
signer: RefCell<&'a mut tonic_lnd::SignerClient>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally lol

signer: tonic_lnd::SignerClient,
}

impl<'a> LndNodeSigner<'a> {
pub(crate) fn new(pubkey: PublicKey, signer: &'a mut tonic_lnd::SignerClient) -> Self {
impl LndNodeSigner {
pub(crate) fn new(pubkey: PublicKey, signer: tonic_lnd::SignerClient) -> Self {
LndNodeSigner {
pubkey,
secp_ctx: Secp256k1::new(),
signer: RefCell::new(signer),
signer,
}
}
}

impl<'a> NodeSigner for LndNodeSigner<'a> {
impl NodeSigner for LndNodeSigner {
/// Get node id based on the provided [`Recipient`].
///
/// This method must return the same value each time it is called with a given [`Recipient`]
Expand Down Expand Up @@ -287,7 +286,7 @@ impl<'a> NodeSigner for LndNodeSigner<'a> {
*other_key
};

let shared_secret = match block_on(self.signer.borrow_mut().derive_shared_key(
let shared_secret = match block_on(self.signer.clone().derive_shared_key(
tonic_lnd::signrpc::SharedKeyRequest {
ephemeral_pubkey: tweaked_key.serialize().into_iter().collect::<Vec<u8>>(),
key_desc: None,
Expand Down
8 changes: 3 additions & 5 deletions src/onion_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl LndkOnionMessenger {
>(
&self,
current_peers: HashMap<PublicKey, bool>,
ln_client: &mut tonic_lnd::LightningClient,
ln_client: &tonic_lnd::LightningClient,
onion_messenger: OnionMessenger<ES, NS, L, NL, MR, OMH, CMH>,
network: Network,
signals: LifecycleSignals,
Expand Down Expand Up @@ -266,10 +266,8 @@ impl LndkOnionMessenger {
}
});

// Consume events is our main controlling loop, so we run it inline here. We use a RefCell
// in onion_messenger to allow interior mutability (see LndNodeSigner) so this
// function can't safely be passed off to another thread. This function is expected
// to finish if any producing thread exits (because we're no longer receiving the
// Consume events is our main controlling loop, so we run it inline here. This function is
// expected to finish if any producing thread exits (because we're no longer receiving the
// events we need).
let rate_limiter = &mut TokenLimiter::new(
current_peers.keys().copied(),
Expand Down