Skip to content

Commit a5a1f7e

Browse files
author
Antoine Riard
committed
Add checks that amt_to_forward and outgoing_cltv_value are within
acceptable ranges
1 parent 0f24a67 commit a5a1f7e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ln/channelmanager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,15 @@ impl ChannelMessageHandler for ChannelManager {
16251625
hmac: next_hop_data.hmac.clone(),
16261626
};
16271627

1628-
//TODO: Check amt_to_forward and outgoing_cltv_value are within acceptable ranges!
1628+
let channel_state = self.channel_state.lock().unwrap();
1629+
let chan = channel_state.by_id.get(&msg.channel_id).unwrap();
1630+
let fee = chan.get_our_fee_base_msat(&*self.fee_estimator) + (next_hop_data.data.amt_to_forward * self.fee_proportional_millionths as u64 / 1000000) as u32;
1631+
if msg.amount_msat - fee as u64 >= next_hop_data.data.amt_to_forward {
1632+
return_err!("Prior hop has deviated from specified parameters", 0x1000 | 12, &[0;0]);
1633+
}
1634+
if msg.cltv_expiry - CLTV_EXPIRY_DELTA as u32 >= next_hop_data.data.outgoing_cltv_value {
1635+
return_err!("Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta", 0x1000 | 13, &[0;0]);
1636+
}
16291637

16301638
PendingForwardHTLCInfo {
16311639
onion_packet: Some(outgoing_packet),

0 commit comments

Comments
 (0)