Skip to content

Commit cd4e6e5

Browse files
committed
Update LDK, fixing a circular Arc reference in gossip validation
LDK's gossip validation API basically forced us to have a circular `Arc` reference, leading to memory leaks after `drop`ping an instance of `Node`. This is fixed upstream in LDK PR #4294 which we update to here.
1 parent 890fcc1 commit cd4e6e5

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

src/builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,12 @@ fn build_with_store_internal(
14741474

14751475
let gossip_source = match gossip_source_config {
14761476
GossipSourceConfig::P2PNetwork => {
1477-
let p2p_source =
1478-
Arc::new(GossipSource::new_p2p(Arc::clone(&network_graph), Arc::clone(&logger)));
1477+
let p2p_source = Arc::new(GossipSource::new_p2p(
1478+
Arc::clone(&network_graph),
1479+
Arc::clone(&chain_source),
1480+
Arc::clone(&runtime),
1481+
Arc::clone(&logger),
1482+
));
14791483

14801484
// Reset the RGS sync timestamp in case we somehow switch gossip sources
14811485
{
@@ -1596,12 +1600,6 @@ fn build_with_store_internal(
15961600

15971601
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::downgrade(&peer_manager)));
15981602

1599-
gossip_source.set_gossip_verifier(
1600-
Arc::clone(&chain_source),
1601-
Arc::clone(&peer_manager),
1602-
Arc::clone(&runtime),
1603-
);
1604-
16051603
let connection_manager =
16061604
Arc::new(ConnectionManager::new(Arc::clone(&peer_manager), Arc::clone(&logger)));
16071605

src/gossip.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ pub(crate) enum GossipSource {
3333
}
3434

3535
impl GossipSource {
36-
pub fn new_p2p(network_graph: Arc<Graph>, logger: Arc<Logger>) -> Self {
36+
pub fn new_p2p(
37+
network_graph: Arc<Graph>, chain_source: Arc<ChainSource>, runtime: Arc<Runtime>,
38+
logger: Arc<Logger>,
39+
) -> Self {
40+
let verifier = chain_source.as_utxo_source().map(|utxo_source| {
41+
Arc::new(GossipVerifier::new(
42+
Arc::new(utxo_source),
43+
RuntimeSpawner::new(runtime),
44+
))
45+
});
46+
3747
let gossip_sync = Arc::new(P2PGossipSync::new(
3848
network_graph,
39-
None::<Arc<UtxoLookup>>,
40-
Arc::clone(&logger),
49+
verifier,
50+
logger,
4151
));
4252
Self::P2PNetwork { gossip_sync }
4353
}
@@ -62,27 +72,6 @@ impl GossipSource {
6272
}
6373
}
6474

65-
pub(crate) fn set_gossip_verifier(
66-
&self, chain_source: Arc<ChainSource>, peer_manager: Arc<PeerManager>,
67-
runtime: Arc<Runtime>,
68-
) {
69-
match self {
70-
Self::P2PNetwork { gossip_sync } => {
71-
if let Some(utxo_source) = chain_source.as_utxo_source() {
72-
let spawner = RuntimeSpawner::new(Arc::clone(&runtime));
73-
let gossip_verifier = Arc::new(GossipVerifier::new(
74-
Arc::new(utxo_source),
75-
spawner,
76-
Arc::clone(gossip_sync),
77-
peer_manager,
78-
));
79-
gossip_sync.add_utxo_lookup(Some(gossip_verifier));
80-
}
81-
},
82-
_ => (),
83-
}
84-
}
85-
8675
pub async fn update_rgs_snapshot(&self) -> Result<u32, Error> {
8776
match self {
8877
Self::P2PNetwork { gossip_sync: _, .. } => Ok(0),

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub(crate) type Scorer = CombinedScorer<Arc<Graph>, Arc<Logger>>;
253253

254254
pub(crate) type Graph = gossip::NetworkGraph<Arc<Logger>>;
255255

256-
pub(crate) type UtxoLookup = GossipVerifier<RuntimeSpawner, Arc<UtxoSourceClient>, Arc<Logger>>;
256+
pub(crate) type UtxoLookup = GossipVerifier<RuntimeSpawner, Arc<UtxoSourceClient>>;
257257

258258
pub(crate) type P2PGossipSync =
259259
lightning::routing::gossip::P2PGossipSync<Arc<Graph>, Arc<UtxoLookup>, Arc<Logger>>;

0 commit comments

Comments
 (0)