Skip to content

Commit 8caa487

Browse files
Add htcl min/max to CounterpartyForwardingInfo
1 parent 78bbcc9 commit 8caa487

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,10 +5384,16 @@ impl<Signer: Sign> Channel<Signer> {
53845384
if msg.contents.htlc_minimum_msat >= self.channel_value_satoshis * 1000 {
53855385
return Err(ChannelError::Close("Minimum htlc value is greater than channel value".to_string()));
53865386
}
5387+
let htlc_maximum_msat = match msg.contents.htlc_maximum_msat {
5388+
OptionalField::Present(htcl_max) => Some(htcl_max),
5389+
OptionalField::Absent => None
5390+
};
53875391
self.counterparty_forwarding_info = Some(CounterpartyForwardingInfo {
53885392
fee_base_msat: msg.contents.fee_base_msat,
53895393
fee_proportional_millionths: msg.contents.fee_proportional_millionths,
5390-
cltv_expiry_delta: msg.contents.cltv_expiry_delta
5394+
cltv_expiry_delta: msg.contents.cltv_expiry_delta,
5395+
htlc_minimum_msat: msg.contents.htlc_minimum_msat,
5396+
htlc_maximum_msat,
53915397
});
53925398

53935399
Ok(())
@@ -5774,12 +5780,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
57745780
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
57755781
self.minimum_depth.unwrap_or(0).write(writer)?;
57765782

5783+
let mut htlc_maximum_msat = None;
57775784
match &self.counterparty_forwarding_info {
57785785
Some(info) => {
57795786
1u8.write(writer)?;
57805787
info.fee_base_msat.write(writer)?;
57815788
info.fee_proportional_millionths.write(writer)?;
57825789
info.cltv_expiry_delta.write(writer)?;
5790+
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5791+
info.htlc_maximum_msat.unwrap_or(0).write(writer)?;
5792+
htlc_maximum_msat = info.htlc_maximum_msat;
57835793
},
57845794
None => 0u8.write(writer)?
57855795
}
@@ -5842,6 +5852,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
58425852
(17, self.announcement_sigs_state, required),
58435853
(19, self.latest_inbound_scid_alias, option),
58445854
(21, self.outbound_scid_alias, required),
5855+
(23, htlc_maximum_msat, option),
58455856
});
58465857

58475858
Ok(())
@@ -6040,13 +6051,29 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60406051
let _dummy: u32 = Readable::read(reader)?;
60416052
}
60426053

6043-
let counterparty_forwarding_info = match <u8 as Readable>::read(reader)? {
6044-
0 => None,
6045-
1 => Some(CounterpartyForwardingInfo {
6046-
fee_base_msat: Readable::read(reader)?,
6047-
fee_proportional_millionths: Readable::read(reader)?,
6048-
cltv_expiry_delta: Readable::read(reader)?,
6049-
}),
6054+
// Read fields for `CounterpartyForwardingInfo`. As the `htlc_maximum_msat` may be
6055+
// updated after the TLV Optional variant has been read depending on if they're used,
6056+
// we construct the `CounterpartyForwardingInfo` struct after TLV Optional variants
6057+
// have been read.
6058+
let mut fee_base_msat: u32 = 0;
6059+
let mut fee_proportional_millionths: u32 = 0;
6060+
let mut cltv_expiry_delta: u16 = 0;
6061+
let mut htlc_maximum_msat = None;
6062+
let has_forwarding_info = match <u8 as Readable>::read(reader)? {
6063+
0 => false,
6064+
1 => {
6065+
fee_base_msat = Readable::read(reader)?;
6066+
fee_proportional_millionths = Readable::read(reader)?;
6067+
cltv_expiry_delta = Readable::read(reader)?;
6068+
if ver == 1 {
6069+
// Read the old serialization from version 0.0.98.
6070+
htlc_maximum_msat = Some(Readable::read(reader)?);
6071+
} else {
6072+
// Read the 8 bytes of backwards-compatibility data.
6073+
let _dummy: u64 = Readable::read(reader)?;
6074+
}
6075+
true
6076+
},
60506077
_ => return Err(DecodeError::InvalidValue),
60516078
};
60526079

@@ -6116,8 +6143,22 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
61166143
(17, announcement_sigs_state, option),
61176144
(19, latest_inbound_scid_alias, option),
61186145
(21, outbound_scid_alias, option),
6146+
(23, htlc_maximum_msat, option),
61196147
});
61206148

6149+
// Construct the `CounterpartyForwardingInfo` after the TLV Optional variant for
6150+
// `htlc_maximum_msat` has been read.
6151+
let counterparty_forwarding_info = match has_forwarding_info {
6152+
false => None,
6153+
true => Some(CounterpartyForwardingInfo {
6154+
fee_base_msat,
6155+
fee_proportional_millionths,
6156+
cltv_expiry_delta,
6157+
htlc_minimum_msat: counterparty_htlc_minimum_msat,
6158+
htlc_maximum_msat
6159+
})
6160+
};
6161+
61216162
if let Some(preimages) = preimages_opt {
61226163
let mut iter = preimages.into_iter();
61236164
for htlc in pending_outbound_htlcs.iter_mut() {

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,10 @@ pub struct CounterpartyForwardingInfo {
11591159
/// such that the outgoing HTLC is forwardable to this counterparty. See `msgs::ChannelUpdate`'s
11601160
/// `cltv_expiry_delta` for more details.
11611161
pub cltv_expiry_delta: u16,
1162+
/// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
1163+
pub htlc_minimum_msat: u64,
1164+
/// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
1165+
pub htlc_maximum_msat: Option<u64>,
11621166
}
11631167

11641168
/// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
@@ -6054,6 +6058,8 @@ impl_writeable_tlv_based!(CounterpartyForwardingInfo, {
60546058
(2, fee_base_msat, required),
60556059
(4, fee_proportional_millionths, required),
60566060
(6, cltv_expiry_delta, required),
6061+
(8, htlc_minimum_msat, required),
6062+
(10, htlc_maximum_msat, option),
60576063
});
60586064

60596065
impl_writeable_tlv_based!(ChannelCounterparty, {

0 commit comments

Comments
 (0)