Skip to content

Commit 7c25533

Browse files
f Fix CounterpartyForwardingInfo htlc min/max
1 parent 28c676c commit 7c25533

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,16 +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 {
5387+
let outbound_htlc_maximum_msat = match msg.contents.htlc_maximum_msat {
53885388
OptionalField::Present(htcl_max) => Some(htcl_max),
53895389
OptionalField::Absent => None
53905390
};
53915391
self.counterparty_forwarding_info = Some(CounterpartyForwardingInfo {
53925392
fee_base_msat: msg.contents.fee_base_msat,
53935393
fee_proportional_millionths: msg.contents.fee_proportional_millionths,
53945394
cltv_expiry_delta: msg.contents.cltv_expiry_delta,
5395-
htlc_minimum_msat: msg.contents.htlc_minimum_msat,
5396-
htlc_maximum_msat,
5395+
outbound_htlc_minimum_msat: msg.contents.htlc_minimum_msat,
5396+
outbound_htlc_maximum_msat,
53975397
});
53985398

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

5783-
let mut htlc_maximum_msat = None;
57845783
match &self.counterparty_forwarding_info {
57855784
Some(info) => {
57865785
1u8.write(writer)?;
57875786
info.fee_base_msat.write(writer)?;
57885787
info.fee_proportional_millionths.write(writer)?;
57895788
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;
57935789
},
57945790
None => 0u8.write(writer)?
57955791
}
@@ -5852,7 +5848,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
58525848
(17, self.announcement_sigs_state, required),
58535849
(19, self.latest_inbound_scid_alias, option),
58545850
(21, self.outbound_scid_alias, required),
5855-
(23, htlc_maximum_msat, option),
5851+
(23, self.counterparty_forwarding_info.as_ref().map(|info| info.outbound_htlc_maximum_msat).unwrap_or(None), option),
58565852
});
58575853

58585854
Ok(())
@@ -6051,28 +6047,16 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60516047
let _dummy: u32 = Readable::read(reader)?;
60526048
}
60536049

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,
6050+
// Read fields for `CounterpartyForwardingInfo`. As the `outbound_htlc_maximum_msat` is a
6051+
// TLV Optional variant, we construct the `CounterpartyForwardingInfo` struct after it ha
6052+
// been read.
6053+
let (has_forwarding_info, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta) = match <u8 as Readable>::read(reader)? {
6054+
0 => (false, 0, 0, 0),
60646055
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
6056+
let fee_base_msat: u32 = Readable::read(reader)?;
6057+
let fee_proportional_millionths: u32 = Readable::read(reader)?;
6058+
let cltv_expiry_delta: u16 = Readable::read(reader)?;
6059+
(true, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta)
60766060
},
60776061
_ => return Err(DecodeError::InvalidValue),
60786062
};
@@ -6126,6 +6110,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
61266110
let mut announcement_sigs_state = Some(AnnouncementSigsState::NotSent);
61276111
let mut latest_inbound_scid_alias = None;
61286112
let mut outbound_scid_alias = None;
6113+
let mut outbound_htlc_maximum_msat = None;
61296114

61306115
read_tlv_fields!(reader, {
61316116
(0, announcement_sigs, option),
@@ -6143,19 +6128,19 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
61436128
(17, announcement_sigs_state, option),
61446129
(19, latest_inbound_scid_alias, option),
61456130
(21, outbound_scid_alias, option),
6146-
(23, htlc_maximum_msat, option),
6131+
(23, outbound_htlc_maximum_msat, option),
61476132
});
61486133

61496134
// Construct the `CounterpartyForwardingInfo` after the TLV Optional variant for
6150-
// `htlc_maximum_msat` has been read.
6135+
// `outbound_htlc_maximum_msat` has been read.
61516136
let counterparty_forwarding_info = match has_forwarding_info {
61526137
false => None,
61536138
true => Some(CounterpartyForwardingInfo {
61546139
fee_base_msat,
61556140
fee_proportional_millionths,
61566141
cltv_expiry_delta,
6157-
htlc_minimum_msat: counterparty_htlc_minimum_msat,
6158-
htlc_maximum_msat
6142+
outbound_htlc_minimum_msat: counterparty_htlc_minimum_msat,
6143+
outbound_htlc_maximum_msat
61596144
})
61606145
};
61616146

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,9 @@ pub struct CounterpartyForwardingInfo {
11601160
/// `cltv_expiry_delta` for more details.
11611161
pub cltv_expiry_delta: u16,
11621162
/// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
1163-
pub htlc_minimum_msat: u64,
1163+
pub outbound_htlc_minimum_msat: u64,
11641164
/// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
1165-
pub htlc_maximum_msat: Option<u64>,
1165+
pub outbound_htlc_maximum_msat: Option<u64>,
11661166
}
11671167

11681168
/// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
@@ -6058,8 +6058,8 @@ impl_writeable_tlv_based!(CounterpartyForwardingInfo, {
60586058
(2, fee_base_msat, required),
60596059
(4, fee_proportional_millionths, required),
60606060
(6, cltv_expiry_delta, required),
6061-
(8, htlc_minimum_msat, required),
6062-
(10, htlc_maximum_msat, option),
6061+
(7, outbound_htlc_minimum_msat, required),
6062+
(8, outbound_htlc_maximum_msat, option),
60636063
});
60646064

60656065
impl_writeable_tlv_based!(ChannelCounterparty, {

0 commit comments

Comments
 (0)