Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Consensus: Proof of Work (#3473)
Browse files Browse the repository at this point in the history
* consensus-pow: init primtives and verifier

* consensus-pow: add total difficulty auxiliary

* consensus-pow: implement total difficulty chain selection

* consensus-pow: implement pow import queue

* consensus-pow-primitives: add mine into PowApi

* consensus-pow: implement mining

* Update lock file

* Style fixes

No run-on expressions allowed.

* consensus-pow: refactor register_pow_inherent_data_provider

* consensus-pow: make PowApi::mine yieldable

* consensus-pow: better mining loop

* Add missing license header

* consensus-pow-primitives: clarify the meaning of None for PowApi::verify

* consensus-pow: changing total difficulty addition to use saturating add

* consensus-pow: change mine-loop error to log on error! level

* consensus-pow: allow inserting arbitrary preruntime digest for pow

The preruntime digest can be intepreted by the runtime as the block author/coinbase.

* Fix line width

* More line width fixes

* consensus-pow: separate difficulty, verify API

This makes it more apparent that currently in PoW engine, `difficulty` should
be input, not output.

* srml-pow: implementation of average_span difficulty adjustment

* srml-pow: basic blake2 algo example

* srml-pow-average-span: make it not require genesis config

* srml-pow: add support for authorship

* Missing license headers

* consensus-pow: PowAlgorithm trait generalization

* Missing docs for consensus-pow

* More docs

* node-runtime: bump impl_version

* Add rationale for difficulty type

* consensus-pow: refactor aux_key

* Update lock file

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/primitives/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Update core/consensus/pow/primitives/src/lib.rs

Co-Authored-By: Sergei Pepyakin <[email protected]>

* Remove PowRuntimeAlgorithm

* block_id -> parent_block_id

* Auxiliary data -> auxiliary storage data

* Fix error message

* Fix compile

* Update core/consensus/pow/primitives/src/lib.rs

Co-Authored-By: DemiMarie-parity <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: DemiMarie-parity <[email protected]>

* Update core/consensus/pow/primitives/src/lib.rs

Co-Authored-By: DemiMarie-parity <[email protected]>

* Update core/consensus/pow/src/lib.rs

Co-Authored-By: DemiMarie-parity <[email protected]>

* Fix crate description

* More docs

* Address grumbles

1. Make preruntime Optional.
2. Add more docs on what is `preruntie` and `round`.
3. Replace `Default::default` with the approriate type.
  • Loading branch information
sorpaas authored Sep 6, 2019
1 parent 499a88c commit b9e1782
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"core/consensus/rhd",
"core/consensus/slots",
"core/consensus/uncles",
"core/consensus/pow",
"core/executor",
"core/executor/runtime-test",
"core/finality-grandpa",
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/aura/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
substrate-client = { path = "../../../client", default-features = false }
app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }

[features]
default = ["std"]
Expand Down
18 changes: 18 additions & 0 deletions core/consensus/pow/Cargo.toml
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 <[email protected]>"]
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"] }
21 changes: 21 additions & 0 deletions core/consensus/pow/primitives/Cargo.toml
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 <[email protected]>"]
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",
]
36 changes: 36 additions & 0 deletions core/consensus/pow/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 Proof-of-Work (PoW) consensus.
#![cfg_attr(not(feature = "std"), no_std)]

use rstd::vec::Vec;
use sr_primitives::ConsensusEngineId;

/// The `ConsensusEngineId` of PoW.
pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_'];

/// 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. Very few PoW chains use difficulty values
/// larger than `u128::max_value()`.
pub type Difficulty = u128;

/// Type of seal.
pub type Seal = Vec<u8>;
Loading

0 comments on commit b9e1782

Please sign in to comment.