Skip to content

Commit 660852f

Browse files
stanislav-tkachMTDK1
authored andcommitted
Migrate finality-grandpa to the 2018 edition (paritytech#1797)
1 parent 873bfc9 commit 660852f

File tree

19 files changed

+71
-106
lines changed

19 files changed

+71
-106
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/finality-grandpa/Cargo.toml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@
22
name = "substrate-finality-grandpa"
33
version = "0.1.0"
44
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
56

67
[dependencies]
78
futures = "0.1"
8-
parity-codec = "3.0"
9-
parity-codec-derive = "3.0"
10-
sr-primitives = { path = "../sr-primitives" }
11-
substrate-consensus-common = { path = "../consensus/common" }
12-
substrate-primitives = { path = "../primitives" }
13-
substrate-client = { path = "../client" }
14-
substrate-network = { path = "../network" }
15-
substrate-service = { path = "../service", optional = true }
169
log = "0.4"
1710
parking_lot = "0.7.1"
1811
tokio = "0.1.7"
19-
substrate-finality-grandpa-primitives = { path = "primitives" }
2012
rand = "0.6"
21-
22-
[dependencies.finality-grandpa]
23-
version = "0.6.0"
24-
features = ["derive-codec"]
13+
parity-codec = "3.0"
14+
parity-codec-derive = "3.0"
15+
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" }
16+
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" }
17+
substrate-primitives = { path = "../primitives" }
18+
client = { package = "substrate-client", path = "../client" }
19+
network = { package = "substrate-network", path = "../network" }
20+
service = { package = "substrate-service", path = "../service", optional = true }
21+
fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "primitives" }
22+
grandpa = { package = "finality-grandpa", version = "0.6.0", features = ["derive-codec"] }
2523

2624
[dev-dependencies]
27-
substrate-network = { path = "../network", features = ["test-helpers"] }
28-
substrate-keyring = { path = "../keyring" }
29-
substrate-test-client = { path = "../test-client"}
25+
network = { package = "substrate-network", path = "../network", features = ["test-helpers"] }
26+
keyring = { package = "substrate-keyring", path = "../keyring" }
27+
test_client = { package = "substrate-test-client", path = "../test-client"}
3028
env_logger = "0.6"
3129

3230
[features]
3331
default = ["service-integration"]
34-
service-integration = ["substrate-service"]
32+
service-integration = ["service"]

core/finality-grandpa/primitives/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
name = "substrate-finality-grandpa-primitives"
33
version = "0.1.0"
44
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
56

67
[dependencies]
7-
substrate-client = { path = "../../client", default-features = false }
8+
client = { package = "substrate-client", path = "../../client", default-features = false }
89
substrate-primitives = { path = "../../primitives", default-features = false }
910
parity-codec = { version = "3.0", default-features = false }
1011
parity-codec-derive = { version = "3.0", default-features = false }
1112
sr-primitives = { path = "../../sr-primitives", default-features = false }
12-
sr-std = { path = "../../sr-std", default-features = false }
13+
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
1314

1415
[features]
1516
default = ["std"]
1617
std = [
1718
"substrate-primitives/std",
18-
"substrate-client/std",
19+
"client/std",
1920
"parity-codec/std",
2021
"parity-codec-derive/std",
2122
"sr-primitives/std",
22-
"sr-std/std",
23+
"rstd/std",
2324
]

core/finality-grandpa/primitives/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,10 @@
2222
#[cfg(not(feature = "std"))]
2323
extern crate alloc;
2424

25-
extern crate substrate_primitives;
26-
extern crate sr_primitives;
27-
extern crate parity_codec;
28-
29-
#[macro_use]
30-
extern crate parity_codec_derive;
31-
32-
#[macro_use]
33-
extern crate substrate_client as client;
34-
35-
extern crate sr_std as rstd;
36-
25+
use parity_codec_derive::{Encode, Decode};
3726
use substrate_primitives::Ed25519AuthorityId;
3827
use sr_primitives::traits::{DigestFor, NumberFor};
28+
use client::decl_runtime_apis;
3929
use rstd::vec::Vec;
4030

