Skip to content

Commit 989d8a6

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 1a101ba commit 989d8a6

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,9 +1009,9 @@ 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),
@@ -1020,18 +1020,23 @@ where
10201020
"Missing reply path when responding to {} onion message",
10211021
T::msg_type()
10221022
);
1023-
return
1023+
return Ok(None)
10241024
}
10251025
};
10261026

1027-
let _ = self.find_path_and_enqueue_onion_message(
1027+
let res = self.find_path_and_enqueue_onion_message(
10281028
response.message, Destination::BlindedPath(response.reply_path), reply_path,
10291029
format_args!(
10301030
"when responding to {} onion message with path_id {:02x?}",
10311031
T::msg_type(),
10321032
response.path_id
10331033
)
10341034
);
1035+
1036+
match res {
1037+
Ok(result) => Ok(Some(result)),
1038+
Err(result) => Err(result)
1039+
}
10351040
}
10361041

10371042
#[cfg(test)]
@@ -1118,14 +1123,14 @@ where
11181123
|reply_path| Responder::new(reply_path, path_id)
11191124
);
11201125
let response_instructions = self.offers_handler.handle_message(msg, responder);
1121-
self.handle_onion_message_response(response_instructions);
1126+
let _ = self.handle_onion_message_response(response_instructions);
11221127
},
11231128
ParsedOnionMessageContents::Custom(msg) => {
11241129
let responder = reply_path.map(
11251130
|reply_path| Responder::new(reply_path, path_id)
11261131
);
11271132
let response_instructions = self.custom_handler.handle_custom_message(msg, responder);
1128-
self.handle_onion_message_response(response_instructions);
1133+
let _ = self.handle_onion_message_response(response_instructions);
11291134
},
11301135
}
11311136
},

0 commit comments

Comments
 (0)