mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01:02 +00:00
Migrate finality-grandpa to the 2018 edition (#1797)
This commit is contained in:
committed by
Robert Habermeier
parent
c122e8eee8
commit
34e3487035
@@ -2,33 +2,31 @@
|
||||
name = "substrate-finality-grandpa"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1"
|
||||
parity-codec = "3.0"
|
||||
parity-codec-derive = "3.0"
|
||||
sr-primitives = { path = "../sr-primitives" }
|
||||
substrate-consensus-common = { path = "../consensus/common" }
|
||||
substrate-primitives = { path = "../primitives" }
|
||||
substrate-client = { path = "../client" }
|
||||
substrate-network = { path = "../network" }
|
||||
substrate-service = { path = "../service", optional = true }
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
tokio = "0.1.7"
|
||||
substrate-finality-grandpa-primitives = { path = "primitives" }
|
||||
rand = "0.6"
|
||||
|
||||
[dependencies.finality-grandpa]
|
||||
version = "0.6.0"
|
||||
features = ["derive-codec"]
|
||||
parity-codec = "3.0"
|
||||
parity-codec-derive = "3.0"
|
||||
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" }
|
||||
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" }
|
||||
substrate-primitives = { path = "../primitives" }
|
||||
client = { package = "substrate-client", path = "../client" }
|
||||
network = { package = "substrate-network", path = "../network" }
|
||||
service = { package = "substrate-service", path = "../service", optional = true }
|
||||
fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "primitives" }
|
||||
grandpa = { package = "finality-grandpa", version = "0.6.0", features = ["derive-codec"] }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-network = { path = "../network", features = ["test-helpers"] }
|
||||
substrate-keyring = { path = "../keyring" }
|
||||
substrate-test-client = { path = "../test-client"}
|
||||
network = { package = "substrate-network", path = "../network", features = ["test-helpers"] }
|
||||
keyring = { package = "substrate-keyring", path = "../keyring" }
|
||||
test_client = { package = "substrate-test-client", path = "../test-client"}
|
||||
env_logger = "0.6"
|
||||
|
||||
[features]
|
||||
default = ["service-integration"]
|
||||
service-integration = ["substrate-service"]
|
||||
service-integration = ["service"]
|
||||
|
||||
@@ -2,22 +2,23 @@
|
||||
name = "substrate-finality-grandpa-primitives"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
substrate-client = { path = "../../client", default-features = false }
|
||||
client = { package = "substrate-client", path = "../../client", default-features = false }
|
||||
substrate-primitives = { path = "../../primitives", default-features = false }
|
||||
parity-codec = { version = "3.0", default-features = false }
|
||||
parity-codec-derive = { version = "3.0", default-features = false }
|
||||
sr-primitives = { path = "../../sr-primitives", default-features = false }
|
||||
sr-std = { path = "../../sr-std", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"substrate-primitives/std",
|
||||
"substrate-client/std",
|
||||
"client/std",
|
||||
"parity-codec/std",
|
||||
"parity-codec-derive/std",
|
||||
"sr-primitives/std",
|
||||
"sr-std/std",
|
||||
"rstd/std",
|
||||
]
|
||||
|
||||
@@ -22,20 +22,10 @@
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
extern crate substrate_primitives;
|
||||
extern crate sr_primitives;
|
||||
extern crate parity_codec;
|
||||
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_client as client;
|
||||
|
||||
extern crate sr_std as rstd;
|
||||
|
||||
use parity_codec_derive::{Encode, Decode};
|
||||
use substrate_primitives::Ed25519AuthorityId;
|
||||
use sr_primitives::traits::{DigestFor, NumberFor};
|
||||
use client::decl_runtime_apis;
|
||||
use rstd::vec::Vec;
|
||||
|
||||
/// A scheduled change of authority set.
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
use parking_lot::RwLock;
|
||||
use substrate_primitives::Ed25519AuthorityId;
|
||||
use grandpa::VoterSet;
|
||||
use parity_codec_derive::{Encode, Decode};
|
||||
use log::{debug, info};
|
||||
|
||||
use std::cmp::Ord;
|
||||
use std::fmt::Debug;
|
||||
@@ -276,7 +278,7 @@ impl<H, N: Add<Output=N> + Clone> PendingChange<H, N> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn ignore_existing_changes<A>(_a: &A) -> Result<(), ::Error> {
|
||||
fn ignore_existing_changes<A>(_a: &A) -> Result<(), crate::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,12 @@ use std::sync::Arc;
|
||||
use grandpa::VoterSet;
|
||||
use futures::prelude::*;
|
||||
use futures::sync::mpsc;
|
||||
use codec::{Encode, Decode};
|
||||
use log::{debug, trace};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use substrate_primitives::{ed25519, Ed25519AuthorityId};
|
||||
use runtime_primitives::traits::Block as BlockT;
|
||||
use tokio::timer::Interval;
|
||||
use {Error, Network, Message, SignedMessage, Commit, CompactCommit};
|
||||
use crate::{Error, Network, Message, SignedMessage, Commit, CompactCommit};
|
||||
|
||||
fn localized_payload<E: Encode>(round: u64, set_id: u64, message: &E) -> Vec<u8> {
|
||||
(message, round, set_id).encode()
|
||||
@@ -245,9 +246,9 @@ pub(crate) fn check_message_sig<Block: BlockT>(
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
) -> Result<(), ()> {
|
||||
let as_public = ::ed25519::Public::from_raw(id.0);
|
||||
let as_public = ed25519::Public::from_raw(id.0);
|
||||
let encoded_raw = localized_payload(round, set_id, message);
|
||||
if ::ed25519::verify_strong(signature, &encoded_raw, as_public) {
|
||||
if ed25519::verify_strong(signature, &encoded_raw, as_public) {
|
||||
Ok(())
|
||||
} else {
|
||||
debug!(target: "afg", "Bad signature on message from {:?}", id);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use parity_codec_derive::{Encode, Decode};
|
||||
|
||||
/// Consensus-related data changes tracker.
|
||||
#[derive(Clone, Debug, Encode, Decode)]
|
||||
|
||||
@@ -18,7 +18,8 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use codec::Encode;
|
||||
use log::{debug, warn, info};
|
||||
use parity_codec::Encode;
|
||||
use futures::prelude::*;
|
||||
use tokio::timer::Delay;
|
||||
|
||||
@@ -38,10 +39,10 @@ use crate::{
|
||||
AUTHORITY_SET_KEY, CONSENSUS_CHANGES_KEY, LAST_COMPLETED_KEY,
|
||||
Commit, Config, Error, Network, Precommit, Prevote, LastCompleted,
|
||||
};
|
||||
use authorities::{AuthoritySet, SharedAuthoritySet};
|
||||
use consensus_changes::SharedConsensusChanges;
|
||||
use justification::GrandpaJustification;
|
||||
use until_imported::UntilVoteTargetImported;
|
||||
use crate::authorities::{AuthoritySet, SharedAuthoritySet};
|
||||
use crate::consensus_changes::SharedConsensusChanges;
|
||||
use crate::justification::GrandpaJustification;
|
||||
use crate::until_imported::UntilVoteTargetImported;
|
||||
|
||||
/// The environment we run GRANDPA in.
|
||||
pub(crate) struct Environment<B, E, Block: BlockT, N: Network<Block>, RA> {
|
||||
@@ -246,7 +247,7 @@ impl<B, E, Block: BlockT<Hash=H256>, N, RA> voter::Environment<Block::Hash, Numb
|
||||
let prevote_timer = Delay::new(now + self.config.gossip_duration * 2);
|
||||
let precommit_timer = Delay::new(now + self.config.gossip_duration * 4);
|
||||
|
||||
let incoming = ::communication::checked_message_stream::<Block, _>(
|
||||
let incoming = crate::communication::checked_message_stream::<Block, _>(
|
||||
round,
|
||||
self.set_id,
|
||||
self.network.messages_for(round, self.set_id),
|
||||
@@ -256,7 +257,7 @@ impl<B, E, Block: BlockT<Hash=H256>, N, RA> voter::Environment<Block::Hash, Numb
|
||||
let local_key = self.config.local_key.as_ref()
|
||||
.filter(|pair| self.voters.contains_key(&pair.public().into()));
|
||||
|
||||
let (out_rx, outgoing) = ::communication::outgoing_messages::<Block, _>(
|
||||
let (out_rx, outgoing) = crate::communication::outgoing_messages::<Block, _>(
|
||||
round,
|
||||
self.set_id,
|
||||
local_key.cloned(),
|
||||
|
||||
@@ -36,7 +36,8 @@ use client::{
|
||||
error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult},
|
||||
light::fetcher::RemoteCallRequest,
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use parity_codec_derive::{Encode, Decode};
|
||||
use grandpa::BlockNumberOps;
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{
|
||||
@@ -44,7 +45,7 @@ use runtime_primitives::traits::{
|
||||
};
|
||||
use substrate_primitives::{Ed25519AuthorityId, H256};
|
||||
|
||||
use justification::GrandpaJustification;
|
||||
use crate::justification::GrandpaJustification;
|
||||
|
||||
/// Prepare proof-of-finality for the given block.
|
||||
///
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use codec::Encode;
|
||||
use log::{debug, trace, info};
|
||||
use parity_codec::Encode;
|
||||
use futures::sync::mpsc;
|
||||
|
||||
use client::{blockchain, CallExecutor, Client};
|
||||
@@ -35,10 +36,10 @@ use runtime_primitives::traits::{
|
||||
use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher};
|
||||
|
||||
use crate::{AUTHORITY_SET_KEY, Error};
|
||||
use authorities::SharedAuthoritySet;
|
||||
use consensus_changes::SharedConsensusChanges;
|
||||
use environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet};
|
||||
use justification::GrandpaJustification;
|
||||
use crate::authorities::SharedAuthoritySet;
|
||||
use crate::consensus_changes::SharedConsensusChanges;
|
||||
use crate::environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet};
|
||||
use crate::justification::GrandpaJustification;
|
||||
|
||||
/// A block-import handler for GRANDPA.
|
||||
///
|
||||
@@ -123,7 +124,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA> BlockImport<Block>
|
||||
fn import_block(&self, mut block: ImportBlock<Block>, new_authorities: Option<Vec<Ed25519AuthorityId>>)
|
||||
-> Result<ImportResult, Self::Error>
|
||||
{
|
||||
use authorities::PendingChange;
|
||||
use crate::authorities::PendingChange;
|
||||
use client::blockchain::HeaderBackend;
|
||||
|
||||
let hash = block.post_header().hash();
|
||||
|
||||
@@ -20,7 +20,8 @@ use client::{CallExecutor, Client};
|
||||
use client::backend::Backend;
|
||||
use client::blockchain::HeaderBackend;
|
||||
use client::error::{Error as ClientError, ErrorKind as ClientErrorKind};
|
||||
use codec::Decode;
|
||||
use parity_codec::Decode;
|
||||
use parity_codec_derive::{Encode, Decode};
|
||||
use grandpa::VoterSet;
|
||||
use grandpa::{Error as GrandpaError};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
@@ -28,7 +29,7 @@ use runtime_primitives::traits::{NumberFor, Block as BlockT, Header as HeaderT};
|
||||
use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher};
|
||||
|
||||
use crate::{Commit, Error};
|
||||
use communication;
|
||||
use crate::communication;
|
||||
|
||||
/// A GRANDPA justification for block finality, it includes a commit message and
|
||||
/// an ancestry proof including all headers routing all precommit target blocks
|
||||
|
||||
@@ -52,45 +52,15 @@
|
||||
//! any signaled changes based on whether the signaling block is included in the
|
||||
//! newly-finalized chain.
|
||||
|
||||
extern crate finality_grandpa as grandpa;
|
||||
extern crate futures;
|
||||
extern crate substrate_client as client;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
extern crate substrate_consensus_common as consensus_common;
|
||||
extern crate substrate_network as network;
|
||||
extern crate substrate_primitives;
|
||||
extern crate tokio;
|
||||
extern crate parking_lot;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_finality_grandpa_primitives as fg_primitives;
|
||||
extern crate rand;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(feature="service-integration")]
|
||||
extern crate substrate_service as service;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate substrate_keyring as keyring;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate substrate_test_client as test_client;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate env_logger;
|
||||
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
use futures::prelude::*;
|
||||
use log::{debug, info, warn};
|
||||
use futures::sync::{self, mpsc, oneshot};
|
||||
use client::{
|
||||
BlockchainEvents, CallExecutor, Client, backend::Backend,
|
||||
error::Error as ClientError,
|
||||
};
|
||||
use client::blockchain::HeaderBackend;
|
||||
use codec::{Encode, Decode};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use runtime_primitives::traits::{
|
||||
NumberFor, Block as BlockT, Header as HeaderT, DigestFor, ProvideRuntimeApi, Hash as HashT,
|
||||
DigestItemFor, DigestItem,
|
||||
@@ -407,7 +377,7 @@ pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
|
||||
authority_set
|
||||
}
|
||||
Some(raw) => ::authorities::AuthoritySet::decode(&mut &raw[..])
|
||||
Some(raw) => crate::authorities::AuthoritySet::decode(&mut &raw[..])
|
||||
.ok_or_else(|| ::client::error::ErrorKind::Backend(
|
||||
format!("GRANDPA authority set kept in invalid format")
|
||||
))?
|
||||
@@ -466,7 +436,7 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
|
||||
{
|
||||
// verification stream
|
||||
let commit_in = ::communication::checked_commit_stream::<Block, _>(
|
||||
let commit_in = crate::communication::checked_commit_stream::<Block, _>(
|
||||
set_id,
|
||||
network.commit_messages(set_id),
|
||||
voters.clone(),
|
||||
@@ -483,7 +453,7 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
.map(|pair| voters.contains_key(&pair.public().into()))
|
||||
.unwrap_or(false);
|
||||
|
||||
let commit_out = ::communication::CommitsOut::<Block, _>::new(
|
||||
let commit_out = crate::communication::CommitsOut::<Block, _>::new(
|
||||
network.clone(),
|
||||
set_id,
|
||||
is_voter,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use client;
|
||||
use service::{FullBackend, FullExecutor, ServiceFactory};
|
||||
|
||||
pub type BlockImportForService<F> = ::GrandpaBlockImport<
|
||||
pub type BlockImportForService<F> = crate::GrandpaBlockImport<
|
||||
FullBackend<F>,
|
||||
FullExecutor<F>,
|
||||
<F as ServiceFactory>::Block,
|
||||
@@ -32,9 +32,9 @@ pub type BlockImportForService<F> = ::GrandpaBlockImport<
|
||||
>,
|
||||
>;
|
||||
|
||||
pub type LinkHalfForService<F> = ::LinkHalf<
|
||||
pub type LinkHalfForService<F> = crate::LinkHalf<
|
||||
FullBackend<F>,
|
||||
FullExecutor<F>,
|
||||
<F as ServiceFactory>::Block,
|
||||
<F as ServiceFactory>::RuntimeApi
|
||||
>;
|
||||
>;
|
||||
|
||||
@@ -29,7 +29,7 @@ use client::{
|
||||
runtime_api::{Core, RuntimeVersion, ApiExt},
|
||||
};
|
||||
use test_client::{self, runtime::BlockNumber};
|
||||
use codec::Decode;
|
||||
use parity_codec::Decode;
|
||||
use consensus_common::{BlockOrigin, ForkChoiceStrategy, ImportBlock, ImportResult};
|
||||
use consensus_common::import_queue::{SharedBlockImport, SharedJustificationImport};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -372,7 +372,7 @@ fn run_to_completion(blocks: u64, net: Arc<Mutex<GrandpaTestNet>>, peers: &[Keyr
|
||||
for (peer_id, key) in peers.iter().enumerate() {
|
||||
let highest_finalized = highest_finalized.clone();
|
||||
let (client, link) = {
|
||||
let mut net = net.lock();
|
||||
let net = net.lock();
|
||||
// temporary needed for some reason
|
||||
let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed");
|
||||
(
|
||||
@@ -469,7 +469,7 @@ fn finalize_3_voters_1_observer() {
|
||||
|
||||
for (peer_id, local_key) in all_peers.enumerate() {
|
||||
let (client, link) = {
|
||||
let mut net = net.lock();
|
||||
let net = net.lock();
|
||||
let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed");
|
||||
(
|
||||
net.peers[peer_id].client().clone(),
|
||||
@@ -546,7 +546,7 @@ fn transition_3_voters_twice_1_observer() {
|
||||
assert_eq!(peer.client().info().unwrap().chain.best_number, 1,
|
||||
"Peer #{} failed to sync", i);
|
||||
|
||||
let set_raw = peer.client().backend().get_aux(::AUTHORITY_SET_KEY).unwrap().unwrap();
|
||||
let set_raw = peer.client().backend().get_aux(crate::AUTHORITY_SET_KEY).unwrap().unwrap();
|
||||
let set = AuthoritySet::<Hash, BlockNumber>::decode(&mut &set_raw[..]).unwrap();
|
||||
|
||||
assert_eq!(set.current(), (0, make_ids(peers_a).as_slice()));
|
||||
@@ -620,7 +620,7 @@ fn transition_3_voters_twice_1_observer() {
|
||||
|
||||
for (peer_id, local_key) in all_peers {
|
||||
let (client, link) = {
|
||||
let mut net = net.lock();
|
||||
let net = net.lock();
|
||||
let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed");
|
||||
(
|
||||
net.peers[peer_id].client().clone(),
|
||||
@@ -632,7 +632,7 @@ fn transition_3_voters_twice_1_observer() {
|
||||
.take_while(|n| Ok(n.header.number() < &30))
|
||||
.for_each(move |_| Ok(()))
|
||||
.map(move |()| {
|
||||
let set_raw = client.backend().get_aux(::AUTHORITY_SET_KEY).unwrap().unwrap();
|
||||
let set_raw = client.backend().get_aux(crate::AUTHORITY_SET_KEY).unwrap().unwrap();
|
||||
let set = AuthoritySet::<Hash, BlockNumber>::decode(&mut &set_raw[..]).unwrap();
|
||||
|
||||
assert_eq!(set.current(), (2, make_ids(peers_c).as_slice()));
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
use super::{BlockStatus, Error, SignedMessage, CompactCommit};
|
||||
|
||||
use log::{debug, warn};
|
||||
use client::ImportNotifications;
|
||||
use futures::prelude::*;
|
||||
use futures::stream::Fuse;
|
||||
@@ -114,8 +115,8 @@ impl<Block: BlockT, Status, I, M> Stream for UntilImported<Block, Status, I, M>
|
||||
Async::Ready(Some(input)) => {
|
||||
// new input: schedule wait of any parts which require
|
||||
// blocks to be known.
|
||||
let mut ready = &mut self.ready;
|
||||
let mut pending = &mut self.pending;
|
||||
let ready = &mut self.ready;
|
||||
let pending = &mut self.pending;
|
||||
M::schedule_wait(
|
||||
input,
|
||||
&self.status_check,
|
||||
@@ -300,7 +301,7 @@ impl<Block: BlockT> BlockUntilImported<Block> for BlockCommitMessage<Block> {
|
||||
// check integrity: all precommits for same hash have same number.
|
||||
let canon_number = match checked_hashes.entry(target_hash) {
|
||||
Entry::Occupied(entry) => entry.get().number().clone(),
|
||||
Entry::Vacant(mut entry) => {
|
||||
Entry::Vacant(entry) => {
|
||||
if let Some(number) = status_check.block_number(target_hash)? {
|
||||
entry.insert(KnownOrUnknown::Known(number));
|
||||
number
|
||||
|
||||
Reference in New Issue
Block a user