Skip to content

Commit f6c580b

Browse files
Add htcl min/max to CounterpartyForwardingInfo
1 parent a62179c commit f6c580b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 2 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 outbound_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+
outbound_htlc_minimum_msat: Some(msg.contents.htlc_minimum_msat),
5396+
outbound_htlc_maximum_msat,
53915397
});
53925398

53935399
Ok(())
@@ -5842,6 +5848,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
58425848
(17, self.announcement_sigs_state, required),
58435849
(19, self.latest_inbound_scid_alias, option),
58445850
(21, self.outbound_scid_alias, required),
5851+
(23, self.counterparty_forwarding_info.as_ref().map(|info| info.outbound_htlc_maximum_msat).unwrap_or(None), option),
58455852
});
58465853

58475854
Ok(())
@@ -6040,12 +6047,14 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60406047
let _dummy: u32 = Readable::read(reader)?;
60416048
}
60426049

6043-
let counterparty_forwarding_info = match <u8 as Readable>::read(reader)? {
6050+
let mut counterparty_forwarding_info = match <u8 as Readable>::read(reader)? {
60446051
0 => None,
60456052
1 => Some(CounterpartyForwardingInfo {
60466053
fee_base_msat: Readable::read(reader)?,
60476054
fee_proportional_millionths: Readable::read(reader)?,
60486055
cltv_expiry_delta: Readable::read(reader)?,
6056+
outbound_htlc_minimum_msat: Some(counterparty_htlc_minimum_msat),
6057+
outbound_htlc_maximum_msat: None,
60496058
}),
60506059
_ => return Err(DecodeError::InvalidValue),
60516060
};
@@ -6099,6 +6108,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60996108
let mut announcement_sigs_state = Some(AnnouncementSigsState::NotSent);
61006109
let mut latest_inbound_scid_alias = None;
61016110
let mut outbound_scid_alias = None;
6111+
let mut outbound_htlc_maximum_msat = None;
61026112

61036113
read_tlv_fields!(reader, {
61046114
(0, announcement_sigs, option),
@@ -6116,8 +6126,14 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
61166126
(17, announcement_sigs_state, option),
61176127
(19, latest_inbound_scid_alias, option),
61186128
(21, outbound_scid_alias, option),
6129+
(23, outbound_htlc_maximum_msat, option),
61196130
});
61206131

6132+
if outbound_htlc_maximum_msat.is_some() && counterparty_forwarding_info.is_some() {
6133+
let cf_info = counterparty_forwarding_info.as_mut().unwrap();
6134+
cf_info.outbound_htlc_maximum_msat = outbound_htlc_maximum_msat;
6135+
}
6136+
61216137
if let Some(preimages) = preimages_opt {
61226138
let mut iter = preimages.into_iter();
61236139
for htlc in pending_outbound_htlcs.iter_mut() {

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,11 @@ 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. This field
1163+
/// is only None for `CounterpartyForwardingInfo` objects serialized prior to LDK 0.0.107
1164+
pub outbound_htlc_minimum_msat: Option<u64>,
1165+
/// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
1166+
pub outbound_htlc_maximum_msat: Option<u64>,
11621167
}
11631168

11641169
/// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
@@ -6055,6 +6060,8 @@ impl_writeable_tlv_based!(CounterpartyForwardingInfo, {
60556060
(2, fee_base_msat, required),
60566061
(4, fee_proportional_millionths, required),
60576062
(6, cltv_expiry_delta, required),
6063+
(7, outbound_htlc_minimum_msat, option),
6064+
(9, outbound_htlc_maximum_msat, option),
60586065
});
60596066

60606067
impl_writeable_tlv_based!(ChannelCounterparty, {

0 commit comments

Comments
 (0)