Skip to content

Commit 454d70d

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

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,23 @@ 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), Ok(conflicting_fee)) =
699+
(self.calculate_fee(tx), self.calculate_fee(&conflicting_tx))
700+
{
701+
let fee_rate = fee as f32 / tx.weight().to_vbytes_ceil() as f32;
702+
let conflicting_fee_rate =
703+
conflicting_fee as f32 / conflicting_tx.weight().to_vbytes_ceil() as f32;
704+
if conflicting_fee > fee && conflicting_fee_rate > fee_rate {
705+
return Ok(None);
706+
}
707+
} else if conflicting_tx.txid() > tx.txid() {
708+
// If fee rates cannot be distinguished, then conflicting tx has priority if
709+
// txid of conflicting tx > txid of original tx
710+
return Ok(None);
711+
}
712+
}
696713
}
697714

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

0 commit comments

Comments
 (0)