|
4 | 4 |
|
5 | 5 | use chain::transaction::OutPoint;
|
6 | 6 | use chain::chaininterface::{ChainListener, ChainWatchInterface};
|
7 |
| -use chain::keysinterface::{KeysInterface, SpendableOutputDescriptor}; |
| 7 | +use chain::keysinterface::{KeysInterface, SpendableOutputDescriptor, KeysManager}; |
8 | 8 | use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
|
9 | 9 | use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT};
|
10 | 10 | use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ManyChannelMonitor, ANTI_REORG_DELAY};
|
11 |
| -use ln::channel::{ACCEPTED_HTLC_SCRIPT_WEIGHT, OFFERED_HTLC_SCRIPT_WEIGHT}; |
| 11 | +use ln::channel::{ACCEPTED_HTLC_SCRIPT_WEIGHT, OFFERED_HTLC_SCRIPT_WEIGHT, Channel, ChannelError}; |
12 | 12 | use ln::onion_utils;
|
13 | 13 | use ln::router::{Route, RouteHop};
|
14 | 14 | use ln::msgs;
|
@@ -1727,7 +1727,15 @@ fn channel_monitor_network_test() {
|
1727 | 1727 | fn test_justice_tx() {
|
1728 | 1728 | // Test justice txn built on revoked HTLC-Success tx, against both sides
|
1729 | 1729 |
|
1730 |
| - let nodes = create_network(2, &[None, None]); |
| 1730 | + let mut alice_config = UserConfig::new(); |
| 1731 | + alice_config.channel_options.announced_channel = true; |
| 1732 | + alice_config.peer_channel_config_limits.force_announced_channel_preference = false; |
| 1733 | + alice_config.own_channel_config.our_to_self_delay = 6 * 24 * 5; |
| 1734 | + let mut bob_config = UserConfig::new(); |
| 1735 | + bob_config.channel_options.announced_channel = true; |
| 1736 | + bob_config.peer_channel_config_limits.force_announced_channel_preference = false; |
| 1737 | + bob_config.own_channel_config.our_to_self_delay = 6 * 24 * 3; |
| 1738 | + let nodes = create_network(2, &[Some(alice_config), Some(bob_config)]); |
1731 | 1739 | // Create some new channels:
|
1732 | 1740 | let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new());
|
1733 | 1741 |
|
@@ -5879,3 +5887,61 @@ fn test_upfront_shutdown_script() {
|
5879 | 5887 | _ => panic!("Unexpected event"),
|
5880 | 5888 | }
|
5881 | 5889 | }
|
| 5890 | + |
| 5891 | +#[test] |
| 5892 | +fn test_user_configurable_csv_delay() { |
| 5893 | + // We test our channel constructors yield errors when we pass them absurd csv delay |
| 5894 | + |
| 5895 | + let mut low_our_to_self_config = UserConfig::new(); |
| 5896 | + low_our_to_self_config.own_channel_config.our_to_self_delay = 6; |
| 5897 | + let mut high_their_to_self_config = UserConfig::new(); |
| 5898 | + high_their_to_self_config.peer_channel_config_limits.their_to_self_delay = 100; |
| 5899 | + let nodes = create_network(2, &[Some(high_their_to_self_config.clone()), None]); |
| 5900 | + |
| 5901 | + // We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in Channel::new_outbound() |
| 5902 | + let keys_manager: Arc<KeysInterface> = Arc::new(KeysManager::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()), 10, 20)); |
| 5903 | + if let Err(error) = Channel::new_outbound(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), 1000000, 1000000, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) { |
| 5904 | + match error { |
| 5905 | + APIError::APIMisuseError { err } => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); }, |
| 5906 | + _ => panic!("Unexpected event"), |
| 5907 | + } |
| 5908 | + } else { assert!(false) } |
| 5909 | + |
| 5910 | + // We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in Channel::new_from_req() |
| 5911 | + nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap(); |
| 5912 | + let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); |
| 5913 | + open_channel.to_self_delay = 200; |
| 5914 | + if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) { |
| 5915 | + match error { |
| 5916 | + ChannelError::Close(err) => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); }, |
| 5917 | + _ => panic!("Unexpected event"), |
| 5918 | + } |
| 5919 | + } else { assert!(false); } |
| 5920 | + |
| 5921 | + // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Chanel::accept_channel() |
| 5922 | + nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1000000, 1000000, 42).unwrap(); |
| 5923 | + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), LocalFeatures::new(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())).unwrap(); |
| 5924 | + let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); |
| 5925 | + accept_channel.to_self_delay = 200; |
| 5926 | + if let Err(error) = nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), LocalFeatures::new(), &accept_channel) { |
| 5927 | + if let Some(error) = error.action { |
| 5928 | + match error { |
| 5929 | + ErrorAction::SendErrorMessage { msg } => { |
| 5930 | + assert_eq!(msg.data,"They wanted our payments to be delayed by a needlessly long period"); |
| 5931 | + }, |
| 5932 | + _ => { assert!(false); } |
| 5933 | + } |
| 5934 | + } else { assert!(false); } |
| 5935 | + } else { assert!(false); } |
| 5936 | + |
| 5937 | + // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Channel::new_from_req() |
| 5938 | + nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap(); |
| 5939 | + let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); |
| 5940 | + open_channel.to_self_delay = 200; |
| 5941 | + if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &high_their_to_self_config) { |
| 5942 | + match error { |
| 5943 | + ChannelError::Close(err) => { assert_eq!(err, "They wanted our payments to be delayed by a needlessly long period"); }, |
| 5944 | + _ => panic!("Unexpected event"), |
| 5945 | + } |
| 5946 | + } else { assert!(false); } |
| 5947 | +} |
0 commit comments