Skip to content

Commit 2d769d6

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 9c724ca commit 2d769d6

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::routing::test_utils::{add_channel, add_or_update_node};
1818
use crate::sign::{NodeSigner, Recipient};
1919
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
2020
use crate::util::test_utils;
21-
use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction, SendError};
21+
use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction, SendError, SendSuccess};
2222
use super::offers::{OffersMessage, OffersMessageHandler};
2323
use super::packet::{OnionMessageContents, Packet};
2424

@@ -351,7 +351,13 @@ 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 res = nodes[0].messenger.handle_onion_message_response(response_instruction);
355+
356+
match res {
357+
Ok(Some(SendSuccess::Buffered)) => assert!(true),
358+
_ => panic!("Unexpected event"),
359+
}
360+
355361
bob.custom_message_handler.expect_message(TestCustomMessage::Response);
356362

357363
pass_along_path(&nodes);

lightning/src/onion_message/messenger.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,24 +1017,24 @@ where
10171017

10181018
/// Handles the response to an [`OnionMessage`] based on its [`ResponseInstruction`],
10191019
/// enqueueing any response for sending.
1020-
pub fn handle_onion_message_response<T: OnionMessageContents>(
1020+
pub fn handle_onion_message_response<T: OnionMessageContents> (
10211021
&self, response: ResponseInstruction<T>
1022-
) {
1022+
) -> Result<Option<SendSuccess>, SendError> {
10231023
let (response, reply_path) = match response {
1024-
ResponseInstruction::WithReplyPath(response) => (response, self.create_blinded_path().ok()),
1024+
ResponseInstruction::WithReplyPath(response) => (response, Some(self.create_blinded_path()?)),
10251025
ResponseInstruction::WithoutReplyPath(response) => (response, None),
1026-
ResponseInstruction::NoResponse => return,
1026+
ResponseInstruction::NoResponse => return Ok(None),
10271027
};
10281028

10291029
let message_type = response.message.msg_type();
1030-
let _ = self.find_path_and_enqueue_onion_message(
1030+
self.find_path_and_enqueue_onion_message(
10311031
response.message, Destination::BlindedPath(response.reply_path), reply_path,
10321032
format_args!(
10331033
"when responding with {} to an onion message with path_id {:02x?}",
10341034
message_type,
10351035
response.path_id
10361036
)
1037-
);
1037+
).map(|result| Some(result))
10381038
}
10391039

10401040
#[cfg(test)]
@@ -1121,14 +1121,14 @@ where
11211121
|reply_path| Responder::new(reply_path, path_id)
11221122
);
11231123
let response_instructions = self.offers_handler.handle_message(msg, responder);
1124-
self.handle_onion_message_response(response_instructions);
1124+
let _ = self.handle_onion_message_response(response_instructions);
11251125
},
11261126
ParsedOnionMessageContents::Custom(msg) => {
11271127
let responder = reply_path.map(
11281128
|reply_path| Responder::new(reply_path, path_id)
11291129
);
11301130
let response_instructions = self.custom_handler.handle_custom_message(msg, responder);
1131-
self.handle_onion_message_response(response_instructions);
1131+
let _ = self.handle_onion_message_response(response_instructions);
11321132
},
11331133
}
11341134
},

0 commit comments

Comments
 (0)