@@ -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
@@ -2330,7 +2330,7 @@ impl ChannelMonitor {
2330
2330
let mut watch_outputs = Vec :: new ( ) ;
2331
2331
let mut spendable_outputs = Vec :: new ( ) ;
2332
2332
let mut htlc_updated = Vec :: new ( ) ;
2333
- let mut bump_candidates = HashMap :: new ( ) ;
2333
+ let mut bump_candidates = HashSet :: new ( ) ;
2334
2334
for tx in txn_matched {
2335
2335
if tx. input . len ( ) == 1 {
2336
2336
// Assuming our keys were not leaked (in which case we're screwed no matter what),
@@ -2396,9 +2396,9 @@ impl ChannelMonitor {
2396
2396
// Scan all input to verify is one of the outpoint spent is of interest for us
2397
2397
let mut claimed_outputs_material = Vec :: new ( ) ;
2398
2398
for inp in & tx. input {
2399
- if let Some ( ancestor_claimable_txid ) = self . claimable_outpoints . get ( & inp. previous_output ) {
2399
+ if let Some ( first_claim_txid_height ) = self . claimable_outpoints . get ( & inp. previous_output ) {
2400
2400
// If outpoint has claim request pending on it...
2401
- if let Some ( claim_material) = self . pending_claim_requests . get_mut ( & ancestor_claimable_txid . 0 ) {
2401
+ if let Some ( claim_material) = self . pending_claim_requests . get_mut ( & first_claim_txid_height . 0 ) {
2402
2402
//... we need to verify equality between transaction outpoints and claim request
2403
2403
// outpoints to know if transaction is the original claim or a bumped one issued
2404
2404
// by us.
@@ -2417,7 +2417,7 @@ impl ChannelMonitor {
2417
2417
// before we could anyway), wait for ANTI_REORG_DELAY and clean the RBF
2418
2418
// tracking map.
2419
2419
if set_equality {
2420
- let new_event = OnchainEvent :: Claim { claim_request : ancestor_claimable_txid . 0 . clone ( ) } ;
2420
+ let new_event = OnchainEvent :: Claim { claim_request : first_claim_txid_height . 0 . clone ( ) } ;
2421
2421
match self . onchain_events_waiting_threshold_conf . entry ( height + ANTI_REORG_DELAY - 1 ) {
2422
2422
hash_map:: Entry :: Occupied ( mut entry) => {
2423
2423
if !entry. get ( ) . contains ( & new_event) {
@@ -2435,7 +2435,7 @@ impl ChannelMonitor {
2435
2435
}
2436
2436
}
2437
2437
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
2438
- bump_candidates. insert ( ancestor_claimable_txid . 0 . clone ( ) , claim_material . clone ( ) ) ;
2438
+ bump_candidates. insert ( first_claim_txid_height . 0 . clone ( ) ) ;
2439
2439
}
2440
2440
break ; //No need to iterate further, either tx is our or their
2441
2441
} else {
@@ -2509,23 +2509,26 @@ impl ChannelMonitor {
2509
2509
}
2510
2510
}
2511
2511
}
2512
- for ( ancestor_claim_txid , ref mut cached_claim_datas) in self . pending_claim_requests . iter_mut ( ) {
2512
+ for ( first_claim_txid , ref mut cached_claim_datas) in self . pending_claim_requests . iter_mut ( ) {
2513
2513
if cached_claim_datas. height_timer == height {
2514
- if let hash_map:: Entry :: Vacant ( entry) = bump_candidates. entry ( ancestor_claim_txid. clone ( ) ) {
2515
- entry. insert ( cached_claim_datas. clone ( ) ) ;
2516
- }
2517
- }
2518
- }
2519
- for ref mut cached_claim_datas in bump_candidates. values_mut ( ) {
2520
- if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . bump_claim_tx ( height, & cached_claim_datas, fee_estimator) {
2521
- cached_claim_datas. height_timer = new_timer;
2522
- cached_claim_datas. feerate_previous = new_feerate;
2523
- broadcaster. broadcast_transaction ( & bump_tx) ;
2514
+ bump_candidates. insert ( first_claim_txid. clone ( ) ) ;
2515
+ }
2516
+ }
2517
+ for first_claim_txid in bump_candidates. iter ( ) {
2518
+ if let Some ( ( new_timer, new_feerate) ) = {
2519
+ if let Some ( claim_material) = self . pending_claim_requests . get ( first_claim_txid) {
2520
+ if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . bump_claim_tx ( height, & claim_material, fee_estimator) {
2521
+ broadcaster. broadcast_transaction ( & bump_tx) ;
2522
+ Some ( ( new_timer, new_feerate) )
2523
+ } else { None }
2524
+ } else { unreachable ! ( ) ; }
2525
+ } {
2526
+ if let Some ( claim_material) = self . pending_claim_requests . get_mut ( first_claim_txid) {
2527
+ claim_material. height_timer = new_timer;
2528
+ claim_material. feerate_previous = new_feerate;
2529
+ } else { unreachable ! ( ) ; }
2524
2530
}
2525
2531
}
2526
- for ( ancestor_claim_txid, cached_claim_datas) in bump_candidates. drain ( ) {
2527
- self . pending_claim_requests . insert ( ancestor_claim_txid, cached_claim_datas) ;
2528
- }
2529
2532
self . last_block_hash = block_hash. clone ( ) ;
2530
2533
( watch_outputs, spendable_outputs, htlc_updated)
2531
2534
}
0 commit comments