]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add inbound htlc min/max to `ChannelDetails`
authorViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Tue, 22 Mar 2022 20:36:18 +0000 (21:36 +0100)
committerViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Tue, 19 Apr 2022 21:54:55 +0000 (23:54 +0200)
fuzz/src/router.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/routing/router.rs

index bff177b19091b47b6b7f2184e1e826240d63a838..4db6587b45626171b54095d7d746246a755d1f76 100644 (file)
@@ -227,6 +227,8 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                                is_usable: true, is_public: true,
                                                                balance_msat: 0,
                                                                outbound_capacity_msat: 0,
+                                                               inbound_htlc_minimum_msat: None,
+                                                               inbound_htlc_maximum_msat: None,
                                                        });
                                                }
                                                Some(&first_hops_vec[..])
index 9ccdf816ad398d764d599b62e45e0e1274391572..12fd6958348f07fed591be0eb79252ede1c30bb2 100644 (file)
@@ -4321,11 +4321,15 @@ impl<Signer: Sign> Channel<Signer> {
        }
 
        /// Allowed in any state (including after shutdown)
-       #[cfg(test)]
        pub fn get_holder_htlc_minimum_msat(&self) -> u64 {
                self.holder_htlc_minimum_msat
        }
 
+       /// Allowed in any state (including after shutdown), but will return none before TheirInitSent
+       pub fn get_holder_htlc_maximum_msat(&self) -> Option<u64> {
+               self.get_htlc_maximum_msat(self.holder_max_htlc_value_in_flight_msat)
+       }
+
        /// Allowed in any state (including after shutdown)
        pub fn get_announced_htlc_max_msat(&self) -> u64 {
                return cmp::min(
@@ -4343,6 +4347,16 @@ impl<Signer: Sign> Channel<Signer> {
                self.counterparty_htlc_minimum_msat
        }
 
+       fn get_htlc_maximum_msat(&self, party_max_htlc_value_in_flight_msat: u64) -> Option<u64> {
+               self.counterparty_selected_channel_reserve_satoshis.map(|counterparty_reserve| {
+                       let holder_reserve = self.holder_selected_channel_reserve_satoshis;
+                       cmp::min(
+                               (self.channel_value_satoshis - counterparty_reserve - holder_reserve) * 1000,
+                               party_max_htlc_value_in_flight_msat
+                       )
+               })
+       }
+
        pub fn get_value_satoshis(&self) -> u64 {
                self.channel_value_satoshis
        }
index 7323930f33093418e5f4453c78f54a6e95e54464..abb20845c6c38290476fc33c189b2ab20e4a972e 100644 (file)
@@ -1046,6 +1046,11 @@ pub struct ChannelDetails {
        pub is_usable: bool,
        /// True if this channel is (or will be) publicly-announced.
        pub is_public: bool,
+       /// The smallest value HTLC (in msat) we will accept, for this channel. This field
+       /// is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.107
+       pub inbound_htlc_minimum_msat: Option<u64>,
+       /// The largest value HTLC (in msat) we currently will accept, for this channel.
+       pub inbound_htlc_maximum_msat: Option<u64>,
 }
 
 impl ChannelDetails {
@@ -1689,6 +1694,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                        is_funding_locked: channel.is_usable(),
                                        is_usable: channel.is_live(),
                                        is_public: channel.should_announce(),
+                                       inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
+                                       inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat()
                                });
                        }
                }
@@ -5918,6 +5925,8 @@ impl_writeable_tlv_based!(ChannelDetails, {
        (28, is_funding_locked, required),
        (30, is_usable, required),
        (32, is_public, required),
+       (33, inbound_htlc_minimum_msat, option),
+       (35, inbound_htlc_maximum_msat, option),
 });
 
 impl_writeable_tlv_based!(PhantomRouteHints, {
index 655a53c2dfeab3007c4660f74f04a67022066db6..5afe052bb9a2ff10b1d2a59985fb248e91abdf1e 100644 (file)
@@ -1750,6 +1750,8 @@ mod tests {
                        force_close_spend_delay: None,
                        is_outbound: true, is_funding_locked: true,
                        is_usable: true, is_public: true,
+                       inbound_htlc_minimum_msat: None,
+                       inbound_htlc_maximum_msat: None,
                }
        }
 
@@ -5475,6 +5477,8 @@ mod benches {
                        is_funding_locked: true,
                        is_usable: true,
                        is_public: true,
+                       inbound_htlc_minimum_msat: None,
+                       inbound_htlc_maximum_msat: None,
                }
        }