Merge pull request #1292 from TheBlueMatt/2022-02-override-handshake-limits
[rust-lightning] / lightning / src / ln / channel.rs
index 26d9dfed0d162d5d7fb9853e68ae476d6083348b..e76656e75ce38e9ee9b65c513ebc8c916e7b4ac7 100644 (file)
@@ -2252,8 +2252,15 @@ impl<Signer: Sign> Channel<Signer> {
        /// This is the amount that would go to us if we close the channel, ignoring any on-chain fees.
        /// See also [`Channel::get_inbound_outbound_available_balance_msat`]
        pub fn get_balance_msat(&self) -> u64 {
-               self.value_to_self_msat
-                       - self.get_outbound_pending_htlc_stats(None).pending_htlcs_value_msat
+               // Include our local balance, plus any inbound HTLCs we know the preimage for, minus any
+               // HTLCs sent or which will be sent after commitment signed's are exchanged.
+               let mut balance_msat = self.value_to_self_msat;
+               for ref htlc in self.pending_inbound_htlcs.iter() {
+                       if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
+                               balance_msat += htlc.amount_msat;
+                       }
+               }
+               balance_msat - self.get_outbound_pending_htlc_stats(None).pending_htlcs_value_msat
        }
 
        pub fn get_holder_counterparty_selected_channel_reserve_satoshis(&self) -> (u64, Option<u64>) {
@@ -4738,9 +4745,6 @@ impl<Signer: Sign> Channel<Signer> {
        /// Will only fail if we're not in a state where channel_announcement may be sent (including
        /// closing).
        ///
-       /// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
-       /// https://github.com/lightningnetwork/lightning-rfc/issues/468
-       ///
        /// This will only return ChannelError::Ignore upon failure.
        fn get_channel_announcement(&self, node_id: PublicKey, chain_hash: BlockHash) -> Result<msgs::UnsignedChannelAnnouncement, ChannelError> {
                if !self.config.announced_channel {