Skip to content

Commit c50ade5

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 d747699 commit c50ade5

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

lightning-liquidity/src/lsps2/client.rs

Lines changed: 30 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,19 @@ where
249250
});
250251
}
251252

252-
Ok(())
253+
event_queue_notifier.enqueue(LSPS2ClientEvent::GetInfoFailed {
254+
request_id: request_id.clone(),
255+
counterparty_node_id: *counterparty_node_id,
256+
error: error.clone(),
257+
});
258+
259+
Err(LightningError {
260+
err: format!(
261+
"Received get_info error response for request {:?}: {:?}",
262+
request_id, error
263+
),
264+
action: ErrorAction::IgnoreAndLog(Level::Error),
265+
})
253266
},
254267
None => {
255268
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 +323,9 @@ where
310323

311324
fn handle_buy_error(
312325
&self, request_id: LSPSRequestId, counterparty_node_id: &PublicKey,
313-
_error: LSPSResponseError,
326+
error: LSPSResponseError,
314327
) -> Result<(), LightningError> {
328+
let event_queue_notifier = self.pending_events.notifier();
315329
let outer_state_lock = self.per_peer_state.read().unwrap();
316330
match outer_state_lock.get(counterparty_node_id) {
317331
Some(inner_state_lock) => {
@@ -322,7 +336,19 @@ where
322336
action: ErrorAction::IgnoreAndLog(Level::Info),
323337
})?;
324338

325-
Ok(())
339+
event_queue_notifier.enqueue(LSPS2ClientEvent::BuyRequestFailed {
340+
request_id: request_id.clone(),
341+
counterparty_node_id: *counterparty_node_id,
342+
error: error.clone(),
343+
});
344+
345+
Err(LightningError {
346+
err: format!(
347+
"Received buy error response for request {:?}: {:?}",
348+
request_id, error
349+
),
350+
action: ErrorAction::IgnoreAndLog(Level::Error),
351+
})
326352
},
327353
None => {
328354
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)