Skip to content
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

Allow responding asynchronously to OnionMessage #2996

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shaavan
Copy link
Contributor

@shaavan shaavan commented Apr 15, 2024

This PR addresses second part of #2882 and builds on #2907

This PR converts handle_onion_message_response into the public function which can be used for asynchronous response to a separately created ResponseInstruction.
Also, this introduces a new variant of ResponseInstruction. This allows creating a reply_path for the receiver while responding to their message.

@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 63.09524% with 31 lines in your changes are missing coverage. Please review.

Project coverage is 89.78%. Comparing base (d3cd080) to head (4ba91a9).
Report is 2 commits behind head on main.

❗ Current head 4ba91a9 differs from pull request most recent head 57bca64. Consider uploading reports for the commit 57bca64 to get more accurate results

Files Patch % Lines
lightning/src/onion_message/messenger.rs 40.38% 31 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2996      +/-   ##
==========================================
- Coverage   89.83%   89.78%   -0.05%     
==========================================
  Files         116      116              
  Lines       96465    96533      +68     
  Branches    96465    96533      +68     
==========================================
+ Hits        86657    86670      +13     
- Misses       7263     7310      +47     
- Partials     2545     2553       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shaavan
Copy link
Contributor Author

shaavan commented Apr 23, 2024

Updated from pr2996.01 to pr2996.02 (diff):

Update:

  1. Synced with base PR (Introduce ResponseInstructions for OnionMessage Handling #2907) to solve merge conflicts.

@shaavan
Copy link
Contributor Author

shaavan commented Apr 24, 2024

cc @jkczyz, @TheBlueMatt

lightning/src/onion_message/functional_tests.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
@shaavan
Copy link
Contributor Author

shaavan commented Apr 26, 2024

Updated from pr2996.02 to pr2996.03 (diff):
Addressed @jkczyz comments:

Updates:

  1. Address nit comments.
  2. Expanded return type of handle_onion_message_response. This change allows access to the success/failure status of sending the response to the user which they can handle appropriately.

@shaavan
Copy link
Contributor Author

shaavan commented May 9, 2024

Updated from pr2996.03 to pr2996.04 (diff):

Updates:

  1. Rebase on main, to resolve conflicts post Introduce ResponseInstructions for OnionMessage Handling #2907 merge.

lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
@shaavan
Copy link
Contributor Author

shaavan commented May 10, 2024

Updated from pr2996.04 to pr2996.05 (diff):
Addressed @TheBlueMatt, @jkczyz comments

Updates:

  1. Expanded respond(), and respond_with_reply_path() documentation.
  2. Updated test to check if we got the expected variant of SendSuccess, when calling handle_onion_message_response.
  3. Refactor the code to improve brevity.
  4. Update handle_onion_message response to fail in case we fail to create a blinded_path.
  5. Fix the Fuzz test.

lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/functional_tests.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/functional_tests.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Show resolved Hide resolved
@shaavan
Copy link
Contributor Author

shaavan commented May 11, 2024

Updated from pr2996.05 to pr2996.06 (diff):
Addressed @jkczyz comments

Updates:

  1. Simplify the respond, and respond_with_reply_path docs to make them concise.
  2. Simplify the result check in the added test.
  3. Introduced logging in handle_onion_message_response if create_blinded_path fails to create reply_path.

…st coverage

This commit modifies handle_onion_message_response to be accessible
publicly as handle_onion_message, enabling users to respond
asynchronously. Additionally, a new test is introduced to validate this
functionality.
@shaavan
Copy link
Contributor Author

shaavan commented May 13, 2024

Updated from pr2996.06 to pr2996.07 (diff):

Updates:

  1. Rebase on main, to fix ci failures.

lightning/src/onion_message/messenger.rs Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
And expand handle_onion_message_response return Type

1. Introduce a new function in OnionMessenger to create blinded paths.
2. Use it in handle_onion_message_response to create a reply_path for
   the right variant and use it in onion_message.
3. Expand the return type of handle_onion_message_response 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.
@shaavan
Copy link
Contributor Author

shaavan commented May 14, 2024

Updated from pr2996.07 to pr2996.08 (diff):
Addressed @TheBlueMatt and @jkczyz comments

Changes:

  1. Expanded docs for respond and respond_with_reply_path so that there purpose is more clearly explained.
  2. Expand log message to also contain the error itself.
  3. nit blinded_path -> reply_path.
  4. Simplified logger -> self.logger, since there are no context to add with the error message within the function.
  5. Improve the code style to be more idiomatic.
  6. Simplified format_args! -> format! for log_trace!


/// Creates a [`ResponseInstruction::WithReplyPath`] for a given response.
///
/// Use when the recipient need to send back a reply to us.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/need/needs

Comment on lines +1092 to +1096
let log_suffix = format!(
"when responding with {} to an onion message with path_id {:02x?}",
message_type,
response.path_id
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may actually want to inline this in both places using format_args!. Otherwise, we are allocating a string even if the user's log level doesn't trigger any logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants