Skip to content

Commit 69acff1

Browse files
committed
Expand the return type of handle_onion_message_response.
The return type is expanded to handle three cases: 1. Ok(None) in case of no response to be sent. 2. Ok(Some(SendSuccess) and Err(SendError) in case of successful and unsuccessful queueing up of response messages respectively. This allows the user to get access to the Success/Failure status of the sending of response and handle it accordingly.
1 parent 8168e7a commit 69acff1

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn async_response_over_one_blinded_hop() {
351351
let response_instruction = nodes[0].custom_message_handler.handle_custom_message(message, responder);
352352

353353
// 6. Simulate Alice asynchronously responding back to Bob with a response.
354-
nodes[0].messenger.handle_onion_message_response(response_instruction);
354+
let _ = nodes[0].messenger.handle_onion_message_response(response_instruction);
355355
bob.custom_message_handler.expect_message(TestCustomMessage::Response);
356356

357357
pass_along_path(&nodes);

lightning/src/onion_message/messenger.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,24 +1009,29 @@ where
10091009

10101010
/// Handles the response to an [`OnionMessage`] based on its [`ResponseInstruction`],
10111011
/// enqueueing any response for sending.
1012-
pub fn handle_onion_message_response<T: OnionMessageContents>(
1012+
pub fn handle_onion_message_response<T: OnionMessageContents> (
10131013
&self, response: ResponseInstruction<T>
1014-
) {
1014+
) -> Result<Option<SendSuccess>, SendError> {
10151015
let (response, reply_path) = match response {
10161016
ResponseInstruction::WithReplyPath(response) => (response, self.create_blinded_path().ok()),
10171017
ResponseInstruction::WithoutReplyPath(response) => (response, None),
1018-
ResponseInstruction::NoResponse => return,
1018+
ResponseInstruction::NoResponse => return Ok(None),
10191019
};
10201020

10211021
let message_type = response.message.msg_type();
1022-
let _ = self.find_path_and_enqueue_onion_message(
1022+
let res = self.find_path_and_enqueue_onion_message(
10231023
response.message, Destination::BlindedPath(response.reply_path), reply_path,
10241024
format_args!(
10251025
"when responding to {} onion message with path_id {:02x?}",
10261026
message_type,
10271027
response.path_id
10281028
)
10291029
);
1030+
1031+
match res {
1032+
Ok(result) => Ok(Some(result)),
1033+
Err(result) => Err(result)
1034+
}
10301035
}
10311036

10321037
#[cfg(test)]
@@ -1113,14 +1118,14 @@ where
11131118
|reply_path| Responder::new(reply_path, path_id)
11141119
);
11151120
let response_instructions = self.offers_handler.handle_message(msg, responder);
1116-
self.handle_onion_message_response(response_instructions);
1121+
let _ = self.handle_onion_message_response(response_instructions);
11171122
},
11181123
ParsedOnionMessageContents::Custom(msg) => {
11191124
let responder = reply_path.map(
11201125
|reply_path| Responder::new(reply_path, path_id)
11211126
);
11221127
let response_instructions = self.custom_handler.handle_custom_message(msg, responder);
1123-
self.handle_onion_message_response(response_instructions);
1128+
let _ = self.handle_onion_message_response(response_instructions);
11241129
},
11251130
}
11261131
},

0 commit comments

Comments
 (0)