Merge bitcoindevkit/bdk#1109: Further improve unconfirmed tx conflict resolution
afbf83c8b0d5c97495e6ceaa39963415edef6911 chain(fix): conflict resolution for txs with same last_seen (Wei Chen) Pull request description: ### Description Fixes #1102. If a conflicting tx has the same `last_seen`, then we check lexicographical sorting of txids. ### Notes to the reviewers The tests for this fix exist in the `TxTemplate` structure in #1064 which may need to be merged first. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: danielabrozzoni: ACK afbf83c8b0d5c97495e6ceaa39963415edef6911 Tree-SHA512: 91b8fbff305b715247501b861ab7ea9e9d9ef99248b05d14e01aacf7e64ad7826f35773e8998cf421dbd04f663714026084c6e817ac5365bce4844c8ea3b7e3f
This commit is contained in:
commit
0a7b60f0f7
@ -789,6 +789,12 @@ impl<A: Anchor> TxGraph<A> {
|
|||||||
if conflicting_tx.last_seen_unconfirmed > tx_last_seen {
|
if conflicting_tx.last_seen_unconfirmed > tx_last_seen {
|
||||||
return Ok(None);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ fn test_tx_conflict_handling() {
|
|||||||
tx_templates: &[
|
tx_templates: &[
|
||||||
TxTemplate {
|
TxTemplate {
|
||||||
tx_name: "tx1",
|
tx_name: "tx1",
|
||||||
inputs: &[TxInTemplate::Bogus],
|
|
||||||
outputs: &[TxOutTemplate::new(40000, Some(0))],
|
outputs: &[TxOutTemplate::new(40000, Some(0))],
|
||||||
anchors: &[block_id!(1, "B")],
|
anchors: &[block_id!(1, "B")],
|
||||||
last_seen: None,
|
last_seen: None,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
TxTemplate {
|
TxTemplate {
|
||||||
tx_name: "tx_conflict_1",
|
tx_name: "tx_conflict_1",
|
||||||
@ -70,14 +70,12 @@ fn test_tx_conflict_handling() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
// correct output if filtered by fee rate: tx1, tx_conflict_1
|
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_2"]),
|
||||||
exp_chain_txs: HashSet::from(["tx1", "tx_conflict_1", "tx_conflict_2"]),
|
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_2", 0)]),
|
||||||
exp_chain_txouts: HashSet::from([("tx1", 0), ("tx_conflict_1", 0), ("tx_conflict_2", 0)]),
|
exp_unspents: HashSet::from([("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_balance: Balance {
|
exp_balance: Balance {
|
||||||
immature: 0,
|
immature: 0,
|
||||||
trusted_pending: 50000, // correct output if filtered by fee rate: 20000
|
trusted_pending: 30000,
|
||||||
untrusted_pending: 0,
|
untrusted_pending: 0,
|
||||||
confirmed: 0,
|
confirmed: 0,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user