Skip to content

Commit edee012

Browse files
author
Antoine Riard
committed
Add test_user_configurable_csv_delay
Extend test_justice_tx with user-set csv delay to test that we are able to claim revokeable outputs with different csv delay between both peers.
1 parent 1494c78 commit edee012

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

src/ln/functional_tests.rs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use chain::keysinterface;
99
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
1010
use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT};
1111
use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ManyChannelMonitor, ANTI_REORG_DELAY};
12-
use ln::channel::{ACCEPTED_HTLC_SCRIPT_WEIGHT, OFFERED_HTLC_SCRIPT_WEIGHT};
12+
use ln::channel::{ACCEPTED_HTLC_SCRIPT_WEIGHT, OFFERED_HTLC_SCRIPT_WEIGHT, Channel, ChannelError};
1313
use ln::onion_utils;
1414
use ln::router::{Route, RouteHop};
1515
use ln::msgs;
@@ -1727,7 +1727,15 @@ fn channel_monitor_network_test() {
17271727
fn test_justice_tx() {
17281728
// Test justice txn built on revoked HTLC-Success tx, against both sides
17291729

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)]);
17311739
// Create some new channels:
17321740
let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1, LocalFeatures::new(), LocalFeatures::new());
17331741

@@ -5878,3 +5886,61 @@ fn test_upfront_shutdown_script() {
58785886
_ => panic!("Unexpected event"),
58795887
}
58805888
}
5889+
5890+
#[test]
5891+
fn test_user_configurable_csv_delay() {
5892+
// We test our channel constructors yield errors when we pass them absurd csv delay
5893+
5894+
let mut low_our_to_self_config = UserConfig::new();
5895+
low_our_to_self_config.own_channel_config.our_to_self_delay = 6;
5896+
let mut high_their_to_self_config = UserConfig::new();
5897+
high_their_to_self_config.peer_channel_config_limits.their_to_self_delay = 100;
5898+
let nodes = create_network(2, &[Some(high_their_to_self_config.clone()), None]);
5899+
5900+
// We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in Channel::new_outbound()
5901+
let keys_manager: Arc<KeysInterface> = Arc::new(keysinterface::KeysManager::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new())));
5902+
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) {
5903+
match error {
5904+
APIError::APIMisuseError { err } => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); },
5905+
_ => panic!("Unexpected event"),
5906+
}
5907+
} else { assert!(false) }
5908+
5909+
// We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in Channel::new_from_req()
5910+
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap();
5911+
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
5912+
open_channel.to_self_delay = 200;
5913+
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) {
5914+
match error {
5915+
ChannelError::Close(err) => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); },
5916+
_ => panic!("Unexpected event"),
5917+
}
5918+
} else { assert!(false); }
5919+
5920+
// We test msg.to_self_delay <= config.their_to_self_delay is enforced in Chanel::accept_channel()
5921+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1000000, 1000000, 42).unwrap();
5922+
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();
5923+
let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
5924+
accept_channel.to_self_delay = 200;
5925+
if let Err(error) = nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), LocalFeatures::new(), &accept_channel) {
5926+
if let Some(error) = error.action {
5927+
match error {
5928+
ErrorAction::SendErrorMessage { msg } => {
5929+
assert_eq!(msg.data,"They wanted our payments to be delayed by a needlessly long period");
5930+
},
5931+
_ => { assert!(false); }
5932+
}
5933+
} else { assert!(false); }
5934+
} else { assert!(false); }
5935+
5936+
// We test msg.to_self_delay <= config.their_to_self_delay is enforced in Channel::new_from_req()
5937+
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap();
5938+
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
5939+
open_channel.to_self_delay = 200;
5940+
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) {
5941+
match error {
5942+
ChannelError::Close(err) => { assert_eq!(err, "They wanted our payments to be delayed by a needlessly long period"); },
5943+
_ => panic!("Unexpected event"),
5944+
}
5945+
} else { assert!(false); }
5946+
}

0 commit comments

Comments
 (0)