rust-lightning icon indicating copy to clipboard operation
rust-lightning copied to clipboard

Add a parallel async event handler to OnionMessenger and pass it directly to BackgroundProcessor

Open TheBlueMatt opened this issue 1 year ago • 1 comments

This adds an OnionMessenger::process_pending_events_async mirroring the same in ChannelManager. However, unlike the one in ChannelManager, this processes the events in parallel by spawning all futures and using the new MultiFuturePoller.

Because OnionMessenger just generates a stream of messages to store/fetch, we first process all the events to store new messages, await them, then process all the events to fetch stored messages, ensuring reordering shouldn't result in lost messages (unless we race with a peer disconnection, which could happen anyway).

TheBlueMatt avatar May 10 '24 21:05 TheBlueMatt

Codecov Report

Attention: Patch coverage is 78.07018% with 25 lines in your changes missing coverage. Please review.

Project coverage is 92.08%. Comparing base (0ffa4b3) to head (fadb268). Report is 76 commits behind head on main.

Files Patch % Lines
lightning/src/util/async_poll.rs 29.41% 11 Missing and 1 partial :warning:
lightning/src/onion_message/messenger.rs 83.82% 7 Missing and 4 partials :warning:
lightning-background-processor/src/lib.rs 93.10% 0 Missing and 2 partials :warning:

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3060      +/-   ##
==========================================
+ Coverage   89.83%   92.08%   +2.25%     
==========================================
  Files         116      118       +2     
  Lines       96472   113057   +16585     
  Branches    96472   113057   +16585     
==========================================
+ Hits        86663   104113   +17450     
+ Misses       7244     6726     -518     
+ Partials     2565     2218     -347     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 10 '24 23:05 codecov-commenter

Looks like 1.63 builds are sad

valentinewallace avatar May 20 '24 15:05 valentinewallace

Addressed @jkczyz's point and squashed:

$ git diff-tree -U1 fadb26875 21aebd2d7
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index 6b7cd5b05..a17f514a5 100644
--- a/lightning-background-processor/src/lib.rs
+++ b/lightning-background-processor/src/lib.rs
@@ -57,5 +57,2 @@ use std::time::Instant;

-#[cfg(not(feature = "std"))]
-use alloc::boxed::Box;
-
 /// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
@@ -696,3 +693,3 @@ where
 		let fetch_time = &fetch_time;
-		Box::pin(async move { // We should be able to drop the Box once our MSRV is 1.68
+		async move { // We should be able to drop the Box once our MSRV is 1.68
 			if let Some(network_graph) = network_graph {
@@ -711,3 +708,3 @@ where
 			event_handler(event).await;
-		})
+		}
 	};

TheBlueMatt avatar Jun 03 '24 20:06 TheBlueMatt

LGTM after the comment about Box is removed.

valentinewallace avatar Jun 03 '24 21:06 valentinewallace

:facepalm:

$ git diff-tree -U1 21aebd2d eedceeb3
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index a17f514a5..a5d56c459 100644
--- a/lightning-background-processor/src/lib.rs
+++ b/lightning-background-processor/src/lib.rs
@@ -693,3 +693,3 @@ where
 		let fetch_time = &fetch_time;
-		async move { // We should be able to drop the Box once our MSRV is 1.68
+		async move {
 			if let Some(network_graph) = network_graph {

TheBlueMatt avatar Jun 03 '24 21:06 TheBlueMatt

Unfortunately tests are still failing due to !Unpin issues.

tnull avatar Jun 04 '24 07:06 tnull

Doh! That's why the Box was there...

TheBlueMatt avatar Jun 04 '24 12:06 TheBlueMatt

Reverted to include the Box again.

TheBlueMatt avatar Jun 04 '24 13:06 TheBlueMatt

lol ffs merged without noticing there were still fixup commits...oh well, they were just doc fixes so not really a big deal.

TheBlueMatt avatar Jun 04 '24 19:06 TheBlueMatt