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 peak height race #16776

Merged
merged 1 commit into from
Nov 8, 2023
Merged

Fix peak height race #16776

merged 1 commit into from
Nov 8, 2023

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Nov 5, 2023

Purpose:

When we add a block, there's a subtle co-routine suspension point in between updating the height-to-hash map and the peak height. There's a comment in the code to highlight this now.

This creates a window where a call to get_peak() fails because the peak height doesn't exist in height-to-hash map.

This is demonstrated in #16774 .

Traceback (most recent call last):
  File "/home/arvid/dev/3/chia-blockchain/tests/core/full_node/test_full_node.py", line 2195, in check_nodes_in_sync
    p2 = full_node_1.full_node.blockchain.get_peak()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arvid/dev/3/chia-blockchain/chia/consensus/blockchain.py", line 191, in get_peak
    return self.height_to_block_record(self._peak_height)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arvid/dev/3/chia-blockchain/chia/consensus/blockchain.py", line 697, in height_to_block_record
    if header_hash is None:
        ^^^^^^^^^^^^^^^^^^^^
ValueError: Height is not in blockchain: 1599

This patch moves the suspension point to make these updates to the height-to-hash map and peak_height atomic.
Then it's possible to remove the try-catch handler in the test.

Current Behavior:

get_peak() may throw an exception if called at an unfortunate time.

New Behavior:

get_peak() always work

@arvidn arvidn added the Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog label Nov 5, 2023
@arvidn arvidn force-pushed the fix-peak-height-race branch 2 times, most recently from 1aa3af3 to 7ddf4b8 Compare November 7, 2023 14:23
@github-actions github-actions bot added merge_conflict Branch has conflicts that prevent merge to main labels Nov 7, 2023
Copy link
Contributor

github-actions bot commented Nov 7, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

1 similar comment
Copy link
Contributor

github-actions bot commented Nov 7, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

…between updating the height-to-hash map and the peak height. This leaves a window for a call to get_peak() to fail, because the peak height doesn't exist in height-to-hash map. This patch moves the suspension point to make these updates atomic. This allows for removing a hack in a test, that previously had to catch this exception
@github-actions github-actions bot removed the merge_conflict Branch has conflicts that prevent merge to main label Nov 7, 2023
Copy link
Contributor

github-actions bot commented Nov 7, 2023

Conflicts have been resolved. A maintainer will review the pull request shortly.

@arvidn arvidn marked this pull request as ready for review November 7, 2023 17:11
@arvidn arvidn requested a review from a team as a code owner November 7, 2023 17:11
Copy link

Pull Request Test Coverage Report for Build 6787938941

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.003%) to 90.303%

Files with Coverage Reduction New Missed Lines %
chia/consensus/blockchain.py 1 94.5%
chia/full_node/full_node_api.py 1 77.41%
chia/server/node_discovery.py 1 79.9%
chia/server/server.py 1 81.45%
chia/timelord/timelord_launcher.py 1 69.77%
chia/full_node/full_node.py 2 84.56%
Totals Coverage Status
Change from base Build 6787911924: 0.003%
Covered Lines: 93088
Relevant Lines: 103035

💛 - Coveralls

@arvidn arvidn mentioned this pull request Nov 8, 2023
Copy link
Contributor

@wjblanke wjblanke left a comment

Choose a reason for hiding this comment

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

aok

@Starttoaster Starttoaster merged commit 5a1c15e into main Nov 8, 2023
254 checks passed
@Starttoaster Starttoaster deleted the fix-peak-height-race branch November 8, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants