@@ -2394,31 +2394,39 @@ impl ChannelMonitor {
2394
2394
}
2395
2395
2396
2396
// Scan all input to verify is one of the outpoint spent is of interest for us
2397
- let mut claimed_outpoints = Vec :: new ( ) ;
2398
- let mut claimed_input_material = Vec :: new ( ) ;
2397
+ let mut claimed_outputs_material = Vec :: new ( ) ;
2399
2398
for inp in & tx. input {
2400
2399
if let Some ( ancestor_claimable_txid) = self . claimable_outpoints . get ( & inp. previous_output ) {
2401
2400
// If outpoint has claim request pending on it...
2402
2401
if let Some ( claim_material) = self . pending_claim_requests . get_mut ( & ancestor_claimable_txid. 0 ) {
2403
2402
//... we need to verify equality between transaction outpoints and claim request
2404
2403
// outpoints to know if transaction is the original claim or a bumped one issued
2405
2404
// by us.
2406
- for claim_inp in claim_material. per_input_material . keys ( ) {
2407
- if * claim_inp == inp. previous_output {
2408
- claimed_outpoints. push ( inp. previous_output . clone ( ) ) ;
2405
+ let mut set_equality = true ;
2406
+ if claim_material. per_input_material . len ( ) != tx. input . len ( ) {
2407
+ set_equality = false ;
2408
+ } else {
2409
+ for ( claim_inp, tx_inp) in claim_material. per_input_material . keys ( ) . zip ( tx. input . iter ( ) ) {
2410
+ if * claim_inp != tx_inp. previous_output {
2411
+ set_equality = false ;
2412
+ }
2409
2413
}
2410
2414
}
2411
- if claimed_outpoints. len ( ) == 0 && claim_material. per_input_material . len ( ) == tx. input . len ( ) { // If true, register claim request to be removed after reaching a block security height
2415
+
2416
+ // If this is our transaction (or our counterparty spent all the outputs
2417
+ // before we could anyway), wait for ANTI_REORG_DELAY and clean the RBF
2418
+ // tracking map.
2419
+ if set_equality {
2412
2420
match self . onchain_events_waiting_threshold_conf . entry ( height + ANTI_REORG_DELAY - 1 ) {
2413
2421
hash_map:: Entry :: Occupied ( _) => { } ,
2414
2422
hash_map:: Entry :: Vacant ( entry) => {
2415
2423
entry. insert ( vec ! [ OnchainEvent :: Claim { claim_request: ancestor_claimable_txid. 0 . clone( ) } ] ) ;
2416
2424
}
2417
2425
}
2418
2426
} else { // If false, generate new claim request with update outpoint set
2419
- for already_claimed in claimed_outpoints . iter ( ) {
2420
- if let Some ( input_material) = claim_material. per_input_material . remove ( & already_claimed ) {
2421
- claimed_input_material . push ( input_material) ;
2427
+ for input in tx . input . iter ( ) {
2428
+ if let Some ( input_material) = claim_material. per_input_material . remove ( & input . previous_output ) {
2429
+ claimed_outputs_material . push ( ( input . previous_output , input_material) ) ;
2422
2430
}
2423
2431
}
2424
2432
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
@@ -2430,11 +2438,11 @@ impl ChannelMonitor {
2430
2438
}
2431
2439
}
2432
2440
}
2433
- for ( outpoint, input_material) in claimed_outpoints . iter ( ) . zip ( claimed_input_material . drain ( ..) ) {
2441
+ for ( outpoint, input_material) in claimed_outputs_material . drain ( ..) {
2434
2442
match self . onchain_events_waiting_threshold_conf . entry ( height + ANTI_REORG_DELAY - 1 ) {
2435
2443
hash_map:: Entry :: Occupied ( _) => { } ,
2436
2444
hash_map:: Entry :: Vacant ( entry) => {
2437
- entry. insert ( vec ! [ OnchainEvent :: ContentiousOutpoint { outpoint: * outpoint , input_material : input_material } ] ) ;
2445
+ entry. insert ( vec ! [ OnchainEvent :: ContentiousOutpoint { outpoint, input_material } ] ) ;
2438
2446
}
2439
2447
}
2440
2448
}
0 commit comments