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
The tx conflict `Scenario` test for unconfirmed txs with the same
last_seen has been amended for its corresponding conflict
resolution bug fix.
  • Loading branch information
LagginTimes committed Nov 8, 2023
1 parent 2f2f138 commit 4861048
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,12 @@ impl<A: Anchor> TxGraph<A> {
if conflicting_tx.last_seen_unconfirmed > tx_last_seen {
return Ok(None);
}
if conflicting_tx.last_seen_unconfirmed == *last_seen
&& conflicting_tx.txid() > tx.txid()
{
// Conflicting tx has priority if txid of conflicting tx > txid of original tx
return Ok(None);
}
}
}

Expand Down
10 changes: 4 additions & 6 deletions crates/chain/tests/test_tx_graph_conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ fn test_tx_conflict_handling() {
..Default::default()
},
],
// correct output if filtered by fee rate: tx1, tx_conflict_1
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_1", "tx_conflict_2"]),
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_1", 0), ("tx_conflict_2", 0)]),
// correct output if filtered by fee rate: tx_conflict_1
exp_unspents: HashSet::from([("tx_conflict_1", 0), ("tx_conflict_2", 0)]),
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_1"]),
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_1", 0)]),
exp_unspents: HashSet::from([("tx_conflict_1", 0)]),
exp_balance: Balance {
immature: 0,
trusted_pending: 50000, // correct output if filtered by fee rate: 20000
trusted_pending: 20000,
untrusted_pending: 0,
confirmed: 0,
},
Expand Down

0 comments on commit 4861048

Please sign in to comment.