Skip to content

Commit 5c65aca

Browse files
committed
chain(fix): conflict resolution for txs with same last_seen
1 parent 2867e88 commit 5c65aca

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,25 @@ impl<A: Anchor> TxGraph<A> {
693693
if conflicting_tx.last_seen_unconfirmed > *last_seen {
694694
return Ok(None);
695695
}
696+
if conflicting_tx.last_seen_unconfirmed == *last_seen {
697+
// Check if conflicting tx has higher absolute fee and fee rate
698+
if let Ok(fee) = self.calculate_fee(tx) {
699+
if let Ok(conflicting_fee) = self.calculate_fee(&conflicting_tx) {
700+
let fee_rate = fee as f32 / tx.weight().to_vbytes_ceil() as f32;
701+
let conflicting_fee_rate = conflicting_fee as f32
702+
/ conflicting_tx.weight().to_vbytes_ceil() as f32;
703+
704+
if conflicting_fee > fee && conflicting_fee_rate > fee_rate {
705+
return Ok(None);
706+
}
707+
}
708+
}
709+
// If fee rates cannot be distinguished, then conflicting tx has priority if txid of
710+
// conflicting tx > txid of original tx
711+
else if conflicting_tx.txid() > tx.txid() {
712+
return Ok(None);
713+
}
714+
}
696715
}
697716

698717
Ok(Some(ChainPosition::Unconfirmed(*last_seen)))

0 commit comments

Comments
 (0)