Skip to content

Conversation

@TheBlueMatt
Copy link
Collaborator

P2PGossipSync is a rather poor design. It currently basically
requires two circular Arc references, leaving NetworkGraphs to
leak if LDK is un-loaded:

  • P2PGossipSync owns/holds a reference to the
    GossipVerifier and GossipVerifier holds an Arc to the
    P2PGossipSync and
  • PeerManager holds a reference to the P2PGossipSync (as the
    gossip message handler) which owns/holds a reference to the
    GossipVerifier, which has a Deref (likely an Arc in
    practice) to the PeerManager.

Instead, we should move towards the same design we have elsewhere -
hold a Notifier and expose waiting on it to the background
processor then poll for completion from there (in this case, as in
others by checking for completion when handling
get_and_clear_pending_msg_events calls).

Fixes #3369

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 31, 2025

I've assigned @tankyleo 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.

Rather than `match`ing on on several optional objects (with another
one to come in a future commit), build an iterator over the futures
using the fact that an `Option` is an iterator.
@TheBlueMatt TheBlueMatt force-pushed the 2025-12-gossip-validate-arc-loop branch 2 times, most recently from 91c5084 to 7d67c24 Compare December 31, 2025 20:29
`P2PGossipSync` is a rather poor design. It currently basically
requires two circular `Arc` references, leaving `NetworkGraph`s to
leak if LDK is un-loaded:
 * `P2PGossipSync` owns/holds a reference to the
   `GossipVerifier` and `GossipVerifier` holds an `Arc` to the
   `P2PGossipSync` and
 * `PeerManager` holds a reference to the `P2PGossipSync` (as the
   gossip message handler) which owns/holds a reference to the
   `GossipVerifier`, which has a `Deref` (likely an `Arc` in
   practice) to the `PeerManager`.

Instead, we should move towards the same design we have elsewhere -
hold a `Notifier` and expose waiting on it to the background
processor then poll for completion from there (in this case, as in
others by checking for completion when handling
`get_and_clear_pending_msg_events` calls).

Here we take the first step towards this, adding a shared
`Notifier` to `PendingChecks` and piping it through to
`UtxoFuture`s so that they can be simply resolved and wake the
background processor (once it waits on the new `Notifier`).
`P2PGossipSync` is a rather poor design. It currently basically
requires two circular `Arc` references, leaving `NetworkGraph`s to
leak if LDK is un-loaded:
 * `P2PGossipSync` owns/holds a reference to the
   `GossipVerifier` and `GossipVerifier` holds an `Arc` to the
   `P2PGossipSync` and
 * `PeerManager` holds a reference to the `P2PGossipSync` (as the
   gossip message handler) which owns/holds a reference to the
   `GossipVerifier`, which has a `Deref` (likely an `Arc` in
   practice) to the `PeerManager`.

Instead, we should move towards the same design we have elsewhere -
hold a `Notifier` and expose waiting on it to the background
processor then poll for completion from there (in this case, as in
others by checking for completion when handling
`get_and_clear_pending_msg_events` calls).

Here we do the bulk of this work, moving `UtxoFuture` resolution
to a simple function that signals the `Notifier` and stores the
result. We then poll to convert the result into forwarded messages
in `P2PGossipSync::get_and_clear_pending_message_events`. Note that
we still rely on manual wakeups from the gossip validator, but that
will be fixed in the next commit.
`P2PGossipSync` is a rather poor design. It currently basically
requires two circular `Arc` references, leaving `NetworkGraph`s to
leak if LDK is un-loaded:
 * `P2PGossipSync` owns/holds a reference to the
   `GossipVerifier` and `GossipVerifier` holds an `Arc` to the
   `P2PGossipSync` and
 * `PeerManager` holds a reference to the `P2PGossipSync` (as the
   gossip message handler) which owns/holds a reference to the
   `GossipVerifier`, which has a `Deref` (likely an `Arc` in
   practice) to the `PeerManager`.

Instead, we should move towards the same design we have elsewhere -
hold a `Notifier` and expose waiting on it to the background
processor then poll for completion from there (in this case, as in
others by checking for completion when handling
`get_and_clear_pending_msg_events` calls).

After the last few commits of setup, here we finally switch to
waking the background processor directly when we detect async
gossip validation completion, allowing us to drop the circular
references in `P2PGossipSync`/`GossipVerifier` entirely.

Fixes lightningdevkit#3369
Now that we do not rely on circular references for `P2PGossipSync`
validation, we no longer need the hacky
`P2PGossipSync::add_utxo_lookup` method to add the gossip
validator after building the `P2PGossipSync` first. Thus, we
remove it here, updating some tests that relied on it.
@TheBlueMatt TheBlueMatt force-pushed the 2025-12-gossip-validate-arc-loop branch from 7d67c24 to 15ddb31 Compare December 31, 2025 22:29
@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 83.79310% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.60%. Comparing base (62c5849) to head (15ddb31).

Files with missing lines Patch % Lines
lightning/src/routing/gossip.rs 30.30% 22 Missing and 1 partial ⚠️
lightning/src/routing/utxo.rs 90.41% 14 Missing and 2 partials ⚠️
lightning-block-sync/src/gossip.rs 0.00% 5 Missing ⚠️
lightning-background-processor/src/lib.rs 96.87% 1 Missing ⚠️
lightning/src/routing/test_utils.rs 97.43% 1 Missing ⚠️
lightning/src/util/wakers.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4294      +/-   ##
==========================================
- Coverage   89.38%   86.60%   -2.78%     
==========================================
  Files         180      158      -22     
  Lines      139834   101863   -37971     
  Branches   139834   101863   -37971     
==========================================
- Hits       124985    88222   -36763     
+ Misses      12262    11224    -1038     
+ Partials     2587     2417     -170     
Flag Coverage Δ
fuzzing 35.25% <15.68%> (+0.04%) ⬆️
tests 85.90% <83.79%> (-2.82%) ⬇️

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.

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.

Drop reference to Self in GossipVerifier::new

2 participants