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(miner): Avoid some duplicate block errors #8150

Merged
merged 4 commits into from
Jan 12, 2024
Merged

fix(miner): Avoid some duplicate block errors #8150

merged 4 commits into from
Jan 12, 2024

Conversation

teor2345
Copy link
Contributor

Motivation

Sometimes one of Zebra's miners will:

  • submit a valid block
  • restart mining on the same template
  • submit a duplicate of that block

This happens when a valid solution is mined quickly, before the block has time to validate, and the template has time to refresh.

PR Author Checklist

Check before marking the PR as ready for review:

  • Will the PR name make sense to users?
  • Does the PR have a priority label?
  • Have you added or updated tests?
  • Is the documentation up to date?

If a checkbox isn't relevant to the PR, mark it as done.

Complex Code or Requirements

This is a pretty standard concurrency bug.

Solution

  • Decrease the time that the template generator waits between RPC calls to 2 seconds
  • When a miner is successful, make it wait for 3 seconds before restarting mining, for block verification and RPC template generation (this time can be increased if the bug still happens)
  • When a block fails, start re-mining after the standard 2 second rate-limit
  • Define a constant for the standard RPC and miner rate-limit, and another constant for the wait time after mining a block

Testing

I've tested this manually and it's no worse that the current code.

Review

This is a routine fix.

Reviewer Checklist

Check before approving the PR:

  • Does the PR scope match the ticket?
  • Are there enough tests to make sure it works? Do the tests cover the PR motivation?
  • Are all the PR blockers dealt with?
    PR blockers can be dealt with in new tickets or PRs.

And check the PR Author checklist is complete.

Follow Up Work

Adjust the constants as needed.

@teor2345 teor2345 added C-bug Category: This is a bug P-Medium ⚡ I-usability Zebra is hard to understand or use A-concurrency Area: Async code, needs extra work to make it work properly. labels Jan 11, 2024
@teor2345 teor2345 self-assigned this Jan 11, 2024
@teor2345 teor2345 requested review from a team as code owners January 11, 2024 23:38
@teor2345 teor2345 requested review from oxarbitrage and removed request for a team January 11, 2024 23:38
@teor2345
Copy link
Contributor Author

Waiting for SSH key to propagate.
ssh: connect to host 34.139.23.104 port 22: Connection refused
ERROR: (gcloud.compute.ssh) Could not SSH into the instance. It is possible that your SSH key has not propagated to the instance yet. Try running this command again. If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic.

https://github.com/ZcashFoundation/zebra/actions/runs/7495982068/job/20407505648?pr=8150#step:13:117

Let's restart this when the other jobs finish.

arya2
arya2 previously approved these changes Jan 12, 2024
Cargo.lock Outdated Show resolved Hide resolved
@teor2345
Copy link
Contributor Author

I manually tested this and there weren't any duplicate blocks after 2 hours of mining on 2 threads.

There is the occasional duplicate indexes error from equihash, but that might be a known issue. Or maybe the latest C code fixes will fix it.

@mergify mergify bot merged commit 54c702e into main Jan 12, 2024
127 checks passed
@mergify mergify bot deleted the solver-dups branch January 12, 2024 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Async code, needs extra work to make it work properly. C-bug Category: This is a bug I-usability Zebra is hard to understand or use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants