plugins: lsps: remove peer_id from transport
What changed, and why it matters
This is a small internal code cleanup in the experimental LSPS (Lightning Service Provider Specification) plugin. It removes a stored peer/node ID from a transport helper struct and instead passes the peer ID as a function argument when sending messages. There is no user-visible behavior change and no security fix.
No security action needed; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors Bolt8Transport in plugins/lsps-plugin/src/lsps0/transport.rs so it no longer stores an endpoint PublicKey. The peer_id is now passed through the Transport trait’s send/notify methods and forwarded to send_custommsg, which is updated to take a reference. Call sites in client.rs and service.rs are adjusted accordingly. This is a pure refactoring with no functional or security change.
Changed components
plugins/lsps-plugin/src/lsps0/transport.rsplugins/lsps-plugin/src/client.rsplugins/lsps-plugin/src/service.rsInspect captured patch +14 / −19
diff --git a/plugins/lsps-plugin/src/client.rs b/plugins/lsps-plugin/src/client.rs
index 9d07ac94..a22d141e 100644
--- a/plugins/lsps-plugin/src/client.rs
+++ b/plugins/lsps-plugin/src/client.rs
@@ -135,7 +135,6 @@ async fn on_lsps_lsps2_getinfo(
// Create Transport and Client
let transport = Bolt8Transport::new(
- &req.lsp_id,
rpc_path.clone(), // Clone path for potential reuse
p.state().hook_manager.clone(),
None, // Use default timeout
@@ -189,7 +188,6 @@ async fn on_lsps_lsps2_buy(
// Create Transport and Client
let transport = Bolt8Transport::new(
- &req.lsp_id,
rpc_path.clone(), // Clone path for potential reuse
p.state().hook_manager.clone(),
None, // Use default timeout
@@ -726,7 +724,6 @@ async fn on_lsps_listprotocols(
// Create the transport first and handle potential errors
let transport = Bolt8Transport::new(
- &req.lsp_id,
rpc_path,
p.state().hook_manager.clone(),
None, // Use default timeout
diff --git a/plugins/lsps-plugin/src/lsps0/transport.rs b/plugins/lsps-plugin/src/lsps0/transport.rs
index 62c387e4..f549ccf8 100644
--- a/plugins/lsps-plugin/src/lsps0/transport.rs
+++ b/plugins/lsps-plugin/src/lsps0/transport.rs
@@ -164,8 +164,6 @@ impl CustomMessageHookManager {
/// receive responses.
#[derive(Clone)]
pub struct Bolt8Transport {
- /// The node ID of the destination node.
- endpoint: cln_rpc::primitives::PublicKey,
/// Path to the Core Lightning RPC socket.
rpc_path: PathBuf,
/// Timeout for requests.
@@ -186,16 +184,12 @@ impl Bolt8Transport {
/// # Returns
/// A new `Bolt8Transport` instance or an error if the node ID is invalid
pub fn new(
- endpoint: &str,
rpc_path: PathBuf,
hook_watcher: CustomMessageHookManager,
timeout: Option<Duration>,
) -> Result<Self, Error> {
- let endpoint = cln_rpc::primitives::PublicKey::from_str(endpoint)
- .map_err(|e| Error::Internal(e.to_string()))?;
let timeout = timeout.unwrap_or(DEFAULT_TIMEOUT);
Ok(Self {
- endpoint,
rpc_path,
request_timeout: timeout,
hook_watcher,
@@ -210,8 +204,13 @@ impl Bolt8Transport {
}
/// Sends a custom message to the destination node.
- async fn send_custom_msg(&self, client: &mut ClnRpc, payload: Vec<u8>) -> Result<(), Error> {
- send_custommsg(client, payload, self.endpoint).await
+ async fn send_custom_msg(
+ &self,
+ client: &mut ClnRpc,
+ peer_id: &PublicKey,
+ payload: Vec<u8>,
+ ) -> Result<(), Error> {
+ send_custommsg(client, payload, peer_id).await
}
/// Waits for a response with timeout.
@@ -230,7 +229,7 @@ impl Bolt8Transport {
pub async fn send_custommsg(
client: &mut ClnRpc,
payload: Vec<u8>,
- peer: PublicKey,
+ peer: &PublicKey,
) -> Result<(), Error> {
let msg = CustomMsg {
message_type: LSPS0_MESSAGE_TYPE,
@@ -239,7 +238,7 @@ pub async fn send_custommsg(
let request = cln_rpc::model::requests::SendcustommsgRequest {
msg: msg.to_string(),
- node_id: peer,
+ node_id: peer.to_owned(),
};
client
@@ -257,7 +256,7 @@ impl Transport for Bolt8Transport {
/// Sends a JSON-RPC request and waits for a response.
async fn send(
&self,
- _peer_id: &PublicKey,
+ peer_id: &PublicKey,
request: String,
) -> core::result::Result<String, Error> {
let id = extract_message_id(&request)?;
@@ -275,7 +274,7 @@ impl Transport for Bolt8Transport {
self.hook_watcher
.subscribe_hook_once(id, Arc::downgrade(&tx_arc))
.await;
- self.send_custom_msg(&mut client, request.into_bytes())
+ self.send_custom_msg(&mut client, peer_id, request.into_bytes())
.await?;
let res = self.wait_for_response(rx).await?;
@@ -300,11 +299,11 @@ impl Transport for Bolt8Transport {
/// Sends a notification without waiting for a response.
async fn notify(
&self,
- _peer_id: &PublicKey,
+ peer_id: &PublicKey,
request: String,
) -> core::result::Result<(), Error> {
let mut client = self.connect_to_node().await?;
- self.send_custom_msg(&mut client, request.into_bytes())
+ self.send_custom_msg(&mut client, peer_id, request.into_bytes())
.await
}
}
diff --git a/plugins/lsps-plugin/src/service.rs b/plugins/lsps-plugin/src/service.rs
index a4450aea..2b443045 100644
--- a/plugins/lsps-plugin/src/service.rs
+++ b/plugins/lsps-plugin/src/service.rs
@@ -189,7 +189,6 @@ impl JsonRpcResponseWriter for LspsResponseWriter {
let mut client = cln_rpc::ClnRpc::new(&self.rpc_path)
.await
.map_err(|e| Error::Internal(e.to_string()))?;
-
- transport::send_custommsg(&mut client, payload.to_vec(), self.peer_id).await
+ transport::send_custommsg(&mut client, payload.to_vec(), &self.peer_id).await
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.