-
Notifications
You must be signed in to change notification settings - Fork 410
LSPS2: Add error handling events for failed client requests #3804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4e77209
1ee90ac
50f3130
0d0dbc4
cea624e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1348,45 +1348,44 @@ where | |
&self, peer_state_lock: &mut MutexGuard<'a, PeerState>, request_id: LSPSRequestId, | ||
counterparty_node_id: PublicKey, request: LSPS2Request, | ||
) -> (Result<(), LightningError>, Option<LSPSMessage>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing but shouldn't the type be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the method returns either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that in this fn, it's indeed either Ok(()), or an error always accompanied by a msg (not optional). But maybe this is a useful type further up the call stack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the rest of the API follows the same pattern of returning Also note that we chose that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Err variant is already not just bubbled up. Both call sites do a match on the result already? I was indeed wondering why the lock had to be dropped before enqueueing. Could be worthy of a comment. This thread is mostly out of curiosity / to learn. No changes requested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes it is, essentially at all callsites?
Well, it's also best practice in general. But yeah. At some point we could even consider a refactoring that would make it infeasible to enqueue while still holding the lock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There is still a match at the call sites.
You mean best practice to not hold the lock longer than necessary? Or not queueing while holding the lock? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The latter. |
||
if self.total_pending_requests.load(Ordering::Relaxed) >= MAX_TOTAL_PENDING_REQUESTS { | ||
let response = LSPS2Response::BuyError(LSPSResponseError { | ||
let create_pending_request_limit_exceeded_response = |error_message: String| { | ||
let error_details = LSPSResponseError { | ||
code: LSPS0_CLIENT_REJECTED_ERROR_CODE, | ||
message: "Reached maximum number of pending requests. Please try again later." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it was very intentional that we hardcoded a standardized response here, because while we want to log the full details, the counterparty shouldn't learn anything about our rate limits. Could you expand what else you mean with "incorrect error response types"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right, that difference got lost in the diff here. Yes, then let's still keep returning the hardcoded error strings to the counterparties, but just make sure the right response type is returned. |
||
.to_string(), | ||
data: None, | ||
}; | ||
let response = match &request { | ||
LSPS2Request::GetInfo(_) => LSPS2Response::GetInfoError(error_details), | ||
LSPS2Request::Buy(_) => LSPS2Response::BuyError(error_details), | ||
}; | ||
let msg = Some(LSPS2Message::Response(request_id.clone(), response).into()); | ||
|
||
let result = Err(LightningError { | ||
err: error_message, | ||
action: ErrorAction::IgnoreAndLog(Level::Debug), | ||
}); | ||
let msg = Some(LSPS2Message::Response(request_id, response).into()); | ||
(result, msg) | ||
}; | ||
|
||
let err = format!( | ||
"Peer {} reached maximum number of total pending requests: {}", | ||
counterparty_node_id, MAX_TOTAL_PENDING_REQUESTS | ||
if self.total_pending_requests.load(Ordering::Relaxed) >= MAX_TOTAL_PENDING_REQUESTS { | ||
let error_message = format!( | ||
"Reached maximum number of total pending requests: {}", | ||
MAX_TOTAL_PENDING_REQUESTS | ||
); | ||
let result = | ||
Err(LightningError { err, action: ErrorAction::IgnoreAndLog(Level::Debug) }); | ||
return (result, msg); | ||
return create_pending_request_limit_exceeded_response(error_message); | ||
} | ||
|
||
if peer_state_lock.pending_requests_and_channels() < MAX_PENDING_REQUESTS_PER_PEER { | ||
peer_state_lock.pending_requests.insert(request_id, request); | ||
self.total_pending_requests.fetch_add(1, Ordering::Relaxed); | ||
(Ok(()), None) | ||
} else { | ||
let response = LSPS2Response::BuyError(LSPSResponseError { | ||
code: LSPS0_CLIENT_REJECTED_ERROR_CODE, | ||
message: "Reached maximum number of pending requests. Please try again later." | ||
.to_string(), | ||
data: None, | ||
}); | ||
let msg = Some(LSPS2Message::Response(request_id, response).into()); | ||
|
||
let err = format!( | ||
let error_message = format!( | ||
"Peer {} reached maximum number of pending requests: {}", | ||
counterparty_node_id, MAX_PENDING_REQUESTS_PER_PEER | ||
); | ||
let result = | ||
Err(LightningError { err, action: ErrorAction::IgnoreAndLog(Level::Debug) }); | ||
|
||
(result, msg) | ||
create_pending_request_limit_exceeded_response(error_message) | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.