Skip to content

Commit 3691cfa

Browse files
committed
gossip: Test NodeFailure events
1 parent 97b48e7 commit 3691cfa

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

lightning/src/routing/gossip.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,7 @@ mod tests {
22652265

22662266
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
22672267
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
2268+
let node_2_id = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
22682269

22692270
{
22702271
// There is no nodes in the table at the beginning.
@@ -2354,7 +2355,54 @@ mod tests {
23542355
assert_eq!(network_graph.read_only().channels().len(), 0);
23552356
// Nodes are also deleted because there are no associated channels anymore
23562357
assert_eq!(network_graph.read_only().nodes().len(), 0);
2357-
// TODO: Test NetworkUpdate::NodeFailure, which is not implemented yet.
2358+
2359+
// Announce a channel to test permanent node failure
2360+
let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
2361+
let short_channel_id = valid_channel_announcement.contents.short_channel_id;
2362+
let chain_source: Option<&test_utils::TestChainSource> = None;
2363+
assert!(network_graph.update_channel_from_announcement(&valid_channel_announcement, &chain_source).is_ok());
2364+
assert!(network_graph.read_only().channels().get(&short_channel_id).is_some());
2365+
2366+
// Non-permanent node failure does not delete any nodes or channels
2367+
network_graph.handle_event(&Event::PaymentPathFailed {
2368+
payment_id: None,
2369+
payment_hash: PaymentHash([0; 32]),
2370+
rejected_by_dest: false,
2371+
all_paths_failed: true,
2372+
path: vec![],
2373+
network_update: Some(NetworkUpdate::NodeFailure {
2374+
node_id: node_2_id,
2375+
is_permanent: false,
2376+
}),
2377+
short_channel_id: None,
2378+
retry: None,
2379+
error_code: None,
2380+
error_data: None,
2381+
});
2382+
2383+
assert!(network_graph.read_only().channels().get(&short_channel_id).is_some());
2384+
assert!(network_graph.read_only().nodes().get(&NodeId::from_pubkey(&node_2_id)).is_some());
2385+
2386+
// Permanent node failure deletes node and its channels
2387+
network_graph.handle_event(&Event::PaymentPathFailed {
2388+
payment_id: None,
2389+
payment_hash: PaymentHash([0; 32]),
2390+
rejected_by_dest: false,
2391+
all_paths_failed: true,
2392+
path: vec![],
2393+
network_update: Some(NetworkUpdate::NodeFailure {
2394+
node_id: node_2_id,
2395+
is_permanent: true,
2396+
}),
2397+
short_channel_id: None,
2398+
retry: None,
2399+
error_code: None,
2400+
error_data: None,
2401+
});
2402+
2403+
assert_eq!(network_graph.read_only().nodes().len(), 0);
2404+
// Channels are also deleted because the associated node has been deleted
2405+
assert_eq!(network_graph.read_only().channels().len(), 0);
23582406
}
23592407

23602408
#[test]

0 commit comments

Comments
 (0)