Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cln-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
socat -d -d UNIX-LISTEN:/tmp/lightning-rpc,reuseaddr,fork TCP:127.0.0.1:9937&

- name: Run CLN integration tests
run: RUSTFLAGS="--cfg cln_test" cargo test --test integration_tests_cln
run: RUSTFLAGS="--cfg cln_test --cfg cycle_tests" cargo test --test integration_tests_cln
2 changes: 1 addition & 1 deletion .github/workflows/lnd-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:

- name: Run LND integration tests
run: LND_CERT_PATH=$LND_DATA_DIR/tls.cert LND_MACAROON_PATH=$LND_DATA_DIR/data/chain/bitcoin/regtest/admin.macaroon
RUSTFLAGS="--cfg lnd_test" cargo test --test integration_tests_lnd -- --exact --show-output
RUSTFLAGS="--cfg lnd_test --cfg cycle_tests" cargo test --test integration_tests_lnd -- --exact --show-output
env:
LND_DATA_DIR: ${{ env.LND_DATA_DIR }}
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
RUSTFLAGS="--cfg no_download" cargo test --features uniffi
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test --features uniffi

doc:
name: Documentation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vss-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
cd ldk-node
export TEST_VSS_BASE_URL="http://localhost:8080/vss"
RUSTFLAGS="--cfg vss_test" cargo test io::vss_store
RUSTFLAGS="--cfg vss_test" cargo test --test integration_tests_vss
RUSTFLAGS="--cfg vss_test --cfg cycle_tests" cargo test --test integration_tests_vss
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand Down Expand Up @@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "62c58495c3cbd47387962f31998899f6bbac8766", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down Expand Up @@ -122,6 +122,7 @@ check-cfg = [
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]

[[bench]]
Expand Down
16 changes: 7 additions & 9 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,8 +1474,12 @@ fn build_with_store_internal(

let gossip_source = match gossip_source_config {
GossipSourceConfig::P2PNetwork => {
let p2p_source =
Arc::new(GossipSource::new_p2p(Arc::clone(&network_graph), Arc::clone(&logger)));
let p2p_source = Arc::new(GossipSource::new_p2p(
Arc::clone(&network_graph),
Arc::clone(&chain_source),
Arc::clone(&runtime),
Arc::clone(&logger),
));

// Reset the RGS sync timestamp in case we somehow switch gossip sources
{
Expand Down Expand Up @@ -1594,13 +1598,7 @@ fn build_with_store_internal(
Arc::clone(&keys_manager),
));

liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::clone(&peer_manager)));

gossip_source.set_gossip_verifier(
Arc::clone(&chain_source),
Arc::clone(&peer_manager),
Arc::clone(&runtime),
);
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::downgrade(&peer_manager)));

let connection_manager =
Arc::new(ConnectionManager::new(Arc::clone(&peer_manager), Arc::clone(&logger)));
Expand Down
37 changes: 13 additions & 24 deletions src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ pub(crate) enum GossipSource {
}

impl GossipSource {
pub fn new_p2p(network_graph: Arc<Graph>, logger: Arc<Logger>) -> Self {
pub fn new_p2p(
network_graph: Arc<Graph>, chain_source: Arc<ChainSource>, runtime: Arc<Runtime>,
logger: Arc<Logger>,
) -> Self {
let verifier = chain_source.as_utxo_source().map(|utxo_source| {
Arc::new(GossipVerifier::new(
Arc::new(utxo_source),
RuntimeSpawner::new(runtime),
))
});

let gossip_sync = Arc::new(P2PGossipSync::new(
network_graph,
None::<Arc<UtxoLookup>>,
Arc::clone(&logger),
verifier,
logger,
));
Self::P2PNetwork { gossip_sync }
}
Expand All @@ -62,27 +72,6 @@ impl GossipSource {
}
}

pub(crate) fn set_gossip_verifier(
&self, chain_source: Arc<ChainSource>, peer_manager: Arc<PeerManager>,
runtime: Arc<Runtime>,
) {
match self {
Self::P2PNetwork { gossip_sync } => {
if let Some(utxo_source) = chain_source.as_utxo_source() {
let spawner = RuntimeSpawner::new(Arc::clone(&runtime));
let gossip_verifier = Arc::new(GossipVerifier::new(
Arc::new(utxo_source),
spawner,
Arc::clone(gossip_sync),
peer_manager,
));
gossip_sync.add_utxo_lookup(Some(gossip_verifier));
}
},
_ => (),
}
}

pub async fn update_rgs_snapshot(&self) -> Result<u32, Error> {
match self {
Self::P2PNetwork { gossip_sync: _, .. } => Ok(0),
Expand Down
12 changes: 6 additions & 6 deletions src/io/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use std::sync::Mutex;

use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::{
check_closed_event, connect_block, create_announced_chan_between_nodes, create_chanmon_cfgs,
create_dummy_block, create_network, create_node_cfgs, create_node_chanmgrs, send_payment,
TestChanMonCfg,
check_added_monitors, check_closed_event, connect_block, create_announced_chan_between_nodes,
create_chanmon_cfgs, create_dummy_block, create_network, create_node_cfgs, create_node_chanmgrs,
send_payment, TestChanMonCfg,
};
use lightning::util::persist::{
KVStore, KVStoreSync, MonitorUpdatingPersister, KVSTORE_NAMESPACE_KEY_MAX_LEN,
};
use lightning::util::test_utils;
use lightning::{check_added_monitors, check_closed_broadcast, io};
use lightning::{check_closed_broadcast, io};
use rand::distr::Alphanumeric;
use rand::{rng, Rng};

Expand Down Expand Up @@ -333,7 +333,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
100000,
);
check_closed_broadcast!(nodes[0], true);
check_added_monitors!(nodes[0], 1);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcast();
assert_eq!(node_txn.len(), 1);
Expand All @@ -345,7 +345,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
let reason = ClosureReason::CommitmentTxConfirmed;
let node_id_0 = nodes[0].node.get_our_node_id();
check_closed_event(&nodes[1], 1, reason, &[node_id_0], 100000);
check_added_monitors!(nodes[1], 1);
check_added_monitors(&nodes[1], 1);

// Make sure everything is persisted as expected after close.
check_persisted_data!(persister_0_max_pending_updates * 2 * EXPECTED_UPDATES_PER_PAYMENT + 1);
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,12 @@ impl Node {
Error::PersistenceFailed
})
}

