Skip to content

Commit 73ae862

Browse files
fixup: Improve LSPS5 event documentation and field naming
- Rename client/lsp fields to counterparty_node_id for consistent terminology - Replace generic String types with more specific Lsps5AppName and Lsps5WebhookUrl - Add comprehensive documentation for all events and fields - Include format specifications (UTF-8, ISO8601) and size constraints - Add request_id field to all relevant events for consistent request tracking - Provide detailed descriptions of error codes and their meanings - Use complete sentences in documentation comments
1 parent 1519b15 commit 73ae862

File tree

1 file changed

+149
-79
lines changed

1 file changed

+149
-79
lines changed

lightning-liquidity/src/lsps5/event.rs

Lines changed: 149 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -15,144 +15,211 @@ use crate::prelude::String;
1515
use crate::prelude::Vec;
1616
use bitcoin::secp256k1::PublicKey;
1717

18-
/// Events emitted by the LSPS5 webhook service (LSP side)
18+
use super::msgs::Lsps5AppName;
19+
use super::msgs::Lsps5WebhookUrl;
20+
21+
/// An event which an bLIP-55 / LSPS5 server should take some action in response to.
1922
#[derive(Debug, Clone, PartialEq, Eq)]
2023
pub enum LSPS5ServiceEvent {
2124
/// A webhook was registered by a client
25+
///
26+
/// This event occurs when a client successfully registers a webhook via `lsps5.set_webhook`.
27+
/// You should store this information to be able to contact the client when they are offline.
2228
WebhookRegistered {
23-
/// Client node ID
24-
client: PublicKey,
25-
/// App name
26-
app_name: String,
27-
/// Webhook URL
28-
url: String,
29-
/// Request ID for tracking
29+
/// Client node ID that registered the webhook
30+
counterparty_node_id: PublicKey,
31+
/// App name provided by the client (up to 64 bytes in UTF-8 format)
32+
app_name: Lsps5AppName,
33+
/// Webhook URL (HTTPS) that should be contacted to notify the client (up to 1024 ASCII characters)
34+
url: Lsps5WebhookUrl,
35+
/// The identifier of the issued bLIP-50 / LSPS5 webhook registration request
36+
///
37+
/// This can be used to track which request this event corresponds to.
3038
request_id: LSPSRequestId,
31-
/// Whether this was a new registration or an update to existing one
39+
/// Whether this was a new registration or an update to existing one with no changes
40+
/// If false, a notification should be sent to the registered webhook
3241
no_change: bool,
3342
},
3443

3544
/// Webhooks were listed for a client
45+
///
46+
/// This event occurs when a client requests their registered webhooks via `lsps5.list_webhooks`.
3647
WebhooksListed {
37-
/// Client node ID
38-
client: PublicKey,
39-
/// App names with registered webhooks
40-
app_names: Vec<String>,
41-
/// Maximum number of webhooks allowed
42-
max_webhooks: u32,
43-
/// Request ID for tracking
48+
/// Client node ID that requested their webhooks
49+
counterparty_node_id: PublicKey,
50+
/// App names with registered webhooks for this client
51+
app_names: Vec<Lsps5AppName>,
52+
/// The identifier of the issued bLIP-50 / LSPS5 webhook listing request
53+
///
54+
/// This can be used to track which request this event corresponds to.
4455
request_id: LSPSRequestId,
56+
/// Maximum number of webhooks allowed by LSP per client
57+
max_webhooks: u32,
4558
},
4659

47-
/// A webhook was removed
60+
/// A webhook was removed by a client
61+
///
62+
/// This event occurs when a client successfully removes a webhook via `lsps5.remove_webhook`.
4863
WebhookRemoved {
49-
/// Client node ID
50-
client: PublicKey,
51-
/// App name
52-
app_name: String,
53-
/// Request ID for tracking
64+
/// Client node ID that removed the webhook
65+
counterparty_node_id: PublicKey,
66+
/// App name that was removed
67+
app_name: Lsps5AppName,
68+
/// The identifier of the issued bLIP-50 / LSPS5 webhook removal request
69+
///
70+
/// This can be used to track which request this event corresponds to.
5471
request_id: LSPSRequestId,
5572
},
5673

57-
/// A notification was sent to a webhook
74+
/// A notification was successfully sent to a client's webhook
75+
///
76+
/// This event occurs after the LSP successfully contacts a client's webhook.
5877
WebhookNotificationSent {
59-
/// Client node ID
60-
client: PublicKey,
61-
/// App name
62-
app_name: String,
63-
/// Webhook URL
64-
url: String,
65-
/// Notification method
78+
/// Client node ID that was notified
79+
counterparty_node_id: PublicKey,
80+
/// App name that was notified
81+
app_name: Lsps5AppName,
82+
/// URL that was contacted
83+
url: Lsps5WebhookUrl,
84+
/// Notification method that was sent to the webhook
6685
method: WebhookNotificationMethod,
67-
/// Timestamp of the notification
86+
/// ISO8601 timestamp of the notification (YYYY-MM-DDThh:mm:ss.uuuZ format)
6887
timestamp: String,
69-
/// Signature of the notification
88+
/// Signature of the notification using the LSP's node ID
7089
signature: String,
7190
},
7291
}
7392

74-
/// Events emitted by the LSPS5 webhook client (Lightning node side)
93+
/// An event which an LSPS5 client should take some action in response to.
7594
#[derive(Debug, Clone, PartialEq, Eq)]
7695
pub enum LSPS5ClientEvent {
7796
/// A webhook was successfully registered with the LSP
97+
///
98+
/// This event is triggered when the LSP confirms successful registration
99+
/// of a webhook via `lsps5.set_webhook`.
78100
WebhookRegistered {
79-
/// LSP node ID
80-
lsp: PublicKey,
81-
/// App name
82-
app_name: String,
83-
/// Webhook URL
84-
url: String,
85-
/// Number of webhooks now registered
101+
/// The node id of the LSP that confirmed the registration
102+
counterparty_node_id: PublicKey,
103+
/// Current number of webhooks registered for this client
86104
num_webhooks: u32,
87-
/// Maximum number of webhooks allowed
105+
/// Maximum number of webhooks allowed by LSP
88106
max_webhooks: u32,
89-
/// Whether this was a new registration or an update to existing one
107+
/// Whether this was an unchanged registration (same app_name and URL)
108+
/// If true, the LSP didn't send a webhook notification for this registration
90109
no_change: bool,
110+
/// The app name that was registered (up to 64 bytes in UTF-8 format)
111+
app_name: Lsps5AppName,
112+
/// The webhook URL that was registered (HTTPS protocol)
113+
url: Lsps5WebhookUrl,
114+
/// The identifier of the issued bLIP-50 / LSPS5 webhook registration request
115+
///
116+
/// This can be used to track which request this event corresponds to.
117+
request_id: LSPSRequestId,
91118
},
92119

93-
/// Failed to register a webhook with the LSP
120+
/// A webhook registration attempt failed
121+
///
122+
/// This event is triggered when the LSP rejects a webhook registration
123+
/// via `lsps5.set_webhook`. This can happen if the app_name or URL is too long,
124+
/// the URL uses an unsupported protocol, or the maximum number of webhooks is reached.
94125
WebhookRegistrationFailed {
95-
/// LSP node ID
96-
lsp: PublicKey,
97-
/// App name
98-
app_name: String,
99-
/// Webhook URL
100-
url: String,
101-
/// Error code
126+
/// The node id of the LSP that rejected the registration
127+
counterparty_node_id: PublicKey,
128+
/// Error code from the LSP (500: too_long, 501: url_parse_error,
129+
/// 502: unsupported_protocol, 503: too_many_webhooks)
102130
error_code: i32,
103-
/// Error message
131+
/// Error message from the LSP
104132
error_message: String,
133+
/// The app name that was attempted
134+
app_name: Lsps5AppName,
135+
/// The webhook URL that was attempted
136+
url: Lsps5WebhookUrl,
137+
/// The identifier of the issued bLIP-50 / LSPS5 webhook registration request
138+
///
139+
/// This can be used to track which request this event corresponds to.
140+
request_id: LSPSRequestId,
105141
},
106142

107-
/// Received list of registered webhooks from the LSP
143+
/// The list of registered webhooks was successfully retrieved
144+
///
145+
/// This event is triggered when the LSP responds to a `lsps5.list_webhooks` request.
108146
WebhooksListed {
109-
/// LSP node ID
110-
lsp: PublicKey,
111-
/// App names with registered webhooks
112-
app_names: Vec<String>,
113-
/// Maximum number of webhooks allowed
147+
/// The node id of the LSP that provided the list
148+
counterparty_node_id: PublicKey,
149+
/// List of app names with registered webhooks
150+
app_names: Vec<Lsps5AppName>,
151+
/// Maximum number of webhooks allowed by LSP
114152
max_webhooks: u32,
153+
/// The identifier of the issued bLIP-50 / LSPS5 list webhooks request
154+
///
155+
/// This can be used to track which request this event corresponds to.
156+
request_id: LSPSRequestId,
115157
},
116158

117-
/// Failed to list webhooks
159+
/// The attempt to list webhooks failed
160+
///
161+
/// This event is triggered when the LSP rejects a `lsps5.list_webhooks` request.
118162
WebhooksListFailed {
119-
/// LSP node ID
120-
lsp: PublicKey,
121-
/// Error code
163+
/// The node id of the LSP that rejected the request
164+
counterparty_node_id: PublicKey,
165+
/// Error code from the LSP
122166
error_code: i32,
123-
/// Error message
167+
/// Error message from the LSP
124168
error_message: String,
169+
/// The identifier of the issued bLIP-50 / LSPS5 list webhooks request
170+
///
171+
/// This can be used to track which request this event corresponds to.
172+
request_id: LSPSRequestId,
125173
},
126174

127175
/// A webhook was successfully removed
176+
///
177+
/// This event is triggered when the LSP confirms successful removal
178+
/// of a webhook via `lsps5.remove_webhook`.
128179
WebhookRemoved {
129-
/// LSP node ID
130-
lsp: PublicKey,
131-
/// App name
132-
app_name: String,
180+
/// The node id of the LSP that confirmed the removal
181+
counterparty_node_id: PublicKey,
182+
/// The app name that was removed
183+
app_name: Lsps5AppName,
184+
/// The identifier of the issued bLIP-50 / LSPS5 remove webhook request
185+
///
186+
/// This can be used to track which request this event corresponds to.
187+
request_id: LSPSRequestId,
133188
},
134189

135-
/// Failed to remove a webhook
190+
/// A webhook removal attempt failed
191+
///
192+
/// This event is triggered when the LSP rejects a webhook removal
193+
/// via `lsps5.remove_webhook`. The most common error is app_name_not_found (1010).
136194
WebhookRemovalFailed {
137-
/// LSP node ID
138-
lsp: PublicKey,
139-
/// App name
140-
app_name: String,
141-
/// Error code
195+
/// The node id of the LSP that rejected the removal
196+
counterparty_node_id: PublicKey,
197+
/// Error code from the LSP (1010: app_name_not_found)
142198
error_code: i32,
143-
/// Error message
199+
/// Error message from the LSP
144200
error_message: String,
201+
/// The app name that was attempted to be removed
202+
app_name: Lsps5AppName,
203+
/// The identifier of the issued bLIP-50 / LSPS5 remove webhook request
204+
///
205+
/// This can be used to track which request this event corresponds to.
206+
request_id: LSPSRequestId,
145207
},
146208

147209
/// A webhook notification was received from the LSP
210+
///
211+
/// This event is triggered when the client receives a webhook notification
212+
/// from the LSP. This can happen for various reasons such as incoming payment,
213+
/// expiring HTLCs, liquidity management requests, or incoming onion messages.
148214
WebhookNotificationReceived {
149-
/// LSP node ID
150-
lsp: PublicKey,
151-
/// The notification method that was received
215+
/// LSP node ID that sent the notification
216+
counterparty_node_id: PublicKey,
217+
/// The notification method that was received (such as webhook_registered,
218+
/// payment_incoming, expiry_soon, liquidity_management_request, onion_message_incoming)
152219
method: WebhookNotificationMethod,
153-
/// Timestamp of the notification
220+
/// Timestamp of the notification in ISO8601 format (YYYY-MM-DDThh:mm:ss.uuuZ)
154221
timestamp: String,
155-
/// Whether the signature verification succeeded
222+
/// Whether the LSP's signature was successfully verified
156223
signature_valid: bool,
157224
/// The notification parameters (might be empty depending on method)
158225
parameters: Option<WebhookNotificationParams>,
@@ -163,8 +230,11 @@ pub enum LSPS5ClientEvent {
163230
#[derive(Debug, Clone, PartialEq, Eq)]
164231
pub enum WebhookNotificationParams {
165232
/// Parameters for lsps5.expiry_soon notification
233+
///
234+
/// This notification is sent when an HTLC or other time-bound contract
235+
/// is within 24 blocks of being timed out, which would cause a channel closure.
166236
ExpirySoon {
167-
/// Block height when timeout occurs
237+
/// Block height when timeout occurs and the LSP would be forced to close the channel
168238
timeout: u32,
169239
},
170240
/// For future extensions of other notification types that might have parameters

0 commit comments

Comments
 (0)