Skip to content

Commit 6644ef1

Browse files
Add inbound htlc min/max to ChannelDetails
1 parent e0b9b74 commit 6644ef1

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

fuzz/src/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
227227
is_usable: true, is_public: true,
228228
balance_msat: 0,
229229
outbound_capacity_msat: 0,
230+
inbound_htlc_minimum_msat: None,
231+
inbound_htlc_maximum_msat: None,
230232
});
231233
}
232234
Some(&first_hops_vec[..])

lightning/src/ln/channel.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4321,11 +4321,15 @@ impl<Signer: Sign> Channel<Signer> {
43214321
}
43224322

43234323
/// Allowed in any state (including after shutdown)
4324-
#[cfg(test)]
43254324
pub fn get_holder_htlc_minimum_msat(&self) -> u64 {
43264325
self.holder_htlc_minimum_msat
43274326
}
43284327

4328+
/// Allowed in any state (including after shutdown), but will return none before TheirInitSent
4329+
pub fn get_holder_htlc_maximum_msat(&self) -> Option<u64> {
4330+
self.get_htlc_maximum_msat(self.holder_max_htlc_value_in_flight_msat)
4331+
}
4332+
43294333
/// Allowed in any state (including after shutdown)
43304334
pub fn get_announced_htlc_max_msat(&self) -> u64 {
43314335
return cmp::min(
@@ -4343,6 +4347,16 @@ impl<Signer: Sign> Channel<Signer> {
43434347
self.counterparty_htlc_minimum_msat
43444348
}
43454349

4350+
fn get_htlc_maximum_msat(&self, party_max_htlc_value_in_flight_msat: u64) -> Option<u64> {
4351+
self.counterparty_selected_channel_reserve_satoshis.map(|counterparty_reserve| {
4352+
let holder_reserve = self.holder_selected_channel_reserve_satoshis;
4353+
cmp::min(
4354+
(self.channel_value_satoshis - counterparty_reserve - holder_reserve) * 1000,
4355+
party_max_htlc_value_in_flight_msat
4356+
)
4357+
})
4358+
}
4359+
43464360
pub fn get_value_satoshis(&self) -> u64 {
43474361
self.channel_value_satoshis
43484362
}

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,11 @@ pub struct ChannelDetails {
10461046
pub is_usable: bool,
10471047
/// True if this channel is (or will be) publicly-announced.
10481048
pub is_public: bool,
1049+
/// The smallest value HTLC (in msat) we will accept, for this channel. This field
1050+
/// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
1051+
pub inbound_htlc_minimum_msat: Option<u64>,
1052+
/// The largest value HTLC (in msat) we currently will accept, for this channel.
1053+
pub inbound_htlc_maximum_msat: Option<u64>,
10491054
}
10501055

10511056
impl ChannelDetails {
@@ -1689,6 +1694,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
16891694
is_funding_locked: channel.is_usable(),
16901695
is_usable: channel.is_live(),
16911696
is_public: channel.should_announce(),
1697+
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
1698+
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat()
16921699
});
16931700
}
16941701
}
@@ -5918,6 +5925,8 @@ impl_writeable_tlv_based!(ChannelDetails, {
59185925
(28, is_funding_locked, required),
59195926
(30, is_usable, required),
59205927
(32, is_public, required),
5928+
(33, inbound_htlc_minimum_msat, option),
5929+
(35, inbound_htlc_maximum_msat, option),
59215930
});
59225931

59235932
impl_writeable_tlv_based!(PhantomRouteHints, {

lightning/src/routing/router.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,8 @@ mod tests {
17501750
force_close_spend_delay: None,
17511751
is_outbound: true, is_funding_locked: true,
17521752
is_usable: true, is_public: true,
1753+
inbound_htlc_minimum_msat: None,
1754+
inbound_htlc_maximum_msat: None,
17531755
}
17541756
}
17551757

@@ -5475,6 +5477,8 @@ mod benches {
54755477
is_funding_locked: true,
54765478
is_usable: true,
54775479
is_public: true,
5480+
inbound_htlc_minimum_msat: None,
5481+
inbound_htlc_maximum_msat: None,
54785482
}
54795483
}
54805484

0 commit comments

Comments
 (0)