1212//! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all
1313//! building, tracking, bumping and notifications functions.
1414
15- #[ cfg( anchors) ]
1615use bitcoin:: PackedLockTime ;
1716use bitcoin:: blockdata:: transaction:: Transaction ;
1817use bitcoin:: blockdata:: transaction:: OutPoint as BitcoinOutPoint ;
1918use bitcoin:: blockdata:: script:: Script ;
20- use bitcoin:: hashes:: Hash ;
21- #[ cfg( anchors) ]
22- use bitcoin:: hashes:: HashEngine ;
23- #[ cfg( anchors) ]
19+ use bitcoin:: hashes:: { Hash , HashEngine } ;
2420use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
2521use bitcoin:: hash_types:: { Txid , BlockHash } ;
2622use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
@@ -29,18 +25,12 @@ use bitcoin::secp256k1;
2925use crate :: sign:: { ChannelSigner , EntropySource , SignerProvider } ;
3026use crate :: ln:: msgs:: DecodeError ;
3127use crate :: ln:: PaymentPreimage ;
32- #[ cfg( anchors) ]
33- use crate :: ln:: chan_utils:: { self , HTLCOutputInCommitment } ;
34- use crate :: ln:: chan_utils:: { ChannelTransactionParameters , HolderCommitmentTransaction } ;
28+ use crate :: ln:: chan_utils:: { self , ChannelTransactionParameters , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
3529use crate :: chain:: ClaimId ;
36- #[ cfg( anchors) ]
37- use crate :: chain:: chaininterface:: ConfirmationTarget ;
38- use crate :: chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , LowerBoundedFeeEstimator } ;
30+ use crate :: chain:: chaininterface:: { ConfirmationTarget , FeeEstimator , BroadcasterInterface , LowerBoundedFeeEstimator } ;
3931use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER } ;
4032use crate :: sign:: WriteableEcdsaChannelSigner ;
41- #[ cfg( anchors) ]
42- use crate :: chain:: package:: PackageSolvingData ;
43- use crate :: chain:: package:: PackageTemplate ;
33+ use crate :: chain:: package:: { PackageSolvingData , PackageTemplate } ;
4434use crate :: util:: logger:: Logger ;
4535use crate :: util:: ser:: { Readable , ReadableArgs , MaybeReadable , UpgradableRequired , Writer , Writeable , VecWriter } ;
4636
@@ -50,7 +40,6 @@ use alloc::collections::BTreeMap;
5040use core:: cmp;
5141use core:: ops:: Deref ;
5242use core:: mem:: replace;
53- #[ cfg( anchors) ]
5443use core:: mem:: swap;
5544use crate :: ln:: features:: ChannelTypeFeatures ;
5645
@@ -181,7 +170,6 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
181170 }
182171}
183172
184- #[ cfg( anchors) ]
185173/// The claim commonly referred to as the pre-signed second-stage HTLC transaction.
186174pub ( crate ) struct ExternalHTLCClaim {
187175 pub ( crate ) commitment_txid : Txid ,
@@ -193,7 +181,6 @@ pub(crate) struct ExternalHTLCClaim {
193181
194182// Represents the different types of claims for which events are yielded externally to satisfy said
195183// claims.
196- #[ cfg( anchors) ]
197184pub ( crate ) enum ClaimEvent {
198185 /// Event yielded to signal that the commitment transaction fee must be bumped to claim any
199186 /// encumbered funds and proceed to HTLC resolution, if any HTLCs exist.
@@ -216,7 +203,6 @@ pub(crate) enum ClaimEvent {
216203pub ( crate ) enum OnchainClaim {
217204 /// A finalized transaction pending confirmation spending the output to claim.
218205 Tx ( Transaction ) ,
219- #[ cfg( anchors) ]
220206 /// An event yielded externally to signal additional inputs must be added to a transaction
221207 /// pending confirmation spending the output to claim.
222208 Event ( ClaimEvent ) ,
@@ -263,7 +249,6 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
263249 // - A channel has been force closed by broadcasting the holder's latest commitment transaction
264250 // - A block being connected/disconnected
265251 // - Learning the preimage for an HTLC we can claim onchain
266- #[ cfg( anchors) ]
267252 pending_claim_events : Vec < ( ClaimId , ClaimEvent ) > ,
268253
269254 // Used to link outpoints claimed in a connected block to a pending claim request. The keys
@@ -440,7 +425,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
440425 locktimed_packages,
441426 pending_claim_requests,
442427 onchain_events_awaiting_threshold_conf,
443- #[ cfg( anchors) ]
444428 pending_claim_events : Vec :: new ( ) ,
445429 secp_ctx,
446430 } )
@@ -461,7 +445,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
461445 claimable_outpoints : HashMap :: new ( ) ,
462446 locktimed_packages : BTreeMap :: new ( ) ,
463447 onchain_events_awaiting_threshold_conf : Vec :: new ( ) ,
464- #[ cfg( anchors) ]
465448 pending_claim_events : Vec :: new ( ) ,
466449 secp_ctx,
467450 }
@@ -475,7 +458,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
475458 self . holder_commitment . to_broadcaster_value_sat ( )
476459 }
477460
478- #[ cfg( anchors) ]
479461 pub ( crate ) fn get_and_clear_pending_claim_events ( & mut self ) -> Vec < ( ClaimId , ClaimEvent ) > {
480462 let mut events = Vec :: new ( ) ;
481463 swap ( & mut events, & mut self . pending_claim_events ) ;
@@ -516,7 +498,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
516498 log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
517499 broadcaster. broadcast_transactions ( & [ & tx] ) ;
518500 } ,
519- #[ cfg( anchors) ]
520501 OnchainClaim :: Event ( event) => {
521502 let log_start = if bumped_feerate { "Yielding fee-bumped" } else { "Replaying" } ;
522503 log_info ! ( logger, "{} onchain event to spend inputs {:?}" , log_start,
@@ -593,25 +574,22 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
593574 // didn't receive confirmation of it before, or not enough reorg-safe depth on top of it).
594575 let new_timer = cached_request. get_height_timer ( cur_height) ;
595576 if cached_request. is_malleable ( ) {
596- #[ cfg( anchors) ]
597- { // Attributes are not allowed on if expressions on our current MSRV of 1.41.
598- if cached_request. requires_external_funding ( ) {
599- let target_feerate_sat_per_1000_weight = cached_request. compute_package_feerate (
600- fee_estimator, ConfirmationTarget :: HighPriority , force_feerate_bump
601- ) ;
602- if let Some ( htlcs) = cached_request. construct_malleable_package_with_external_funding ( self ) {
603- return Some ( (
604- new_timer,
605- target_feerate_sat_per_1000_weight as u64 ,
606- OnchainClaim :: Event ( ClaimEvent :: BumpHTLC {
607- target_feerate_sat_per_1000_weight,
608- htlcs,
609- tx_lock_time : PackedLockTime ( cached_request. package_locktime ( cur_height) ) ,
610- } ) ,
611- ) ) ;
612- } else {
613- return None ;
614- }
577+ if cached_request. requires_external_funding ( ) {
578+ let target_feerate_sat_per_1000_weight = cached_request. compute_package_feerate (
579+ fee_estimator, ConfirmationTarget :: HighPriority , force_feerate_bump
580+ ) ;
581+ if let Some ( htlcs) = cached_request. construct_malleable_package_with_external_funding ( self ) {
582+ return Some ( (
583+ new_timer,
584+ target_feerate_sat_per_1000_weight as u64 ,
585+ OnchainClaim :: Event ( ClaimEvent :: BumpHTLC {
586+ target_feerate_sat_per_1000_weight,
587+ htlcs,
588+ tx_lock_time : PackedLockTime ( cached_request. package_locktime ( cur_height) ) ,
589+ } ) ,
590+ ) ) ;
591+ } else {
592+ return None ;
615593 }
616594 }
617595
@@ -633,9 +611,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
633611 // Untractable packages cannot have their fees bumped through Replace-By-Fee. Some
634612 // packages may support fee bumping through Child-Pays-For-Parent, indicated by those
635613 // which require external funding.
636- #[ cfg( not( anchors) ) ]
637- let inputs = cached_request. inputs ( ) ;
638- #[ cfg( anchors) ]
639614 let mut inputs = cached_request. inputs ( ) ;
640615 debug_assert_eq ! ( inputs. len( ) , 1 ) ;
641616 let tx = match cached_request. finalize_untractable_package ( self , logger) {
@@ -645,7 +620,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
645620 if !cached_request. requires_external_funding ( ) {
646621 return Some ( ( new_timer, 0 , OnchainClaim :: Tx ( tx) ) ) ;
647622 }
648- #[ cfg( anchors) ]
649623 return inputs. find_map ( |input| match input {
650624 // Commitment inputs with anchors support are the only untractable inputs supported
651625 // thus far that require external funding.
@@ -771,7 +745,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
771745 broadcaster. broadcast_transactions ( & [ & tx] ) ;
772746 ClaimId ( tx. txid ( ) . into_inner ( ) )
773747 } ,
774- #[ cfg( anchors) ]
775748 OnchainClaim :: Event ( claim_event) => {
776749 log_info ! ( logger, "Yielding onchain event to spend inputs {:?}" , req. outpoints( ) ) ;
777750 let claim_id = match claim_event {
@@ -886,14 +859,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
886859 // input(s) that already have a confirmed spend. If such spend is
887860 // reorged out of the chain, then we'll attempt to re-spend the
888861 // inputs once we see it.
889- #[ cfg( anchors) ] {
890- #[ cfg( debug_assertions) ] {
891- let existing = self . pending_claim_events . iter ( )
892- . filter ( |entry| entry. 0 == * claim_id) . count ( ) ;
893- assert ! ( existing == 0 || existing == 1 ) ;
894- }
895- self . pending_claim_events . retain ( |entry| entry. 0 != * claim_id) ;
862+ #[ cfg( debug_assertions) ] {
863+ let existing = self . pending_claim_events . iter ( )
864+ . filter ( |entry| entry. 0 == * claim_id) . count ( ) ;
865+ assert ! ( existing == 0 || existing == 1 ) ;
896866 }
867+ self . pending_claim_events . retain ( |entry| entry. 0 != * claim_id) ;
897868 }
898869 }
899870 break ; //No need to iterate further, either tx is our or their
@@ -930,14 +901,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
930901 outpoint, log_bytes!( claim_id. 0 ) ) ;
931902 self . claimable_outpoints . remove ( outpoint) ;
932903 }
933- #[ cfg( anchors) ] {
934- #[ cfg( debug_assertions) ] {
935- let num_existing = self . pending_claim_events . iter ( )
936- . filter ( |entry| entry. 0 == claim_id) . count ( ) ;
937- assert ! ( num_existing == 0 || num_existing == 1 ) ;
938- }
939- self . pending_claim_events . retain ( |( id, _) | * id != claim_id) ;
904+ #[ cfg( debug_assertions) ] {
905+ let num_existing = self . pending_claim_events . iter ( )
906+ . filter ( |entry| entry. 0 == claim_id) . count ( ) ;
907+ assert ! ( num_existing == 0 || num_existing == 1 ) ;
940908 }
909+ self . pending_claim_events . retain ( |( id, _) | * id != claim_id) ;
941910 }
942911 } ,
943912 OnchainEvent :: ContentiousOutpoint { package } => {
@@ -969,7 +938,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
969938 log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
970939 broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
971940 } ,
972- #[ cfg( anchors) ]
973941 OnchainClaim :: Event ( claim_event) => {
974942 log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
975943 #[ cfg( debug_assertions) ] {
@@ -1055,7 +1023,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
10551023 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
10561024 broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
10571025 } ,
1058- #[ cfg( anchors) ]
10591026 OnchainClaim :: Event ( claim_event) => {
10601027 log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
10611028 #[ cfg( debug_assertions) ] {
@@ -1185,7 +1152,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11851152 htlc_tx
11861153 }
11871154
1188- #[ cfg( anchors) ]
11891155 pub ( crate ) fn generate_external_htlc_claim (
11901156 & self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
11911157 ) -> Option < ExternalHTLCClaim > {
0 commit comments