Skip to content

Commit

Permalink
chain(fix): conflict resolution for txs with same last_seen
Browse files Browse the repository at this point in the history
  • Loading branch information
LagginTimes committed Sep 11, 2023
1 parent 2867e88 commit 5c65aca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,25 @@ impl<A: Anchor> TxGraph<A> {
if conflicting_tx.last_seen_unconfirmed > *last_seen {
return Ok(None);
}
if conflicting_tx.last_seen_unconfirmed == *last_seen {
// Check if conflicting tx has higher absolute fee and fee rate
if let Ok(fee) = self.calculate_fee(tx) {
if let Ok(conflicting_fee) = self.calculate_fee(&conflicting_tx) {
let fee_rate = fee as f32 / tx.weight().to_vbytes_ceil() as f32;
let conflicting_fee_rate = conflicting_fee as f32
/ conflicting_tx.weight().to_vbytes_ceil() as f32;

if conflicting_fee > fee && conflicting_fee_rate > fee_rate {
return Ok(None);
}
}
}
// If fee rates cannot be distinguished, then conflicting tx has priority if txid of
// conflicting tx > txid of original tx
else if conflicting_tx.txid() > tx.txid() {
return Ok(None);
}
}
}

Ok(Some(ChainPosition::Unconfirmed(*last_seen)))
Expand Down

0 comments on commit 5c65aca

Please sign in to comment.