12
12
//! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all
13
13
//! building, tracking, bumping and notifications functions.
14
14
15
- #[ cfg( anchors) ]
16
15
use bitcoin:: PackedLockTime ;
17
16
use bitcoin:: blockdata:: transaction:: Transaction ;
18
17
use bitcoin:: blockdata:: transaction:: OutPoint as BitcoinOutPoint ;
19
18
use 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 } ;
24
20
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
25
21
use bitcoin:: hash_types:: { Txid , BlockHash } ;
26
22
use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
@@ -29,18 +25,12 @@ use bitcoin::secp256k1;
29
25
use crate :: sign:: { ChannelSigner , EntropySource , SignerProvider } ;
30
26
use crate :: ln:: msgs:: DecodeError ;
31
27
use 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 } ;
35
29
use 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 } ;
39
31
use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER } ;
40
32
use 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 } ;
44
34
use crate :: util:: logger:: Logger ;
45
35
use crate :: util:: ser:: { Readable , ReadableArgs , MaybeReadable , UpgradableRequired , Writer , Writeable , VecWriter } ;
46
36
@@ -50,7 +40,6 @@ use alloc::collections::BTreeMap;
50
40
use core:: cmp;
51
41
use core:: ops:: Deref ;
52
42
use core:: mem:: replace;
53
- #[ cfg( anchors) ]
54
43
use core:: mem:: swap;
55
44
use crate :: ln:: features:: ChannelTypeFeatures ;
56
45
@@ -181,7 +170,6 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
181
170
}
182
171
}
183
172
184
- #[ cfg( anchors) ]
185
173
/// The claim commonly referred to as the pre-signed second-stage HTLC transaction.
186
174
pub ( crate ) struct ExternalHTLCClaim {
187
175
pub ( crate ) commitment_txid : Txid ,
@@ -193,7 +181,6 @@ pub(crate) struct ExternalHTLCClaim {
193
181
194
182
// Represents the different types of claims for which events are yielded externally to satisfy said
195
183
// claims.
196
- #[ cfg( anchors) ]
197
184
pub ( crate ) enum ClaimEvent {
198
185
/// Event yielded to signal that the commitment transaction fee must be bumped to claim any
199
186
/// encumbered funds and proceed to HTLC resolution, if any HTLCs exist.
@@ -216,7 +203,6 @@ pub(crate) enum ClaimEvent {
216
203
pub ( crate ) enum OnchainClaim {
217
204
/// A finalized transaction pending confirmation spending the output to claim.
218
205
Tx ( Transaction ) ,
219
- #[ cfg( anchors) ]
220
206
/// An event yielded externally to signal additional inputs must be added to a transaction
221
207
/// pending confirmation spending the output to claim.
222
208
Event ( ClaimEvent ) ,
@@ -263,7 +249,6 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
263
249
// - A channel has been force closed by broadcasting the holder's latest commitment transaction
264
250
// - A block being connected/disconnected
265
251
// - Learning the preimage for an HTLC we can claim onchain
266
- #[ cfg( anchors) ]
267
252
pending_claim_events : Vec < ( ClaimId , ClaimEvent ) > ,
268
253
269
254
// 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
440
425
locktimed_packages,
441
426
pending_claim_requests,
442
427
onchain_events_awaiting_threshold_conf,
443
- #[ cfg( anchors) ]
444
428
pending_claim_events : Vec :: new ( ) ,
445
429
secp_ctx,
446
430
} )
@@ -461,7 +445,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
461
445
claimable_outpoints : HashMap :: new ( ) ,
462
446
locktimed_packages : BTreeMap :: new ( ) ,
463
447
onchain_events_awaiting_threshold_conf : Vec :: new ( ) ,
464
- #[ cfg( anchors) ]
465
448
pending_claim_events : Vec :: new ( ) ,
466
449
secp_ctx,
467
450
}
@@ -475,7 +458,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
475
458
self . holder_commitment . to_broadcaster_value_sat ( )
476
459
}
477
460
478
- #[ cfg( anchors) ]
479
461
pub ( crate ) fn get_and_clear_pending_claim_events ( & mut self ) -> Vec < ( ClaimId , ClaimEvent ) > {
480
462
let mut events = Vec :: new ( ) ;
481
463
swap ( & mut events, & mut self . pending_claim_events ) ;
@@ -516,7 +498,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
516
498
log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
517
499
broadcaster. broadcast_transactions ( & [ & tx] ) ;
518
500
} ,
519
- #[ cfg( anchors) ]
520
501
OnchainClaim :: Event ( event) => {
521
502
let log_start = if bumped_feerate { "Yielding fee-bumped" } else { "Replaying" } ;
522
503
log_info ! ( logger, "{} onchain event to spend inputs {:?}" , log_start,
@@ -593,25 +574,22 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
593
574
// didn't receive confirmation of it before, or not enough reorg-safe depth on top of it).
594
575
let new_timer = cached_request. get_height_timer ( cur_height) ;
595
576
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 ;
615
593
}
616
594
}
617
595
@@ -633,9 +611,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
633
611
// Untractable packages cannot have their fees bumped through Replace-By-Fee. Some
634
612
// packages may support fee bumping through Child-Pays-For-Parent, indicated by those
635
613
// which require external funding.
636
- #[ cfg( not( anchors) ) ]
637
- let inputs = cached_request. inputs ( ) ;
638
- #[ cfg( anchors) ]
639
614
let mut inputs = cached_request. inputs ( ) ;
640
615
debug_assert_eq ! ( inputs. len( ) , 1 ) ;
641
616
let tx = match cached_request. finalize_untractable_package ( self , logger) {
@@ -645,7 +620,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
645
620
if !cached_request. requires_external_funding ( ) {
646
621
return Some ( ( new_timer, 0 , OnchainClaim :: Tx ( tx) ) ) ;
647
622
}
648
- #[ cfg( anchors) ]
649
623
return inputs. find_map ( |input| match input {
650
624
// Commitment inputs with anchors support are the only untractable inputs supported
651
625
// thus far that require external funding.
@@ -771,7 +745,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
771
745
broadcaster. broadcast_transactions ( & [ & tx] ) ;
772
746
ClaimId ( tx. txid ( ) . into_inner ( ) )
773
747
} ,
774
- #[ cfg( anchors) ]
775
748
OnchainClaim :: Event ( claim_event) => {
776
749
log_info ! ( logger, "Yielding onchain event to spend inputs {:?}" , req. outpoints( ) ) ;
777
750
let claim_id = match claim_event {
@@ -886,14 +859,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
886
859
// input(s) that already have a confirmed spend. If such spend is
887
860
// reorged out of the chain, then we'll attempt to re-spend the
888
861
// 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 ) ;
896
866
}
867
+ self . pending_claim_events . retain ( |entry| entry. 0 != * claim_id) ;
897
868
}
898
869
}
899
870
break ; //No need to iterate further, either tx is our or their
@@ -930,14 +901,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
930
901
outpoint, log_bytes!( claim_id. 0 ) ) ;
931
902
self . claimable_outpoints . remove ( outpoint) ;
932
903
}
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 ) ;
940
908
}
909
+ self . pending_claim_events . retain ( |( id, _) | * id != claim_id) ;
941
910
}
942
911
} ,
943
912
OnchainEvent :: ContentiousOutpoint { package } => {
@@ -969,7 +938,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
969
938
log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
970
939
broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
971
940
} ,
972
- #[ cfg( anchors) ]
973
941
OnchainClaim :: Event ( claim_event) => {
974
942
log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
975
943
#[ cfg( debug_assertions) ] {
@@ -1055,7 +1023,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1055
1023
log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
1056
1024
broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
1057
1025
} ,
1058
- #[ cfg( anchors) ]
1059
1026
OnchainClaim :: Event ( claim_event) => {
1060
1027
log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
1061
1028
#[ cfg( debug_assertions) ] {
@@ -1185,7 +1152,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1185
1152
htlc_tx
1186
1153
}
1187
1154
1188
- #[ cfg( anchors) ]
1189
1155
pub ( crate ) fn generate_external_htlc_claim (
1190
1156
& self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1191
1157
) -> Option < ExternalHTLCClaim > {
0 commit comments