Skip to content

Commit

Permalink
Expand the return type of handle_onion_message_response.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shaavan committed Apr 26, 2024
1 parent 1a101ba commit 989d8a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lightning/src/onion_message/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn async_response_over_one_blinded_hop() {
let response_instruction = nodes[0].custom_message_handler.handle_custom_message(message, responder);

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

pass_along_path(&nodes);
Expand Down
17 changes: 11 additions & 6 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,9 @@ where

/// Handles the response to an [`OnionMessage`] based on its [`ResponseInstruction`],
/// enqueueing any response for sending.
pub fn handle_onion_message_response<T: OnionMessageContents>(
pub fn handle_onion_message_response<T: OnionMessageContents> (
&self, response: ResponseInstruction<T>
) {
) -> Result<Option<SendSuccess>, SendError> {
let (response, reply_path) = match response {
ResponseInstruction::WithReplyPath(response) => (response, self.create_blinded_path().ok()),
ResponseInstruction::WithoutReplyPath(response) => (response, None),
Expand All @@ -1020,18 +1020,23 @@ where
"Missing reply path when responding to {} onion message",
T::msg_type()
);
return
return Ok(None)
}
};

let _ = self.find_path_and_enqueue_onion_message(
let res = self.find_path_and_enqueue_onion_message(
response.message, Destination::BlindedPath(response.reply_path), reply_path,
format_args!(
"when responding to {} onion message with path_id {:02x?}",
T::msg_type(),
response.path_id
)
);

match res {
Ok(result) => Ok(Some(result)),
Err(result) => Err(result)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -1118,14 +1123,14 @@ where
|reply_path| Responder::new(reply_path, path_id)
);
let response_instructions = self.offers_handler.handle_message(msg, responder);
self.handle_onion_message_response(response_instructions);
let _ = self.handle_onion_message_response(response_instructions);
},
ParsedOnionMessageContents::Custom(msg) => {
let responder = reply_path.map(
|reply_path| Responder::new(reply_path, path_id)
);
let response_instructions = self.custom_handler.handle_custom_message(msg, responder);
self.handle_onion_message_response(response_instructions);
let _ = self.handle_onion_message_response(response_instructions);
},
}
},
Expand Down

0 comments on commit 989d8a6

Please sign in to comment.