Skip to content

Commit 5470de3

Browse files
committed
Add test of 0conf channels getting the funding transaction reorg'd
In a previous version of the 0-conf code we did not correctly handle 0-conf channels getting the funding transaction reorg'd out (and the real SCID possibly changing on us).
1 parent ecace5e commit 5470de3

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

lightning/src/ln/priv_short_conf_tests.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ln::msgs;
2222
use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, OptionalField, ChannelUpdate};
2323
use ln::wire::Encode;
2424
use util::enforcing_trait_impls::EnforcingSigner;
25-
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider};
25+
use util::events::{ClosureReason, Event, MessageSendEvent, MessageSendEventsProvider};
2626
use util::config::UserConfig;
2727
use util::ser::{Writeable, ReadableArgs};
2828
use util::test_utils;
@@ -848,3 +848,52 @@ fn test_public_0conf_channel() {
848848
_ => panic!("Unexpected event"),
849849
};
850850
}
851+
852+
#[test]
853+
fn test_0conf_channel_reorg() {
854+
// If we accept a 0conf channel, which is then confirmed, but then changes SCID in a reorg, we
855+
// have to make sure we handle this correctly (or, currently, just force-close the channel).
856+
857+
let chanmon_cfgs = create_chanmon_cfgs(2);
858+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
859+
let mut chan_config = test_default_channel_config();
860+
chan_config.manually_accept_inbound_channels = true;
861+
862+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config)]);
863+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
864+
865+
// This is the default but we force it on anyway
866+
chan_config.channel_options.announced_channel = true;
867+
let tx = open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config));
868+
869+
// We can use the channel immediately, but we can't announce it until we get 6+ confirmations
870+
send_payment(&nodes[0], &[&nodes[1]], 100_000);
871+
872+
mine_transaction(&nodes[0], &tx);
873+
mine_transaction(&nodes[1], &tx);
874+
875+
// Send a payment using the channel's real SCID, which will be public in a few blocks once we
876+
// can generate a channel_announcement.
877+
let real_scid = nodes[0].node.list_usable_channels()[0].short_channel_id.unwrap();
878+
assert_eq!(nodes[1].node.list_usable_channels()[0].short_channel_id.unwrap(), real_scid);
879+
880+
let (mut route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 10_000);
881+
assert_eq!(route.paths[0][0].short_channel_id, real_scid);
882+
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1]]], 10_000, payment_hash, payment_secret);
883+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
884+
885+
disconnect_blocks(&nodes[0], 1);
886+
disconnect_blocks(&nodes[1], 1);
887+
888+
// At this point the channel no longer has an SCID again. In the future we should likely
889+
// support simply un-setting the SCID and waiting until the channel gets re-confirmed, but for
890+
// now we force-close the channel here.
891+
check_closed_event!(&nodes[0], 1, ClosureReason::ProcessingError {
892+
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs.".to_owned()
893+
});
894+
check_closed_broadcast!(nodes[0], true);
895+
check_closed_event!(&nodes[1], 1, ClosureReason::ProcessingError {
896+
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs.".to_owned()
897+
});
898+
check_closed_broadcast!(nodes[1], true);
899+
}

0 commit comments

Comments
 (0)