@@ -218,6 +218,9 @@ pub(crate) enum OnchainClaim {
218
218
Event ( ClaimEvent ) ,
219
219
}
220
220
221
+ /// An internal identifier to track pending package claims within the `OnchainTxHandler`.
222
+ type PackageID = [ u8 ; 32 ] ;
223
+
221
224
/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
222
225
/// do RBF bumping if possible.
223
226
pub struct OnchainTxHandler < ChannelSigner : Sign > {
@@ -245,11 +248,11 @@ pub struct OnchainTxHandler<ChannelSigner: Sign> {
245
248
// us and is immutable until all outpoint of the claimable set are post-anti-reorg-delay solved.
246
249
// Entry is cache of elements need to generate a bumped claiming transaction (see ClaimTxBumpMaterial)
247
250
#[ cfg( test) ] // Used in functional_test to verify sanitization
248
- pub ( crate ) pending_claim_requests : HashMap < Txid , PackageTemplate > ,
251
+ pub ( crate ) pending_claim_requests : HashMap < PackageID , PackageTemplate > ,
249
252
#[ cfg( not( test) ) ]
250
- pending_claim_requests : HashMap < Txid , PackageTemplate > ,
253
+ pending_claim_requests : HashMap < PackageID , PackageTemplate > ,
251
254
#[ cfg( anchors) ]
252
- pending_claim_events : HashMap < Txid , ClaimEvent > ,
255
+ pending_claim_events : HashMap < PackageID , ClaimEvent > ,
253
256
254
257
// Used to link outpoints claimed in a connected block to a pending claim request.
255
258
// Key is outpoint than monitor parsing has detected we have keys/scripts to claim
@@ -258,9 +261,9 @@ pub struct OnchainTxHandler<ChannelSigner: Sign> {
258
261
// post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
259
262
// block with output gets disconnected.
260
263
#[ cfg( test) ] // Used in functional_test to verify sanitization
261
- pub claimable_outpoints : HashMap < BitcoinOutPoint , ( Txid , u32 ) > ,
264
+ pub claimable_outpoints : HashMap < BitcoinOutPoint , ( PackageID , u32 ) > ,
262
265
#[ cfg( not( test) ) ]
263
- claimable_outpoints : HashMap < BitcoinOutPoint , ( Txid , u32 ) > ,
266
+ claimable_outpoints : HashMap < BitcoinOutPoint , ( PackageID , u32 ) > ,
264
267
265
268
locktimed_packages : BTreeMap < u32 , Vec < PackageTemplate > > ,
266
269
@@ -473,7 +476,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
473
476
// since requests can have outpoints split off.
474
477
if !self . onchain_events_awaiting_threshold_conf . iter ( )
475
478
. any ( |event_entry| if let OnchainEvent :: Claim { claim_request } = event_entry. event {
476
- first_claim_txid_height. 0 == claim_request
479
+ first_claim_txid_height. 0 == claim_request. into_inner ( )
477
480
} else {
478
481
// The onchain event is not a claim, keep seeking until we find one.
479
482
false
@@ -658,11 +661,11 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
658
661
if let Some ( ( new_timer, new_feerate, claim) ) = self . generate_claim ( cur_height, & req, & * fee_estimator, & * logger) {
659
662
req. set_timer ( new_timer) ;
660
663
req. set_feerate ( new_feerate) ;
661
- let txid = match claim {
664
+ let package_id = match claim {
662
665
OnchainClaim :: Tx ( tx) => {
663
666
log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
664
667
broadcaster. broadcast_transaction ( & tx) ;
665
- tx. txid ( )
668
+ tx. txid ( ) . into_inner ( )
666
669
} ,
667
670
#[ cfg( anchors) ]
668
671
OnchainClaim :: Event ( claim_event) => {
@@ -671,15 +674,16 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
671
674
ClaimEvent :: BumpCommitment { ref commitment_tx, .. } => commitment_tx. txid ( ) ,
672
675
ClaimEvent :: BumpHTLC { ref tx_template, .. } => tx_template. txid ( ) ,
673
676
} ;
674
- self . pending_claim_events . insert ( txid, claim_event) ;
675
- txid
677
+ let package_id = txid. into_inner ( ) ;
678
+ self . pending_claim_events . insert ( package_id, claim_event) ;
679
+ package_id
676
680
} ,
677
681
} ;
678
682
for k in req. outpoints ( ) {
679
683
log_info ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
680
- self . claimable_outpoints . insert ( k. clone ( ) , ( txid , conf_height) ) ;
684
+ self . claimable_outpoints . insert ( k. clone ( ) , ( package_id , conf_height) ) ;
681
685
}
682
- self . pending_claim_requests . insert ( txid , req) ;
686
+ self . pending_claim_requests . insert ( package_id , req) ;
683
687
}
684
688
}
685
689
}
@@ -746,7 +750,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
746
750
txid: tx. txid( ) ,
747
751
height: conf_height,
748
752
block_hash: Some ( conf_hash) ,
749
- event: OnchainEvent :: Claim { claim_request: first_claim_txid_height. 0 . clone ( ) }
753
+ event: OnchainEvent :: Claim { claim_request: Txid :: from_inner ( first_claim_txid_height. 0 ) }
750
754
} ;
751
755
if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
752
756
self . onchain_events_awaiting_threshold_conf. push( entry) ;
@@ -802,14 +806,15 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
802
806
if entry. has_reached_confirmation_threshold ( cur_height) {
803
807
match entry. event {
804
808
OnchainEvent :: Claim { claim_request } => {
809
+ let package_id = claim_request. into_inner ( ) ;
805
810
// We may remove a whole set of claim outpoints here, as these one may have
806
811
// been aggregated in a single tx and claimed so atomically
807
- if let Some ( request) = self . pending_claim_requests . remove ( & claim_request ) {
812
+ if let Some ( request) = self . pending_claim_requests . remove ( & package_id ) {
808
813
for outpoint in request. outpoints ( ) {
809
814
log_debug ! ( logger, "Removing claim tracking for {} due to maturation of claim tx {}." , outpoint, claim_request) ;
810
815
self . claimable_outpoints . remove ( & outpoint) ;
811
816
#[ cfg( anchors) ]
812
- self . pending_claim_events . remove ( & claim_request ) ;
817
+ self . pending_claim_events . remove ( & package_id ) ;
813
818
}
814
819
}
815
820
} ,
0 commit comments