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

RFC: Contextual Difficulty #1246

Merged
merged 42 commits into from
Nov 26, 2020

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Nov 4, 2020

Rendered

Status

First draft of reference-level design, focusing on the implementation.
Revised draft of summary, motivation, and guide-level explanation.

I haven't started the test plan yet.
There are some notes in the remaining sections.

Motivation

We need a design for contextual validation of the proof of work difficulty threshold.

Solution

The RFC should focus on Contextual Difficulty Validation, and summarise the Difficulty Validation Service Request in enough detail to justify the relevant design decisions.

Contextual Difficulty Validation - First Alpha

A synchronous contextual verifier that takes a block header (not a full block), and returns a Result that says if the difficulty threshold in the header matches the difficulty adjustment specified by the consensus rules.

Definitions

  • define proof of work, difficulty threshold, work, and cumulative work, and use them consistently
    • update the state RFC with the work definition
  • define and specify the relevant chain for the difficulty consensus rules

Consensus Rules

  • calculate the median proof of work of recent blocks
  • calculate the median time interval between recent blocks
  • scale the median proof of work based on the median time interval
  • allow minimum difficulty blocks on testnet, if the block time gap is larger than the minimum difficulty threshold

Guide-Level Explanation

  • Revised Draft

Detailed Reference Design

  • Implementation

Module Structure

  • implement adjustment calculations in zebra_chain::work::difficulty (existing module)
  • implement header validation in zebra_consensus::block::check
  • write module summary

Follow Up

Difficulty Validation Service Request - see #1166

Related Work

@teor2345 teor2345 added A-docs Area: Documentation C-design Category: Software design work A-consensus Area: Consensus rule updates labels Nov 4, 2020
@teor2345 teor2345 added this to the First Alpha Release milestone Nov 4, 2020
@teor2345 teor2345 self-assigned this Nov 4, 2020
@teor2345
Copy link
Contributor Author

teor2345 commented Nov 4, 2020

@yaahc can you do a quick review to make sure that the definitions and guide-level explanation fit with the current state service design?

In particular, the "relevant chain" for contextual validation needs to work with the non-finalised and finalised state.

I'll also get others to have a look when they have some time.

book/src/dev/rfcs/0006-contextual-difficulty.md Outdated Show resolved Hide resolved
book/src/dev/rfcs/0006-contextual-difficulty.md Outdated Show resolved Hide resolved
book/src/dev/rfcs/0006-contextual-difficulty.md Outdated Show resolved Hide resolved
book/src/dev/rfcs/0006-contextual-difficulty.md Outdated Show resolved Hide resolved
@teor2345 teor2345 mentioned this pull request Nov 5, 2020
6 tasks
Update the design based on the spec bugs in ZcashFoundation#1276, ZcashFoundation#1277, and
zcash/zips#416.

These changes make the difficulty filter into a context-free check,
so we remove it from this contextual validation RFC.
Includes most of the implementation, modules for each function, and
draft notes for some of the remaining parts of the RFC.
@teor2345 teor2345 force-pushed the contextual-difficulty-rfc branch from 39632e8 to ebc0fc2 Compare November 12, 2020 16:01
@teor2345 teor2345 marked this pull request as ready for review November 12, 2020 16:06
@teor2345
Copy link
Contributor Author

This design is now complete enough for an additional review.

The guide-level and reference-level explanations contain a substantially complete first draft.

And finish off the first draft of the RFC.
@teor2345 teor2345 requested a review from yaahc November 16, 2020 00:03
yaahc
yaahc previously approved these changes Nov 19, 2020
Copy link
Contributor

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

:shipit:

yaahc
yaahc previously approved these changes Nov 19, 2020
And fix the median_timespan_bounded comment
yaahc
yaahc previously approved these changes Nov 19, 2020
@teor2345
Copy link
Contributor Author

@yaahc I'm done with the implementation now, so there shouldn't be any more RFC changes.

(Or if there are, I'll open a new pull request.)

@mpguerra
Copy link
Contributor

Do we need another review from @yaahc or are we good to merge this one now?

Copy link
Contributor

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

👍

@teor2345 teor2345 merged commit fc7d37c into ZcashFoundation:main Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-docs Area: Documentation C-design Category: Software design work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants