Skip to content

Commit 50f3130

Browse files
Emit error events and return errors in client error handlers
Update handle_get_info_error and handle_buy_error to: - Emit GetInfoFailed and BuyRequestFailed events to notify users - Return LightningError instead of Ok() to properly signal failures - Use the actual error parameter instead of ignoring it This ensures consistent error handling behavior across LSPS implementations.
1 parent 1ee90ac commit 50f3130

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

lightning-liquidity/src/lsps2/client.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ where
232232

233233
fn handle_get_info_error(
234234
&self, request_id: LSPSRequestId, counterparty_node_id: &PublicKey,
235-
_error: LSPSResponseError,
235+
error: LSPSResponseError,
236236
) -> Result<(), LightningError> {
237+
let event_queue_notifier = self.pending_events.notifier();
237238
let outer_state_lock = self.per_peer_state.read().unwrap();
238239
match outer_state_lock.get(counterparty_node_id) {
239240
Some(inner_state_lock) => {
@@ -249,7 +250,21 @@ where
249250
});
250251
}
251252

252-
Ok(())
253+
let lightning_error = LightningError {
254+
err: format!(
255+
"Received get_info error response for request {:?}: {:?}",
256+
request_id, error
257+
),
258+
action: ErrorAction::IgnoreAndLog(Level::Error),
259+
};
260+
261+
event_queue_notifier.enqueue(LSPS2ClientEvent::GetInfoFailed {
262+
request_id,
263+
counterparty_node_id: *counterparty_node_id,
264+
error,
265+
});
266+
267+
Err(lightning_error)
253268
},
254269
None => {
255270
return Err(LightningError { err: format!("Received error response for a get_info request from an unknown counterparty ({:?})",counterparty_node_id), action: ErrorAction::IgnoreAndLog(Level::Info)});
@@ -310,8 +325,9 @@ where
310325

311326
fn handle_buy_error(
312327
&self, request_id: LSPSRequestId, counterparty_node_id: &PublicKey,
313-
_error: LSPSResponseError,
328+
error: LSPSResponseError,
314329
) -> Result<(), LightningError> {
330+
let event_queue_notifier = self.pending_events.notifier();
315331
let outer_state_lock = self.per_peer_state.read().unwrap();
316332
match outer_state_lock.get(counterparty_node_id) {
317333
Some(inner_state_lock) => {
@@ -322,7 +338,21 @@ where
322338
action: ErrorAction::IgnoreAndLog(Level::Info),
323339
})?;
324340

325-
Ok(())
341+
let lightning_error = LightningError {
342+
err: format!(
343+
"Received buy error response for request {:?}: {:?}",
344+
request_id, error
345+
),
346+
action: ErrorAction::IgnoreAndLog(Level::Error),
347+
};
348+
349+
event_queue_notifier.enqueue(LSPS2ClientEvent::BuyRequestFailed {
350+
request_id,
351+
counterparty_node_id: *counterparty_node_id,
352+
error,
353+
});
354+
355+
Err(lightning_error)
326356
},
327357
None => {
328358
return Err(LightningError { err: format!("Received error response for a buy request from an unknown counterparty ({:?})", counterparty_node_id), action: ErrorAction::IgnoreAndLog(Level::Info)});

0 commit comments

Comments
 (0)