Skip to content

Commit ded9080

Browse files
Merge pull request #2639 from vladimirfomene/fix-final-incorrect-cltv
Fix final incorrect cltv
2 parents 6cafba9 + 33715e8 commit ded9080

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lightning/src/ln/channelmanager.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,7 @@ where
29402940
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
29412941
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
29422942
let current_height: u32 = self.best_block.read().unwrap().height();
2943-
if (outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2943+
if cltv_expiry <= current_height + HTLC_FAIL_BACK_BUFFER + 1 {
29442944
let mut err_data = Vec::with_capacity(12);
29452945
err_data.extend_from_slice(&amt_msat.to_be_bytes());
29462946
err_data.extend_from_slice(&current_height.to_be_bytes());
@@ -11096,6 +11096,30 @@ mod tests {
1109611096
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
1109711097
}
1109811098

11099+
#[test]
11100+
fn test_final_incorrect_cltv(){
11101+
let chanmon_cfg = create_chanmon_cfgs(1);
11102+
let node_cfg = create_node_cfgs(1, &chanmon_cfg);
11103+
let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]);
11104+
let node = create_network(1, &node_cfg, &node_chanmgr);
11105+
11106+
let result = node[0].node.construct_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive {
11107+
amt_msat: 100,
11108+
outgoing_cltv_value: 22,
11109+
payment_metadata: None,
11110+
keysend_preimage: None,
11111+
payment_data: Some(msgs::FinalOnionHopData {
11112+
payment_secret: PaymentSecret([0; 32]), total_msat: 100,
11113+
}),
11114+
custom_tlvs: Vec::new(),
11115+
}, [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None);
11116+
11117+
// Should not return an error as this condition:
11118+
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
11119+
// is not satisfied.
11120+
assert!(result.is_ok());
11121+
}
11122+
1109911123
#[test]
1110011124
fn test_inbound_anchors_manual_acceptance() {
1110111125
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance

0 commit comments

Comments
 (0)