@@ -22,6 +22,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
22
22
use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
23
23
use bitcoin:: secp256k1;
24
24
25
+ use crate :: chain:: chaininterface:: compute_feerate_sat_per_1000_weight;
25
26
use crate :: sign:: { ChannelSigner , EntropySource , SignerProvider } ;
26
27
use crate :: ln:: msgs:: DecodeError ;
27
28
use crate :: ln:: PaymentPreimage ;
@@ -623,19 +624,31 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
623
624
return inputs. find_map ( |input| match input {
624
625
// Commitment inputs with anchors support are the only untractable inputs supported
625
626
// thus far that require external funding.
626
- PackageSolvingData :: HolderFundingOutput ( .. ) => {
627
+ PackageSolvingData :: HolderFundingOutput ( output ) => {
627
628
debug_assert_eq ! ( tx. txid( ) , self . holder_commitment. trust( ) . txid( ) ,
628
629
"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
+
629
645
// We'll locate an anchor output we can spend within the commitment transaction.
630
646
let funding_pubkey = & self . channel_transaction_parameters . holder_pubkeys . funding_pubkey ;
631
647
match chan_utils:: get_anchor_output ( & tx, funding_pubkey) {
632
648
// An anchor output was found, so we should yield a funding event externally.
633
649
Some ( ( idx, _) ) => {
634
650
// TODO: Use a lower confirmation target when both our and the
635
651
// 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) ;
639
652
Some ( (
640
653
new_timer,
641
654
package_target_feerate_sat_per_1000_weight as u64 ,
@@ -739,6 +752,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
739
752
) {
740
753
req. set_timer ( new_timer) ;
741
754
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`.
742
758
let claim_id = match claim {
743
759
OnchainClaim :: Tx ( tx) => {
744
760
log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
0 commit comments