@@ -162,6 +162,12 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
162
162
}
163
163
}
164
164
165
+ /// Represents the different ways an output can be claimed (i.e., spent to an address under our
166
+ /// control) onchain.
167
+ pub ( crate ) enum OnchainClaim {
168
+ /// A finalized transaction pending confirmation spending the output to claim.
169
+ Tx ( Transaction ) ,
170
+ }
165
171
166
172
/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
167
173
/// do RBF bumping if possible.
@@ -378,7 +384,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
378
384
/// (CSV or CLTV following cases). In case of high-fee spikes, claim tx may stuck in the mempool, so you need to bump its feerate quickly using Replace-By-Fee or Child-Pay-For-Parent.
379
385
/// Panics if there are signing errors, because signing operations in reaction to on-chain events
380
386
/// are not expected to fail, and if they do, we may lose funds.
381
- fn generate_claim_tx < F : Deref , L : Deref > ( & mut self , cur_height : u32 , cached_request : & PackageTemplate , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ) -> Option < ( Option < u32 > , u64 , Transaction ) >
387
+ fn generate_claim < F : Deref , L : Deref > ( & mut self , cur_height : u32 , cached_request : & PackageTemplate , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ) -> Option < ( Option < u32 > , u64 , OnchainClaim ) >
382
388
where F :: Target : FeeEstimator ,
383
389
L :: Target : Logger ,
384
390
{
@@ -396,14 +402,14 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
396
402
let transaction = cached_request. finalize_malleable_package ( self , output_value, self . destination_script . clone ( ) , logger) . unwrap ( ) ;
397
403
log_trace ! ( logger, "...with timer {} and feerate {}" , new_timer. unwrap( ) , new_feerate) ;
398
404
assert ! ( predicted_weight >= transaction. weight( ) ) ;
399
- return Some ( ( new_timer, new_feerate, transaction) )
405
+ return Some ( ( new_timer, new_feerate, OnchainClaim :: Tx ( transaction) ) )
400
406
}
401
407
} else {
402
408
// Note: Currently, amounts of holder outputs spending witnesses aren't used
403
409
// as we can't malleate spending package to increase their feerate. This
404
410
// should change with the remaining anchor output patchset.
405
411
if let Some ( transaction) = cached_request. finalize_untractable_package ( self , logger) {
406
- return Some ( ( None , 0 , transaction) ) ;
412
+ return Some ( ( None , 0 , OnchainClaim :: Tx ( transaction) ) ) ;
407
413
}
408
414
}
409
415
None
@@ -475,17 +481,21 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
475
481
// Generate claim transactions and track them to bump if necessary at
476
482
// height timer expiration (i.e in how many blocks we're going to take action).
477
483
for mut req in preprocessed_requests {
478
- if let Some ( ( new_timer, new_feerate, tx ) ) = self . generate_claim_tx ( cur_height, & req, & * fee_estimator, & * logger) {
484
+ if let Some ( ( new_timer, new_feerate, claim ) ) = self . generate_claim ( cur_height, & req, & * fee_estimator, & * logger) {
479
485
req. set_timer ( new_timer) ;
480
486
req. set_feerate ( new_feerate) ;
481
- let txid = tx. txid ( ) ;
487
+ let txid = match claim {
488
+ OnchainClaim :: Tx ( tx) => {
489
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
490
+ broadcaster. broadcast_transaction ( & tx) ;
491
+ tx. txid ( )
492
+ } ,
493
+ } ;
482
494
for k in req. outpoints ( ) {
483
495
log_info ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
484
496
self . claimable_outpoints . insert ( k. clone ( ) , ( txid, conf_height) ) ;
485
497
}
486
498
self . pending_claim_requests . insert ( txid, req) ;
487
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
488
- broadcaster. broadcast_transaction ( & tx) ;
489
499
}
490
500
}
491
501
@@ -603,9 +613,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
603
613
// Build, bump and rebroadcast tx accordingly
604
614
log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
605
615
for ( first_claim_txid, request) in bump_candidates. iter ( ) {
606
- if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . generate_claim_tx ( cur_height, & request, & * fee_estimator, & * logger) {
607
- log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
608
- broadcaster. broadcast_transaction ( & bump_tx) ;
616
+ if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( cur_height, & request, & * fee_estimator, & * logger) {
617
+ match bump_claim {
618
+ OnchainClaim :: Tx ( bump_tx) => {
619
+ log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
620
+ broadcaster. broadcast_transaction ( & bump_tx) ;
621
+ } ,
622
+ }
609
623
if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid) {
610
624
request. set_timer ( new_timer) ;
611
625
request. set_feerate ( new_feerate) ;
@@ -668,11 +682,15 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
668
682
}
669
683
}
670
684
for ( _, request) in bump_candidates. iter_mut ( ) {
671
- if let Some ( ( new_timer, new_feerate, bump_tx ) ) = self . generate_claim_tx ( height, & request, fee_estimator, & & * logger) {
685
+ if let Some ( ( new_timer, new_feerate, bump_claim ) ) = self . generate_claim ( height, & request, fee_estimator, & & * logger) {
672
686
request. set_timer ( new_timer) ;
673
687
request. set_feerate ( new_feerate) ;
674
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
675
- broadcaster. broadcast_transaction ( & bump_tx) ;
688
+ match bump_claim {
689
+ OnchainClaim :: Tx ( bump_tx) => {
690
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
691
+ broadcaster. broadcast_transaction ( & bump_tx) ;
692
+ } ,
693
+ }
676
694
}
677
695
}
678
696
for ( ancestor_claim_txid, request) in bump_candidates. drain ( ) {
0 commit comments