Skip to content

Commit

Permalink
rbf: filter prev coins from confirmed cands
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Nov 24, 2023
1 parent a1e8128 commit 61bfe47
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,16 +1066,24 @@ impl DaemonControl {
must_select: !is_cancel,
})
.collect();
if !is_cancel {
candidate_coins.extend(
db_conn
.coins(&[CoinStatus::Confirmed], &[])
.into_values()
.map(|c| CandidateCoin {
let confirmed_cands: Vec<CandidateCoin> = db_conn
.coins(&[CoinStatus::Confirmed], &[])
.into_values()
.filter_map(|c| {
// In case the user attempts RBF before the previous coins have been updated in the DB,
// they would be returned as confirmed and not spending.
if !prev_coins.contains_key(&c.outpoint) {
Some(CandidateCoin {
coin: c,
must_select: false,
}),
);
})
} else {
None
}
})
.collect();
if !is_cancel {
candidate_coins.extend(&confirmed_cands);
}
// Try with increasing feerate until fee paid by replacement transaction is high enough.
// Replacement fee must be at least:
Expand All @@ -1101,14 +1109,10 @@ impl DaemonControl {
Err(CommandError::CoinSelectionError(_))
if is_cancel && candidate_coins.iter().all(|c| !c.must_select) =>
{
candidate_coins = prev_coins
.values()
.chain(db_conn.coins(&[CoinStatus::Confirmed], &[]).values())
.map(|c| CandidateCoin {
coin: *c,
must_select: prev_coins.contains_key(&c.outpoint),
})
.collect();
for cand in candidate_coins.iter_mut() {
cand.must_select = true;
}
candidate_coins.extend(&confirmed_cands);
continue;
}
Err(e) => {
Expand Down

0 comments on commit 61bfe47

Please sign in to comment.