X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchanmon_update_fail_tests.rs;h=e85a69017f5c484478558e42f73ee7b1bd7079e1;hb=1d3861e5f6a543d882905ebda21656cc0ea231a7;hp=00b6813411c657fc65656a517b3dc9fc11e767d4;hpb=09e167019589dcfc5ee9675ad243b337659eafc7;p=rust-lightning diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 00b68134..e85a6901 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -1160,6 +1160,7 @@ fn test_monitor_update_fail_reestablish() { assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + expect_payment_forwarded!(nodes[1], Some(1000), false); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false); @@ -2318,6 +2319,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f assert_eq!(fulfill_msg, cs_updates.update_fulfill_htlcs[0]); } nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &fulfill_msg); + expect_payment_forwarded!(nodes[1], Some(1000), false); check_added_monitors!(nodes[1], 1); let mut bs_updates = None; @@ -2367,3 +2369,66 @@ fn test_reconnect_dup_htlc_claims() { do_test_reconnect_dup_htlc_claims(HTLCStatusAtDupClaim::HoldingCell, true); do_test_reconnect_dup_htlc_claims(HTLCStatusAtDupClaim::Cleared, true); } + +#[test] +fn test_temporary_error_during_shutdown() { + // Test that temporary failures when updating the monitor's shutdown script do not prevent + // cooperative close. + let mut config = test_default_channel_config(); + config.channel_options.commit_upfront_shutdown_pubkey = false; + + 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(config), Some(config)]); + let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + + *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure)); + *nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure)); + close_channel(&nodes[0], &nodes[1], &channel_id, funding_tx, false); + check_added_monitors!(nodes[0], 1); + check_added_monitors!(nodes[1], 1); +} + +#[test] +fn test_permanent_error_during_sending_shutdown() { + // Test that permanent failures when updating the monitor's shutdown script result in a force + // close when initiating a cooperative close. + let mut config = test_default_channel_config(); + config.channel_options.commit_upfront_shutdown_pubkey = false; + + 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(config), None]); + let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; + *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure)); + + assert!(nodes[0].node.close_channel(&channel_id).is_ok()); + check_closed_broadcast!(nodes[0], true); + check_added_monitors!(nodes[0], 2); +} + +#[test] +fn test_permanent_error_during_handling_shutdown() { + // Test that permanent failures when updating the monitor's shutdown script result in a force + // close when handling a cooperative close. + let mut config = test_default_channel_config(); + config.channel_options.commit_upfront_shutdown_pubkey = false; + + 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, &[None, Some(config)]); + let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; + *nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure)); + + assert!(nodes[0].node.close_channel(&channel_id).is_ok()); + let shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); + nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &shutdown); + check_closed_broadcast!(nodes[1], true); + check_added_monitors!(nodes[1], 2); +}