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

Cumulative fixes to make working with consensus-pow easier #3617

Merged
merged 29 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0f894f0
consensus-pow: add difficulty data to auxiliary
sorpaas Sep 14, 2019
debbb5b
Timestamp api
sorpaas Sep 14, 2019
62fb99a
Implement FinalityProofProvider for ()
sorpaas Sep 14, 2019
fcb81d7
Add DifficultyApi
sorpaas Sep 17, 2019
74b3634
Remove assumption that Difficulty is u128
sorpaas Sep 19, 2019
a1b49b1
Use a separate trait for add instead of hard-code it as Saturating
sorpaas Sep 19, 2019
9775ece
Some convenience functions to work with PowVerifier
sorpaas Sep 20, 2019
526b860
Try to fix mining unstability
sorpaas Sep 20, 2019
912c032
Fix generic resolution
sorpaas Sep 20, 2019
4beec1a
Unused best_header variable
sorpaas Sep 20, 2019
ff7a3f8
Fix hash calculation
sorpaas Sep 20, 2019
a484830
Remove artificial sleep
sorpaas Sep 20, 2019
58395dc
Tweak proposer waiting time
sorpaas Sep 20, 2019
f431d63
Revert sleep removal
sorpaas Sep 20, 2019
53e8bea
Pass sync oracle to mining
sorpaas Sep 20, 2019
e417b3f
Expose build time as a parameter
sorpaas Sep 20, 2019
547112b
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas Sep 21, 2019
f9b76ec
Update lock file
sorpaas Sep 21, 2019
fb71f77
Fix compile
sorpaas Sep 21, 2019
8888f16
Support skipping check_inherents for ancient blocks
sorpaas Sep 22, 2019
23bbb53
Move difficulty fetch function out of loop
sorpaas Sep 23, 2019
b8745ba
Remove seed from mining
sorpaas Sep 24, 2019
bf26edf
Better comments
sorpaas Sep 24, 2019
d94fe48
Add TotalDifficulty definition for U256 and u128
sorpaas Sep 24, 2019
1719905
Update core/consensus/pow/src/lib.rs
sorpaas Oct 3, 2019
96d6a7e
Rename TotalDifficulty::add -> increment
sorpaas Oct 3, 2019
bf76102
Use SelectChain to fetch the best header/hash
sorpaas Oct 3, 2019
dd428de
Merge branch 'master' of https://github.com/paritytech/substrate into…
sorpaas Oct 3, 2019
7229cd0
Update lock file
sorpaas Oct 3, 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
2 changes: 2 additions & 0 deletions core/consensus/pow/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }

[features]
default = ["std"]
Expand All @@ -18,4 +19,5 @@ std = [
"substrate-client/std",
"sr-primitives/std",
"primitives/std",
"codec/std",
]
10 changes: 10 additions & 0 deletions core/consensus/pow/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

use rstd::vec::Vec;
use sr_primitives::ConsensusEngineId;
use codec::Decode;
use substrate_client::decl_runtime_apis;

/// The `ConsensusEngineId` of PoW.
pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_'];
Expand All @@ -34,3 +36,11 @@ pub type Difficulty = u128;

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

decl_runtime_apis! {
/// API necessary for timestamp-based difficulty adjustment algorithms.
pub trait TimestampApi<Moment: Decode> {
/// Return the timestamp in the current block.
fn timestamp() -> Moment;
}
}
4 changes: 4 additions & 0 deletions core/consensus/pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fn aux_key(hash: &H256) -> Vec<u8> {
/// Auxiliary storage data for PoW.
#[derive(Encode, Decode, Clone, Debug, Default)]
pub struct PowAux {
/// Difficulty.
pub difficulty: Difficulty,
sorpaas marked this conversation as resolved.
Show resolved Hide resolved
/// Total difficulty.
pub total_difficulty: Difficulty,
}
Expand Down Expand Up @@ -208,6 +210,7 @@ impl<B: BlockT<Hash=H256>, C, Algorithm> Verifier<B> for PowVerifier<C, Algorith
header,
BlockId::Hash(parent_hash),
)?;
aux.difficulty = difficulty;
aux.total_difficulty = aux.total_difficulty.saturating_add(difficulty);

if let Some(inner_body) = body.take() {
Expand Down Expand Up @@ -396,6 +399,7 @@ fn mine_loop<B: BlockT<Hash=H256>, C, Algorithm, E>(
}
};

aux.difficulty = difficulty;
aux.total_difficulty = aux.total_difficulty.saturating_add(difficulty);
let hash = header.hash();

Expand Down
6 changes: 6 additions & 0 deletions core/network/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pub trait FinalityProofProvider<Block: BlockT>: Send + Sync {
fn prove_finality(&self, for_block: Block::Hash, request: &[u8]) -> Result<Option<Vec<u8>>, Error>;
}

impl<Block: BlockT> FinalityProofProvider<Block> for () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the finality proof provider is optional when creating the service.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try to provide a reproducible test case, but I think what I had trouble with is that if I remove .with_finality_proof_provider for the service builder, the whole type resolution will fail. But maybe we should fix that instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I see, it will fail to infer the generic type of the optional finality proof provider.

fn prove_finality(&self, _for_block: Block::Hash, _request: &[u8]) -> Result<Option<Vec<u8>>, Error> {
Ok(None)
}
}

impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static,
Expand Down