]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Track funding amount in HolderFundingOutput
authorWilmer Paulino <wilmer.paulino@gmail.com>
Wed, 27 Jul 2022 21:58:43 +0000 (14:58 -0700)
committerWilmer Paulino <wilmer.paulino@gmail.com>
Tue, 18 Oct 2022 19:22:53 +0000 (12:22 -0700)
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.

lightning/src/chain/channelmonitor.rs
lightning/src/chain/package.rs

index d6c14c68cf17e082921ef62125186398e25d81c8..920cbd060fca84b57b165a27f3c47e8ff3fce17d 100644 (file)
@@ -2884,7 +2884,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
 
                let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
                if should_broadcast {
-                       let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone(), self.onchain_tx_handler.opt_anchors());
+                       let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone(), self.channel_value_satoshis, self.onchain_tx_handler.opt_anchors());
                        let commitment_package = PackageTemplate::build_package(self.funding_info.0.txid.clone(), self.funding_info.0.index as u32, PackageSolvingData::HolderFundingOutput(funding_outp), self.best_block.height(), false, self.best_block.height());
                        claimable_outpoints.push(commitment_package);
                        self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0));
index 3b6ebb4223ce9febe42516ad41c26a4bc38efcdc..20507c3f942278974905ab878e3a5f4c4c828f49 100644 (file)
@@ -286,14 +286,16 @@ impl_writeable_tlv_based!(HolderHTLCOutput, {
 #[derive(Clone, PartialEq, Eq)]
 pub(crate) struct HolderFundingOutput {
        funding_redeemscript: Script,
+       funding_amount: Option<u64>,
        opt_anchors: Option<()>,
 }
 
 
 impl HolderFundingOutput {
-       pub(crate) fn build(funding_redeemscript: Script, opt_anchors: bool) -> Self {
+       pub(crate) fn build(funding_redeemscript: Script, funding_amount: u64, opt_anchors: bool) -> Self {
                HolderFundingOutput {
                        funding_redeemscript,
+                       funding_amount: Some(funding_amount),
                        opt_anchors: if opt_anchors { Some(()) } else { None },
                }
        }
@@ -306,6 +308,7 @@ impl HolderFundingOutput {
 impl_writeable_tlv_based!(HolderFundingOutput, {
        (0, funding_redeemscript, required),
        (1, opt_anchors, option),
+       (3, funding_amount, option),
 });
 
 /// A wrapper encapsulating all in-protocol differing outputs types.
@@ -325,15 +328,18 @@ pub(crate) enum PackageSolvingData {
 impl PackageSolvingData {
        fn amount(&self) -> u64 {
                let amt = match self {
-                       PackageSolvingData::RevokedOutput(ref outp) => { outp.amount },
-                       PackageSolvingData::RevokedHTLCOutput(ref outp) => { outp.amount },
-                       PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => { outp.htlc.amount_msat / 1000 },
-                       PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => { outp.htlc.amount_msat / 1000 },
+                       PackageSolvingData::RevokedOutput(ref outp) => outp.amount,
+                       PackageSolvingData::RevokedHTLCOutput(ref outp) => outp.amount,
+                       PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
+                       PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
                        // Note: Currently, amounts of holder outputs spending witnesses aren't used
                        // as we can't malleate spending package to increase their feerate. This
                        // should change with the remaining anchor output patchset.
-                       PackageSolvingData::HolderHTLCOutput(..) => { unreachable!() },
-                       PackageSolvingData::HolderFundingOutput(..) => { unreachable!() },
+                       PackageSolvingData::HolderHTLCOutput(..) => unreachable!(),
+                       PackageSolvingData::HolderFundingOutput(ref outp) => {
+                               debug_assert!(outp.opt_anchors());
+                               outp.funding_amount.unwrap()
+                       }
                };
                amt
        }