Skip to content

Commit 0ffb568

Browse files
committed
Send peers error messages for failures due to invalid batch funding
If we fail to fund a batch open we'll force-close all channels in the batch, however would previously fail to send error messages to our peers for any channels we were due to test after the one that failed. This commit fixes that issue, sending the required error messages to allow our peers to clean up their state.
1 parent 4f4bf67 commit 0ffb568

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

lightning/src/ln/channelmanager.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4732,11 +4732,20 @@ eprintln!("FAILING HERE, setting result");
47324732
for (channel_id, counterparty_node_id) in channels_to_remove {
47334733
per_peer_state.get(&counterparty_node_id)
47344734
.map(|peer_state_mutex| peer_state_mutex.lock().unwrap())
4735-
.and_then(|mut peer_state| peer_state.channel_by_id.remove(&channel_id))
4736-
.map(|mut chan| {
4735+
.and_then(|mut peer_state| peer_state.channel_by_id.remove(&channel_id).map(|chan| (chan, peer_state)))
4736+
.map(|(mut chan, mut peer_state)| {
47374737
update_maps_on_chan_removal!(self, &chan.context());
47384738
let closure_reason = ClosureReason::ProcessingError { err: e.clone() };
47394739
shutdown_results.push(chan.context_mut().force_shutdown(false, closure_reason));
4740+
peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
4741+
node_id: counterparty_node_id,
4742+
action: msgs::ErrorAction::SendErrorMessage {
4743+
msg: msgs::ErrorMessage {
4744+
channel_id,
4745+
data: "Failed to fund channel".to_owned(),
4746+
}
4747+
},
4748+
});
47404749
});
47414750
}
47424751
}

lightning/src/ln/functional_tests.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -10110,14 +10110,9 @@ fn test_non_final_funding_tx() {
1011010110
},
1011110111
_ => panic!()
1011210112
}
10113-
let events = nodes[0].node.get_and_clear_pending_events();
10114-
assert_eq!(events.len(), 1);
10115-
match events[0] {
10116-
Event::ChannelClosed { channel_id, .. } => {
10117-
assert_eq!(channel_id, temp_channel_id);
10118-
},
10119-
_ => panic!("Unexpected event"),
10120-
}
10113+
let err = "Error in transaction funding: Misuse error: Funding transaction absolute timelock is non-final".to_owned();
10114+
check_closed_events(&nodes[0], &[ExpectedCloseEvent::from_id_reason(temp_channel_id, false, ClosureReason::ProcessingError { err })]);
10115+
assert_eq!(get_err_msg(&nodes[0], &nodes[1].node.get_our_node_id()).data, "Failed to fund channel");
1012110116
}
1012210117

1012310118
#[test]

lightning/src/ln/shutdown_tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,14 @@ fn batch_funding_failure() {
14341434
// We currently spuriously send `FundingCreated` for the first channel and then immediately
14351435
// fail both channels, which isn't ideal but should be fine.
14361436
assert!(matches!(msgs[0],
1437-
MessageSendEvent::SendFundingCreated { msg: msgs::FundingCreated { temporary_channel_id: temp_chan_id_a, .. }, .. }
1437+
MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage {
1438+
msg: msgs::ErrorMessage { channel_id: temp_chan_id_b, .. }, ..
1439+
}, .. }
14381440
));
14391441
assert!(matches!(msgs[1],
1442+
MessageSendEvent::SendFundingCreated { msg: msgs::FundingCreated { temporary_channel_id: temp_chan_id_a, .. }, .. }
1443+
));
1444+
assert!(matches!(msgs[2],
14401445
MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage {
14411446
msg: msgs::ErrorMessage { channel_id: post_funding_chan_id_a, .. }, ..
14421447
}, .. }

0 commit comments

Comments
 (0)