Skip to content

Commit 3325025

Browse files
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: https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
1 parent 989304e commit 3325025

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lightning/src/ln/channelmanager.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ where
29382938
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
29392939
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
29402940
let current_height: u32 = self.best_block.read().unwrap().height();
2941-
if (outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2941+
if (cltv_expiry as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
29422942
let mut err_data = Vec::with_capacity(12);
29432943
err_data.extend_from_slice(&amt_msat.to_be_bytes());
29442944
err_data.extend_from_slice(&current_height.to_be_bytes());
@@ -11054,6 +11054,26 @@ mod tests {
1105411054
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
1105511055
}
1105611056

11057+
#[test]
11058+
fn test_final_incorrect_cltv(){
11059+
let chanmon_cfg = create_chanmon_cfgs(1);
11060+
let node_cfg = create_node_cfgs(1, &chanmon_cfg);
11061+
let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]);
11062+
let node = create_network(1, &node_cfg, &node_chanmgr);
11063+
11064+
let result = node[0].node.construct_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive {
11065+
amt_msat: 100,
11066+
outgoing_cltv_value: 22,
11067+
payment_metadata: None,
11068+
keysend_preimage: None,
11069+
payment_data: Some(msgs::FinalOnionHopData {
11070+
payment_secret: PaymentSecret([0; 32]), total_msat: 100,
11071+
}),
11072+
custom_tlvs: Vec::new(),
11073+
}, [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None);
11074+
assert!(!result.is_err());
11075+
}
11076+
1105711077
#[test]
1105811078
fn test_inbound_anchors_manual_acceptance() {
1105911079
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance

0 commit comments

Comments
 (0)