Skip to content

Commit 79411c7

Browse files
committed
Reject 0conf channel in accept_inbound_channel
1 parent cfab760 commit 79411c7

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4203,8 +4203,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
42034203
if accept_0conf {
42044204
channel.get_mut().set_0conf();
42054205
} else if channel.get().get_channel_type().requires_zero_conf() {
4206-
return Err(APIError::APIMisuseError { err: "This channel requires 0conf. Please use accept_inbound_channel_from_trusted_peer_0conf to accept.".to_owned() });
4206+
let send_msg_err_event = events::MessageSendEvent::HandleError {
4207+
node_id: channel.get().get_counterparty_node_id(),
4208+
action: msgs::ErrorAction::SendErrorMessage{
4209+
msg: msgs::ErrorMessage { channel_id: temporary_channel_id.clone(), data: "No zero confirmation channels accepted".to_owned(), }
4210+
}
4211+
};
4212+
channel_state.pending_msg_events.push(send_err_msg_event);
4213+
let _ = remove_channel!(self, channel_state, channel);
4214+
return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
42074215
}
4216+
42084217
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
42094218
node_id: channel.get().get_counterparty_node_id(),
42104219
msg: channel.get_mut().accept_inbound_channel(user_channel_id),

lightning/src/ln/functional_tests.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10063,7 +10063,7 @@ fn test_zero_conf_accept_reject() {
1006310063
let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
1006410064
channel_type_features.set_zero_conf_required();
1006510065

10066-
// Check we reject zero conf channels by default
10066+
// 1. Check we reject zero conf channels by default
1006710067
let chanmon_cfgs = create_chanmon_cfgs(2);
1006810068
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1006910069
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -10076,15 +10076,15 @@ fn test_zero_conf_accept_reject() {
1007610076

1007710077
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel_msg);
1007810078

10079-
let events = nodes[1].node.get_and_clear_pending_msg_events();
10080-
match events[0] {
10079+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
10080+
match msg_events[0] {
1008110081
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg, .. }, .. } => {
1008210082
assert_eq!(msg.data, "No zero confirmation channels accepted".to_owned());
1008310083
},
1008410084
_ => panic!(),
1008510085
}
1008610086

10087-
// Check we can manually accept zero conf channels
10087+
// 2. Check we can manually accept zero conf channels via the right method
1008810088
let mut manually_accept_conf = UserConfig::default();
1008910089
manually_accept_conf.manually_accept_inbound_channels = true;
1009010090

@@ -10094,12 +10094,13 @@ fn test_zero_conf_accept_reject() {
1009410094
&[None, Some(manually_accept_conf.clone())]);
1009510095
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1009610096

10097+
// 2.1 First try the non-0conf method to manually accept
1009710098
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42,
1009810099
Some(manually_accept_conf)).unwrap();
1009910100
let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel,
1010010101
nodes[1].node.get_our_node_id());
1010110102

10102-
open_channel_msg.channel_type = Some(channel_type_features);
10103+
open_channel_msg.channel_type = Some(channel_type_features.clone());
1010310104

1010410105
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(),
1010510106
&open_channel_msg);
@@ -10114,14 +10115,41 @@ fn test_zero_conf_accept_reject() {
1011410115
// Assert we fail to accept via the non-0conf method
1011510116
assert!(nodes[1].node.accept_inbound_channel(&temporary_channel_id,
1011610117
&nodes[0].node.get_our_node_id(), 0).is_err());
10118+
},
10119+
_ => panic!(),
10120+
}
10121+
10122+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
10123+
match msg_events[0] {
10124+
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg, .. }, .. } => {
10125+
assert_eq!(msg.data, "No zero confirmation channels accepted".to_owned());
10126+
},
10127+
_ => panic!(),
10128+
}
10129+
10130+
// 2.2 Try again with the 0conf method to manually accept
10131+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42,
10132+
Some(manually_accept_conf)).unwrap();
10133+
let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel,
10134+
nodes[1].node.get_our_node_id());
10135+
10136+
open_channel_msg.channel_type = Some(channel_type_features);
10137+
10138+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(),
10139+
&open_channel_msg);
10140+
10141+
let events = nodes[1].node.get_and_clear_pending_events();
10142+
10143+
match events[0] {
10144+
Event::OpenChannelRequest { temporary_channel_id, .. } => {
1011710145
// Assert we can accept via the 0conf method
1011810146
assert!(nodes[1].node.accept_inbound_channel_from_trusted_peer_0conf(
1011910147
&temporary_channel_id, &nodes[0].node.get_our_node_id(), 0).is_ok());
1012010148
},
1012110149
_ => panic!(),
1012210150
}
1012310151

10124-
// Don't handle generated events
10152+
// Don't handle remaining events
1012510153
nodes[1].node.get_and_clear_pending_msg_events();
1012610154
nodes[1].node.get_and_clear_pending_events();
1012710155
}

0 commit comments

Comments
 (0)