Skip to content

Commit 809a227

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 a7d2b6a commit 809a227

File tree

4 files changed

+31
-51
lines changed

4 files changed

+31
-51
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ default = []
3939
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
4040
#lightning-macros = { version = "0.2.0" }
4141

42-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["std"] }
43-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0" }
44-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0" }
46-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0" }
49-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0" }
42+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["std"] }
43+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891" }
44+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891" }
46+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891" }
49+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891" }
5353

5454
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5555
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -78,13 +78,13 @@ log = { version = "0.4.22", default-features = false, features = ["std"]}
7878
vss-client = { package = "vss-client-ng", version = "0.4" }
7979
prost = { version = "0.11.6", default-features = false}
8080
#bitcoin-payment-instructions = { version = "0.6" }
81-
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "a9ad849a0eb7b155a688d713de6d9010cb48f073" }
81+
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "fdca6c62f2fe2c53427d3e51e322a49aa7323ee2" }
8282

8383
[target.'cfg(windows)'.dependencies]
8484
winapi = { version = "0.3", features = ["winbase"] }
8585

8686
[dev-dependencies]
87-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "1c730c8a16e28cc8e0c4817717ee63c97abcf4b0", features = ["std", "_test_utils"] }
87+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5236dba053a3f4f01cf0c32ce42b609a93738891", features = ["std", "_test_utils"] }
8888
proptest = "1.0.0"
8989
regex = "1.5.6"
9090
criterion = { version = "0.7.0", features = ["async_tokio"] }

src/builder.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bitcoin::key::Secp256k1;
2020
use bitcoin::secp256k1::PublicKey;
2121
use bitcoin::{BlockHash, Network};
2222
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
23-
use lightning::chain::{chainmonitor, BestBlock, Watch};
23+
use lightning::chain::{chainmonitor, BestBlock};
2424
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManagerReadArgs};
2525
use lightning::ln::msgs::{RoutingMessageHandler, SocketAddress};
2626
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
@@ -1481,8 +1481,12 @@ fn build_with_store_internal(
14811481

14821482
let gossip_source = match gossip_source_config {
14831483
GossipSourceConfig::P2PNetwork => {
1484-
let p2p_source =
1485-
Arc::new(GossipSource::new_p2p(Arc::clone(&network_graph), Arc::clone(&logger)));
1484+
let p2p_source = Arc::new(GossipSource::new_p2p(
1485+
Arc::clone(&network_graph),
1486+
Arc::clone(&chain_source),
1487+
Arc::clone(&runtime),
1488+
Arc::clone(&logger),
1489+
));
14861490

14871491
// Reset the RGS sync timestamp in case we somehow switch gossip sources
14881492
{
@@ -1606,12 +1610,6 @@ fn build_with_store_internal(
16061610

16071611
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::downgrade(&peer_manager)));
16081612

1609-
gossip_source.set_gossip_verifier(
1610-
Arc::clone(&chain_source),
1611-
Arc::clone(&peer_manager),
1612-
Arc::clone(&runtime),
1613-
);
1614-
16151613
let connection_manager =
16161614
Arc::new(ConnectionManager::new(Arc::clone(&peer_manager), Arc::clone(&logger)));
16171615

src/gossip.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::chain::ChainSource;
1717
use crate::config::RGS_SYNC_TIMEOUT_SECS;
1818
use crate::logger::{log_trace, LdkLogger, Logger};
1919
use crate::runtime::Runtime;
20-
use crate::types::{GossipSync, Graph, P2PGossipSync, PeerManager, RapidGossipSync, UtxoLookup};
20+
use crate::types::{GossipSync, Graph, P2PGossipSync, RapidGossipSync};
2121
use crate::Error;
2222

2323
pub(crate) enum GossipSource {
@@ -33,12 +33,15 @@ pub(crate) enum GossipSource {
3333
}
3434

3535
impl GossipSource {
36-
pub fn new_p2p(network_graph: Arc<Graph>, logger: Arc<Logger>) -> Self {
37-
let gossip_sync = Arc::new(P2PGossipSync::new(
38-
network_graph,
39-
None::<Arc<UtxoLookup>>,
40-
Arc::clone(&logger),
41-
));
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(Arc::new(utxo_source), RuntimeSpawner::new(runtime)))
42+
});
43+
44+
let gossip_sync = Arc::new(P2PGossipSync::new(network_graph, verifier, logger));
4245
Self::P2PNetwork { gossip_sync }
4346
}
4447

@@ -62,27 +65,6 @@ impl GossipSource {
6265
}
6366
}
6467

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-
8668
pub async fn update_rgs_snapshot(&self) -> Result<u32, Error> {
8769
match self {
8870
Self::P2PNetwork { gossip_sync: _, .. } => Ok(0),

src/types.rs

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

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

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

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

0 commit comments

Comments
 (0)