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

Consensus: Proof of Work #3473

Merged
merged 59 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ea409c6
consensus-pow: init primtives and verifier
sorpaas Aug 23, 2019
ceb0595
consensus-pow: add total difficulty auxiliary
sorpaas Aug 23, 2019
634e789
consensus-pow: implement total difficulty chain selection
sorpaas Aug 23, 2019
19c215c
consensus-pow: implement pow import queue
sorpaas Aug 23, 2019
ba0d5c7
consensus-pow-primitives: add mine into PowApi
sorpaas Aug 23, 2019
6d78b8c
consensus-pow: implement mining
sorpaas Aug 23, 2019
ac6daab
Update lock file
sorpaas Aug 23, 2019
a94a48f
Style fixes
gavofyork Aug 24, 2019
286f260
consensus-pow: refactor register_pow_inherent_data_provider
sorpaas Aug 26, 2019
41d59d3
consensus-pow: make PowApi::mine yieldable
sorpaas Aug 26, 2019
766426f
consensus-pow: better mining loop
sorpaas Aug 26, 2019
a434955
Add missing license header
sorpaas Aug 26, 2019
69b0fc1
consensus-pow-primitives: clarify the meaning of None for PowApi::verify
sorpaas Aug 26, 2019
573c39f
consensus-pow: changing total difficulty addition to use saturating add
sorpaas Aug 26, 2019
dd85dae
consensus-pow: change mine-loop error to log on error! level
sorpaas Aug 26, 2019
67bda93
consensus-pow: allow inserting arbitrary preruntime digest for pow
sorpaas Aug 26, 2019
90e7639
Fix line width
sorpaas Aug 26, 2019
ccb1445
More line width fixes
sorpaas Aug 26, 2019
95d75d7
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas Aug 26, 2019
0198ae5
consensus-pow: separate difficulty, verify API
sorpaas Aug 27, 2019
b0134e0
srml-pow: implementation of average_span difficulty adjustment
sorpaas Aug 27, 2019
942cc9f
srml-pow: basic blake2 algo example
sorpaas Aug 27, 2019
dde1ea2
srml-pow-average-span: make it not require genesis config
sorpaas Aug 27, 2019
c68cee4
srml-pow: add support for authorship
sorpaas Aug 27, 2019
006005b
Missing license headers
sorpaas Aug 27, 2019
2abe98e
consensus-pow: PowAlgorithm trait generalization
sorpaas Aug 27, 2019
4171baf
Missing docs for consensus-pow
sorpaas Aug 27, 2019
43a3df8
More docs
sorpaas Aug 27, 2019
0e9b0b9
node-runtime: bump impl_version
sorpaas Aug 27, 2019
9551717
Add rationale for difficulty type
sorpaas Aug 27, 2019
4385df1
consensus-pow: refactor aux_key
sorpaas Aug 27, 2019
f62ae66
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas Aug 27, 2019
a7182cd
Update lock file
sorpaas Aug 27, 2019
7c3098d
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
4866949
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
fdc6e67
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
acc9d10
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
940eb3b
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
015893f
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
5ea5c1b
Update core/consensus/pow/src/lib.rs
sorpaas Aug 27, 2019
220963b
Update core/consensus/pow/primitives/src/lib.rs
sorpaas Aug 27, 2019
012b664
Update core/consensus/pow/primitives/src/lib.rs
sorpaas Aug 27, 2019
745d604
Remove PowRuntimeAlgorithm
sorpaas Aug 28, 2019
46d35a3
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas Aug 28, 2019
6086f3f
block_id -> parent_block_id
sorpaas Aug 29, 2019
221bcd6
Auxiliary data -> auxiliary storage data
sorpaas Aug 29, 2019
44e2885
Fix error message
sorpaas Aug 29, 2019
9c92009
Merge branch 'master' into pow
sorpaas Aug 29, 2019
68efcfe
Fix compile
sorpaas Aug 29, 2019
8d576c9
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas Aug 29, 2019
fb6344e
Update core/consensus/pow/primitives/src/lib.rs
sorpaas Aug 29, 2019
5ad5755
Update core/consensus/pow/src/lib.rs
sorpaas Aug 29, 2019
1a6cc58
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas Sep 2, 2019
20b1ab1
Update core/consensus/pow/primitives/src/lib.rs
sorpaas Sep 2, 2019
68316b6
Merge branch 'pow' of https://github.com/paritytech/substrate into pow
sorpaas Sep 2, 2019
bf1576b
Update core/consensus/pow/src/lib.rs
sorpaas Sep 4, 2019
910f173
Fix crate description
sorpaas Sep 5, 2019
4732737
More docs
sorpaas Sep 5, 2019
b227b98
Address grumbles
sorpaas Sep 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 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 Expand Up @@ -94,6 +95,7 @@ members = [
"srml/system",
"srml/timestamp",
"srml/treasury",
"srml/pow",
"node/cli",
"node/executor",
"node/primitives",
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",
]
71 changes: 71 additions & 0 deletions core/consensus/pow/primitives/src/lib.rs
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.
sorpaas marked this conversation as resolved.
Show resolved Hide resolved

#![cfg_attr(not(feature = "std"), no_std)]
sorpaas marked this conversation as resolved.
Show resolved Hide 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.
Show resolved Hide 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.
Show resolved Hide resolved
/// 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.
Show resolved Hide resolved
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,
) -> bool;

/// Mine a seal that satisfy the given difficulty.
fn mine(
pre_hash: &H256,
seed: &H256,
difficulty: Difficulty,
round: u32,
) -> Option<Seal>;
}
}
Loading