]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test manual funding transaction `Event::DiscardFunding` generation 2024-08-3259-followups
authorMatt Corallo <git@bluematt.me>
Wed, 28 Aug 2024 14:50:52 +0000 (14:50 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 28 Aug 2024 14:50:52 +0000 (14:50 +0000)
lightning/src/ln/functional_tests.rs

index 12f1466e02568903781d0143d80c1c4959661d18..a85bb1ae4a20d5348d44d7cde88ab257d62f13a9 100644 (file)
@@ -18,7 +18,7 @@ use crate::chain::channelmonitor;
 use crate::chain::channelmonitor::{CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
 use crate::chain::transaction::OutPoint;
 use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
-use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
+use crate::events::{Event, FundingInfo, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
 use crate::ln::types::{ChannelId, PaymentPreimage, PaymentSecret, PaymentHash};
 use crate::ln::channel::{CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, ChannelPhase};
 use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
@@ -11209,6 +11209,48 @@ fn test_accept_inbound_channel_errors_queued() {
                open_channel_msg.common_fields.temporary_channel_id);
 }
 
+#[test]
+fn test_manual_funding_abandon() {
+       let mut cfg = UserConfig::default();
+       cfg.channel_handshake_config.minimum_depth = 1;
+       let chanmon_cfgs = create_chanmon_cfgs(2);
+       let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+       let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg), Some(cfg)]);
+       let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+       assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).is_ok());
+       let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
+
+       nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel);
+       let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
+
+       nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
+       let (temporary_channel_id, _tx, funding_outpoint) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
+       nodes[0].node.unsafe_manual_funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), funding_outpoint).unwrap();
+       check_added_monitors!(nodes[0], 0);
+
+       let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
+       nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created);
+       check_added_monitors!(nodes[1], 1);
+       expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
+
+       let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
+       let err = msgs::ErrorMessage { channel_id: funding_signed.channel_id, data: "".to_string() };
+       nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &err);
+
+       let close_events = nodes[0].node.get_and_clear_pending_events();
+       assert_eq!(close_events.len(), 2);
+       assert!(close_events.iter().any(|ev| matches!(ev, Event::ChannelClosed { .. })));
+       assert!(close_events.iter().any(|ev| match ev {
+               Event::DiscardFunding { channel_id, funding_info: FundingInfo::OutPoint { outpoint } } => {
+                       assert_eq!(*channel_id, err.channel_id);
+                       assert_eq!(*outpoint, funding_outpoint);
+                       true
+               }
+               _ => false,
+       }));
+}
+
 #[test]
 fn test_funding_signed_event() {
        let mut cfg = UserConfig::default();