Skip to content

Commit a4c3461

Browse files
committed
f - add test coverage
1 parent 6d426e1 commit a4c3461

File tree

6 files changed

+125
-2
lines changed

6 files changed

+125
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4515,7 +4515,6 @@ where
45154515
last_local_balance_msat: Some(shutdown_res.last_local_balance_msat),
45164516
}, None));
45174517

4518-
// Emit SpliceFailed event immediately after ChannelClosed if there was an active splice negotiation
45194518
if let Some(splice_funding_failed) = shutdown_res.splice_funding_failed.take() {
45204519
pending_events.push_back((events::Event::SpliceFailed {
45214520
channel_id: shutdown_res.channel_id,

lightning/src/ln/functional_test_utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ macro_rules! get_event_msg {
10341034
/// Get an error message from the pending events queue.
10351035
pub fn get_err_msg(node: &Node, recipient: &PublicKey) -> msgs::ErrorMessage {
10361036
let events = node.node.get_and_clear_pending_msg_events();
1037+
dbg!(&events);
10371038
assert_eq!(events.len(), 1);
10381039
match events[0] {
10391040
MessageSendEvent::HandleError {
@@ -2128,6 +2129,7 @@ pub struct ExpectedCloseEvent {
21282129
pub channel_id: Option<ChannelId>,
21292130
pub counterparty_node_id: Option<PublicKey>,
21302131
pub discard_funding: bool,
2132+
pub splice_failed: bool,
21312133
pub reason: Option<ClosureReason>,
21322134
pub channel_funding_txo: Option<OutPoint>,
21332135
pub user_channel_id: Option<u128>,
@@ -2142,6 +2144,7 @@ impl ExpectedCloseEvent {
21422144
channel_id: Some(channel_id),
21432145
counterparty_node_id: None,
21442146
discard_funding,
2147+
splice_failed: false,
21452148
reason: Some(reason),
21462149
channel_funding_txo: None,
21472150
user_channel_id: None,
@@ -2153,8 +2156,9 @@ impl ExpectedCloseEvent {
21532156
pub fn check_closed_events(node: &Node, expected_close_events: &[ExpectedCloseEvent]) {
21542157
let closed_events_count = expected_close_events.len();
21552158
let discard_events_count = expected_close_events.iter().filter(|e| e.discard_funding).count();
2159+
let splice_events_count = expected_close_events.iter().filter(|e| e.splice_failed).count();
21562160
let events = node.node.get_and_clear_pending_events();
2157-
assert_eq!(events.len(), closed_events_count + discard_events_count, "{:?}", events);
2161+
assert_eq!(events.len(), closed_events_count + discard_events_count + splice_events_count, "{:?}", events);
21582162
for expected_event in expected_close_events {
21592163
assert!(events.iter().any(|e| matches!(
21602164
e,
@@ -2184,6 +2188,10 @@ pub fn check_closed_events(node: &Node, expected_close_events: &[ExpectedCloseEv
21842188
events.iter().filter(|e| matches!(e, Event::DiscardFunding { .. },)).count(),
21852189
discard_events_count
21862190
);
2191+
assert_eq!(
2192+
events.iter().filter(|e| matches!(e, Event::SpliceFailed { .. },)).count(),
2193+
splice_events_count
2194+
);
21872195
}
21882196

21892197
/// Check that a channel's closing channel events has been issued
@@ -2205,6 +2213,7 @@ pub fn check_closed_event(
22052213
channel_id: None,
22062214
counterparty_node_id: Some(*node_id),
22072215
discard_funding: is_check_discard_funding,
2216+
splice_failed: false,
22082217
reason: Some(expected_reason.clone()),
22092218
channel_funding_txo: None,
22102219
user_channel_id: None,

lightning/src/ln/monitor_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ fn do_test_revoked_counterparty_commitment_balances(keyed_anchors: bool, p2a_anc
14671467
channel_id: Some(chan_id),
14681468
counterparty_node_id: Some(nodes[0].node.get_our_node_id()),
14691469
discard_funding: false,
1470+
splice_failed: false,
14701471
reason: None, // Could be due to any HTLC timing out, so don't bother checking
14711472
channel_funding_txo: None,
14721473
user_channel_id: None,

lightning/src/ln/reorg_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ fn test_set_outpoints_partial_claiming() {
503503
channel_id: Some(chan.2),
504504
counterparty_node_id: Some(nodes[0].node.get_our_node_id()),
505505
discard_funding: false,
506+
splice_failed: false,
506507
reason: None, // Could be due to either HTLC timing out, so don't bother checking
507508
channel_funding_txo: None,
508509
user_channel_id: None,

lightning/src/ln/shutdown_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) {
636636
channel_id: None,
637637
counterparty_node_id: Some(node_a_id),
638638
discard_funding: false,
639+
splice_failed: false,
639640
reason: Some(ClosureReason::LocallyInitiatedCooperativeClosure),
640641
channel_funding_txo: None,
641642
user_channel_id: None,
@@ -645,6 +646,7 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) {
645646
channel_id: None,
646647
counterparty_node_id: Some(node_c_id),
647648
discard_funding: false,
649+
splice_failed: false,
648650
reason: Some(ClosureReason::CounterpartyInitiatedCooperativeClosure),
649651
channel_funding_txo: None,
650652
user_channel_id: None,

lightning/src/ln/splicing_tests.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,114 @@ fn fail_splice_on_tx_abort() {
10111011
let tx_abort = get_event_msg!(initiator, MessageSendEvent::SendTxAbort, node_id_acceptor);
10121012
acceptor.node.handle_tx_abort(node_id_initiator, &tx_abort);
10131013
}
1014+
1015+
#[test]
1016+
fn fail_splice_on_channel_close() {
1017+
let chanmon_cfgs = create_chanmon_cfgs(2);
1018+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1019+
let config = test_default_anchors_channel_config();
1020+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]);
1021+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1022+
1023+
let initiator = &nodes[0];
1024+
let acceptor = &nodes[1];
1025+
1026+
let _node_id_initiator = initiator.node.get_our_node_id();
1027+
let node_id_acceptor = acceptor.node.get_our_node_id();
1028+
1029+
let initial_channel_capacity = 100_000;
1030+
let (_, _, channel_id, _) =
1031+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, initial_channel_capacity, 0);
1032+
1033+
let coinbase_tx = provide_anchor_reserves(&nodes);
1034+
let splice_in_amount = initial_channel_capacity / 2;
1035+
let contribution = SpliceContribution::SpliceIn {
1036+
value: Amount::from_sat(splice_in_amount),
1037+
inputs: vec![FundingTxInput::new_p2wpkh(coinbase_tx, 0).unwrap()],
1038+
change_script: Some(nodes[0].wallet_source.get_change_script().unwrap()),
1039+
};
1040+
1041+
// Close the channel before completion of interactive-tx construction.
1042+
let _ = complete_splice_handshake(initiator, acceptor, channel_id, contribution.clone());
1043+
let _tx_add_input =
1044+
get_event_msg!(initiator, MessageSendEvent::SendTxAddInput, node_id_acceptor);
1045+
1046+
initiator
1047+
.node
1048+
.force_close_broadcasting_latest_txn(&channel_id, &node_id_acceptor, "test".to_owned())
1049+
.unwrap();
1050+
handle_bump_events(initiator, true, 0);
1051+
check_closed_events(
1052+
&nodes[0],
1053+
&[ExpectedCloseEvent {
1054+
channel_id: Some(channel_id),
1055+
discard_funding: false,
1056+
splice_failed: true,
1057+
channel_funding_txo: None,
1058+
user_channel_id: Some(42),
1059+
..Default::default()
1060+
}],
1061+
);
1062+
check_closed_broadcast(&nodes[0], 1, true);
1063+
check_added_monitors(&nodes[0], 1);
1064+
}
1065+
1066+
#[test]
1067+
fn fail_quiescent_action_on_channel_close() {
1068+
let chanmon_cfgs = create_chanmon_cfgs(2);
1069+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1070+
let config = test_default_anchors_channel_config();
1071+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]);
1072+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1073+
1074+
let initiator = &nodes[0];
1075+
let acceptor = &nodes[1];
1076+
1077+
let _node_id_initiator = initiator.node.get_our_node_id();
1078+
let node_id_acceptor = acceptor.node.get_our_node_id();
1079+
1080+
let initial_channel_capacity = 100_000;
1081+
let (_, _, channel_id, _) =
1082+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, initial_channel_capacity, 0);
1083+
1084+
let coinbase_tx = provide_anchor_reserves(&nodes);
1085+
let splice_in_amount = initial_channel_capacity / 2;
1086+
let contribution = SpliceContribution::SpliceIn {
1087+
value: Amount::from_sat(splice_in_amount),
1088+
inputs: vec![FundingTxInput::new_p2wpkh(coinbase_tx, 0).unwrap()],
1089+
change_script: Some(nodes[0].wallet_source.get_change_script().unwrap()),
1090+
};
1091+
1092+
// Close the channel before completion of STFU handshake.
1093+
initiator
1094+
.node
1095+
.splice_channel(
1096+
&channel_id,
1097+
&node_id_acceptor,
1098+
contribution,
1099+
FEERATE_FLOOR_SATS_PER_KW,
1100+
None,
1101+
)
1102+
.unwrap();
1103+
1104+
let _stfu_init = get_event_msg!(initiator, MessageSendEvent::SendStfu, node_id_acceptor);
1105+
1106+
initiator
1107+
.node
1108+
.force_close_broadcasting_latest_txn(&channel_id, &node_id_acceptor, "test".to_owned())
1109+
.unwrap();
1110+
handle_bump_events(initiator, true, 0);
1111+
check_closed_events(
1112+
&nodes[0],
1113+
&[ExpectedCloseEvent {
1114+
channel_id: Some(channel_id),
1115+
discard_funding: false,
1116+
splice_failed: true,
1117+
channel_funding_txo: None,
1118+
user_channel_id: Some(42),
1119+
..Default::default()
1120+
}],
1121+
);
1122+
check_closed_broadcast(&nodes[0], 1, true);
1123+
check_added_monitors(&nodes[0], 1);
1124+
}

0 commit comments

Comments
 (0)