Merge pull request #2089 from wpaulino/bump-transaction-event-handler
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 19 Jun 2023 22:45:54 +0000 (22:45 +0000)
committerGitHub <noreply@github.com>
Mon, 19 Jun 2023 22:45:54 +0000 (22:45 +0000)
Add BumpTransaction event handler

1  2 
lightning/src/chain/channelmonitor.rs
lightning/src/events/mod.rs
lightning/src/util/ser.rs

index d3052b5fed4087f6de9ccd9dd7fc3047106fbf60,f0a2e80def635ea52589e99fa56b789b118754b7..1a9afb7cca75d55f4dc2d37de30c43b5e59f4ff1
@@@ -651,40 -651,6 +651,40 @@@ pub enum Balance 
        },
  }
  
 +impl Balance {
 +      /// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
 +      /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
 +      /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
 +      /// [`Balance::MaybePreimageClaimableHTLC`].
 +      ///
 +      /// On-chain fees required to claim the balance are not included in this amount.
 +      pub fn claimable_amount_satoshis(&self) -> u64 {
 +              match self {
 +                      Balance::ClaimableOnChannelClose {
 +                              claimable_amount_satoshis,
 +                      } => *claimable_amount_satoshis,
 +                      Balance::ClaimableAwaitingConfirmations {
 +                              claimable_amount_satoshis,
 +                              ..
 +                      } => *claimable_amount_satoshis,
 +                      Balance::ContentiousClaimable {
 +                              claimable_amount_satoshis,
 +                              ..
 +                      } => *claimable_amount_satoshis,
 +                      Balance::MaybeTimeoutClaimableHTLC {
 +                              ..
 +                      } => 0,
 +                      Balance::MaybePreimageClaimableHTLC {
 +                              ..
 +                      } => 0,
 +                      Balance::CounterpartyRevokedOutputClaimable {
 +                              claimable_amount_satoshis,
 +                              ..
 +                      } => *claimable_amount_satoshis,
 +              }
 +      }
 +}
 +
  /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
  #[derive(PartialEq, Eq)]
  struct IrrevocablyResolvedHTLC {
@@@ -2539,7 -2505,7 +2539,7 @@@ impl<Signer: WriteableEcdsaChannelSigne
                let mut ret = Vec::new();
                mem::swap(&mut ret, &mut self.pending_events);
                #[cfg(anchors)]
-               for claim_event in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
+               for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
                        match claim_event {
                                ClaimEvent::BumpCommitment {
                                        package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx,
                                        let commitment_tx_fee_satoshis = self.channel_value_satoshis -
                                                commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value);
                                        ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose {
+                                               claim_id,
                                                package_target_feerate_sat_per_1000_weight,
                                                commitment_tx,
                                                commitment_tx_fee_satoshis,
                                                });
                                        }
                                        ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
+                                               claim_id,
                                                target_feerate_sat_per_1000_weight,
                                                htlc_descriptors,
                                                tx_lock_time,
index ff51bf7d3baa08d80afe4063829d1f568feb2750,88b3239b7ef8fed29e3134f9d0216de7495c0440..fa4c86cd0ddea84b6970536455737517756edf52
@@@ -33,8 -33,6 +33,6 @@@ use crate::util::string::UntrustedStrin
  use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
  
  use bitcoin::{PackedLockTime, Transaction, OutPoint};
- #[cfg(anchors)]
- use bitcoin::{Txid, TxIn, TxOut, Witness};
  use bitcoin::blockdata::script::Script;
  use bitcoin::hashes::Hash;
  use bitcoin::hashes::sha256::Hash as Sha256;
@@@ -855,7 -853,7 +853,7 @@@ impl Writeable for Event 
                                        (3, via_channel_id, option),
                                        (4, amount_msat, required),
                                        (5, via_user_channel_id, option),
 -                                      (6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
 +                                      // Type 6 was `user_payment_id` on 0.0.103 and earlier
                                        (7, claim_deadline, option),
                                        (8, payment_preimage, option),
                                        (9, onion_fields, option),
@@@ -1059,7 -1057,7 +1057,7 @@@ impl MaybeReadable for Event 
                                        let mut payment_secret = None;
                                        let mut amount_msat = 0;
                                        let mut receiver_node_id = None;
 -                                      let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
 +                                      let mut _user_payment_id = None::<u64>; // Used in 0.0.103 and earlier, no longer written in 0.0.116+.
                                        let mut via_channel_id = None;
                                        let mut claim_deadline = None;
                                        let mut via_user_channel_id = None;
index fb0d0ad8e44e9eb40d203c50b4cf2efaa8af88a3,7e69f72b0eadace9f2896b59f57de7747ce4b74d..6d66d353ff568f8958ac72cd383ef951e568822f
@@@ -37,13 -37,13 +37,14 @@@ use bitcoin::hashes::sha256d::Hash as S
  use bitcoin::hash_types::{Txid, BlockHash};
  use core::marker::Sized;
  use core::time::Duration;
+ use crate::chain::ClaimId;
  use crate::ln::msgs::DecodeError;
  #[cfg(taproot)]
  use crate::ln::msgs::PartialSignatureWithNonce;
  use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
  
  use crate::util::byte_utils::{be48_to_array, slice_to_be48};
 +use crate::util::string::UntrustedString;
  
  /// serialization buffer size
  pub const MAX_BUF_SIZE: usize = 64 * 1024;
@@@ -630,21 -630,6 +631,21 @@@ impl<'a> From<&'a String> for WithoutLe
        fn from(s: &'a String) -> Self { Self(s) }
  }
  
 +
 +impl Writeable for WithoutLength<&UntrustedString> {
 +      #[inline]
 +      fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
 +              WithoutLength(&self.0.0).write(w)
 +      }
 +}
 +impl Readable for WithoutLength<UntrustedString> {
 +      #[inline]
 +      fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
 +              let s: WithoutLength<String> = Readable::read(r)?;
 +              Ok(Self(UntrustedString(s.0)))
 +      }
 +}
 +
  impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
        #[inline]
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@@ -1409,6 -1394,18 +1410,18 @@@ impl Readable for TransactionU16LenLimi
        }
  }
  
+ impl Writeable for ClaimId {
+       fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+               self.0.write(writer)
+       }
+ }
+ impl Readable for ClaimId {
+       fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+               Ok(Self(Readable::read(reader)?))
+       }
+ }
  #[cfg(test)]
  mod tests {
        use core::convert::TryFrom;