Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve unconfirmed tx conflict resolution #1109

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should be documented, but I don't want to hold up merging, so I'm going to do it as a part of #1188

return Ok(None);
}
}
}

Expand Down
12 changes: 5 additions & 7 deletions crates/chain/tests/test_tx_graph_conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ fn test_tx_conflict_handling() {
tx_templates: &[
TxTemplate {
tx_name: "tx1",
inputs: &[TxInTemplate::Bogus],
outputs: &[TxOutTemplate::new(40000, Some(0))],
anchors: &[block_id!(1, "B")],
last_seen: None,
..Default::default()
},
TxTemplate {
tx_name: "tx_conflict_1",
Expand All @@ -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_2"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this needs docs, will do it as a part of #1188

exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_2", 0)]),
exp_unspents: HashSet::from([("tx_conflict_2", 0)]),
exp_balance: Balance {
immature: 0,
trusted_pending: 50000, // correct output if filtered by fee rate: 20000
trusted_pending: 30000,
untrusted_pending: 0,
confirmed: 0,
},
Expand Down
Loading