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

Conversation

LagginTimes
Copy link
Contributor

@LagginTimes LagginTimes commented Sep 1, 2023

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:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

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

Having considered it again I'm not sure if it's a good idea to make this change. It's a half-fix. This tie-break will not necessarily reflect what full mempool nodes decide since it doesn't consider the feerates of parents etc. I do think it's a good idea to tie-break consistently and deterministically (so just arbitrarily choose txid by lexical order). We could do the simplest thing here and then make an issue to implement logic which reflects mempool rules of bitcoin core.

If we were to do this one I'd expect to have a few more tests. I don't think each branch here can be reach with each test.

cc @danielabrozzoni @evanlinjin wdyt?

@danielabrozzoni
Copy link
Member

I agree with Lloyd's points, tie-breaking by tx feerate doesn't make much sense, as it's the package feerate that counts. We can go with tie-breaking by txid for now.

I also wonder how often it happens that two transactions have the same last_seen.

@LagginTimes
Copy link
Contributor Author

Updated to tiebreak by txid only.

Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

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

ACK c4aea75

These two commits should be squashed.
Thanks @LagginTimes.

@notmandatory
Copy link
Member

I'm hoping we can fix the CI issues with #1183 but if that doesn't happen #1182 and then this PR will need a rebase.

@nondiremanuel
Copy link

As per today's discussion in the Lib Team Call, this PR probably needs to be rebased after the ci fix of #1182

The tx conflict `Scenario` test for unconfirmed txs with the same
last_seen has been amended for its corresponding conflict
resolution bug fix.
@LagginTimes
Copy link
Contributor Author

Rebased with #1182 CI fixes.

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

ACK afbf83c

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

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

@danielabrozzoni danielabrozzoni merged commit 0a7b60f into bitcoindevkit:master Nov 9, 2023
12 checks passed
@notmandatory notmandatory mentioned this pull request Jan 3, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Further improve unconfirmed tx conflict resolution
5 participants