Move `PeerState` and related types to `peer_state.rs` module
What changed, and why it matters
This commit is a pure code reorganization: it moves the PeerState type and related helper types from the service.rs file into a new peer_state.rs module. No behavior changes, security fixes, or vulnerability patches are present.
No security action needed. Treat as routine refactoring during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff shows a refactor-only change under the lsps1_service feature. PeerState, OutboundCRChannel, OutboundRequestState, OutboundLSPS1Config, and ChannelStateError are relocated to lightning-liquidity/src/lsps1/peer_state.rs. Visibility is adjusted from private to pub(super) to allow cross-module access within lsps1. The service.rs file now imports these types from the new module. Logic, error handling, and data structures remain identical.
Changed components
lightning-liquidity/src/lsps1/service.rslightning-liquidity/src/lsps1/peer_state.rslightning-liquidity/src/lsps1/mod.rsInspect captured patch +87 / −64
diff --git a/lightning-liquidity/src/lsps1/mod.rs b/lightning-liquidity/src/lsps1/mod.rs
index b068b18..bdfc404 100644
--- a/lightning-liquidity/src/lsps1/mod.rs
+++ b/lightning-liquidity/src/lsps1/mod.rs
@@ -13,4 +13,6 @@ pub mod client;
pub mod event;
pub mod msgs;
#[cfg(lsps1_service)]
+mod peer_state;
+#[cfg(lsps1_service)]
pub mod service;
diff --git a/lightning-liquidity/src/lsps1/peer_state.rs b/lightning-liquidity/src/lsps1/peer_state.rs
new file mode 100644
index 0000000..71eeb66
--- /dev/null
+++ b/lightning-liquidity/src/lsps1/peer_state.rs
@@ -0,0 +1,84 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+//! Contains peer state objects that are used by `LSPS1ServiceHandler`.
+
+use super::msgs::{LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentInfo, LSPS1Request};
+
+use crate::lsps0::ser::{LSPSDateTime, LSPSRequestId};
+use crate::prelude::HashMap;
+
+use lightning::ln::msgs::{ErrorAction, LightningError};
+use lightning::util::logger::Level;
+
+#[derive(Default)]
+pub(super) struct PeerState {
+ pub(super) outbound_channels_by_order_id: HashMap<LSPS1OrderId, OutboundCRChannel>,
+ pub(super) pending_requests: HashMap<LSPSRequestId, LSPS1Request>,
+}
+
+impl PeerState {
+ pub(super) fn insert_outbound_channel(
+ &mut self, order_id: LSPS1OrderId, channel: OutboundCRChannel,
+ ) {
+ self.outbound_channels_by_order_id.insert(order_id, channel);
+ }
+}
+
+struct ChannelStateError(String);
+
+impl From<ChannelStateError> for LightningError {
+ fn from(value: ChannelStateError) -> Self {
+ LightningError { err: value.0, action: ErrorAction::IgnoreAndLog(Level::Info) }
+ }
+}
+
+#[derive(PartialEq, Debug)]
+pub(super) enum OutboundRequestState {
+ OrderCreated { order_id: LSPS1OrderId },
+ WaitingPayment { order_id: LSPS1OrderId },
+}
+
+impl OutboundRequestState {
+ fn awaiting_payment(&self) -> Result<Self, ChannelStateError> {
+ match self {
+ OutboundRequestState::OrderCreated { order_id } => {
+ Ok(OutboundRequestState::WaitingPayment { order_id: order_id.clone() })
+ },
+ state => Err(ChannelStateError(format!("TODO. JIT Channel was in state: {:?}", state))),
+ }
+ }
+}
+
+pub(super) struct OutboundLSPS1Config {
+ pub(super) order: LSPS1OrderParams,
+ pub(super) created_at: LSPSDateTime,
+ pub(super) payment: LSPS1PaymentInfo,
+}
+
+pub(super) struct OutboundCRChannel {
+ pub(super) state: OutboundRequestState,
+ pub(super) config: OutboundLSPS1Config,
+}
+
+impl OutboundCRChannel {
+ pub(super) fn new(
+ order: LSPS1OrderParams, created_at: LSPSDateTime, order_id: LSPS1OrderId,
+ payment: LSPS1PaymentInfo,
+ ) -> Self {
+ Self {
+ state: OutboundRequestState::OrderCreated { order_id },
+ config: OutboundLSPS1Config { order, created_at, payment },
+ }
+ }
+ pub(super) fn awaiting_payment(&mut self) -> Result<(), LightningError> {
+ self.state = self.state.awaiting_payment()?;
+ Ok(())
+ }
+}
diff --git a/lightning-liquidity/src/lsps1/service.rs b/lightning-liquidity/src/lsps1/service.rs
index 7d138e3..ac97b61 100644
--- a/lightning-liquidity/src/lsps1/service.rs
+++ b/lightning-liquidity/src/lsps1/service.rs
@@ -20,6 +20,7 @@ use super::msgs::{
LSPS1OrderState, LSPS1PaymentInfo, LSPS1Request, LSPS1Response,
LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
};
+use super::peer_state::{OutboundCRChannel, PeerState};
use crate::message_queue::MessageQueue;
use crate::events::EventQueue;
@@ -48,70 +49,6 @@ pub struct LSPS1ServiceConfig {
pub supported_options: Option<LSPS1Options>,
}
-struct ChannelStateError(String);
-
-impl From<ChannelStateError> for LightningError {
- fn from(value: ChannelStateError) -> Self {
- LightningError { err: value.0, action: ErrorAction::IgnoreAndLog(Level::Info) }
- }
-}
-
-#[derive(PartialEq, Debug)]
-enum OutboundRequestState {
- OrderCreated { order_id: LSPS1OrderId },
- WaitingPayment { order_id: LSPS1OrderId },
-}
-
-impl OutboundRequestState {
- fn awaiting_payment(&self) -> Result<Self, ChannelStateError> {
- match self {
- OutboundRequestState::OrderCreated { order_id } => {
- Ok(OutboundRequestState::WaitingPayment { order_id: order_id.clone() })
- },
- state => Err(ChannelStateError(format!("TODO. JIT Channel was in state: {:?}", state))),
- }
- }
-}
-
-struct OutboundLSPS1Config {
- order: LSPS1OrderParams,
- created_at: LSPSDateTime,
- payment: LSPS1PaymentInfo,
-}
-
-struct OutboundCRChannel {
- state: OutboundRequestState,
- config: OutboundLSPS1Config,
-}
-
-impl OutboundCRChannel {
- fn new(
- order: LSPS1OrderParams, created_at: LSPSDateTime, order_id: LSPS1OrderId,
- payment: LSPS1PaymentInfo,
- ) -> Self {
- Self {
- state: OutboundRequestState::OrderCreated { order_id },
- config: OutboundLSPS1Config { order, created_at, payment },
- }
- }
- fn awaiting_payment(&mut self) -> Result<(), LightningError> {
- self.state = self.state.awaiting_payment()?;
- Ok(())
- }
-}
-
-#[derive(Default)]
-struct PeerState {
- outbound_channels_by_order_id: HashMap<LSPS1OrderId, OutboundCRChannel>,
- pending_requests: HashMap<LSPSRequestId, LSPS1Request>,
-}
-
-impl PeerState {
- fn insert_outbound_channel(&mut self, order_id: LSPS1OrderId, channel: OutboundCRChannel) {
- self.outbound_channels_by_order_id.insert(order_id, channel);
- }
-}
-
/// The main object allowing to send and receive bLIP-51 / LSPS1 messages.
pub struct LSPS1ServiceHandler<ES: EntropySource, CM: Deref + Clone, K: KVStore + Clone>
where
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.