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

MARF'ed Nakamoto chainstate #4930

Merged
merged 91 commits into from
Jul 11, 2024
Merged

MARF'ed Nakamoto chainstate #4930

merged 91 commits into from
Jul 11, 2024

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Jun 29, 2024

This PR addresses #4810 and #4900 by computing the block hash of a Nakamoto block as its signer sighash. That is, Nakamoto blocks no longer commit to signer signatures. This change vastly simplifies the task of the signers to agree on whether or not a block is part of the canonical fork -- they do not need to agree on which of them signed and which did not, and they can compute a valid block signature by obtaining a threshold of any set of signatures independently of the miner.

In addition, this PR addresses block malleability by MARF'ing the Nakamoto chainstate. Now, queries on tenures, tenure-start blocks, and other chainstate data that is not directly keyed to a specific Nakamoto block are carried out relative to a Nakamoto chain tip. The chainstate DB now tracks per-fork data about tenures, instead of naively assuming that there will be one valid history of tenure-changes per Bitcoin fork.

This change makes the Stacks blockchain much more robust in the face of Nakamoto forks, which can arise for unavoidable but benign reasons, such as when a tenure-start block for a short-lived sortition is being processed concurrently with a new sortition (in which case, the orphaned tenure-start block would be accepted into the chainstate even though it conflicts with a Nakamoto block at the same height). Furthermore, should there ever arise multiple Nakamoto forks for any reason (due to a bug, a policy, or a benign cause), the node's chainstate will remain in a consistent and usable state.

In doing so, this change completely separates policy from mechanism regarding fork selection. It places the burden of deciding which Nakamoto forks can be built upon exclusively on the signers (a policy), and makes the Stacks node amenable to handling any such forks regardless of how they arise, without complaint (a mechanism for effecting a fork-choice policy).

… actually higher than the memoized fork, and also, add get_nakamoto_tip_block_id() to SortitionHandle to facilitate querying the canonical Nakamoto tip
… chains coordinator requires querying it from the canonical fork memoized in the sortition DB. The reason I think this is safe here (and only here) is because forks can't happen arbitrarily. The memoized tip at the end of the prepare phase is practically guaranteed to point to the same reward set on all nodes, since the reward set is calculated at the start of the prepare phase.
…m elsewhere), and use malleablized blocks in the 10-sortitions-with-10-blocks-and-extensions test
…ecifically by a block ID must be carried out relative to a designated chain tip. Adds support for MARF'ing all the data for all affected methods, and rewrites all affected methods to use it.
… obtain method for blocks, and rewrite all methods to use the MARF for queries that are not specific to a block ID
… field and change its primary key. A tenure is recorded for a given block with a tenure change.
… test, so we can simulate the presence of multiple (!!) nakamoto forks per Bitcoin fork and verify that the node still behaves correctly. Also, add torture tests for MARF'ed methods, to be performed for each processed block.
…hainstate within a particular fork, and deduce when we're ready to process unconfirmed tenures by the absence of confirmed tenure downloaders
@jcnelson
Copy link
Member Author

So, the nakamoto_attempt_time integration test passes locally, but it takes 31 minutes to run. It might intermittently fail CI.

Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

Just a couple comments, otherwise looks good to me.

@jcnelson jcnelson requested a review from kantai July 11, 2024 20:39
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! 🎉

…state DBs since a node may be stopped and restarted during genesis sync (and failure to accept DB version 6 would lead to a panic)
@jcnelson jcnelson enabled auto-merge July 11, 2024 21:04
@jcnelson jcnelson added this pull request to the merge queue Jul 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 11, 2024
@saralab saralab added this pull request to the merge queue Jul 11, 2024
Merged via the queue into develop with commit 3001794 Jul 11, 2024
1 check passed
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants