Skip to content

Commit 4861048

Browse files
committed
chain(fix): conflict resolution for txs with same last_seen
The tx conflict `Scenario` test for unconfirmed txs with the same last_seen has been amended for its corresponding conflict resolution bug fix.
1 parent 2f2f138 commit 4861048

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ impl<A: Anchor> TxGraph<A> {
789789
if conflicting_tx.last_seen_unconfirmed > tx_last_seen {
790790
return Ok(None);
791791
}
792+
if conflicting_tx.last_seen_unconfirmed == *last_seen
793+
&& conflicting_tx.txid() > tx.txid()
794+
{
795+
// Conflicting tx has priority if txid of conflicting tx > txid of original tx
796+
return Ok(None);
797+
}
792798
}
793799
}
794800

crates/chain/tests/test_tx_graph_conflicts.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ fn test_tx_conflict_handling() {
7070
..Default::default()
7171
},
7272
],
73-
// correct output if filtered by fee rate: tx1, tx_conflict_1
74-
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_1", "tx_conflict_2"]),
75-
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_1", 0), ("tx_conflict_2", 0)]),
76-
// correct output if filtered by fee rate: tx_conflict_1
77-
exp_unspents: HashSet::from([("tx_conflict_1", 0), ("tx_conflict_2", 0)]),
73+
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_1"]),
74+
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_1", 0)]),
75+
exp_unspents: HashSet::from([("tx_conflict_1", 0)]),
7876
exp_balance: Balance {
7977
immature: 0,
80-
trusted_pending: 50000, // correct output if filtered by fee rate: 20000
78+
trusted_pending: 20000,
8179
untrusted_pending: 0,
8280
confirmed: 0,
8381
},

0 commit comments

Comments
 (0)