Skip to content

Commit 11f9a89

Browse files
committed
Revert "fix(test): Implement conditional channel opening based on aliases and addresses"
This reverts commit 4fd1cb8 as unit tests need to be kept deterministic, i.e., opening announced channels is a deliberate choice on a per test case basis.
1 parent c9ebeb6 commit 11f9a89

File tree

5 files changed

+316
-419
lines changed

5 files changed

+316
-419
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ impl Node {
654654
continue;
655655
}
656656
ChannelAnnouncementStatus::Announceable => {
657-
// Broadcast node announcement.
658657
let addresses = bcast_config.listening_addresses.clone().unwrap_or(Vec::new());
659658
if let Some(node_alias) = node_alias.as_ref() {
660659
bcast_pm.broadcast_node_announcement([0; 3], node_alias.0, addresses);

tests/common/mod.rs

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -204,36 +204,24 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
204204
pub(crate) fn random_node_alias() -> Option<NodeAlias> {
205205
let mut rng = thread_rng();
206206
let ranged_val = rng.gen_range(0..10);
207-
208-
let alias = format!("ldk-node-{}", ranged_val);
209-
let mut bytes = [0u8; 32];
210-
bytes[..alias.as_bytes().len()].copy_from_slice(alias.as_bytes());
211-
212-
Some(NodeAlias(bytes))
213-
}
214-
215-
pub(crate) fn random_announce_channel() -> bool {
216-
let mut rng = thread_rng();
217-
let ranged_val = rng.gen_range(0..=1);
218207
match ranged_val {
219-
0 => false,
220-
_ => true,
208+
0 => None,
209+
val => {
210+
let alias = format!("ldk-node-{}", val);
211+
let mut bytes = [0u8; 32];
212+
bytes[..alias.as_bytes().len()].copy_from_slice(alias.as_bytes());
213+
Some(NodeAlias(bytes))
214+
},
221215
}
222216
}
223217

224-
pub(crate) fn random_config(anchor_channels: bool, announce_channel: bool) -> Config {
218+
pub(crate) fn random_config(anchor_channels: bool) -> Config {
225219
let mut config = Config::default();
226220

227221
if !anchor_channels {
228222
config.anchor_channels_config = None;
229223
}
230224

231-
if announce_channel {
232-
let alias = random_node_alias();
233-
println!("Setting random LDK node alias: {:?}", alias);
234-
config.node_alias = alias;
235-
}
236-
237225
config.network = Network::Regtest;
238226
config.onchain_wallet_sync_interval_secs = 100000;
239227
config.wallet_sync_interval_secs = 100000;
@@ -247,6 +235,10 @@ pub(crate) fn random_config(anchor_channels: bool, announce_channel: bool) -> Co
247235
println!("Setting random LDK listening addresses: {:?}", rand_listening_addresses);
248236
config.listening_addresses = Some(rand_listening_addresses);
249237

238+
let alias = random_node_alias();
239+
println!("Setting random LDK node alias: {:?}", alias);
240+
config.node_alias = alias;
241+
250242
config.log_level = LogLevel::Gossip;
251243

252244
config
@@ -269,15 +261,14 @@ macro_rules! setup_builder {
269261
pub(crate) use setup_builder;
270262

271263
pub(crate) fn setup_two_nodes(
272-
electrsd: &ElectrsD, allow_0conf: bool, anchor_channels: bool,
273-
anchors_trusted_no_reserve: bool, announce_channel: bool,
264+
electrsd: &ElectrsD, allow_0conf: bool, anchor_channels: bool, anchors_trusted_no_reserve: bool,
274265
) -> (TestNode, TestNode) {
275266
println!("== Node A ==");
276-
let config_a = random_config(anchor_channels, announce_channel);
267+
let config_a = random_config(anchor_channels);
277268
let node_a = setup_node(electrsd, config_a);
278269

279270
println!("\n== Node B ==");
280-
let mut config_b = random_config(anchor_channels, announce_channel);
271+
let mut config_b = random_config(anchor_channels);
281272
if allow_0conf {
282273
config_b.trusted_peers_0conf.push(node_a.node_id());
283274
}
@@ -415,28 +406,15 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
415406
pub fn open_channel(
416407
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, electrsd: &ElectrsD,
417408
) {
418-
if node_a.config().node_alias.is_some() {
419-
node_a
420-
.open_announced_channel(
421-
node_b.node_id(),
422-
node_b.listening_addresses().unwrap().first().unwrap().clone(),
423-
funding_amount_sat,
424-
None,
425-
None,
426-
)
427-
.unwrap();
428-
} else {
429-
node_a
430-
.open_channel(
431-
node_b.node_id(),
432-
node_b.listening_addresses().unwrap().first().unwrap().clone(),
433-
funding_amount_sat,
434-
None,
435-
None,
436-
)
437-
.unwrap();
438-
}
439-
409+
node_a
410+
.open_announced_channel(
411+
node_b.node_id(),
412+
node_b.listening_addresses().unwrap().first().unwrap().clone(),
413+
funding_amount_sat,
414+
None,
415+
None,
416+
)
417+
.unwrap();
440418
assert!(node_a.list_peers().iter().find(|c| { c.node_id == node_b.node_id() }).is_some());
441419

442420
let funding_txo_a = expect_channel_pending_event!(node_a, node_b.node_id());
@@ -472,28 +450,15 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
472450
println!("\nA -- open_channel -> B");
473451
let funding_amount_sat = 2_080_000;
474452
let push_msat = (funding_amount_sat / 2) * 1000; // balance the channel
475-
476-
if node_a.config().node_alias.is_some() {
477-
node_a
478-
.open_announced_channel(
479-
node_b.node_id(),
480-
node_b.listening_addresses().unwrap().first().unwrap().clone(),
481-
funding_amount_sat,
482-
Some(push_msat),
483-
None,
484-
)
485-
.unwrap();
486-
} else {
487-
node_a
488-
.open_channel(
489-
node_b.node_id(),
490-
node_b.listening_addresses().unwrap().first().unwrap().clone(),
491-
funding_amount_sat,
492-
Some(push_msat),
493-
None,
494-
)
495-
.unwrap();
496-
}
453+
node_a
454+
.open_channel(
455+
node_b.node_id(),
456+
node_b.listening_addresses().unwrap().first().unwrap().clone(),
457+
funding_amount_sat,
458+
Some(push_msat),
459+
None,
460+
)
461+
.unwrap();
497462

498463
assert_eq!(node_a.list_peers().first().unwrap().node_id, node_b.node_id());
499464
assert!(node_a.list_peers().first().unwrap().is_persisted);

tests/integration_tests_cln.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
mod common;
1111

12-
use common::random_announce_channel;
1312
use ldk_node::bitcoin::secp256k1::PublicKey;
1413
use ldk_node::bitcoin::Amount;
1514
use ldk_node::lightning::ln::msgs::SocketAddress;
@@ -44,7 +43,7 @@ fn test_cln() {
4443
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1);
4544

4645
// Setup LDK Node
47-
let config = common::random_config(true, random_announce_channel());
46+
let config = common::random_config(true);
4847
let mut builder = Builder::from_config(config);
4948
builder.set_esplora_server("http://127.0.0.1:3002".to_string());
5049

@@ -83,19 +82,8 @@ fn test_cln() {
8382
// Open the channel
8483
let funding_amount_sat = 1_000_000;
8584

86-
if node.config().node_alias.is_none() {
87-
node.open_channel(cln_node_id, cln_address, funding_amount_sat, Some(500_000_000), None)
88-
.unwrap();
89-
} else {
90-
node.open_announced_channel(
91-
cln_node_id,
92-
cln_address,
93-
funding_amount_sat,
94-
Some(500_000_000),
95-
None,
96-
)
85+
node.open_channel(cln_node_id, cln_address, funding_amount_sat, Some(500_000_000), None)
9786
.unwrap();
98-
}
9987

10088
let funding_txo = common::expect_channel_pending_event!(node, cln_node_id);
10189
common::wait_for_tx(&electrs_client, funding_txo.txid);

0 commit comments

Comments
 (0)