Skip to content

Commit e94e403

Browse files
authored
Merge pull request #1711 from TheBlueMatt/2022-08-0conf-panic
Fix spurious panic on receipt of a block while awaiting funding
2 parents 3a3c931 + cb1db61 commit e94e403

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4771,6 +4771,9 @@ impl<Signer: Sign> Channel<Signer> {
47714771
}
47724772

47734773
fn check_get_channel_ready(&mut self, height: u32) -> Option<msgs::ChannelReady> {
4774+
// Called:
4775+
// * always when a new block/transactions are confirmed with the new height
4776+
// * when funding is signed with a height of 0
47744777
if self.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
47754778
return None;
47764779
}
@@ -4796,7 +4799,7 @@ impl<Signer: Sign> Channel<Signer> {
47964799
// We got a reorg but not enough to trigger a force close, just ignore.
47974800
false
47984801
} else {
4799-
if self.channel_state < ChannelState::ChannelFunded as u32 {
4802+
if self.funding_tx_confirmation_height != 0 && self.channel_state < ChannelState::ChannelFunded as u32 {
48004803
// We should never see a funding transaction on-chain until we've received
48014804
// funding_signed (if we're an outbound channel), or seen funding_generated (if we're
48024805
// an inbound channel - before that we have no known funding TXID). The fuzzer,

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,3 +958,45 @@ fn test_zero_conf_accept_reject() {
958958
_ => panic!(),
959959
}
960960
}
961+
962+
#[test]
963+
fn test_connect_before_funding() {
964+
// Tests for a particularly dumb explicit panic that existed prior to 0.0.111 for 0conf
965+
// channels. If we received a block while awaiting funding for 0-conf channels we'd hit an
966+
// explicit panic when deciding if we should broadcast our channel_ready message.
967+
let chanmon_cfgs = create_chanmon_cfgs(2);
968+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
969+
970+
let mut manually_accept_conf = test_default_channel_config();
971+
manually_accept_conf.manually_accept_inbound_channels = true;
972+
973+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf)]);
974+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
975+
976+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 10_001, 42, None).unwrap();
977+
let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
978+
979+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel);
980+
let events = nodes[1].node.get_and_clear_pending_events();
981+
assert_eq!(events.len(), 1);
982+
match events[0] {
983+
Event::OpenChannelRequest { temporary_channel_id, .. } => {
984+
nodes[1].node.accept_inbound_channel_from_trusted_peer_0conf(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 0).unwrap();
985+
},
986+
_ => panic!("Unexpected event"),
987+
};
988+
989+
let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
990+
assert_eq!(accept_channel.minimum_depth, 0);
991+
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
992+
993+
let events = nodes[0].node.get_and_clear_pending_events();
994+
assert_eq!(events.len(), 1);
995+
match events[0] {
996+
Event::FundingGenerationReady { .. } => {},
997+
_ => panic!("Unexpected event"),
998+
}
999+
1000+
connect_blocks(&nodes[0], 1);
1001+
connect_blocks(&nodes[1], 1);
1002+
}

0 commit comments

Comments
 (0)