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

Reduce `Box`ing using `impl Trait` in trait methods post-MSRV-bump

Open TheBlueMatt opened this issue 1 month ago • 14 comments

A handful of cleanups now that we bumped the MSRV and can use impl Trait in trait methods.

TheBlueMatt avatar Oct 25 '25 18:10 TheBlueMatt

👋 Thanks for assigning @tnull as a reviewer! I'll wait for their review and will help manage the review process. Once they submit their review, I'll check if a second reviewer would be helpful.

ldk-reviews-bot avatar Oct 25 '25 18:10 ldk-reviews-bot

There's still a few Box::pins in lightning-background-processor that we really should be able to get rid of, but its not entirely trivial so I didn't do it here.

TheBlueMatt avatar Oct 25 '25 18:10 TheBlueMatt

Codecov Report

:x: Patch coverage is 73.94636% with 68 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 89.32%. Comparing base (e42e74e) to head (b1f1ee2). :warning: Report is 106 commits behind head on main.

Files with missing lines Patch % Lines
lightning-background-processor/src/lib.rs 0.00% 20 Missing :warning:
lightning-block-sync/src/rest.rs 27.77% 13 Missing :warning:
lightning-block-sync/src/rpc.rs 27.77% 13 Missing :warning:
lightning-block-sync/src/gossip.rs 0.00% 9 Missing :warning:
lightning/src/util/test_utils.rs 25.00% 6 Missing :warning:
lightning-persister/src/fs_store.rs 90.90% 4 Missing :warning:
lightning-net-tokio/src/lib.rs 60.00% 2 Missing :warning:
lightning-liquidity/src/lsps2/service.rs 85.71% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4175      +/-   ##
==========================================
- Coverage   89.33%   89.32%   -0.01%     
==========================================
  Files         180      180              
  Lines      138055   138076      +21     
  Branches   138055   138076      +21     
==========================================
+ Hits       123326   123333       +7     
- Misses      12122    12141      +19     
+ Partials     2607     2602       -5     
Flag Coverage Δ
fuzzing 33.56% <12.41%> (-0.01%) :arrow_down:
tests 88.71% <73.94%> (-0.01%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

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

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 25 '25 21:10 codecov[bot]

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

ldk-reviews-bot avatar Oct 27 '25 07:10 ldk-reviews-bot

Given how much this cleans up the new async traits, I do wonder if we want to ship this for 0.2 afterall?

Meh, I don't think they clean them up that much, they just remove a Box::pin, and actually they become a bit more annoying to work with (see the few places we have to keep the Box::pin cause of rustc mess). It becomes a bit easier to work with in edition 2024, which luckily a downstream crate could choose to use if they want.

TheBlueMatt avatar Oct 27 '25 12:10 TheBlueMatt

Rebased to pick up #4180, this should now pass CI (modulo fuzzing, which still confuses me).

TheBlueMatt avatar Oct 30 '25 14:10 TheBlueMatt

The CI failure is https://github.com/bitcoindevkit/rust-electrum-client/issues/181 which is unrelated to this PR and its just that we're now testing it.

TheBlueMatt avatar Oct 30 '25 15:10 TheBlueMatt

Rebased for the restoration of the lazy flag.

TheBlueMatt avatar Oct 31 '25 14:10 TheBlueMatt

Fixed a bunk rebase.

TheBlueMatt avatar Nov 03 '25 13:11 TheBlueMatt

Oops, fixed a no-std error in the new BP stuff:

$ git diff-tree -U1 05717d0860 20697053c
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index 874c82f19d..bc0d42ac19 100644
--- a/lightning-background-processor/src/lib.rs
+++ b/lightning-background-processor/src/lib.rs
@@ -43,2 +43,4 @@ use lightning::util::ser::Writeable;

+#[cfg(not(c_bindings))]
+use lightning::io::Error;
 use lightning::ln::channelmanager::AChannelManager;
@@ -53,2 +55,4 @@ use lightning::sign::{
 };
+#[cfg(not(c_bindings))]
+use lightning::util::async_poll::MaybeSend;
 use lightning::util::logger::Logger;
@@ -430,4 +434,3 @@ impl KVStore for DummyKVStore {
 		&self, _: &str, _: &str, _: &str,
-	) -> impl core::future::Future<Output = Result<Vec<u8>, lightning::io::Error>> + Send + 'static
-	{
+	) -> impl core::future::Future<Output = Result<Vec<u8>, Error>> + MaybeSend + 'static {
 		async { unimplemented!() }
@@ -437,3 +440,3 @@ impl KVStore for DummyKVStore {
 		&self, _: &str, _: &str, _: &str, _: Vec<u8>,
-	) -> impl core::future::Future<Output = Result<(), lightning::io::Error>> + Send + 'static {
+	) -> impl core::future::Future<Output = Result<(), Error>> + MaybeSend + 'static {
 		async { unimplemented!() }
@@ -443,3 +446,3 @@ impl KVStore for DummyKVStore {
 		&self, _: &str, _: &str, _: &str, _: bool,
-	) -> impl core::future::Future<Output = Result<(), lightning::io::Error>> + Send + 'static {
+	) -> impl core::future::Future<Output = Result<(), Error>> + MaybeSend + 'static {
 		async { unimplemented!() }
@@ -449,4 +452,3 @@ impl KVStore for DummyKVStore {
 		&self, _: &str, _: &str,
-	) -> impl core::future::Future<Output = Result<Vec<String>, lightning::io::Error>> + Send + 'static
-	{
+	) -> impl core::future::Future<Output = Result<Vec<String>, Error>> + MaybeSend + 'static {
 		async { unimplemented!() }

TheBlueMatt avatar Nov 04 '25 12:11 TheBlueMatt

This needs another rebase unfortunately. Also, good opportunity to check whether the electrum-client release really fixed our doc builds.

tnull avatar Nov 04 '25 20:11 tnull

Oops, no big deal, done.

TheBlueMatt avatar Nov 05 '25 01:11 TheBlueMatt

Feel free to rebase once more as we just landed https://github.com/lightningdevkit/rust-lightning/pull/4206 to check for breakages.

tnull avatar Nov 05 '25 12:11 tnull

Rebased to drop the duplicative CI fixes.

TheBlueMatt avatar Nov 10 '25 15:11 TheBlueMatt