4131
/// A scheduled change of authority set.

core/finality-grandpa/src/authorities.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use parking_lot::RwLock;
2020
use substrate_primitives::Ed25519AuthorityId;
2121
use grandpa::VoterSet;
22+
use parity_codec_derive::{Encode, Decode};
23+
use log::{debug, info};
2224

2325
use std::cmp::Ord;
2426
use std::fmt::Debug;
@@ -276,7 +278,7 @@ impl<H, N: Add<Output=N> + Clone> PendingChange<H, N> {
276278
mod tests {
277279
use super::*;
278280

279-
fn ignore_existing_changes<A>(_a: &A) -> Result<(), ::Error> {
281+
fn ignore_existing_changes<A>(_a: &A) -> Result<(), crate::Error> {
280282
Ok(())
281283
}
282284

core/finality-grandpa/src/communication.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ use std::sync::Arc;
2323
use grandpa::VoterSet;
2424
use futures::prelude::*;
2525
use futures::sync::mpsc;
26-
use codec::{Encode, Decode};
26+
use log::{debug, trace};
27+
use parity_codec::{Encode, Decode};
2728
use substrate_primitives::{ed25519, Ed25519AuthorityId};
2829
use runtime_primitives::traits::Block as BlockT;
2930
use tokio::timer::Interval;
30-
use {Error, Network, Message, SignedMessage, Commit, CompactCommit};
31+
use crate::{Error, Network, Message, SignedMessage, Commit, CompactCommit};
3132

3233
fn localized_payload<E: Encode>(round: u64, set_id: u64, message: &E) -> Vec<u8> {
3334
(message, round, set_id).encode()
@@ -245,9 +246,9 @@ pub(crate) fn check_message_sig<Block: BlockT>(
245246
round: u64,
246247
set_id: u64,
247248
) -> Result<(), ()> {
248-
let as_public = ::ed25519::Public::from_raw(id.0);
249+
let as_public = ed25519::Public::from_raw(id.0);
249250
let encoded_raw = localized_payload(round, set_id, message);
250-
if ::ed25519::verify_strong(signature, &encoded_raw, as_public) {
251+
if ed25519::verify_strong(signature, &encoded_raw, as_public) {
251252
Ok(())
252253
} else {
253254
debug!(target: "afg", "Bad signature on message from {:?}", id);

core/finality-grandpa/src/consensus_changes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use std::sync::Arc;
18+
use parity_codec_derive::{Encode, Decode};
1819

1920
/// Consensus-related data changes tracker.
2021
#[derive(Clone, Debug, Encode, Decode)]

core/finality-grandpa/src/environment.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use std::fmt;
1818
use std::sync::Arc;
1919
use std::time::{Duration, Instant};
2020

21-
use codec::Encode;
21+
use log::{debug, warn, info};
22+
use parity_codec::Encode;
2223
use futures::prelude::*;
2324
use tokio::timer::Delay;
2425

@@ -38,10 +39,10 @@ use crate::{
3839
AUTHORITY_SET_KEY, CONSENSUS_CHANGES_KEY, LAST_COMPLETED_KEY,
3940
Commit, Config, Error, Network, Precommit, Prevote, LastCompleted,
4041
};
41-
use authorities::{AuthoritySet, SharedAuthoritySet};
42-
use consensus_changes::SharedConsensusChanges;
43-
use justification::GrandpaJustification;
44-
use until_imported::UntilVoteTargetImported;
42+
use crate::authorities::{AuthoritySet, SharedAuthoritySet};
43+
use crate::consensus_changes::SharedConsensusChanges;
44+
use crate::justification::GrandpaJustification;
45+
use crate::until_imported::UntilVoteTargetImported;
4546

4647
/// The environment we run GRANDPA in.
4748
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
246247
let prevote_timer = Delay::new(now + self.config.gossip_duration * 2);
247248
let precommit_timer = Delay::new(now + self.config.gossip_duration * 4);
248249

249-
let incoming = ::communication::checked_message_stream::<Block, _>(
250+
let incoming = crate::communication::checked_message_stream::<Block, _>(
250251
round,
251252
self.set_id,
252253
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
256257
let local_key = self.config.local_key.as_ref()
257258
.filter(|pair| self.voters.contains_key(&pair.public().into()));
258259

259-
let (out_rx, outgoing) = ::communication::outgoing_messages::<Block, _>(
260+
let (out_rx, outgoing) = crate::communication::outgoing_messages::<Block, _>(
260261
round,
261262
self.set_id,
262263
local_key.cloned(),

core/finality-grandpa/src/finality_proof.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ use client::{
3636
error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult},
3737
light::fetcher::RemoteCallRequest,
3838
};
39-
use codec::{Encode, Decode};
39+
use parity_codec::{Encode, Decode};
40+
use parity_codec_derive::{Encode, Decode};
4041
use grandpa::BlockNumberOps;
4142
use runtime_primitives::generic::BlockId;
4243
use runtime_primitives::traits::{
4344
NumberFor, Block as BlockT, Header as HeaderT, One,
4445
};
4546
use substrate_primitives::{Ed25519AuthorityId, H256};
4647

47-
use justification::GrandpaJustification;
48+
use crate::justification::GrandpaJustification;
4849

4950
/// Prepare proof-of-finality for the given block.
5051
///

core/finality-grandpa/src/import.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
use std::sync::Arc;
1818

19-
use codec::Encode;
19+
use log::{debug, trace, info};
20+
use parity_codec::Encode;
2021
use futures::sync::mpsc;
2122

2223
use client::{blockchain, CallExecutor, Client};
@@ -35,10 +36,10 @@ use runtime_primitives::traits::{
3536
use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher};
3637

3738
use crate::{AUTHORITY_SET_KEY, Error};
38-
use authorities::SharedAuthoritySet;
39-
use consensus_changes::SharedConsensusChanges;
40-
use environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet};
41-
use justification::GrandpaJustification;
39+
use crate::authorities::SharedAuthoritySet;
40+
use crate::consensus_changes::SharedConsensusChanges;
41+
use crate::environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet};
42+
use crate::justification::GrandpaJustification;
4243

4344
/// A block-import handler for GRANDPA.
4445
///
@@ -123,7 +124,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA> BlockImport<Block>
123124
fn import_block(&self, mut block: ImportBlock<Block>, new_authorities: Option<Vec<Ed25519AuthorityId>>)
124125
-> Result<ImportResult, Self::Error>
125126
{
126-
use authorities::PendingChange;
127+
use crate::authorities::PendingChange;
127128
use client::blockchain::HeaderBackend;
128129

129130
let hash = block.post_header().hash();

core/finality-grandpa/src/justification.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ use client::{CallExecutor, Client};
2020
use client::backend::Backend;
2121
use client::blockchain::HeaderBackend;
2222
use client::error::{Error as ClientError, ErrorKind as ClientErrorKind};
23-
use codec::Decode;
23+
use parity_codec::Decode;
24+
use parity_codec_derive::{Encode, Decode};
2425
use grandpa::VoterSet;
2526
use grandpa::{Error as GrandpaError};
2627
use runtime_primitives::generic::BlockId;
2728
use runtime_primitives::traits::{NumberFor, Block as BlockT, Header as HeaderT};
2829
use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher};
2930

3031
use crate::{Commit, Error};
31-
use communication;
32+
use crate::communication;
3233

3334
/// A GRANDPA justification for block finality, it includes a commit message and
3435
/// an ancestry proof including all headers routing all precommit target blocks

core/finality-grandpa/src/lib.rs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,45 +52,15 @@
5252
//! any signaled changes based on whether the signaling block is included in the
5353
//! newly-finalized chain.
5454
55-
extern crate finality_grandpa as grandpa;
56-
extern crate futures;
57-
extern crate substrate_client as client;
58-
extern crate sr_primitives as runtime_primitives;
59-
extern crate substrate_consensus_common as consensus_common;
60-
extern crate substrate_network as network;
61-
extern crate substrate_primitives;
62-
extern crate tokio;
63-
extern crate parking_lot;
64-
extern crate parity_codec as codec;
65-
extern crate substrate_finality_grandpa_primitives as fg_primitives;
66-
extern crate rand;
67-
68-
#[macro_use]
69-
extern crate log;
70-
71-
#[cfg(feature="service-integration")]
72-
extern crate substrate_service as service;
73-
74-
#[cfg(test)]
75-
extern crate substrate_keyring as keyring;
76-
77-
#[cfg(test)]
78-
extern crate substrate_test_client as test_client;
79-
80-
#[cfg(test)]
81-
extern crate env_logger;
82-
83-
#[macro_use]
84-
extern crate parity_codec_derive;
85-
8655
use futures::prelude::*;
56+
use log::{debug, info, warn};
8757
use futures::sync::{self, mpsc, oneshot};
8858
use client::{
8959
BlockchainEvents, CallExecutor, Client, backend::Backend,
9060
error::Error as ClientError,
9161
};
9262
use client::blockchain::HeaderBackend;
93-
use codec::{Encode, Decode};
63+
use parity_codec::{Encode, Decode};
9464
use runtime_primitives::traits::{
9565
NumberFor, Block as BlockT, Header as HeaderT, DigestFor, ProvideRuntimeApi, Hash as HashT,
9666
DigestItemFor, DigestItem,
@@ -407,7 +377,7 @@ pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
407377

408378
authority_set
409379
}
410-
Some(raw) => ::authorities::AuthoritySet::decode(&mut &raw[..])
380+
Some(raw) => crate::authorities::AuthoritySet::decode(&mut &raw[..])
411381
.ok_or_else(|| ::client::error::ErrorKind::Backend(
412382
format!("GRANDPA authority set kept in invalid format")
413383
))?
@@ -466,7 +436,7 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
466436
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
467437
{
468438
// verification stream
469-
let commit_in = ::communication::checked_commit_stream::<Block, _>(
439+
let commit_in = crate::communication::checked_commit_stream::<Block, _>(
470440
set_id,
471441
network.commit_messages(set_id),
472442
voters.clone(),
@@ -483,7 +453,7 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
483453
.map(|pair| voters.contains_key(&pair.public().into()))
484454
.unwrap_or(false);
485455

486-
let commit_out = ::communication::CommitsOut::<Block, _>::new(
456+
let commit_out = crate::communication::CommitsOut::<Block, _>::new(
487457
network.clone(),
488458
set_id,
489459
is_voter,

core/finality-grandpa/src/service_integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use client;
2020
use service::{FullBackend, FullExecutor, ServiceFactory};
2121

22-
pub type BlockImportForService<F> = ::GrandpaBlockImport<
22+
pub type BlockImportForService<F> = crate::GrandpaBlockImport<
2323
FullBackend<F>,
2424
FullExecutor<F>,
2525
<F as ServiceFactory>::Block,
@@ -32,9 +32,9 @@ pub type BlockImportForService<F> = ::GrandpaBlockImport<
3232
>,
3333
>;
3434

35-
pub type LinkHalfForService<F> = ::LinkHalf<
35+
pub type LinkHalfForService<F> = crate::LinkHalf<
3636
FullBackend<F>,
3737
FullExecutor<F>,
3838
<F as ServiceFactory>::Block,
3939
<F as ServiceFactory>::RuntimeApi
40-
>;
40+
>;

0 commit comments

Comments
 (0)