You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ln/functional_tests.rs
+305Lines changed: 305 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6602,3 +6602,308 @@ fn test_onion_failure() {
6602
6602
msg.onion_routing_packet = onion_packet;
6603
6603
}, ||{},true,Some(21),None);
6604
6604
}
6605
+
6606
+
#[test]
6607
+
fntest_update_add_htlc_bolt2(){
6608
+
use util::rng;
6609
+
use std::sync::atomic::Ordering;
6610
+
usesuper::channelmanager::HTLCSource;
6611
+
usesuper::channel::ChannelError;
6612
+
6613
+
let secp_ctx = Secp256k1::new();
6614
+
6615
+
// BOLT 2 Requirements for Sender
6616
+
// BOLT 2 Requirement: MUST NOT offer amount_msat it cannot pay for in the remote commitment transaction at the current feerate_per_kw (see "Updating Fees") while maintaining its channel reserve.
6617
+
//TODO: I don't believe this is explicitly enforced when sending an HTLC but as the Fee aspect of the BOLT specs is in flux leaving this as a TODO.
6618
+
6619
+
// BOLT2 Requirement: MUST offer amount_msat greater than 0.
6620
+
// BOLT2 Requirement: MUST NOT offer amount_msat below the receiving node's htlc_minimum_msat (same validation check catches both of these)
6621
+
letmut nodes = create_network(2);
6622
+
let chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,95000000);
6623
+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(),None,&[],100000,TEST_FINAL_CLTV).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys,&our_payment_hash);
6636
+
6637
+
let err = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().send_htlc(0, our_payment_hash,TEST_FINAL_CLTV,HTLCSource::OutboundRoute{
6638
+
route: route.clone(),
6639
+
session_priv: session_priv.clone(),
6640
+
first_hop_htlc_msat:100000,
6641
+
}, onion_packet);
6642
+
6643
+
ifletErr(ChannelError::Ignore(_)) = err {
6644
+
assert!(true);
6645
+
}else{
6646
+
assert!(false);
6647
+
}
6648
+
6649
+
//BOLT 2 Requirement: MUST set cltv_expiry less than 500000000.
6650
+
//TODO: This is not currently explicitly checked when sending an HTLC and exists as TODO in the channel::send_htlc(...) function
6651
+
//It is enforced when constructing a route.
6652
+
6653
+
// BOLT 2 Requirement: if result would be offering more than the remote's max_accepted_htlcs HTLCs, in the remote commitment transaction: MUST NOT add an HTLC.
6654
+
letmut nodes = create_network(2);
6655
+
let chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,0);
6656
+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(),None,&[],100000,TEST_FINAL_CLTV).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys,&our_payment_hash);
6669
+
6670
+
let max_accepted_htlcs = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().their_max_accepted_htlcs;
6671
+
6672
+
for _i in0..max_accepted_htlcs {
6673
+
let _ = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().send_htlc(10000, our_payment_hash,TEST_FINAL_CLTV,HTLCSource::OutboundRoute{
6674
+
route: route.clone(),
6675
+
session_priv: session_priv.clone(),
6676
+
first_hop_htlc_msat:0,
6677
+
}, onion_packet.clone());
6678
+
}
6679
+
6680
+
let err = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().send_htlc(10000, our_payment_hash,TEST_FINAL_CLTV,HTLCSource::OutboundRoute{
6681
+
route: route.clone(),
6682
+
session_priv: session_priv.clone(),
6683
+
first_hop_htlc_msat:0,
6684
+
}, onion_packet);
6685
+
6686
+
ifletErr(ChannelError::Ignore(_)) = err {
6687
+
assert!(true);
6688
+
}else{
6689
+
assert!(false);
6690
+
}
6691
+
//Clear any unhandled msg events.
6692
+
let _ = nodes[0].node.get_and_clear_pending_msg_events();
6693
+
let _ = nodes[1].node.get_and_clear_pending_msg_events();
6694
+
6695
+
// BOLT 2 Requirement: if the sum of total offered HTLCs would exceed the remote's max_htlc_value_in_flight_msat: MUST NOT add an HTLC.
6696
+
letmut nodes = create_network(2);
6697
+
let chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,0);
6698
+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(),None,&[],100000,TEST_FINAL_CLTV).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys,&our_payment_hash);
6711
+
6712
+
let err = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().send_htlc(10000001, our_payment_hash,TEST_FINAL_CLTV,HTLCSource::OutboundRoute{
6713
+
route: route.clone(),
6714
+
session_priv: session_priv.clone(),
6715
+
first_hop_htlc_msat:0,
6716
+
}, onion_packet);
6717
+
6718
+
ifletErr(ChannelError::Ignore(_)) = err {
6719
+
assert!(true);
6720
+
}else{
6721
+
assert!(false);
6722
+
}
6723
+
6724
+
// BOLT 2 Requirement: if the sum of total offered HTLCs would exceed the remote's max_htlc_value_in_flight_msat: MUST NOT add an HTLC.
6725
+
// BOLT 2 Requirement: MUST increase the value of id by 1 for each successive offer.
6726
+
letmut nodes = create_network(2);
6727
+
let chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,0);
6728
+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(),None,&[],100000,TEST_FINAL_CLTV).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys,&our_payment_hash);
6741
+
6742
+
for expected_id in0..2{
6743
+
let res = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().send_htlc(100000, our_payment_hash,TEST_FINAL_CLTV,HTLCSource::OutboundRoute{
6744
+
route: route.clone(),
6745
+
session_priv: session_priv.clone(),
6746
+
first_hop_htlc_msat:0,
6747
+
}, onion_packet.clone());
6748
+
6749
+
ifletOk(Some(msg)) = res {
6750
+
assert_eq!(msg.htlc_id, expected_id);
6751
+
}else{
6752
+
assert!(false);
6753
+
}
6754
+
}
6755
+
6756
+
// BOLT 2 Requirements for Receiver
6757
+
6758
+
//BOLT2 Requirement: receiving an amount_msat equal to 0, OR less than its own htlc_minimum_msat -> SHOULD fail the channel.
6759
+
letmut nodes = create_network(2);
6760
+
let chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,95000000);
6761
+
let htlc_minimum_msat:u64;
6762
+
{
6763
+
let chan_lock = nodes[0].node.channel_state.lock().unwrap();
6764
+
let channel = chan_lock.by_id.get(&chan.2).unwrap();
let _ = nodes[1].node.get_and_clear_pending_msg_events();
6782
+
6783
+
//BOLT2 Requirement: receiving an amount_msat that the sending node cannot afford at the current feerate_per_kw (while maintaining its channel reserve): SHOULD fail the channel
6784
+
letmut nodes = create_network(2);
6785
+
let _chan = create_announced_chan_between_nodes_with_value(&nodes,0,1,100000,95000000);
6786
+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(),None,&[],3999999,TEST_FINAL_CLTV).unwrap();
0 commit comments