@@ -251,12 +251,12 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
251
251
#[ cfg( anchors) ]
252
252
pending_claim_events : HashMap < PackageID , ClaimEvent > ,
253
253
254
- // Used to link outpoints claimed in a connected block to a pending claim request.
255
- // Key is outpoint than monitor parsing has detected we have keys/scripts to claim
256
- // Value is ( pending claim request identifier, confirmation_block), identifier
257
- // is txid of the initial claiming transaction and is immutable until outpoint is
258
- // post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
259
- // block with output gets disconnected.
254
+ // Used to link outpoints claimed in a connected block to a pending claim request. The keys
255
+ // represent the outpoints that our `ChannelMonitor` has detected we have keys/scripts to
256
+ // claim. The values track the pending claim request identifier and the initial confirmation
257
+ // block height, and are immutable until the outpoint has enough confirmations to meet our
258
+ // [`ANTI_REORG_DELAY`]. The initial confirmation block height is used to remove the entry if
259
+ // the block gets disconnected.
260
260
#[ cfg( test) ] // Used in functional_test to verify sanitization
261
261
pub claimable_outpoints : HashMap < BitcoinOutPoint , ( PackageID , u32 ) > ,
262
262
#[ cfg( not( test) ) ]
@@ -494,12 +494,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
494
494
// transaction is reorged out.
495
495
let mut all_inputs_have_confirmed_spend = true ;
496
496
for outpoint in request_outpoints. iter ( ) {
497
- if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( * outpoint) {
497
+ if let Some ( ( request_package_id , _ ) ) = self . claimable_outpoints . get ( * outpoint) {
498
498
// We check for outpoint spends within claims individually rather than as a set
499
499
// since requests can have outpoints split off.
500
500
if !self . onchain_events_awaiting_threshold_conf . iter ( )
501
501
. any ( |event_entry| if let OnchainEvent :: Claim { package_id } = event_entry. event {
502
- first_claim_txid_height . 0 == package_id
502
+ * request_package_id == package_id
503
503
} else {
504
504
// The onchain event is not a claim, keep seeking until we find one.
505
505
false
@@ -744,9 +744,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
744
744
// Scan all input to verify is one of the outpoint spent is of interest for us
745
745
let mut claimed_outputs_material = Vec :: new ( ) ;
746
746
for inp in & tx. input {
747
- if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( & inp. previous_output ) {
747
+ if let Some ( ( package_id , _ ) ) = self . claimable_outpoints . get ( & inp. previous_output ) {
748
748
// If outpoint has claim request pending on it...
749
- if let Some ( request) = self . pending_claim_requests . get_mut ( & first_claim_txid_height . 0 ) {
749
+ if let Some ( request) = self . pending_claim_requests . get_mut ( package_id ) {
750
750
//... we need to verify equality between transaction outpoints and claim request
751
751
// outpoints to know if transaction is the original claim or a bumped one issued
752
752
// by us.
@@ -766,7 +766,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
766
766
txid: tx. txid( ) ,
767
767
height: conf_height,
768
768
block_hash: Some ( conf_hash) ,
769
- event: OnchainEvent :: Claim { package_id: first_claim_txid_height . 0 }
769
+ event: OnchainEvent :: Claim { package_id: * package_id }
770
770
} ;
771
771
if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
772
772
self . onchain_events_awaiting_threshold_conf. push( entry) ;
@@ -793,7 +793,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
793
793
}
794
794
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
795
795
if at_least_one_drop {
796
- bump_candidates. insert ( first_claim_txid_height . 0 . clone ( ) , request. clone ( ) ) ;
796
+ bump_candidates. insert ( * package_id , request. clone ( ) ) ;
797
797
}
798
798
}
799
799
break ; //No need to iterate further, either tx is our or their
@@ -846,17 +846,17 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
846
846
}
847
847
848
848
// Check if any pending claim request must be rescheduled
849
- for ( first_claim_txid , ref request) in self . pending_claim_requests . iter ( ) {
849
+ for ( package_id , request) in self . pending_claim_requests . iter ( ) {
850
850
if let Some ( h) = request. timer ( ) {
851
851
if cur_height >= h {
852
- bump_candidates. insert ( * first_claim_txid , ( * request) . clone ( ) ) ;
852
+ bump_candidates. insert ( * package_id , request. clone ( ) ) ;
853
853
}
854
854
}
855
855
}
856
856
857
857
// Build, bump and rebroadcast tx accordingly
858
858
log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
859
- for ( first_claim_txid , request) in bump_candidates. iter ( ) {
859
+ for ( package_id , request) in bump_candidates. iter ( ) {
860
860
if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( cur_height, & request, & * fee_estimator, & * logger) {
861
861
match bump_claim {
862
862
OnchainClaim :: Tx ( bump_tx) => {
@@ -866,10 +866,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
866
866
#[ cfg( anchors) ]
867
867
OnchainClaim :: Event ( claim_event) => {
868
868
log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
869
- self . pending_claim_events . insert ( * first_claim_txid , claim_event) ;
869
+ self . pending_claim_events . insert ( * package_id , claim_event) ;
870
870
} ,
871
871
}
872
- if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid ) {
872
+ if let Some ( request) = self . pending_claim_requests . get_mut ( package_id ) {
873
873
request. set_timer ( new_timer) ;
874
874
request. set_feerate ( new_feerate) ;
875
875
}
@@ -915,12 +915,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
915
915
//- resurect outpoint back in its claimable set and regenerate tx
916
916
match entry. event {
917
917
OnchainEvent :: ContentiousOutpoint { package } => {
918
- if let Some ( ancestor_claimable_txid ) = self . claimable_outpoints . get ( package. outpoints ( ) [ 0 ] ) {
919
- if let Some ( request) = self . pending_claim_requests . get_mut ( & ancestor_claimable_txid . 0 ) {
918
+ if let Some ( pending_claim ) = self . claimable_outpoints . get ( package. outpoints ( ) [ 0 ] ) {
919
+ if let Some ( request) = self . pending_claim_requests . get_mut ( & pending_claim . 0 ) {
920
920
request. merge_package ( package) ;
921
921
// Using a HashMap guarantee us than if we have multiple outpoints getting
922
922
// resurrected only one bump claim tx is going to be broadcast
923
- bump_candidates. insert ( ancestor_claimable_txid . clone ( ) , request. clone ( ) ) ;
923
+ bump_candidates. insert ( pending_claim . clone ( ) , request. clone ( ) ) ;
924
924
}
925
925
}
926
926
} ,
@@ -930,7 +930,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
930
930
self . onchain_events_awaiting_threshold_conf . push ( entry) ;
931
931
}
932
932
}
933
- for ( _first_claim_txid_height , request) in bump_candidates. iter_mut ( ) {
933
+ for ( ( _package_id , _ ) , request) in bump_candidates. iter_mut ( ) {
934
934
if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( height, & request, fee_estimator, & & * logger) {
935
935
request. set_timer ( new_timer) ;
936
936
request. set_feerate ( new_feerate) ;
@@ -942,7 +942,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
942
942
#[ cfg( anchors) ]
943
943
OnchainClaim :: Event ( claim_event) => {
944
944
log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
945
- self . pending_claim_events . insert ( _first_claim_txid_height . 0 , claim_event) ;
945
+ self . pending_claim_events . insert ( _package_id , claim_event) ;
946
946
} ,
947
947
}
948
948
}
0 commit comments