@@ -162,6 +162,9 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
162
162
}
163
163
}
164
164
165
+ pub ( crate ) enum OnchainClaim {
166
+ Tx ( Transaction ) ,
167
+ }
165
168
166
169
/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
167
170
/// do RBF bumping if possible.
@@ -378,7 +381,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
378
381
/// (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
382
/// Panics if there are signing errors, because signing operations in reaction to on-chain events
380
383
/// 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 ) >
384
+ 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
385
where F :: Target : FeeEstimator ,
383
386
L :: Target : Logger ,
384
387
{
@@ -396,14 +399,14 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
396
399
let transaction = cached_request. finalize_malleable_package ( self , output_value, self . destination_script . clone ( ) , logger) . unwrap ( ) ;
397
400
log_trace ! ( logger, "...with timer {} and feerate {}" , new_timer. unwrap( ) , new_feerate) ;
398
401
assert ! ( predicted_weight >= transaction. weight( ) ) ;
399
- return Some ( ( new_timer, new_feerate, transaction) )
402
+ return Some ( ( new_timer, new_feerate, OnchainClaim :: Tx ( transaction) ) )
400
403
}
401
404
} else {
402
405
// Note: Currently, amounts of holder outputs spending witnesses aren't used
403
406
// as we can't malleate spending package to increase their feerate. This
404
407
// should change with the remaining anchor output patchset.
405
408
if let Some ( transaction) = cached_request. finalize_untractable_package ( self , logger) {
406
- return Some ( ( None , 0 , transaction) ) ;
409
+ return Some ( ( None , 0 , OnchainClaim :: Tx ( transaction) ) ) ;
407
410
}
408
411
}
409
412
None
@@ -475,17 +478,21 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
475
478
// Generate claim transactions and track them to bump if necessary at
476
479
// height timer expiration (i.e in how many blocks we're going to take action).
477
480
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) {
481
+ if let Some ( ( new_timer, new_feerate, claim ) ) = self . generate_claim ( cur_height, & req, & * fee_estimator, & * logger) {
479
482
req. set_timer ( new_timer) ;
480
483
req. set_feerate ( new_feerate) ;
481
- let txid = tx. txid ( ) ;
482
- for k in req. outpoints ( ) {
483
- log_info ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
484
- self . claimable_outpoints . insert ( k. clone ( ) , ( txid, conf_height) ) ;
484
+ match claim {
485
+ OnchainClaim :: Tx ( tx) => {
486
+ let txid = tx. txid ( ) ;
487
+ for k in req. outpoints ( ) {
488
+ log_info ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
489
+ self . claimable_outpoints . insert ( k. clone ( ) , ( txid, conf_height) ) ;
490
+ }
491
+ self . pending_claim_requests . insert ( txid, req) ;
492
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
493
+ broadcaster. broadcast_transaction ( & tx) ;
494
+ } ,
485
495
}
486
- self . pending_claim_requests . insert ( txid, req) ;
487
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
488
- broadcaster. broadcast_transaction ( & tx) ;
489
496
}
490
497
}
491
498
@@ -603,9 +610,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
603
610
// Build, bump and rebroadcast tx accordingly
604
611
log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
605
612
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) ;
613
+ if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( cur_height, & request, & * fee_estimator, & * logger) {
614
+ match bump_claim {
615
+ OnchainClaim :: Tx ( bump_tx) => {
616
+ log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
617
+ broadcaster. broadcast_transaction ( & bump_tx) ;
618
+ } ,
619
+ }
609
620
if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid) {
610
621
request. set_timer ( new_timer) ;
611
622
request. set_feerate ( new_feerate) ;
@@ -668,11 +679,15 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
668
679
}
669
680
}
670
681
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) {
682
+ if let Some ( ( new_timer, new_feerate, bump_claim ) ) = self . generate_claim ( height, & request, fee_estimator, & & * logger) {
672
683
request. set_timer ( new_timer) ;
673
684
request. set_feerate ( new_feerate) ;
674
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
675
- broadcaster. broadcast_transaction ( & bump_tx) ;
685
+ match bump_claim {
686
+ OnchainClaim :: Tx ( bump_tx) => {
687
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
688
+ broadcaster. broadcast_transaction ( & bump_tx) ;
689
+ } ,
690
+ }
676
691
}
677
692
}
678
693
for ( ancestor_claim_txid, request) in bump_candidates. drain ( ) {
0 commit comments