@@ -41,7 +41,7 @@ use util::logger::Logger;
41
41
use util:: ser:: { ReadableArgs , Readable , Writer , Writeable , WriterWriteAdaptor , U48 } ;
42
42
use util:: { byte_utils, events} ;
43
43
44
- use std:: collections:: { HashMap , hash_map} ;
44
+ use std:: collections:: { HashMap , hash_map, HashSet } ;
45
45
use std:: sync:: { Arc , Mutex } ;
46
46
use std:: { hash, cmp, mem} ;
47
47
@@ -2337,7 +2337,7 @@ impl ChannelMonitor {
2337
2337
let mut watch_outputs = Vec :: new ( ) ;
2338
2338
let mut spendable_outputs = Vec :: new ( ) ;
2339
2339
let mut htlc_updated = Vec :: new ( ) ;
2340
- let mut bump_candidates = HashMap :: new ( ) ;
2340
+ let mut bump_candidates = HashSet :: new ( ) ;
2341
2341
for tx in txn_matched {
2342
2342
if tx. input . len ( ) == 1 {
2343
2343
// Assuming our keys were not leaked (in which case we're screwed no matter what),
@@ -2403,9 +2403,9 @@ impl ChannelMonitor {
2403
2403
// Scan all input to verify is one of the outpoint spent is of interest for us
2404
2404
let mut claimed_outputs_material = Vec :: new ( ) ;
2405
2405
for inp in & tx. input {
2406
- if let Some ( ancestor_claimable_txid ) = self . claimable_outpoints . get ( & inp. previous_output ) {
2406
+ if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( & inp. previous_output ) {
2407
2407
// If outpoint has claim request pending on it...
2408
- if let Some ( claim_material) = self . pending_claim_requests . get_mut ( & ancestor_claimable_txid . 0 ) {
2408
+ if let Some ( claim_material) = self . pending_claim_requests . get_mut ( & first_claim_txid_height . 0 ) {
2409
2409
//... we need to verify equality between transaction outpoints and claim request
2410
2410
// outpoints to know if transaction is the original claim or a bumped one issued
2411
2411
// by us.
@@ -2422,7 +2422,7 @@ impl ChannelMonitor {
2422
2422
2423
2423
macro_rules! clean_claim_request_after_safety_delay {
2424
2424
( ) => {
2425
- let new_event = OnchainEvent :: Claim { claim_request: ancestor_claimable_txid . 0 . clone( ) } ;
2425
+ let new_event = OnchainEvent :: Claim { claim_request: first_claim_txid_height . 0 . clone( ) } ;
2426
2426
match self . onchain_events_waiting_threshold_conf. entry( height + ANTI_REORG_DELAY - 1 ) {
2427
2427
hash_map:: Entry :: Occupied ( mut entry) => {
2428
2428
if !entry. get( ) . contains( & new_event) {
@@ -2452,7 +2452,7 @@ impl ChannelMonitor {
2452
2452
}
2453
2453
}
2454
2454
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
2455
- bump_candidates. insert ( ancestor_claimable_txid . 0 . clone ( ) , claim_material . clone ( ) ) ;
2455
+ bump_candidates. insert ( first_claim_txid_height . 0 . clone ( ) ) ;
2456
2456
}
2457
2457
break ; //No need to iterate further, either tx is our or their
2458
2458
} else {
@@ -2526,23 +2526,26 @@ impl ChannelMonitor {
2526
2526
}
2527
2527
}
2528
2528
}
2529
- for ( ancestor_claim_txid , ref mut cached_claim_datas) in self . pending_claim_requests . iter_mut ( ) {
2529
+ for ( first_claim_txid , ref mut cached_claim_datas) in self . pending_claim_requests . iter_mut ( ) {
2530
2530
if cached_claim_datas. height_timer == height {
2531
- if let hash_map:: Entry :: Vacant ( entry) = bump_candidates. entry ( ancestor_claim_txid. clone ( ) ) {
2532
- entry. insert ( cached_claim_datas. clone ( ) ) ;
2533
- }
2534
- }
2535
- }
2536
- for ref mut cached_claim_datas in bump_candidates. values_mut ( ) {
2537
- if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . bump_claim_tx ( height, & cached_claim_datas, fee_estimator) {
2538
- cached_claim_datas. height_timer = new_timer;
2539
- cached_claim_datas. feerate_previous = new_feerate;
2540
- broadcaster. broadcast_transaction ( & bump_tx) ;
2531
+ bump_candidates. insert ( first_claim_txid. clone ( ) ) ;
2532
+ }
2533
+ }
2534
+ for first_claim_txid in bump_candidates. iter ( ) {
2535
+ if let Some ( ( new_timer, new_feerate) ) = {
2536
+ if let Some ( claim_material) = self . pending_claim_requests . get ( first_claim_txid) {
2537
+ if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . bump_claim_tx ( height, & claim_material, fee_estimator) {
2538
+ broadcaster. broadcast_transaction ( & bump_tx) ;
2539
+ Some ( ( new_timer, new_feerate) )
2540
+ } else { None }
2541
+ } else { unreachable ! ( ) ; }
2542
+ } {
2543
+ if let Some ( claim_material) = self . pending_claim_requests . get_mut ( first_claim_txid) {
2544
+ claim_material. height_timer = new_timer;
2545
+ claim_material. feerate_previous = new_feerate;
2546
+ } else { unreachable ! ( ) ; }
2541
2547
}
2542
2548
}
2543
- for ( ancestor_claim_txid, cached_claim_datas) in bump_candidates. drain ( ) {
2544
- self . pending_claim_requests . insert ( ancestor_claim_txid, cached_claim_datas) ;
2545
- }
2546
2549
self . last_block_hash = block_hash. clone ( ) ;
2547
2550
( watch_outputs, spendable_outputs, htlc_updated)
2548
2551
}
0 commit comments