mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
fix: use the update_add_htlc's cltv_expiry for comparison
As noted in BOLT 4, we should be using the update_add_htlc's cltv_expiry,
not the CLTV expiry set by the sender in the onion for this comparison.
See here: 4dcc377209/04-onion-routing.md (L334)
This commit is contained in:
parent
6cafba9f5b
commit
33715e87d8
1 changed files with 25 additions and 1 deletions
|
@ -2940,7 +2940,7 @@ where
|
||||||
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
|
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
|
||||||
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
|
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
|
||||||
let current_height: u32 = self.best_block.read().unwrap().height();
|
let current_height: u32 = self.best_block.read().unwrap().height();
|
||||||
if (outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
|
if cltv_expiry <= current_height + HTLC_FAIL_BACK_BUFFER + 1 {
|
||||||
let mut err_data = Vec::with_capacity(12);
|
let mut err_data = Vec::with_capacity(12);
|
||||||
err_data.extend_from_slice(&amt_msat.to_be_bytes());
|
err_data.extend_from_slice(&amt_msat.to_be_bytes());
|
||||||
err_data.extend_from_slice(¤t_height.to_be_bytes());
|
err_data.extend_from_slice(¤t_height.to_be_bytes());
|
||||||
|
@ -11096,6 +11096,30 @@ mod tests {
|
||||||
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
|
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_final_incorrect_cltv(){
|
||||||
|
let chanmon_cfg = create_chanmon_cfgs(1);
|
||||||
|
let node_cfg = create_node_cfgs(1, &chanmon_cfg);
|
||||||
|
let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]);
|
||||||
|
let node = create_network(1, &node_cfg, &node_chanmgr);
|
||||||
|
|
||||||
|
let result = node[0].node.construct_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive {
|
||||||
|
amt_msat: 100,
|
||||||
|
outgoing_cltv_value: 22,
|
||||||
|
payment_metadata: None,
|
||||||
|
keysend_preimage: None,
|
||||||
|
payment_data: Some(msgs::FinalOnionHopData {
|
||||||
|
payment_secret: PaymentSecret([0; 32]), total_msat: 100,
|
||||||
|
}),
|
||||||
|
custom_tlvs: Vec::new(),
|
||||||
|
}, [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None);
|
||||||
|
|
||||||
|
// Should not return an error as this condition:
|
||||||
|
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
|
||||||
|
// is not satisfied.
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inbound_anchors_manual_acceptance() {
|
fn test_inbound_anchors_manual_acceptance() {
|
||||||
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance
|
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance
|
||||||
|
|
Loading…
Add table
Reference in a new issue