Skip to content

Conversation

TheBlueMatt
Copy link
Collaborator

Mostly a fix for #4111 but also drops a pile of unnecessary Arcs.

Both `OutputSweeperSync` and `LiquidityManagerSync` added `Arc`s to
their internal state to allow returning a reference to that
internal state in testing. While this is required to get a
forever-lifetime reference to that state, we don't actually need
that in testing.

Instead, we turn off the borrow checker in the
`lightning-background-processor` async tests where required,
avoiding the extra heap indirection.
Given the future returned from async BP methods will be concrete on
whatever types get used, there's not much reason to require that
the arguments be `'static`, we can let Rust figure out if they're
`'static` (and thus the returned future is `'static`).
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Sep 24, 2025

👋 Thanks for assigning @joostjager 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.

@TheBlueMatt TheBlueMatt added this to the 0.2 milestone Sep 24, 2025
@TheBlueMatt
Copy link
Collaborator Author

Tagging 0.2 as #4111 is a really awk API currently and I'd rather not ship it, but if it slips so be it.

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 72.86822% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.55%. Comparing base (4c9c211) to head (5e679b4).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
lightning-background-processor/src/lib.rs 66.30% 31 Missing ⚠️
lightning-liquidity/src/utils/time.rs 0.00% 3 Missing ⚠️
lightning-liquidity/src/manager.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4119      +/-   ##
==========================================
+ Coverage   88.52%   88.55%   +0.02%     
==========================================
  Files         179      179              
  Lines      134270   134310      +40     
  Branches   134270   134310      +40     
==========================================
+ Hits       118865   118939      +74     
+ Misses      12655    12612      -43     
- Partials     2750     2759       +9     
Flag Coverage Δ
fuzzing 21.81% <35.29%> (+0.01%) ⬆️
tests 88.39% <72.86%> (+0.02%) ⬆️

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

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

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

There's no need for these given `DefaultTimeProvider` is a unit
struct.
`OutputSweeper::new_with_kv_store_sync` is a pretty strange API -
it allows building an async `OutputSweeper` where the only `await`s
are on a sync `KVStore`, ie will immediately block until the IO
operation completes.

While this isn't broken (futures are allowed to take their time,
and async runtimes have to handle this, though they often don't
handle it particularly well), its pretty weird. It seems to exist
largely for `process_events_async_with_kv_store_sync`, which does
async `Event` handling but sync `KVStore` operations (like the
existing pre-0.2 "async" background processor).

Instead, we allow passing an `OutputSweeperSync` to
`process_events_async_with_kv_store_sync`, keeping the API
consistent such that a user would use the appropriate
`OutputSweeper` variant, but fetching the inner async
`OutputSweeper` inside the BP.
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Please let's not merge this before having confirmed this won't break LDK Node builds. I'll need at least 2, maybe more refactoring PRs on LDK Node's end, before we can actually confirm these change here don't mess something up.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Alright, now confirmed this doesn't break anything for LDK Node.

Not quite sure if avoiding some Arcs is worth the effort and last-minute churn (or the unsafe code for that matter), but changes LGTM.

let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));

// Yes, you can unsafe { turn off the borrow checker }
let lm_async: &'static LiquidityManager<_, _, _, _, _, _> = unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

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

This commit has a nice end result, but this - I am not sure how many devs understand it...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I hope the comment is clear enough? Easy to just update the comment later if it makes it more readable.


/// A wrapper around a [`KVStoreSync`] that implements the [`KVStore`] trait. It is not necessary to use this type
/// directly.
#[derive(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, so instead of ref counting, this will now be cloned

O: Deref,
K: Deref,
OS: Deref<Target = OutputSweeper<T, D, F, CF, KVStoreSyncWrapper<K>, L, O>>,
OS: Deref<Target = OutputSweeperSync<T, D, F, CF, K, L, O>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Unclear to me now why I didn't do this in the first place.

@TheBlueMatt TheBlueMatt merged commit b6f3705 into lightningdevkit:main Sep 25, 2025
25 checks passed
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.

4 participants