#[cfg(cycle_tests)]
/// Fetch a reference to the inner NetworkGraph, for Arc cycle detection
pub fn fetch_ref(&self) -> std::sync::Weak<Graph> {
Arc::downgrade(&self.network_graph)
}
}

impl Drop for Node {
Expand Down
10 changes: 5 additions & 5 deletions src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use std::collections::HashMap;
use std::ops::Deref;
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, Mutex, RwLock, Weak};
use std::time::Duration;

use bitcoin::hashes::{sha256, Hash};
Expand Down Expand Up @@ -291,7 +291,7 @@ where
lsps2_service: Option<LSPS2Service>,
wallet: Arc<Wallet>,
channel_manager: Arc<ChannelManager>,
peer_manager: RwLock<Option<Arc<PeerManager>>>,
peer_manager: RwLock<Option<Weak<PeerManager>>>,
keys_manager: Arc<KeysManager>,
liquidity_manager: Arc<LiquidityManager>,
config: Arc<Config>,
Expand All @@ -302,7 +302,7 @@ impl<L: Deref> LiquiditySource<L>
where
L::Target: LdkLogger,
{
pub(crate) fn set_peer_manager(&self, peer_manager: Arc<PeerManager>) {
pub(crate) fn set_peer_manager(&self, peer_manager: Weak<PeerManager>) {
*self.peer_manager.write().unwrap() = Some(peer_manager);
}

Expand Down Expand Up @@ -715,8 +715,8 @@ where
return;
};

let init_features = if let Some(peer_manager) =
self.peer_manager.read().unwrap().as_ref()
let init_features = if let Some(Some(peer_manager)) =
self.peer_manager.read().unwrap().as_ref().map(|weak| weak.upgrade())
{
// Fail if we're not connected to the prospective channel partner.
if let Some(peer) = peer_manager.peer_by_node_id(&their_network_key) {
Expand Down
10 changes: 10 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ impl LogWriter for Writer {
}
}

#[cfg(cycle_tests)]
/// Our log writer
pub struct Logger {
/// Specifies the logger's writer.
writer: Writer,
}

#[cfg(not(cycle_tests))]
pub(crate) struct Logger {
/// Specifies the logger's writer.
writer: Writer,
Expand All @@ -195,10 +203,12 @@ impl Logger {
Ok(Self { writer: Writer::FileWriter { file_path, max_log_level } })
}

/// Creates a new logger writing to the `log` crate
pub fn new_log_facade() -> Self {
Self { writer: Writer::LogFacadeWriter }
}

/// Creates a new logger writing to an underlying [`LogWriter`]
pub fn new_custom_writer(log_writer: Arc<dyn LogWriter>) -> Self {
Self { writer: Writer::CustomWriter(log_writer) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub(crate) type Scorer = CombinedScorer<Arc<Graph>, Arc<Logger>>;

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

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

pub(crate) type P2PGossipSync =
lightning::routing::gossip::P2PGossipSync<Arc<Graph>, Arc<UtxoLookup>, Arc<Logger>>;
Expand Down
46 changes: 43 additions & 3 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) mod logging;
use std::collections::{HashMap, HashSet};
use std::env;
use std::future::Future;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::time::Duration;
Expand Down Expand Up @@ -261,10 +262,49 @@ pub(crate) fn random_config(anchor_channels: bool) -> TestConfig {
TestConfig { node_config, ..Default::default() }
}

pub struct TestNode {
#[cfg(feature = "uniffi")]
inner: Option<Arc<Node>>,
#[cfg(not(feature = "uniffi"))]
inner: Option<Node>,
}

#[cfg(feature = "uniffi")]
type TestNode = Arc<Node>;
impl From<Arc<Node>> for TestNode {
fn from(inner: Arc<Node>) -> Self {
Self { inner: Some(inner) }
}
}

#[cfg(not(feature = "uniffi"))]
type TestNode = Node;
impl From<Node> for TestNode {
fn from(inner: Node) -> Self {
Self { inner: Some(inner) }
}
}

impl Deref for TestNode {
type Target = Node;
fn deref(&self) -> &Node {
#[cfg(feature = "uniffi")]
{
self.inner.as_ref().unwrap().deref()
}
#[cfg(not(feature = "uniffi"))]
{
&self.inner.as_ref().unwrap()
}
}
}

#[cfg(cycle_tests)]
impl Drop for TestNode {
fn drop(&mut self) {
let graph_ref = (**self).fetch_ref();
self.inner.take();
assert_eq!(graph_ref.strong_count(), 0);
}
}

#[derive(Clone)]
pub(crate) enum TestChainSource<'a> {
Expand Down Expand Up @@ -430,7 +470,7 @@ pub(crate) fn setup_node_for_async_payments(
node.start().unwrap();
assert!(node.status().is_running);
assert!(node.status().latest_fee_rate_cache_update_timestamp.is_some());
node
node.into()
}

pub(crate) async fn generate_blocks_and_wait<E: ElectrumApi>(
Expand Down
Loading
Loading