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

fix(rpc): Avoid selecting duplicate transactions in block templates #6006

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Jan 19, 2023

Motivation

The block template should not contain duplicate transactions.

Closes #5982.

Solution

  • Logs hashes of mempool transactions returned by FullTransactions request.
  • Logs selected mempool transaction hashes and unpaid actions.
  • Removes candidate transactions from candidate transaction collections during selection.

Review

Part of regular scheduled work.

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

- Creates a new WeightedIndex instead of updating the weights

- Logs tx hashes and unpaid_actions in getblocktemplate
@arya2 arya2 added C-bug Category: This is a bug A-consensus Area: Consensus rule updates P-High 🔥 A-rpc Area: Remote Procedure Call interfaces I-lose-funds Zebra loses user funds labels Jan 19, 2023
@arya2 arya2 requested a review from a team as a code owner January 19, 2023 23:00
@arya2 arya2 requested review from teor2345 and removed request for a team January 19, 2023 23:00
@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Merging #6006 (b1cec4f) into main (67194c4) will decrease coverage by 0.07%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6006      +/-   ##
==========================================
- Coverage   78.01%   77.94%   -0.07%     
==========================================
  Files         312      312              
  Lines       38997    38997              
==========================================
- Hits        30425    30398      -27     
- Misses       8572     8599      +27     

@teor2345 teor2345 changed the title fix(rpc): Avoid duplicate mempool transaction selection fix(rpc): Avoid duplicate transactions in block templates Jan 20, 2023
@teor2345 teor2345 changed the title fix(rpc): Avoid duplicate transactions in block templates fix(rpc): Avoid selecting duplicate transactions in block templates Jan 20, 2023
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks good, just a few tweaks for usability and maintenance.

How do you know this fix works?
Can you find a second reviewer for this PR?

@arya2 arya2 requested a review from oxarbitrage January 20, 2023 00:57
@arya2
Copy link
Contributor Author

arya2 commented Jan 20, 2023

Looks good, just a few tweaks for usability and maintenance.

How do you know this fix works?

It failed about 10 in ~30 tests before the change and 0 in ~20 tests after the change.

I checked the logic for the mempool and it shouldn't be returning any duplicate transactions, I also checked the hashes returned by the FullTransactions request several times to be sure that the duplicates were from the selection logic.

The new selection logic doesn't clone candidate transactions anymore so I think that guarantees against duplication there.

I tried to be thorough in confirming that the new logic works, I think update_weights wasn't behaving as expected due to subtracting floating point values from the total weight.

Can you find a second reviewer for this PR?

Good idea, I added @oxarbitrage as a reviewer.

Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

I think it looks good, i made a few manual calls and got no duplicates.

I was thinking on making a script that just runs getblocktemplate and check there are no duplicate transactions however i am not really sure if it worth it.

If we think it does, we can think on the test for it in a separated issue with lower priority.

@teor2345
Copy link
Contributor

Looks good, just a few tweaks for usability and maintenance.
How do you know this fix works?

It failed about 10 in ~30 tests before the change and 0 in ~20 tests after the change.

I checked the logic for the mempool and it shouldn't be returning any duplicate transactions, I also checked the hashes returned by the FullTransactions request several times to be sure that the duplicates were from the selection logic.

The new selection logic doesn't clone candidate transactions anymore so I think that guarantees against duplication there.

I tried to be thorough in confirming that the new logic works, I think update_weights wasn't behaving as expected due to subtracting floating point values from the total weight.

We already have a CI test PR that will catch this bug, so I don't think we need any other tests.

mergify bot added a commit that referenced this pull request Jan 23, 2023
@mergify mergify bot merged commit 53b4466 into main Jan 23, 2023
@mergify mergify bot deleted the gbt-fix-dup-tx branch January 23, 2023 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-rpc Area: Remote Procedure Call interfaces C-bug Category: This is a bug I-lose-funds Zebra loses user funds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zebra's block template can contain duplicate transactions
4 participants