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

hotfix: remove chain stall race condition #5508

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Nov 27, 2024

This fixes a race condition in the block proposal API endpoint whereby the node was incorrectly loading the sortition view from its view of the canonical sortition tip, instead of the sortition tip identified by the block's header's consensus_hash field. Doing this lead to a chain-halt due to a race condition.

Here's what I'm pretty sure happened, but could use some extra validation:

  1. Bitcoin blocks 872,121 and 872,122 arrived very closely to each other on all Stacks nodes
  2. The miner who won sortition in 872,121 produced a block in the tenure for 872,121, but used the sortition view of 872,122 to produce the block (this is a bug).
  3. The signers successfully validated Stacks block 264,671 against Bitcoin block 872,122, since that was the canonical tip (this is also a bug). This block happened to have a contract-call transaction whose execution depends on burn-block-height
  4. The signers signed Stacks block 264,671 and broadcasted it
  5. Stacks nodes all failed to append 264,671 because they validate it against the sortition view defined by the block's tenure (which was 872,121).
  6. The chain stalled because all signers had marked 264,671 as globally accepted even though it would later prove to be invalid, and would never accept a sibling block

@jcnelson jcnelson requested a review from a team as a code owner November 27, 2024 03:38
hstove
hstove previously approved these changes Nov 27, 2024
Copy link
Contributor

@hstove hstove left a comment

Choose a reason for hiding this comment

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

Overall this LGTM! Great find and the fix in the validation endpoint makes a lot of sense.

testnet/stacks-node/src/nakamoto_node/miner.rs Outdated Show resolved Hide resolved
@jcnelson
Copy link
Member Author

@hstove Hmm I'm not sure. Is this change necessary? I'm not sure that self.burn_block is the tip (ie in the case of a tenure extend), I'll have to look into it more in the morning.

Ah, yes, you're right -- self.burn_tip is the sortition of the TenureExtend's burn view (if continuing a tenure), or is the same as the burn election snapshot (if starting a new tenure). Will revert.

jferrant
jferrant previously approved these changes Nov 27, 2024
obycode
obycode previously approved these changes Nov 27, 2024
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

🙌

@jcnelson
Copy link
Member Author

Todo: the proposal validation logic needs to load the current burn view -- it's either the burn view in the block's Extend-type TenureChange if present, or the parent block's burn view if absent.

@jcnelson jcnelson dismissed stale reviews from obycode and jferrant via f56bfc7 November 27, 2024 18:41
jferrant
jferrant previously approved these changes Nov 27, 2024
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants