@@ -22,6 +22,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
2222use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
2323use bitcoin:: secp256k1;
2424
25+ use crate :: chain:: chaininterface:: compute_feerate_sat_per_1000_weight;
2526use crate :: sign:: { ChannelSigner , EntropySource , SignerProvider } ;
2627use crate :: ln:: msgs:: DecodeError ;
2728use crate :: ln:: PaymentPreimage ;
@@ -623,19 +624,31 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
623624 return inputs. find_map ( |input| match input {
624625 // Commitment inputs with anchors support are the only untractable inputs supported
625626 // thus far that require external funding.
626- PackageSolvingData :: HolderFundingOutput ( .. ) => {
627+ PackageSolvingData :: HolderFundingOutput ( output ) => {
627628 debug_assert_eq ! ( tx. txid( ) , self . holder_commitment. trust( ) . txid( ) ,
628629 "Holder commitment transaction mismatch" ) ;
630+
631+ let conf_target = ConfirmationTarget :: HighPriority ;
632+ let package_target_feerate_sat_per_1000_weight = cached_request
633+ . compute_package_feerate ( fee_estimator, conf_target, force_feerate_bump) ;
634+ if let Some ( input_amount_sat) = output. funding_amount {
635+ let fee_sat = input_amount_sat - tx. output . iter ( ) . map ( |output| output. value ) . sum :: < u64 > ( ) ;
636+ if compute_feerate_sat_per_1000_weight ( fee_sat, tx. weight ( ) as u64 ) >=
637+ package_target_feerate_sat_per_1000_weight
638+ {
639+ log_debug ! ( logger, "Commitment transaction {} already meets required feerate {} sat/kW" ,
640+ tx. txid( ) , package_target_feerate_sat_per_1000_weight) ;
641+ return Some ( ( new_timer, 0 , OnchainClaim :: Tx ( tx. clone ( ) ) ) ) ;
642+ }
643+ }
644+
629645 // We'll locate an anchor output we can spend within the commitment transaction.
630646 let funding_pubkey = & self . channel_transaction_parameters . holder_pubkeys . funding_pubkey ;
631647 match chan_utils:: get_anchor_output ( & tx, funding_pubkey) {
632648 // An anchor output was found, so we should yield a funding event externally.
633649 Some ( ( idx, _) ) => {
634650 // TODO: Use a lower confirmation target when both our and the
635651 // counterparty's latest commitment don't have any HTLCs present.
636- let conf_target = ConfirmationTarget :: HighPriority ;
637- let package_target_feerate_sat_per_1000_weight = cached_request
638- . compute_package_feerate ( fee_estimator, conf_target, force_feerate_bump) ;
639652 Some ( (
640653 new_timer,
641654 package_target_feerate_sat_per_1000_weight as u64 ,
@@ -739,6 +752,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
739752 ) {
740753 req. set_timer ( new_timer) ;
741754 req. set_feerate ( new_feerate) ;
755+ // Once a pending claim has an id assigned, it remains fixed until the claim is
756+ // satisfied, regardless of whether the claim switches between different variants of
757+ // `OnchainClaim`.
742758 let claim_id = match claim {
743759 OnchainClaim :: Tx ( tx) => {
744760 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
0 commit comments