This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Merged
Consensus: Proof of Work #3473
Changes from 33 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
ea409c6
consensus-pow: init primtives and verifier
sorpaas ceb0595
consensus-pow: add total difficulty auxiliary
sorpaas 634e789
consensus-pow: implement total difficulty chain selection
sorpaas 19c215c
consensus-pow: implement pow import queue
sorpaas ba0d5c7
consensus-pow-primitives: add mine into PowApi
sorpaas 6d78b8c
consensus-pow: implement mining
sorpaas ac6daab
Update lock file
sorpaas a94a48f
Style fixes
gavofyork 286f260
consensus-pow: refactor register_pow_inherent_data_provider
sorpaas 41d59d3
consensus-pow: make PowApi::mine yieldable
sorpaas 766426f
consensus-pow: better mining loop
sorpaas a434955
Add missing license header
sorpaas 69b0fc1
consensus-pow-primitives: clarify the meaning of None for PowApi::verify
sorpaas 573c39f
consensus-pow: changing total difficulty addition to use saturating add
sorpaas dd85dae
consensus-pow: change mine-loop error to log on error! level
sorpaas 67bda93
consensus-pow: allow inserting arbitrary preruntime digest for pow
sorpaas 90e7639
Fix line width
sorpaas ccb1445
More line width fixes
sorpaas 95d75d7
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas 0198ae5
consensus-pow: separate difficulty, verify API
sorpaas b0134e0
srml-pow: implementation of average_span difficulty adjustment
sorpaas 942cc9f
srml-pow: basic blake2 algo example
sorpaas dde1ea2
srml-pow-average-span: make it not require genesis config
sorpaas c68cee4
srml-pow: add support for authorship
sorpaas 006005b
Missing license headers
sorpaas 2abe98e
consensus-pow: PowAlgorithm trait generalization
sorpaas 4171baf
Missing docs for consensus-pow
sorpaas 43a3df8
More docs
sorpaas 0e9b0b9
node-runtime: bump impl_version
sorpaas 9551717
Add rationale for difficulty type
sorpaas 4385df1
consensus-pow: refactor aux_key
sorpaas f62ae66
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas a7182cd
Update lock file
sorpaas 7c3098d
Update core/consensus/pow/src/lib.rs
sorpaas 4866949
Update core/consensus/pow/src/lib.rs
sorpaas fdc6e67
Update core/consensus/pow/src/lib.rs
sorpaas acc9d10
Update core/consensus/pow/src/lib.rs
sorpaas 940eb3b
Update core/consensus/pow/src/lib.rs
sorpaas 015893f
Update core/consensus/pow/src/lib.rs
sorpaas 5ea5c1b
Update core/consensus/pow/src/lib.rs
sorpaas 220963b
Update core/consensus/pow/primitives/src/lib.rs
sorpaas 012b664
Update core/consensus/pow/primitives/src/lib.rs
sorpaas 745d604
Remove PowRuntimeAlgorithm
sorpaas 46d35a3
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas 6086f3f
block_id -> parent_block_id
sorpaas 221bcd6
Auxiliary data -> auxiliary storage data
sorpaas 44e2885
Fix error message
sorpaas 9c92009
Merge branch 'master' into pow
sorpaas 68efcfe
Fix compile
sorpaas 8d576c9
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas fb6344e
Update core/consensus/pow/primitives/src/lib.rs
sorpaas 5ad5755
Update core/consensus/pow/src/lib.rs
sorpaas 1a6cc58
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas 20b1ab1
Update core/consensus/pow/primitives/src/lib.rs
sorpaas 68316b6
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas bf1576b
Update core/consensus/pow/src/lib.rs
sorpaas 910f173
Fix crate description
sorpaas 4732737
More docs
sorpaas b227b98
Address grumbles
sorpaas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [package] | ||
| name = "substrate-consensus-pow" | ||
| version = "2.0.0" | ||
| authors = ["Parity Technologies <admin@parity.io>"] | ||
| description = "PoW consensus algorithm for substrate" | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } | ||
| primitives = { package = "substrate-primitives", path = "../../primitives" } | ||
| sr-primitives = { path = "../../sr-primitives" } | ||
| client = { package = "substrate-client", path = "../../client" } | ||
| srml-timestamp = { path = "../../../srml/timestamp" } | ||
| inherents = { package = "substrate-inherents", path = "../../inherents" } | ||
| pow-primitives = { package = "substrate-consensus-pow-primitives", path = "primitives" } | ||
| consensus-common = { package = "substrate-consensus-common", path = "../common" } | ||
| log = "0.4" | ||
| futures-preview = { version = "=0.3.0-alpha.17", features = ["compat"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [package] | ||
| name = "substrate-consensus-pow-primitives" | ||
| version = "2.0.0" | ||
| authors = ["Parity Technologies <admin@parity.io>"] | ||
| description = "Primitives for Aura consensus" | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| substrate-client = { path = "../../../client", default-features = false } | ||
| rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } | ||
| sr-primitives = { path = "../../../sr-primitives", default-features = false } | ||
| primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "rstd/std", | ||
| "substrate-client/std", | ||
| "sr-primitives/std", | ||
| "primitives/std", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright 2017-2019 Parity Technologies (UK) Ltd. | ||
| // This file is part of Substrate. | ||
|
|
||
| // Substrate is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Primitives for Substrate PoW consensus. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
sorpaas marked this conversation as resolved.
|
||
|
|
||
| use substrate_client::decl_runtime_apis; | ||
| use rstd::vec::Vec; | ||
| use sr_primitives::ConsensusEngineId; | ||
| use primitives::H256; | ||
|
|
||
| /// The `ConsensusEngineId` of PoW. | ||
| pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_']; | ||
|
sorpaas marked this conversation as resolved.
|
||
|
|
||
| /// Type of difficulty. | ||
| /// | ||
| /// For runtime designed for Substrate, it's always possible to fit its total | ||
| /// difficulty range under `u128::max_value()` because it can be freely scaled | ||
| /// up or scaled down. Practially, nearly no PoW chains uses difficulty values | ||
|
sorpaas marked this conversation as resolved.
Outdated
|
||
| /// larger than `u128::max_value()`. | ||
| pub type Difficulty = u128; | ||
|
|
||
| /// Type of seal. | ||
| pub type Seal = Vec<u8>; | ||
|
|
||
| decl_runtime_apis! { | ||
| /// API necessary for block authorship with Proof of Work. | ||
| /// | ||
| /// This API allows online upgrades of PoW algorithms as well as the difficulty | ||
| /// adjustment algorithm. Note that we always validate difficulty and seals | ||
| /// against the parent block. This means that in the case of code upgrade, the | ||
| /// first block that upgraded the code will still use the old algorithm. The block | ||
| /// after that will switch to the new algorithm. | ||
| /// | ||
| /// All functions here should not modify block state. Instead, state modifications | ||
| /// related to PoW should use `on_initialize` and `on_finalize` routine. | ||
|
sorpaas marked this conversation as resolved.
Outdated
|
||
| pub trait PowApi { | ||
| /// Return the difficulty that should be applied for the next block. | ||
| fn difficulty() -> Difficulty; | ||
|
|
||
| /// Verify a given proof of work against the given difficulty. | ||
| /// Note that `pre_hash` is always a hash of a direct child. | ||
| fn verify( | ||
| pre_hash: &H256, | ||
| seal: &Seal, | ||
| difficulty: Difficulty | ||
|
sorpaas marked this conversation as resolved.
Outdated
|
||
| ) -> bool; | ||
|
|
||
| /// Mine a seal that satisfy the given difficulty. | ||
| fn mine( | ||
| pre_hash: &H256, | ||
| seed: &H256, | ||
| difficulty: Difficulty, | ||
| round: u32 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sorpaas marked this conversation as resolved.
Outdated
|
||
| ) -> Option<Seal>; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.