@@ -2940,7 +2940,7 @@ where
2940
2940
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
2941
2941
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
2942
2942
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 {
2944
2944
let mut err_data = Vec::with_capacity(12);
2945
2945
err_data.extend_from_slice(&amt_msat.to_be_bytes());
2946
2946
err_data.extend_from_slice(¤t_height.to_be_bytes());
@@ -11096,6 +11096,30 @@ mod tests {
11096
11096
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
11097
11097
}
11098
11098
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
+
11099
11123
#[test]
11100
11124
fn test_inbound_anchors_manual_acceptance() {
11101
11125
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance
0 commit comments