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

ZIP-221: Validate chain history commitments in the non-finalized state #2135

Closed
6 tasks
mpguerra opened this issue May 11, 2021 · 3 comments · Fixed by #2396
Closed
6 tasks

ZIP-221: Validate chain history commitments in the non-finalized state #2135

mpguerra opened this issue May 11, 2021 · 3 comments · Fixed by #2396
Assignees
Labels
C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks S-needs-design Status: Needs a design decision

Comments

@mpguerra
Copy link
Contributor

mpguerra commented May 11, 2021

Is your feature request related to a problem?

In order to implement ZIP-221 in Zebra, we will need to update our implementation of Zebra state for non-finalized chains, and validate chain history commitments in the non-finalized state.

Describe the solution you'd like

Maintaining history

  • Add a history MMR data field to the Chain type
    • this stores the MMR history for each non-finalized tip
  • When adding a block to a non-finalized tip:
  • When forking a new side-chain:
    • clone the list of MMR entries
    • rollback blocks using Zebra's API for Tree::truncate_leaf
    • add blocks using Zebra's API for Tree::append_leaf
    • prune unused entries using Zebra's pruning function

Contextual validation of non-checkpoint blocks

  • Add a post-fork contextual validation function to the check module
  • Call it from commit_block and commit_new_chain, right before we add the block to the chain
  • Check that the history commitment from the history MMR matches the history commitment in the block header
    • if it doesn't, return a new BlockError variant

Describe alternatives you've considered

We could re-calculate each side-chain starting from the finalized tip.

We could keep the (non-finalized) leaf nodes for each non-finalized block, and share forked block state using Arc or im. However this:

  • costs some RAM
  • should only be done as part of a redesign that avoids rollbacks entirely

Additional context

See #2091 (comment) for further details

@mpguerra mpguerra added NU Genesis Network Upgrade: Genesis block specific tasks C-enhancement Category: This is an improvement S-needs-triage Status: A bug report needs triage NU-5 Network Upgrade: NU5 specific tasks labels May 11, 2021
@mpguerra mpguerra added S-needs-design Status: Needs a design decision P-Medium and removed NU Genesis Network Upgrade: Genesis block specific tasks S-needs-triage Status: A bug report needs triage labels May 11, 2021
@mpguerra mpguerra added this to the 2021 Sprint 11 - Zcon2 milestone May 13, 2021
@teor2345
Copy link
Contributor

teor2345 commented Jun 2, 2021

We need the sapling tree root for this change, so testing and full implementation are blocked by the sapling part of #1287.

@teor2345 teor2345 changed the title ZIP-221: Update Zebra state implementation for non-finalized chains ZIP-221: Validate chain history in the non-finalized state Jun 14, 2021
@teor2345 teor2345 changed the title ZIP-221: Validate chain history in the non-finalized state ZIP-221: Validate chain history commitments in the non-finalized state Jun 14, 2021
@conradoplg conradoplg mentioned this issue Jun 25, 2021
3 tasks
@mpguerra mpguerra linked a pull request Jun 29, 2021 that will close this issue
3 tasks
@teor2345
Copy link
Contributor

teor2345 commented Jul 8, 2021

#2396 does not actually close this ticket

@teor2345 teor2345 reopened this Jul 8, 2021
@conradoplg
Copy link
Collaborator

#2562 ended up being similar to this

I think this one can be closed by #2609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks S-needs-design Status: Needs a design decision
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants