@@ -255,12 +255,12 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
255
255
#[ cfg( anchors) ]
256
256
pending_claim_events : HashMap < PackageID , ClaimEvent > ,
257
257
258
- // Used to link outpoints claimed in a connected block to a pending claim request.
259
- // Key is outpoint than monitor parsing has detected we have keys/scripts to claim
260
- // Value is ( pending claim request identifier, confirmation_block), identifier
261
- // is txid of the initial claiming transaction and is immutable until outpoint is
262
- // post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
263
- // block with output gets disconnected.
258
+ // Used to link outpoints claimed in a connected block to a pending claim request. The keys
259
+ // represent the outpoints that our `ChannelMonitor` has detected we have keys/scripts to claim.
260
+ // The values track the pending claim request identifier and the initial confirmation block
261
+ // height, and are immutable until the outpoint is has enough confirmations to meet our
262
+ // [`ANTI_REORG_DELAY`]. The initial confirmation block height is used to remove the entry if
263
+ // the block gets disconnected.
264
264
#[ cfg( test) ] // Used in functional_test to verify sanitization
265
265
pub claimable_outpoints : HashMap < BitcoinOutPoint , ( PackageID , u32 ) > ,
266
266
#[ cfg( not( test) ) ]
@@ -498,12 +498,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
498
498
// transaction is reorged out.
499
499
let mut all_inputs_have_confirmed_spend = true ;
500
500
for outpoint in request_outpoints. iter ( ) {
501
- if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( * outpoint) {
501
+ if let Some ( ( request_package_id , _ ) ) = self . claimable_outpoints . get ( * outpoint) {
502
502
// We check for outpoint spends within claims individually rather than as a set
503
503
// since requests can have outpoints split off.
504
504
if !self . onchain_events_awaiting_threshold_conf . iter ( )
505
505
. any ( |event_entry| if let OnchainEvent :: Claim { package_id } = event_entry. event {
506
- first_claim_txid_height . 0 == package_id
506
+ * request_package_id == package_id
507
507
} else {
508
508
// The onchain event is not a claim, keep seeking until we find one.
509
509
false
@@ -748,9 +748,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
748
748
// Scan all input to verify is one of the outpoint spent is of interest for us
749
749
let mut claimed_outputs_material = Vec :: new ( ) ;
750
750
for inp in & tx. input {
751
- if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( & inp. previous_output ) {
751
+ if let Some ( ( package_id , _ ) ) = self . claimable_outpoints . get ( & inp. previous_output ) {
752
752
// If outpoint has claim request pending on it...
753
- if let Some ( request) = self . pending_claim_requests . get_mut ( & first_claim_txid_height . 0 ) {
753
+ if let Some ( request) = self . pending_claim_requests . get_mut ( package_id ) {
754
754
//... we need to verify equality between transaction outpoints and claim request
755
755
// outpoints to know if transaction is the original claim or a bumped one issued
756
756
// by us.
@@ -770,7 +770,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
770
770
txid: tx. txid( ) ,
771
771
height: conf_height,
772
772
block_hash: Some ( conf_hash) ,
773
- event: OnchainEvent :: Claim { package_id: first_claim_txid_height . 0 }
773
+ event: OnchainEvent :: Claim { package_id: * package_id }
774
774
} ;
775
775
if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
776
776
self . onchain_events_awaiting_threshold_conf. push( entry) ;
@@ -797,7 +797,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
797
797
}
798
798
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
799
799
if at_least_one_drop {
800
- bump_candidates. insert ( first_claim_txid_height . 0 . clone ( ) , request. clone ( ) ) ;
800
+ bump_candidates. insert ( * package_id , request. clone ( ) ) ;
801
801
}
802
802
}
803
803
break ; //No need to iterate further, either tx is our or their
@@ -850,17 +850,17 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
850
850
}
851
851
852
852
// Check if any pending claim request must be rescheduled
853
- for ( first_claim_txid , ref request) in self . pending_claim_requests . iter ( ) {
853
+ for ( package_id , request) in self . pending_claim_requests . iter ( ) {
854
854
if let Some ( h) = request. timer ( ) {
855
855
if cur_height >= h {
856
- bump_candidates. insert ( * first_claim_txid , ( * request) . clone ( ) ) ;
856
+ bump_candidates. insert ( * package_id , request. clone ( ) ) ;
857
857
}
858
858
}
859
859
}
860
860
861
861
// Build, bump and rebroadcast tx accordingly
862
862
log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
863
- for ( first_claim_txid , request) in bump_candidates. iter ( ) {
863
+ for ( package_id , request) in bump_candidates. iter ( ) {
864
864
if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( cur_height, & request, & * fee_estimator, & * logger) {
865
865
match bump_claim {
866
866
OnchainClaim :: Tx ( bump_tx) => {
@@ -870,10 +870,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
870
870
#[ cfg( anchors) ]
871
871
OnchainClaim :: Event ( claim_event) => {
872
872
log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
873
- self . pending_claim_events . insert ( * first_claim_txid , claim_event) ;
873
+ self . pending_claim_events . insert ( * package_id , claim_event) ;
874
874
} ,
875
875
}
876
- if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid ) {
876
+ if let Some ( request) = self . pending_claim_requests . get_mut ( package_id ) {
877
877
request. set_timer ( new_timer) ;
878
878
request. set_feerate ( new_feerate) ;
879
879
}
@@ -934,7 +934,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
934
934
self . onchain_events_awaiting_threshold_conf . push ( entry) ;
935
935
}
936
936
}
937
- for ( _first_claim_txid_height , request) in bump_candidates. iter_mut ( ) {
937
+ for ( ( _package_id , _ ) , request) in bump_candidates. iter_mut ( ) {
938
938
if let Some ( ( new_timer, new_feerate, bump_claim) ) = self . generate_claim ( height, & request, fee_estimator, & & * logger) {
939
939
request. set_timer ( new_timer) ;
940
940
request. set_feerate ( new_feerate) ;
@@ -946,7 +946,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
946
946
#[ cfg( anchors) ]
947
947
OnchainClaim :: Event ( claim_event) => {
948
948
log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
949
- self . pending_claim_events . insert ( _first_claim_txid_height . 0 , claim_event) ;
949
+ self . pending_claim_events . insert ( _package_id , claim_event) ;
950
950
} ,
951
951
}
952
952
}
0 commit comments