Skip to content

Commit 2921e82

Browse files
committed
chain(fix): conflict resolution for txs with same last_seen
1 parent 2e4bc3c commit 2921e82

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
@@ -790,6 +790,23 @@ impl<A: Anchor> TxGraph<A> {
790790
return Ok(None);
791791
}
792792
}
793+
if conflicting_tx.last_seen_unconfirmed == *last_seen {
794+
// Check if conflicting tx has higher absolute fee and fee rate
795+
if let (Ok(fee), Ok(conflicting_fee)) =
796+
(self.calculate_fee(tx), self.calculate_fee(&conflicting_tx))
797+
{
798+
let fee_rate = fee as f32 / tx.weight().to_vbytes_ceil() as f32;
799+
let conflicting_fee_rate =
800+
conflicting_fee as f32 / conflicting_tx.weight().to_vbytes_ceil() as f32;
801+
if conflicting_fee > fee && conflicting_fee_rate > fee_rate {
802+
return Ok(None);
803+
}
804+
} else if conflicting_tx.txid() > tx.txid() {
805+
// If fee rates cannot be distinguished, then conflicting tx has priority if
806+
// txid of conflicting tx > txid of original tx
807+
return Ok(None);
808+
}
809+
}
793810
}
794811

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

0 commit comments

Comments
 (0)