@@ -162,6 +162,12 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
162162 }
163163}
164164
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+ }
165171
166172/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
167173/// do RBF bumping if possible.
@@ -378,7 +384,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
378384 /// (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.
379385 /// Panics if there are signing errors, because signing operations in reaction to on-chain events
380386 /// 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 ) >
382388 where F :: Target : FeeEstimator ,
383389 L :: Target : Logger ,
384390 {
@@ -396,14 +402,14 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
396402 let transaction = cached_request. finalize_malleable_package ( self , output_value, self . destination_script . clone ( ) , logger) . unwrap ( ) ;
397403 log_trace ! ( logger, "...with timer {} and feerate {}" , new_timer. unwrap( ) , new_feerate) ;
398404 assert ! ( predicted_weight >= transaction. weight( ) ) ;
399- return Some ( ( new_timer, new_feerate, transaction) )
405+ return Some ( ( new_timer, new_feerate, OnchainClaim :: Tx ( transaction) ) )
400406 }
401407 } else {
402408 // Note: Currently, amounts of holder outputs spending witnesses aren't used
403409 // as we can't malleate spending package to increase their feerate. This
404410 // should change with the remaining anchor output patchset.
405411 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) ) ) ;
407413 }
408414 }
409415 None
@@ -475,17 +481,21 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
475481 // Generate claim transactions and track them to bump if necessary at
476482 // height timer expiration (i.e in how many blocks we're going to take action).
477483 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) {
479485 req. set_timer ( new_timer) ;
480486 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+ } ;
482494 for k in req. outpoints ( ) {
483495 log_info ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
484496 self . claimable_outpoints . insert ( k. clone ( ) , ( txid, conf_height) ) ;
485497 }
486498 self . pending_claim_requests . insert ( txid, req) ;
487- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
488- broadcaster. broadcast_transaction ( & tx) ;
489499 }
490500 }
491501
@@ -603,9 +613,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
603613 // Build, bump and rebroadcast tx accordingly
604614 log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
605615 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+ }
609623 if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid) {
610624 request. set_timer ( new_timer) ;
611625 request. set_feerate ( new_feerate) ;
@@ -668,11 +682,15 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
668682 }
669683 }
670684 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) {
672686 request. set_timer ( new_timer) ;
673687 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+ }
676694 }
677695 }
678696 for ( ancestor_claim_txid, request) in bump_candidates. drain ( ) {
0 commit comments