]> Untitled Git - bdk/commitdiff
chain(fix): conflict resolution for txs with same last_seen
authorWei Chen <wzc110@gmail.com>
Fri, 1 Sep 2023 09:58:47 +0000 (17:58 +0800)
committerWei Chen <wzc110@gmail.com>
Wed, 8 Nov 2023 21:46:09 +0000 (05:46 +0800)
The tx conflict `Scenario` test for unconfirmed txs with the same
last_seen has been amended for its corresponding conflict
resolution bug fix.

crates/chain/src/tx_graph.rs
crates/chain/tests/test_tx_graph_conflicts.rs

index 1f7bcdb1225fe0ab8ae56721b60793357653f031..6fb1ee4fa7a5d1725dd43ecc0aab92eaf83000ae 100644 (file)
@@ -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);
+                }
             }
         }
 
index 1794d8452f1f05bc48cd9265c1056d439e3344fe..53a19b0222f90560e72b2c8450339e73bd6fd0f7 100644 (file)
@@ -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",
@@ -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"]),
+            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,
             },