Skip to content

Commit 6a775ea

Browse files
TheBlueMattAntoine Riard
authored andcommitted
Dont RBF a tx twice if it hits RBF timer when one input is spent
1 parent ae042eb commit 6a775ea

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ impl ChannelMonitor {
23312331
let mut watch_outputs = Vec::new();
23322332
let mut spendable_outputs = Vec::new();
23332333
let mut htlc_updated = Vec::new();
2334-
let mut bump_candidates = Vec::new();
2334+
let mut bump_candidates = HashMap::new();
23352335
for tx in txn_matched {
23362336
if tx.input.len() == 1 {
23372337
// Assuming our keys were not leaked (in which case we're screwed no matter what),
@@ -2436,7 +2436,7 @@ impl ChannelMonitor {
24362436
}
24372437
}
24382438
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
2439-
bump_candidates.push((ancestor_claimable_txid.0.clone(), claim_material.clone()));
2439+
bump_candidates.insert(ancestor_claimable_txid.0.clone(), claim_material.clone());
24402440
}
24412441
break; //No need to iterate further, either tx is our or their
24422442
} else {
@@ -2512,17 +2512,19 @@ impl ChannelMonitor {
25122512
}
25132513
for (ancestor_claim_txid, ref mut cached_claim_datas) in self.pending_claim_requests.iter_mut() {
25142514
if cached_claim_datas.height_timer == height {
2515-
bump_candidates.push((ancestor_claim_txid.clone(), cached_claim_datas.clone()));
2515+
if let hash_map::Entry::Vacant(entry) = bump_candidates.entry(ancestor_claim_txid.clone()) {
2516+
entry.insert(cached_claim_datas.clone());
2517+
}
25162518
}
25172519
}
2518-
for &mut (_, ref mut cached_claim_datas) in bump_candidates.iter_mut() {
2520+
for ref mut cached_claim_datas in bump_candidates.values_mut() {
25192521
if let Some((new_timer, new_feerate, bump_tx)) = self.bump_claim_tx(height, &cached_claim_datas, fee_estimator) {
25202522
cached_claim_datas.height_timer = new_timer;
25212523
cached_claim_datas.feerate_previous = new_feerate;
25222524
broadcaster.broadcast_transaction(&bump_tx);
25232525
}
25242526
}
2525-
for (ancestor_claim_txid, cached_claim_datas) in bump_candidates.drain(..) {
2527+
for (ancestor_claim_txid, cached_claim_datas) in bump_candidates.drain() {
25262528
self.pending_claim_requests.insert(ancestor_claim_txid, cached_claim_datas);
25272529
}
25282530
self.last_block_hash = block_hash.clone();

0 commit comments

Comments
 (0)