diff --git a/Cargo.lock b/Cargo.lock index 299f639219437..92db97a36c943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,8 +520,8 @@ dependencies = [ "sp-beefy", "sp-blockchain", "sp-consensus", + "sp-consensus-grandpa", "sp-core", - "sp-finality-grandpa", "sp-keyring", "sp-keystore", "sp-mmr-primitives", @@ -3601,6 +3601,7 @@ dependencies = [ "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", + "sp-consensus-grandpa", "sp-core", "sp-inherents", "sp-io", @@ -4806,9 +4807,9 @@ dependencies = [ "sc-consensus", "sc-consensus-babe", "sc-consensus-epochs", + "sc-consensus-grandpa", "sc-consensus-slots", "sc-executor", - "sc-finality-grandpa", "sc-keystore", "sc-network", "sc-network-common", @@ -4829,8 +4830,8 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", + "sp-consensus-grandpa", "sp-core", - "sp-finality-grandpa", "sp-inherents", "sp-io", "sp-keyring", @@ -4928,8 +4929,8 @@ dependencies = [ "sc-consensus-babe", "sc-consensus-babe-rpc", "sc-consensus-epochs", - "sc-finality-grandpa", - "sc-finality-grandpa-rpc", + "sc-consensus-grandpa", + "sc-consensus-grandpa-rpc", "sc-rpc", "sc-rpc-api", "sc-rpc-spec-v2", @@ -4973,8 +4974,8 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-consensus-aura", + "sc-consensus-grandpa", "sc-executor", - "sc-finality-grandpa", "sc-keystore", "sc-rpc", "sc-rpc-api", @@ -4987,8 +4988,8 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-aura", + "sp-consensus-grandpa", "sp-core", - "sp-finality-grandpa", "sp-inherents", "sp-io", "sp-keyring", @@ -5024,6 +5025,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-consensus-aura", + "sp-consensus-grandpa", "sp-core", "sp-inherents", "sp-offchain", @@ -5866,8 +5868,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-application-crypto", + "sp-consensus-grandpa", "sp-core", - "sp-finality-grandpa", "sp-io", "sp-keyring", "sp-runtime", @@ -8304,6 +8306,76 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "sc-consensus-grandpa" +version = "0.10.0-dev" +dependencies = [ + "ahash 0.8.3", + "array-bytes", + "assert_matches", + "async-trait", + "dyn-clone", + "finality-grandpa", + "fork-tree", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.8.5", + "sc-block-builder", + "sc-chain-spec", + "sc-client-api", + "sc-consensus", + "sc-network", + "sc-network-common", + "sc-network-gossip", + "sc-network-test", + "sc-telemetry", + "sc-utils", + "serde", + "serde_json", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-grandpa", + "sp-core", + "sp-keyring", + "sp-keystore", + "sp-runtime", + "sp-tracing", + "substrate-prometheus-endpoint", + "substrate-test-runtime-client", + "thiserror", + "tokio", +] + +[[package]] +name = "sc-consensus-grandpa-rpc" +version = "0.10.0-dev" +dependencies = [ + "finality-grandpa", + "futures", + "jsonrpsee", + "log", + "parity-scale-codec", + "sc-block-builder", + "sc-client-api", + "sc-consensus-grandpa", + "sc-rpc", + "serde", + "sp-blockchain", + "sp-consensus-grandpa", + "sp-core", + "sp-keyring", + "sp-runtime", + "substrate-test-runtime-client", + "thiserror", + "tokio", +] + [[package]] name = "sc-consensus-manual-seal" version = "0.10.0-dev" @@ -8476,76 +8548,6 @@ dependencies = [ "wat", ] -[[package]] -name = "sc-finality-grandpa" -version = "0.10.0-dev" -dependencies = [ - "ahash 0.8.3", - "array-bytes", - "assert_matches", - "async-trait", - "dyn-clone", - "finality-grandpa", - "fork-tree", - "futures", - "futures-timer", - "log", - "parity-scale-codec", - "parking_lot 0.12.1", - "rand 0.8.5", - "sc-block-builder", - "sc-chain-spec", - "sc-client-api", - "sc-consensus", - "sc-network", - "sc-network-common", - "sc-network-gossip", - "sc-network-test", - "sc-telemetry", - "sc-utils", - "serde", - "serde_json", - "sp-api", - "sp-application-crypto", - "sp-arithmetic", - "sp-blockchain", - "sp-consensus", - "sp-core", - "sp-finality-grandpa", - "sp-keyring", - "sp-keystore", - "sp-runtime", - "sp-tracing", - "substrate-prometheus-endpoint", - "substrate-test-runtime-client", - "thiserror", - "tokio", -] - -[[package]] -name = "sc-finality-grandpa-rpc" -version = "0.10.0-dev" -dependencies = [ - "finality-grandpa", - "futures", - "jsonrpsee", - "log", - "parity-scale-codec", - "sc-block-builder", - "sc-client-api", - "sc-finality-grandpa", - "sc-rpc", - "serde", - "sp-blockchain", - "sp-core", - "sp-finality-grandpa", - "sp-keyring", - "sp-runtime", - "substrate-test-runtime-client", - "thiserror", - "tokio", -] - [[package]] name = "sc-informant" version = "0.10.0-dev" @@ -8673,7 +8675,7 @@ dependencies = [ "smallvec", "sp-blockchain", "sp-consensus", - "sp-finality-grandpa", + "sp-consensus-grandpa", "sp-runtime", "substrate-prometheus-endpoint", "thiserror", @@ -8745,8 +8747,8 @@ dependencies = [ "sp-arithmetic", "sp-blockchain", "sp-consensus", + "sp-consensus-grandpa", "sp-core", - "sp-finality-grandpa", "sp-runtime", "sp-test-primitives", "sp-tracing", @@ -9114,7 +9116,7 @@ dependencies = [ "sc-client-api", "sc-consensus-babe", "sc-consensus-epochs", - "sc-finality-grandpa", + "sc-consensus-grandpa", "serde", "serde_json", "sp-blockchain", @@ -9893,6 +9895,23 @@ dependencies = [ "sp-timestamp", ] +[[package]] +name = "sp-consensus-grandpa" +version = "4.0.0-dev" +dependencies = [ + "finality-grandpa", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-core", + "sp-keystore", + "sp-runtime", + "sp-std", +] + [[package]] name = "sp-consensus-pow" version = "0.10.0-dev" @@ -10023,23 +10042,6 @@ dependencies = [ "sp-storage", ] -[[package]] -name = "sp-finality-grandpa" -version = "4.0.0-dev" -dependencies = [ - "finality-grandpa", - "log", - "parity-scale-codec", - "scale-info", - "serde", - "sp-api", - "sp-application-crypto", - "sp-core", - "sp-keystore", - "sp-runtime", - "sp-std", -] - [[package]] name = "sp-inherents" version = "4.0.0-dev" @@ -10801,9 +10803,9 @@ dependencies = [ "sp-consensus", "sp-consensus-aura", "sp-consensus-babe", + "sp-consensus-grandpa", "sp-core", "sp-externalities", - "sp-finality-grandpa", "sp-inherents", "sp-io", "sp-keyring", diff --git a/Cargo.toml b/Cargo.toml index 80dd2b90f85c2..88c9c1998f415 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,8 @@ members = [ "client/consensus/babe/rpc", "client/consensus/common", "client/consensus/epochs", + "client/consensus/grandpa", + "client/consensus/grandpa/rpc", "client/consensus/manual-seal", "client/consensus/pow", "client/consensus/slots", @@ -38,8 +40,6 @@ members = [ "client/executor/runtime-test", "client/executor/wasmi", "client/executor/wasmtime", - "client/finality-grandpa", - "client/finality-grandpa/rpc", "client/informant", "client/keystore", "client/merkle-mountain-range", @@ -184,6 +184,7 @@ members = [ "primitives/consensus/aura", "primitives/consensus/babe", "primitives/consensus/common", + "primitives/consensus/grandpa", "primitives/consensus/pow", "primitives/consensus/slots", "primitives/consensus/vrf", @@ -193,7 +194,6 @@ members = [ "primitives/database", "primitives/debug-derive", "primitives/externalities", - "primitives/finality-grandpa", "primitives/inherents", "primitives/io", "primitives/keyring", diff --git a/bin/node-template/node/Cargo.toml b/bin/node-template/node/Cargo.toml index 364cfa25d3c6b..979c00120ddb7 100644 --- a/bin/node-template/node/Cargo.toml +++ b/bin/node-template/node/Cargo.toml @@ -32,8 +32,8 @@ sc-consensus-aura = { version = "0.10.0-dev", path = "../../../client/consensus/ sp-consensus-aura = { version = "0.10.0-dev", path = "../../../primitives/consensus/aura" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } -sc-finality-grandpa = { version = "0.10.0-dev", path = "../../../client/finality-grandpa" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../../primitives/finality-grandpa" } +sc-consensus-grandpa = { version = "0.10.0-dev", path = "../../../client/consensus/grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../../primitives/consensus/grandpa" } sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" } sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } sp-io = { version = "7.0.0", path = "../../../primitives/io" } diff --git a/bin/node-template/node/src/chain_spec.rs b/bin/node-template/node/src/chain_spec.rs index ef34ec369a77f..e978596beb7b1 100644 --- a/bin/node-template/node/src/chain_spec.rs +++ b/bin/node-template/node/src/chain_spec.rs @@ -4,8 +4,8 @@ use node_template_runtime::{ }; use sc_service::ChainType; use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{sr25519, Pair, Public}; -use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::traits::{IdentifyAccount, Verify}; // The URL for the telemetry server. diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index c3dc098cdfb3a..e121db820f2a3 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -102,7 +102,7 @@ pub fn run() -> sc_cli::Result<()> { let PartialComponents { client, task_manager, backend, .. } = service::new_partial(&config)?; let aux_revert = Box::new(|client, _, blocks| { - sc_finality_grandpa::revert(client, blocks)?; + sc_consensus_grandpa::revert(client, blocks)?; Ok(()) }); Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index d7d075efd98ab..98485a7ad674c 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -3,8 +3,8 @@ use node_template_runtime::{self, opaque::Block, RuntimeApi}; use sc_client_api::BlockBackend; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; +use sc_consensus_grandpa::SharedVoterState; pub use sc_executor::NativeElseWasmExecutor; -use sc_finality_grandpa::SharedVoterState; use sc_keystore::LocalKeystore; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams}; use sc_telemetry::{Telemetry, TelemetryWorker}; @@ -46,13 +46,13 @@ pub fn new_partial( sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, ( - sc_finality_grandpa::GrandpaBlockImport< + sc_consensus_grandpa::GrandpaBlockImport< FullBackend, Block, FullClient, FullSelectChain, >, - sc_finality_grandpa::LinkHalf, + sc_consensus_grandpa::LinkHalf, Option, ), >, @@ -103,7 +103,7 @@ pub fn new_partial( client.clone(), ); - let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import( + let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import( client.clone(), &(client.clone() as Arc<_>), select_chain.clone(), @@ -177,7 +177,7 @@ pub fn new_full(mut config: Configuration) -> Result ))), }; } - let grandpa_protocol_name = sc_finality_grandpa::protocol_standard_name( + let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), &config.chain_spec, ); @@ -185,8 +185,8 @@ pub fn new_full(mut config: Configuration) -> Result config .network .extra_sets - .push(sc_finality_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone())); - let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( + .push(sc_consensus_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone())); + let warp_sync = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), Vec::default(), @@ -298,7 +298,7 @@ pub fn new_full(mut config: Configuration) -> Result let keystore = if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; - let grandpa_config = sc_finality_grandpa::Config { + let grandpa_config = sc_consensus_grandpa::Config { // FIXME #1578 make this available through chainspec gossip_duration: Duration::from_millis(333), justification_period: 512, @@ -316,11 +316,11 @@ pub fn new_full(mut config: Configuration) -> Result // and vote data availability than the observer. The observer has not // been tested extensively yet and having most nodes in a network run it // could lead to finality stalls. - let grandpa_config = sc_finality_grandpa::GrandpaParams { + let grandpa_config = sc_consensus_grandpa::GrandpaParams { config: grandpa_config, link: grandpa_link, network, - voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(), + voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(), prometheus_registry, shared_voter_state: SharedVoterState::empty(), telemetry: telemetry.as_ref().map(|x| x.handle()), @@ -331,7 +331,7 @@ pub fn new_full(mut config: Configuration) -> Result task_manager.spawn_essential_handle().spawn_blocking( "grandpa-voter", None, - sc_finality_grandpa::run_grandpa_voter(grandpa_config)?, + sc_consensus_grandpa::run_grandpa_voter(grandpa_config)?, ); } diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index dd453d9f1ec79..55fdea7f59031 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -30,6 +30,7 @@ frame-executive = { version = "4.0.0-dev", default-features = false, path = "../ sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" } sp-block-builder = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/block-builder"} sp-consensus-aura = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/aura" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/consensus/grandpa" } sp-core = { version = "7.0.0", default-features = false, path = "../../../primitives/core" } sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents"} sp-offchain = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/offchain" } @@ -78,6 +79,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", + "sp-consensus-grandpa/std", "sp-core/std", "sp-inherents/std", "sp-offchain/std", diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index ff9ac66d6afec..57e4470c762ac 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -6,9 +6,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use pallet_grandpa::{ - fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, -}; +use pallet_grandpa::AuthorityId as GrandpaId; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -429,29 +427,29 @@ impl_runtime_apis! { } } - impl fg_primitives::GrandpaApi for Runtime { - fn grandpa_authorities() -> GrandpaAuthorityList { + impl sp_consensus_grandpa::GrandpaApi for Runtime { + fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList { Grandpa::grandpa_authorities() } - fn current_set_id() -> fg_primitives::SetId { + fn current_set_id() -> sp_consensus_grandpa::SetId { Grandpa::current_set_id() } fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: fg_primitives::EquivocationProof< + _equivocation_proof: sp_consensus_grandpa::EquivocationProof< ::Hash, NumberFor, >, - _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, + _key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof, ) -> Option<()> { None } fn generate_key_ownership_proof( - _set_id: fg_primitives::SetId, + _set_id: sp_consensus_grandpa::SetId, _authority_id: GrandpaId, - ) -> Option { + ) -> Option { // NOTE: this is the only implementation possible since we've // defined our key owner proof type as a bottom type (i.e. a type // with no values). diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 9ec06d9d9cab1..b93019b7cc219 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -47,7 +47,7 @@ rand = "0.8" # primitives sp-authority-discovery = { version = "4.0.0-dev", path = "../../../primitives/authority-discovery" } sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" } -grandpa-primitives = { version = "4.0.0-dev", package = "sp-finality-grandpa", path = "../../../primitives/finality-grandpa" } +grandpa-primitives = { version = "4.0.0-dev", package = "sp-consensus-grandpa", path = "../../../primitives/consensus/grandpa" } sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } sp-core = { version = "7.0.0", path = "../../../primitives/core" } sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } @@ -70,7 +70,7 @@ sc-network = { version = "0.10.0-dev", path = "../../../client/network" } sc-network-common = { version = "0.10.0-dev", path = "../../../client/network/common" } sc-consensus-slots = { version = "0.10.0-dev", path = "../../../client/consensus/slots" } sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" } -grandpa = { version = "0.10.0-dev", package = "sc-finality-grandpa", path = "../../../client/finality-grandpa" } +grandpa = { version = "0.10.0-dev", package = "sc-consensus-grandpa", path = "../../../client/consensus/grandpa" } sc-rpc = { version = "4.0.0-dev", path = "../../../client/rpc" } sc-basic-authorship = { version = "0.10.0-dev", path = "../../../client/basic-authorship" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" } diff --git a/bin/node/rpc/Cargo.toml b/bin/node/rpc/Cargo.toml index f34922a287dfe..0ea6f49bd6094 100644 --- a/bin/node/rpc/Cargo.toml +++ b/bin/node/rpc/Cargo.toml @@ -22,8 +22,8 @@ sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" } sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" } sc-consensus-babe-rpc = { version = "0.10.0-dev", path = "../../../client/consensus/babe/rpc" } sc-consensus-epochs = { version = "0.10.0-dev", path = "../../../client/consensus/epochs" } -sc-finality-grandpa = { version = "0.10.0-dev", path = "../../../client/finality-grandpa" } -sc-finality-grandpa-rpc = { version = "0.10.0-dev", path = "../../../client/finality-grandpa/rpc" } +sc-consensus-grandpa = { version = "0.10.0-dev", path = "../../../client/consensus/grandpa" } +sc-consensus-grandpa-rpc = { version = "0.10.0-dev", path = "../../../client/consensus/grandpa/rpc" } sc-rpc = { version = "4.0.0-dev", path = "../../../client/rpc" } sc-rpc-api = { version = "0.10.0-dev", path = "../../../client/rpc-api" } sc-rpc-spec-v2 = { version = "0.10.0-dev", path = "../../../client/rpc-spec-v2" } diff --git a/bin/node/rpc/src/lib.rs b/bin/node/rpc/src/lib.rs index 40e4de6b9dd62..7c2f7c15e05c8 100644 --- a/bin/node/rpc/src/lib.rs +++ b/bin/node/rpc/src/lib.rs @@ -38,7 +38,7 @@ use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index}; use sc_client_api::AuxStore; use sc_consensus_babe::{BabeConfiguration, Epoch}; use sc_consensus_epochs::SharedEpochChanges; -use sc_finality_grandpa::{ +use sc_consensus_grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, }; use sc_rpc::SubscriptionTaskExecutor; @@ -120,7 +120,7 @@ where use mmr_rpc::{Mmr, MmrApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use sc_consensus_babe_rpc::{Babe, BabeApiServer}; - use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer}; + use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer}; use sc_rpc::dev::{Dev, DevApiServer}; use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer}; use sc_sync_state_rpc::{SyncState, SyncStateApiServer}; diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 3df4596aaad90..993108bf732b1 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -27,6 +27,7 @@ log = { version = "0.4.17", default-features = false } # primitives sp-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/authority-discovery" } sp-consensus-babe = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/babe" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/consensus/grandpa" } sp-block-builder = { path = "../../../primitives/block-builder", default-features = false, version = "4.0.0-dev" } sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents" } node-primitives = { version = "2.0.0", default-features = false, path = "../primitives" } @@ -134,6 +135,7 @@ std = [ "pallet-authority-discovery/std", "pallet-authorship/std", "sp-consensus-babe/std", + "sp-consensus-grandpa/std", "pallet-babe/std", "pallet-bags-list/std", "pallet-balances/std", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 14b74425f094b..f8589036f7853 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -52,9 +52,6 @@ use frame_system::{ pub use node_primitives::{AccountId, Signature}; use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; use pallet_election_provider_multi_phase::SolutionAccuracyOf; -use pallet_grandpa::{ - fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, -}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_nfts::PalletFeatures; use pallet_nis::WithMaximumOf; @@ -63,6 +60,7 @@ pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdj use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ @@ -1957,21 +1955,21 @@ impl_runtime_apis! { } } - impl fg_primitives::GrandpaApi for Runtime { - fn grandpa_authorities() -> GrandpaAuthorityList { + impl sp_consensus_grandpa::GrandpaApi for Runtime { + fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList { Grandpa::grandpa_authorities() } - fn current_set_id() -> fg_primitives::SetId { + fn current_set_id() -> sp_consensus_grandpa::SetId { Grandpa::current_set_id() } fn submit_report_equivocation_unsigned_extrinsic( - equivocation_proof: fg_primitives::EquivocationProof< + equivocation_proof: sp_consensus_grandpa::EquivocationProof< ::Hash, NumberFor, >, - key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, + key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof, ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; @@ -1982,14 +1980,14 @@ impl_runtime_apis! { } fn generate_key_ownership_proof( - _set_id: fg_primitives::SetId, + _set_id: sp_consensus_grandpa::SetId, authority_id: GrandpaId, - ) -> Option { + ) -> Option { use codec::Encode; - Historical::prove((fg_primitives::KEY_TYPE, authority_id)) + Historical::prove((sp_consensus_grandpa::KEY_TYPE, authority_id)) .map(|p| p.encode()) - .map(fg_primitives::OpaqueKeyOwnershipProof::new) + .map(sp_consensus_grandpa::OpaqueKeyOwnershipProof::new) } } diff --git a/client/beefy/Cargo.toml b/client/beefy/Cargo.toml index 2976d1474012a..eb616823680aa 100644 --- a/client/beefy/Cargo.toml +++ b/client/beefy/Cargo.toml @@ -43,7 +43,7 @@ tempfile = "3.1.0" tokio = "1.22.0" sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" } sc-network-test = { version = "0.8.0", path = "../network/test" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../primitives/finality-grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../primitives/consensus/grandpa" } sp-keyring = { version = "7.0.0", path = "../../primitives/keyring" } sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" } substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } diff --git a/client/consensus/grandpa/Cargo.toml b/client/consensus/grandpa/Cargo.toml new file mode 100644 index 0000000000000..511e546aa7256 --- /dev/null +++ b/client/consensus/grandpa/Cargo.toml @@ -0,0 +1,60 @@ +[package] +name = "sc-consensus-grandpa" +version = "0.10.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "Integration of the GRANDPA finality gadget into substrate." +documentation = "https://docs.rs/sc-consensus-grandpa" +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +ahash = "0.8.2" +array-bytes = "4.1" +async-trait = "0.1.57" +dyn-clone = "1.0" +finality-grandpa = { version = "0.16.1", features = ["derive-codec"] } +futures = "0.3.21" +futures-timer = "3.0.1" +log = "0.4.17" +parity-scale-codec = { version = "3.2.2", features = ["derive"] } +parking_lot = "0.12.1" +rand = "0.8.5" +serde_json = "1.0.85" +thiserror = "1.0" +fork-tree = { version = "3.0.0", path = "../../../utils/fork-tree" } +prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" } +sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" } +sc-chain-spec = { version = "4.0.0-dev", path = "../../../client/chain-spec" } +sc-client-api = { version = "4.0.0-dev", path = "../../api" } +sc-consensus = { version = "0.10.0-dev", path = "../common" } +sc-network = { version = "0.10.0-dev", path = "../../network" } +sc-network-gossip = { version = "0.10.0-dev", path = "../../network-gossip" } +sc-network-common = { version = "0.10.0-dev", path = "../../network/common" } +sc-telemetry = { version = "4.0.0-dev", path = "../../telemetry" } +sc-utils = { version = "4.0.0-dev", path = "../../utils" } +sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } +sp-application-crypto = { version = "7.0.0", path = "../../../primitives/application-crypto" } +sp-arithmetic = { version = "6.0.0", path = "../../../primitives/arithmetic" } +sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } +sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sp-core = { version = "7.0.0", path = "../../../primitives/core" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../../primitives/consensus/grandpa" } +sp-keystore = { version = "0.13.0", path = "../../../primitives/keystore" } +sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } + +[dev-dependencies] +assert_matches = "1.3.0" +finality-grandpa = { version = "0.16.1", features = ["derive-codec", "test-helpers"] } +serde = "1.0.136" +tokio = "1.22.0" +sc-network = { version = "0.10.0-dev", path = "../../network" } +sc-network-test = { version = "0.8.0", path = "../../network/test" } +sp-keyring = { version = "7.0.0", path = "../../../primitives/keyring" } +sp-tracing = { version = "6.0.0", path = "../../../primitives/tracing" } +substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" } diff --git a/client/finality-grandpa/README.md b/client/consensus/grandpa/README.md similarity index 100% rename from client/finality-grandpa/README.md rename to client/consensus/grandpa/README.md diff --git a/client/consensus/grandpa/rpc/Cargo.toml b/client/consensus/grandpa/rpc/Cargo.toml new file mode 100644 index 0000000000000..4880b50d30630 --- /dev/null +++ b/client/consensus/grandpa/rpc/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "sc-consensus-grandpa-rpc" +version = "0.10.0-dev" +authors = ["Parity Technologies "] +description = "RPC extensions for the GRANDPA finality gadget" +repository = "https://github.com/paritytech/substrate/" +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" +readme = "README.md" +homepage = "https://substrate.io" + +[dependencies] +finality-grandpa = { version = "0.16.1", features = ["derive-codec"] } +futures = "0.3.16" +jsonrpsee = { version = "0.16.2", features = ["client-core", "server", "macros"] } +log = "0.4.8" +parity-scale-codec = { version = "3.2.2", features = ["derive"] } +serde = { version = "1.0.105", features = ["derive"] } +thiserror = "1.0" +sc-client-api = { version = "4.0.0-dev", path = "../../../api" } +sc-consensus-grandpa = { version = "0.10.0-dev", path = "../" } +sc-rpc = { version = "4.0.0-dev", path = "../../../rpc" } +sp-blockchain = { version = "4.0.0-dev", path = "../../../../primitives/blockchain" } +sp-core = { version = "7.0.0", path = "../../../../primitives/core" } +sp-runtime = { version = "7.0.0", path = "../../../../primitives/runtime" } + +[dev-dependencies] +sc-block-builder = { version = "0.10.0-dev", path = "../../../block-builder" } +sc-rpc = { version = "4.0.0-dev", features = ["test-helpers"], path = "../../../rpc" } +sp-core = { version = "7.0.0", path = "../../../../primitives/core" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../../../primitives/consensus/grandpa" } +sp-keyring = { version = "7.0.0", path = "../../../../primitives/keyring" } +substrate-test-runtime-client = { version = "2.0.0", path = "../../../../test-utils/runtime/client" } +tokio = { version = "1.22.0", features = ["macros"] } diff --git a/client/finality-grandpa/rpc/README.md b/client/consensus/grandpa/rpc/README.md similarity index 100% rename from client/finality-grandpa/rpc/README.md rename to client/consensus/grandpa/rpc/README.md diff --git a/client/finality-grandpa/rpc/src/error.rs b/client/consensus/grandpa/rpc/src/error.rs similarity index 97% rename from client/finality-grandpa/rpc/src/error.rs rename to client/consensus/grandpa/rpc/src/error.rs index 885408d8f1d3b..4884380cd22d0 100644 --- a/client/finality-grandpa/rpc/src/error.rs +++ b/client/consensus/grandpa/rpc/src/error.rs @@ -35,7 +35,7 @@ pub enum Error { VoterStateReportsUnreasonablyLargeNumbers, /// GRANDPA prove finality failed. #[error("GRANDPA prove finality rpc failed: {0}")] - ProveFinalityFailed(#[from] sc_finality_grandpa::FinalityProofError), + ProveFinalityFailed(#[from] sc_consensus_grandpa::FinalityProofError), } /// The error codes returned by jsonrpc. diff --git a/client/finality-grandpa/rpc/src/finality.rs b/client/consensus/grandpa/rpc/src/finality.rs similarity index 88% rename from client/finality-grandpa/rpc/src/finality.rs rename to client/consensus/grandpa/rpc/src/finality.rs index dd1f0af8606c6..f8ec01781ac6b 100644 --- a/client/finality-grandpa/rpc/src/finality.rs +++ b/client/consensus/grandpa/rpc/src/finality.rs @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize}; -use sc_finality_grandpa::FinalityProofProvider; +use sc_consensus_grandpa::FinalityProofProvider; use sp_runtime::traits::{Block as BlockT, NumberFor}; #[derive(Serialize, Deserialize)] @@ -31,7 +31,7 @@ pub trait RpcFinalityProofProvider { fn rpc_prove_finality( &self, block: NumberFor, - ) -> Result, sc_finality_grandpa::FinalityProofError>; + ) -> Result, sc_consensus_grandpa::FinalityProofError>; } impl RpcFinalityProofProvider for FinalityProofProvider @@ -43,7 +43,7 @@ where fn rpc_prove_finality( &self, block: NumberFor, - ) -> Result, sc_finality_grandpa::FinalityProofError> { + ) -> Result, sc_consensus_grandpa::FinalityProofError> { self.prove_finality(block).map(|x| x.map(|y| EncodedFinalityProof(y.into()))) } } diff --git a/client/finality-grandpa/rpc/src/lib.rs b/client/consensus/grandpa/rpc/src/lib.rs similarity index 96% rename from client/finality-grandpa/rpc/src/lib.rs rename to client/consensus/grandpa/rpc/src/lib.rs index 8f06531be5f41..c6298bff969bd 100644 --- a/client/finality-grandpa/rpc/src/lib.rs +++ b/client/consensus/grandpa/rpc/src/lib.rs @@ -35,7 +35,7 @@ mod finality; mod notification; mod report; -use sc_finality_grandpa::GrandpaJustificationStream; +use sc_consensus_grandpa::GrandpaJustificationStream; use sc_rpc::SubscriptionTaskExecutor; use sp_runtime::traits::{Block as BlockT, NumberFor}; @@ -105,7 +105,7 @@ where fn subscribe_justifications(&self, mut sink: SubscriptionSink) -> SubscriptionResult { let stream = self.justification_stream.subscribe(100_000).map( - |x: sc_finality_grandpa::GrandpaJustification| { + |x: sc_consensus_grandpa::GrandpaJustification| { JustificationNotification::from(x) }, ); @@ -143,7 +143,7 @@ mod tests { }; use parity_scale_codec::{Decode, Encode}; use sc_block_builder::{BlockBuilder, RecordProof}; - use sc_finality_grandpa::{ + use sc_consensus_grandpa::{ report, AuthorityId, FinalityProof, GrandpaJustification, GrandpaJustificationSender, }; use sp_blockchain::HeaderBackend; @@ -200,7 +200,7 @@ mod tests { fn rpc_prove_finality( &self, _block: NumberFor, - ) -> Result, sc_finality_grandpa::FinalityProofError> { + ) -> Result, sc_consensus_grandpa::FinalityProofError> { Ok(Some(EncodedFinalityProof( self.finality_proof .as_ref() @@ -216,7 +216,7 @@ mod tests { let voter_id_1 = AuthorityId::from_slice(&[1; 32]).unwrap(); let voters_best: HashSet<_> = vec![voter_id_1].into_iter().collect(); - let best_round_state = sc_finality_grandpa::report::RoundState { + let best_round_state = sc_consensus_grandpa::report::RoundState { total_weight: 100_u64.try_into().unwrap(), threshold_weight: 67_u64.try_into().unwrap(), prevote_current_weight: 50.into(), @@ -225,7 +225,7 @@ mod tests { precommit_ids: HashSet::new(), }; - let past_round_state = sc_finality_grandpa::report::RoundState { + let past_round_state = sc_consensus_grandpa::report::RoundState { total_weight: 100_u64.try_into().unwrap(), threshold_weight: 67_u64.try_into().unwrap(), prevote_current_weight: 100.into(), @@ -364,7 +364,7 @@ mod tests { }; let msg = finality_grandpa::Message::Precommit(precommit.clone()); - let encoded = sp_finality_grandpa::localized_payload(round, set_id, &msg); + let encoded = sp_consensus_grandpa::localized_payload(round, set_id, &msg); let signature = peers[0].sign(&encoded[..]).into(); let precommit = finality_grandpa::SignedPrecommit { diff --git a/client/finality-grandpa/rpc/src/notification.rs b/client/consensus/grandpa/rpc/src/notification.rs similarity index 96% rename from client/finality-grandpa/rpc/src/notification.rs rename to client/consensus/grandpa/rpc/src/notification.rs index 45e7d34889b3f..42b9123ed8c14 100644 --- a/client/finality-grandpa/rpc/src/notification.rs +++ b/client/consensus/grandpa/rpc/src/notification.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use parity_scale_codec::Encode; -use sc_finality_grandpa::GrandpaJustification; +use sc_consensus_grandpa::GrandpaJustification; use serde::{Deserialize, Serialize}; use sp_runtime::traits::Block as BlockT; diff --git a/client/finality-grandpa/rpc/src/report.rs b/client/consensus/grandpa/rpc/src/report.rs similarity index 97% rename from client/finality-grandpa/rpc/src/report.rs rename to client/consensus/grandpa/rpc/src/report.rs index 58e59d8aec606..ae4fd76d2857a 100644 --- a/client/finality-grandpa/rpc/src/report.rs +++ b/client/consensus/grandpa/rpc/src/report.rs @@ -24,7 +24,7 @@ use std::{ use serde::{Deserialize, Serialize}; -use sc_finality_grandpa::{report, AuthorityId, SharedAuthoritySet, SharedVoterState}; +use sc_consensus_grandpa::{report, AuthorityId, SharedAuthoritySet, SharedVoterState}; use crate::error::Error; diff --git a/client/finality-grandpa/src/authorities.rs b/client/consensus/grandpa/src/authorities.rs similarity index 99% rename from client/finality-grandpa/src/authorities.rs rename to client/consensus/grandpa/src/authorities.rs index 245c6bfe3c300..623223e41eb82 100644 --- a/client/finality-grandpa/src/authorities.rs +++ b/client/consensus/grandpa/src/authorities.rs @@ -27,7 +27,7 @@ use parity_scale_codec::{Decode, Encode}; use parking_lot::MappedMutexGuard; use sc_consensus::shared_data::{SharedData, SharedDataLocked}; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_INFO}; -use sp_finality_grandpa::{AuthorityId, AuthorityList}; +use sp_consensus_grandpa::{AuthorityId, AuthorityList}; use crate::{SetId, LOG_TARGET}; diff --git a/client/finality-grandpa/src/aux_schema.rs b/client/consensus/grandpa/src/aux_schema.rs similarity index 99% rename from client/finality-grandpa/src/aux_schema.rs rename to client/consensus/grandpa/src/aux_schema.rs index fbb0ab8a8bb06..97a8bc660317a 100644 --- a/client/finality-grandpa/src/aux_schema.rs +++ b/client/consensus/grandpa/src/aux_schema.rs @@ -27,7 +27,7 @@ use parity_scale_codec::{Decode, Encode}; use fork_tree::ForkTree; use sc_client_api::backend::AuxStore; use sp_blockchain::{Error as ClientError, Result as ClientResult}; -use sp_finality_grandpa::{AuthorityList, RoundNumber, SetId}; +use sp_consensus_grandpa::{AuthorityList, RoundNumber, SetId}; use sp_runtime::traits::{Block as BlockT, NumberFor}; use crate::{ @@ -501,8 +501,8 @@ pub(crate) fn load_authorities( #[cfg(test)] mod test { use super::*; + use sp_consensus_grandpa::AuthorityId; use sp_core::{crypto::UncheckedFrom, H256}; - use sp_finality_grandpa::AuthorityId; use substrate_test_runtime_client::{self, runtime::Block}; fn dummy_id() -> AuthorityId { diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/consensus/grandpa/src/communication/gossip.rs similarity index 99% rename from client/finality-grandpa/src/communication/gossip.rs rename to client/consensus/grandpa/src/communication/gossip.rs index 65e765a4cb244..cf476f8e32222 100644 --- a/client/finality-grandpa/src/communication/gossip.rs +++ b/client/consensus/grandpa/src/communication/gossip.rs @@ -95,7 +95,7 @@ use sc_network_common::protocol::role::ObservedRole; use sc_network_gossip::{MessageIntent, ValidatorContext}; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG}; use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; -use sp_finality_grandpa::AuthorityId; +use sp_consensus_grandpa::AuthorityId; use sp_runtime::traits::{Block as BlockT, NumberFor, Zero}; use super::{benefit, cost, Round, SetId, NEIGHBOR_REBROADCAST_PERIOD}; @@ -931,7 +931,7 @@ impl Inner { return Action::Discard(cost::UNKNOWN_VOTER) } - if !sp_finality_grandpa::check_message_signature( + if !sp_consensus_grandpa::check_message_signature( &full.message.message, &full.message.id, &full.message.signature, diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/consensus/grandpa/src/communication/mod.rs similarity index 99% rename from client/finality-grandpa/src/communication/mod.rs rename to client/consensus/grandpa/src/communication/mod.rs index 3c1de1f4699d8..d3ade4bf3d49d 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/consensus/grandpa/src/communication/mod.rs @@ -61,7 +61,7 @@ use gossip::{ }; use sc_network_common::service::{NetworkBlock, NetworkSyncForkRequest}; use sc_utils::mpsc::TracingUnboundedReceiver; -use sp_finality_grandpa::{AuthorityId, AuthoritySignature, RoundNumber, SetId as SetIdNumber}; +use sp_consensus_grandpa::{AuthorityId, AuthoritySignature, RoundNumber, SetId as SetIdNumber}; pub mod gossip; mod periodic; @@ -739,7 +739,7 @@ impl Sink> for OutgoingMessages { // when locals exist, sign messages on import if let Some(ref keystore) = self.keystore { let target_hash = *(msg.target().0); - let signed = sp_finality_grandpa::sign_message( + let signed = sp_consensus_grandpa::sign_message( keystore.keystore(), msg, keystore.local_id().clone(), @@ -842,7 +842,7 @@ fn check_compact_commit( use crate::communication::gossip::Misbehavior; use finality_grandpa::Message as GrandpaMessage; - if !sp_finality_grandpa::check_message_signature_with_buffer( + if !sp_consensus_grandpa::check_message_signature_with_buffer( &GrandpaMessage::Precommit(precommit.clone()), id, sig, @@ -934,7 +934,7 @@ fn check_catch_up( for (msg, id, sig) in messages { signatures_checked += 1; - if !sp_finality_grandpa::check_message_signature_with_buffer( + if !sp_consensus_grandpa::check_message_signature_with_buffer( &msg, id, sig, round, set_id, buf, ) { debug!(target: LOG_TARGET, "Bad catch up message signature {}", id); diff --git a/client/finality-grandpa/src/communication/periodic.rs b/client/consensus/grandpa/src/communication/periodic.rs similarity index 100% rename from client/finality-grandpa/src/communication/periodic.rs rename to client/consensus/grandpa/src/communication/periodic.rs diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/consensus/grandpa/src/communication/tests.rs similarity index 97% rename from client/finality-grandpa/src/communication/tests.rs rename to client/consensus/grandpa/src/communication/tests.rs index 19c2e4fef45e4..21e2e978c8767 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/consensus/grandpa/src/communication/tests.rs @@ -37,7 +37,7 @@ use sc_network_common::{ use sc_network_gossip::Validator; use sc_network_test::{Block, Hash}; use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; -use sp_finality_grandpa::AuthorityList; +use sp_consensus_grandpa::AuthorityList; use sp_keyring::Ed25519Keyring; use sp_runtime::traits::NumberFor; use std::{ @@ -237,8 +237,8 @@ fn config() -> crate::Config { fn voter_set_state() -> SharedVoterSetState { use crate::{authorities::AuthoritySet, environment::VoterSetState}; use finality_grandpa::round::State as RoundState; + use sp_consensus_grandpa::AuthorityId; use sp_core::{crypto::ByteArray, H256}; - use sp_finality_grandpa::AuthorityId; let state = RoundState::genesis((H256::zero(), 0)); let base = state.prevote_ghost.unwrap(); @@ -306,7 +306,7 @@ fn good_commit_leads_to_relay() { let target_number = 500; let precommit = finality_grandpa::Precommit { target_hash, target_number }; - let payload = sp_finality_grandpa::localized_payload( + let payload = sp_consensus_grandpa::localized_payload( round, set_id, &finality_grandpa::Message::Precommit(precommit.clone()), @@ -318,7 +318,7 @@ fn good_commit_leads_to_relay() { for (i, key) in private.iter().enumerate() { precommits.push(precommit.clone()); - let signature = sp_finality_grandpa::AuthoritySignature::from(key.sign(&payload[..])); + let signature = sp_consensus_grandpa::AuthoritySignature::from(key.sign(&payload[..])); auth_data.push((signature, public[i].0.clone())) } @@ -456,7 +456,7 @@ fn bad_commit_leads_to_report() { let target_number = 500; let precommit = finality_grandpa::Precommit { target_hash, target_number }; - let payload = sp_finality_grandpa::localized_payload( + let payload = sp_consensus_grandpa::localized_payload( round, set_id, &finality_grandpa::Message::Precommit(precommit.clone()), @@ -468,7 +468,7 @@ fn bad_commit_leads_to_report() { for (i, key) in private.iter().enumerate() { precommits.push(precommit.clone()); - let signature = sp_finality_grandpa::AuthoritySignature::from(key.sign(&payload[..])); + let signature = sp_consensus_grandpa::AuthoritySignature::from(key.sign(&payload[..])); auth_data.push((signature, public[i].0.clone())) } @@ -631,7 +631,7 @@ fn local_chain_spec() -> Box { } } let chain_spec = GenericChainSpec::::from_json_bytes( - &include_bytes!("../../../chain-spec/res/chain_spec.json")[..], + &include_bytes!("../../../../chain-spec/res/chain_spec.json")[..], ) .unwrap(); chain_spec.cloned_box() diff --git a/client/finality-grandpa/src/environment.rs b/client/consensus/grandpa/src/environment.rs similarity index 99% rename from client/finality-grandpa/src/environment.rs rename to client/consensus/grandpa/src/environment.rs index cdc98fc2206a8..3425426617115 100644 --- a/client/finality-grandpa/src/environment.rs +++ b/client/consensus/grandpa/src/environment.rs @@ -42,7 +42,7 @@ use sc_client_api::{ use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO}; use sp_blockchain::HeaderMetadata; use sp_consensus::SelectChain as SelectChainT; -use sp_finality_grandpa::{ +use sp_consensus_grandpa::{ AuthorityId, AuthoritySignature, Equivocation, EquivocationProof, GrandpaApi, RoundNumber, SetId, GRANDPA_ENGINE_ID, }; diff --git a/client/finality-grandpa/src/finality_proof.rs b/client/consensus/grandpa/src/finality_proof.rs similarity index 98% rename from client/finality-grandpa/src/finality_proof.rs rename to client/consensus/grandpa/src/finality_proof.rs index b042d6fce9f7a..8a8a688583e34 100644 --- a/client/finality-grandpa/src/finality_proof.rs +++ b/client/consensus/grandpa/src/finality_proof.rs @@ -42,7 +42,7 @@ use std::sync::Arc; use parity_scale_codec::{Decode, Encode}; use sc_client_api::backend::Backend; use sp_blockchain::{Backend as BlockchainBackend, HeaderBackend}; -use sp_finality_grandpa::GRANDPA_ENGINE_ID; +use sp_consensus_grandpa::GRANDPA_ENGINE_ID; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header as HeaderT, NumberFor, One}, @@ -264,8 +264,8 @@ mod tests { use sc_block_builder::BlockBuilderProvider; use sc_client_api::{apply_aux, LockImportRun}; use sp_consensus::BlockOrigin; + use sp_consensus_grandpa::GRANDPA_ENGINE_ID as ID; use sp_core::crypto::UncheckedFrom; - use sp_finality_grandpa::GRANDPA_ENGINE_ID as ID; use sp_keyring::Ed25519Keyring; use substrate_test_runtime_client::{ runtime::{Block, Header, H256}, @@ -279,7 +279,7 @@ mod tests { /// AND if at least one of those headers is invalid, all other MUST be considered invalid. fn check_finality_proof( current_set_id: SetId, - current_authorities: sp_finality_grandpa::AuthorityList, + current_authorities: sp_consensus_grandpa::AuthorityList, remote_proof: Vec, ) -> sp_blockchain::Result> where @@ -402,7 +402,7 @@ mod tests { }; let grandpa_just: GrandpaJustification = - sp_finality_grandpa::GrandpaJustification::
{ + sp_consensus_grandpa::GrandpaJustification::
{ round: 8, votes_ancestries: Vec::new(), commit, @@ -442,7 +442,7 @@ mod tests { }; let msg = finality_grandpa::Message::Precommit(precommit.clone()); - let encoded = sp_finality_grandpa::localized_payload(round, set_id, &msg); + let encoded = sp_consensus_grandpa::localized_payload(round, set_id, &msg); let signature = voter.sign(&encoded[..]).into(); let signed_precommit = finality_grandpa::SignedPrecommit { diff --git a/client/finality-grandpa/src/import.rs b/client/consensus/grandpa/src/import.rs similarity index 99% rename from client/finality-grandpa/src/import.rs rename to client/consensus/grandpa/src/import.rs index 19c42463715fb..c1f6cb566dae9 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/consensus/grandpa/src/import.rs @@ -31,8 +31,8 @@ use sc_utils::mpsc::TracingUnboundedSender; use sp_api::{Core, RuntimeApiInfo, TransactionFor}; use sp_blockchain::{well_known_cache_keys, BlockStatus}; use sp_consensus::{BlockOrigin, Error as ConsensusError, SelectChain}; +use sp_consensus_grandpa::{ConsensusLog, GrandpaApi, ScheduledChange, SetId, GRANDPA_ENGINE_ID}; use sp_core::hashing::twox_128; -use sp_finality_grandpa::{ConsensusLog, GrandpaApi, ScheduledChange, SetId, GRANDPA_ENGINE_ID}; use sp_runtime::{ generic::OpaqueDigestItemId, traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero}, diff --git a/client/finality-grandpa/src/justification.rs b/client/consensus/grandpa/src/justification.rs similarity index 93% rename from client/finality-grandpa/src/justification.rs rename to client/consensus/grandpa/src/justification.rs index 1534ca752cb6e..c300a3d7ac43c 100644 --- a/client/finality-grandpa/src/justification.rs +++ b/client/consensus/grandpa/src/justification.rs @@ -25,7 +25,7 @@ use std::{ use finality_grandpa::{voter_set::VoterSet, Error as GrandpaError}; use parity_scale_codec::{Decode, Encode}; use sp_blockchain::{Error as ClientError, HeaderBackend}; -use sp_finality_grandpa::AuthorityId; +use sp_consensus_grandpa::AuthorityId; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor}; use crate::{AuthorityList, Commit, Error}; @@ -41,22 +41,22 @@ use crate::{AuthorityList, Commit, Error}; #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)] pub struct GrandpaJustification { /// The GRANDPA justification for block finality. - pub justification: sp_finality_grandpa::GrandpaJustification, + pub justification: sp_consensus_grandpa::GrandpaJustification, _block: PhantomData, } -impl From> +impl From> for GrandpaJustification { - fn from(justification: sp_finality_grandpa::GrandpaJustification) -> Self { + fn from(justification: sp_consensus_grandpa::GrandpaJustification) -> Self { Self { justification, _block: Default::default() } } } -impl Into> +impl Into> for GrandpaJustification { - fn into(self) -> sp_finality_grandpa::GrandpaJustification { + fn into(self) -> sp_consensus_grandpa::GrandpaJustification { self.justification } } @@ -122,7 +122,7 @@ impl GrandpaJustification { } } - Ok(sp_finality_grandpa::GrandpaJustification { round, commit, votes_ancestries }.into()) + Ok(sp_consensus_grandpa::GrandpaJustification { round, commit, votes_ancestries }.into()) } /// Decode a GRANDPA justification and validate the commit and the votes' @@ -205,7 +205,7 @@ impl GrandpaJustification { let mut buf = Vec::new(); let mut visited_hashes = HashSet::new(); for signed in self.justification.commit.precommits.iter() { - if !sp_finality_grandpa::check_message_signature_with_buffer( + if !sp_consensus_grandpa::check_message_signature_with_buffer( &finality_grandpa::Message::Precommit(signed.precommit.clone()), &signed.id, &signed.signature, diff --git a/client/finality-grandpa/src/lib.rs b/client/consensus/grandpa/src/lib.rs similarity index 99% rename from client/finality-grandpa/src/lib.rs rename to client/consensus/grandpa/src/lib.rs index 4f72bb0521554..ef4beb51b4fff 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/consensus/grandpa/src/lib.rs @@ -75,10 +75,10 @@ use sp_api::ProvideRuntimeApi; use sp_application_crypto::AppKey; use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata, Result as ClientResult}; use sp_consensus::SelectChain; -use sp_core::{crypto::ByteArray, traits::CallContext}; -use sp_finality_grandpa::{ +use sp_consensus_grandpa::{ AuthorityList, AuthoritySignature, SetId, CLIENT_LOG_TARGET as LOG_TARGET, }; +use sp_core::{crypto::ByteArray, traits::CallContext}; use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use sp_runtime::{ generic::BlockId, @@ -146,7 +146,7 @@ use environment::{Environment, VoterSetState}; use until_imported::UntilGlobalMessageBlocksImported; // Re-export these two because it's just so damn convenient. -pub use sp_finality_grandpa::{ +pub use sp_consensus_grandpa::{ AuthorityId, AuthorityPair, CatchUp, Commit, CompactCommit, GrandpaApi, Message, Precommit, Prevote, PrimaryPropose, ScheduledChange, SignedMessage, }; @@ -1091,7 +1091,7 @@ where Poll::Ready(Ok(())) => { // voters don't conclude naturally return Poll::Ready(Err(Error::Safety( - "finality-grandpa inner voter has concluded.".into(), + "consensus-grandpa inner voter has concluded.".into(), ))) }, Poll::Ready(Err(CommandOrError::Error(e))) => { diff --git a/client/finality-grandpa/src/notification.rs b/client/consensus/grandpa/src/notification.rs similarity index 100% rename from client/finality-grandpa/src/notification.rs rename to client/consensus/grandpa/src/notification.rs diff --git a/client/finality-grandpa/src/observer.rs b/client/consensus/grandpa/src/observer.rs similarity index 99% rename from client/finality-grandpa/src/observer.rs rename to client/consensus/grandpa/src/observer.rs index af56f2ac341a4..b382430ef3d4c 100644 --- a/client/finality-grandpa/src/observer.rs +++ b/client/consensus/grandpa/src/observer.rs @@ -32,7 +32,7 @@ use sc_telemetry::TelemetryHandle; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_blockchain::HeaderMetadata; use sp_consensus::SelectChain; -use sp_finality_grandpa::AuthorityId; +use sp_consensus_grandpa::AuthorityId; use sp_keystore::SyncCryptoStorePtr; use sp_runtime::traits::{Block as BlockT, NumberFor}; diff --git a/client/finality-grandpa/src/tests.rs b/client/consensus/grandpa/src/tests.rs similarity index 99% rename from client/finality-grandpa/src/tests.rs rename to client/consensus/grandpa/src/tests.rs index 1a1f20797852a..7cc5e75fa148c 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/consensus/grandpa/src/tests.rs @@ -35,10 +35,10 @@ use sc_network_test::{ }; use sp_api::{ApiRef, ProvideRuntimeApi}; use sp_consensus::{BlockOrigin, Error as ConsensusError, SelectChain}; -use sp_core::H256; -use sp_finality_grandpa::{ +use sp_consensus_grandpa::{ AuthorityList, EquivocationProof, GrandpaApi, OpaqueKeyOwnershipProof, GRANDPA_ENGINE_ID, }; +use sp_core::H256; use sp_keyring::Ed25519Keyring; use sp_keystore::{testing::KeyStore as TestKeyStore, SyncCryptoStore, SyncCryptoStorePtr}; use sp_runtime::{ @@ -398,7 +398,7 @@ async fn run_to_completion( fn add_scheduled_change(block: &mut Block, change: ScheduledChange) { block.header.digest_mut().push(DigestItem::Consensus( GRANDPA_ENGINE_ID, - sp_finality_grandpa::ConsensusLog::ScheduledChange(change).encode(), + sp_consensus_grandpa::ConsensusLog::ScheduledChange(change).encode(), )); } @@ -409,7 +409,7 @@ fn add_forced_change( ) { block.header.digest_mut().push(DigestItem::Consensus( GRANDPA_ENGINE_ID, - sp_finality_grandpa::ConsensusLog::ForcedChange(median_last_finalized, change).encode(), + sp_consensus_grandpa::ConsensusLog::ForcedChange(median_last_finalized, change).encode(), )); } @@ -1798,7 +1798,7 @@ async fn justification_with_equivocation() { let precommit = finality_grandpa::Precommit { target_hash, target_number }; let msg = finality_grandpa::Message::Precommit(precommit.clone()); - let encoded = sp_finality_grandpa::localized_payload(round, set_id, &msg); + let encoded = sp_consensus_grandpa::localized_payload(round, set_id, &msg); let precommit = finality_grandpa::SignedPrecommit { precommit: precommit.clone(), @@ -1871,7 +1871,7 @@ async fn imports_justification_for_regular_blocks_on_import() { }; let msg = finality_grandpa::Message::Precommit(precommit.clone()); - let encoded = sp_finality_grandpa::localized_payload(round, set_id, &msg); + let encoded = sp_consensus_grandpa::localized_payload(round, set_id, &msg); let signature = peers[0].sign(&encoded[..]).into(); let precommit = finality_grandpa::SignedPrecommit { @@ -1946,13 +1946,13 @@ async fn grandpa_environment_doesnt_send_equivocation_reports_for_itself() { // reporting the equivocation should fail since the offender is a local // authority (i.e. we have keys in our keystore for the given id) - let equivocation_proof = sp_finality_grandpa::Equivocation::Prevote(equivocation.clone()); + let equivocation_proof = sp_consensus_grandpa::Equivocation::Prevote(equivocation.clone()); assert!(matches!(environment.report_equivocation(equivocation_proof), Err(Error::Safety(_)))); // if we set the equivocation offender to another id for which we don't have // keys it should work equivocation.identity = TryFrom::try_from(&[1; 32][..]).unwrap(); - let equivocation_proof = sp_finality_grandpa::Equivocation::Prevote(equivocation); + let equivocation_proof = sp_consensus_grandpa::Equivocation::Prevote(equivocation); assert!(environment.report_equivocation(equivocation_proof).is_ok()); } diff --git a/client/finality-grandpa/src/until_imported.rs b/client/consensus/grandpa/src/until_imported.rs similarity index 99% rename from client/finality-grandpa/src/until_imported.rs rename to client/consensus/grandpa/src/until_imported.rs index f9ecb7df34e06..14f32ecc88366 100644 --- a/client/finality-grandpa/src/until_imported.rs +++ b/client/consensus/grandpa/src/until_imported.rs @@ -38,7 +38,7 @@ use parking_lot::Mutex; use prometheus_endpoint::{register, Gauge, PrometheusError, Registry, U64}; use sc_client_api::{BlockImportNotification, ImportNotifications}; use sc_utils::mpsc::TracingUnboundedReceiver; -use sp_finality_grandpa::AuthorityId; +use sp_consensus_grandpa::AuthorityId; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor}; use std::{ diff --git a/client/finality-grandpa/src/voting_rule.rs b/client/consensus/grandpa/src/voting_rule.rs similarity index 100% rename from client/finality-grandpa/src/voting_rule.rs rename to client/consensus/grandpa/src/voting_rule.rs diff --git a/client/finality-grandpa/src/warp_proof.rs b/client/consensus/grandpa/src/warp_proof.rs similarity index 97% rename from client/finality-grandpa/src/warp_proof.rs rename to client/consensus/grandpa/src/warp_proof.rs index f73a0a323e593..cd4fedf96b4c4 100644 --- a/client/finality-grandpa/src/warp_proof.rs +++ b/client/consensus/grandpa/src/warp_proof.rs @@ -25,7 +25,7 @@ use crate::{ use sc_client_api::Backend as ClientBackend; use sc_network_common::sync::warp::{EncodedProof, VerificationResult, WarpSyncProvider}; use sp_blockchain::{Backend as BlockchainBackend, HeaderBackend}; -use sp_finality_grandpa::{AuthorityList, SetId, GRANDPA_ENGINE_ID}; +use sp_consensus_grandpa::{AuthorityList, SetId, GRANDPA_ENGINE_ID}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header as HeaderT, NumberFor, One}, @@ -324,7 +324,7 @@ mod tests { use sc_block_builder::BlockBuilderProvider; use sp_blockchain::HeaderBackend; use sp_consensus::BlockOrigin; - use sp_finality_grandpa::GRANDPA_ENGINE_ID; + use sp_consensus_grandpa::GRANDPA_ENGINE_ID; use sp_keyring::Ed25519Keyring; use sp_runtime::traits::Header as _; use std::sync::Arc; @@ -369,9 +369,9 @@ mod tests { .collect::>(); let digest = sp_runtime::generic::DigestItem::Consensus( - sp_finality_grandpa::GRANDPA_ENGINE_ID, - sp_finality_grandpa::ConsensusLog::ScheduledChange( - sp_finality_grandpa::ScheduledChange { delay: 0u64, next_authorities }, + sp_consensus_grandpa::GRANDPA_ENGINE_ID, + sp_consensus_grandpa::ConsensusLog::ScheduledChange( + sp_consensus_grandpa::ScheduledChange { delay: 0u64, next_authorities }, ) .encode(), ); @@ -394,7 +394,7 @@ mod tests { let precommit = finality_grandpa::Precommit { target_hash, target_number }; let msg = finality_grandpa::Message::Precommit(precommit.clone()); - let encoded = sp_finality_grandpa::localized_payload(42, current_set_id, &msg); + let encoded = sp_consensus_grandpa::localized_payload(42, current_set_id, &msg); let signature = keyring.sign(&encoded[..]).into(); let precommit = finality_grandpa::SignedPrecommit { diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml deleted file mode 100644 index 8a4e0449f2d1c..0000000000000 --- a/client/finality-grandpa/Cargo.toml +++ /dev/null @@ -1,60 +0,0 @@ -[package] -name = "sc-finality-grandpa" -version = "0.10.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "Integration of the GRANDPA finality gadget into substrate." -documentation = "https://docs.rs/sc-finality-grandpa" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -ahash = "0.8.2" -array-bytes = "4.1" -async-trait = "0.1.57" -dyn-clone = "1.0" -finality-grandpa = { version = "0.16.1", features = ["derive-codec"] } -futures = "0.3.21" -futures-timer = "3.0.1" -log = "0.4.17" -parity-scale-codec = { version = "3.2.2", features = ["derive"] } -parking_lot = "0.12.1" -rand = "0.8.5" -serde_json = "1.0.85" -thiserror = "1.0" -fork-tree = { version = "3.0.0", path = "../../utils/fork-tree" } -prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" } -sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" } -sc-chain-spec = { version = "4.0.0-dev", path = "../../client/chain-spec" } -sc-client-api = { version = "4.0.0-dev", path = "../api" } -sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" } -sc-network = { version = "0.10.0-dev", path = "../network" } -sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" } -sc-network-common = { version = "0.10.0-dev", path = "../network/common" } -sc-telemetry = { version = "4.0.0-dev", path = "../telemetry" } -sc-utils = { version = "4.0.0-dev", path = "../utils" } -sp-api = { version = "4.0.0-dev", path = "../../primitives/api" } -sp-application-crypto = { version = "7.0.0", path = "../../primitives/application-crypto" } -sp-arithmetic = { version = "6.0.0", path = "../../primitives/arithmetic" } -sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" } -sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } -sp-core = { version = "7.0.0", path = "../../primitives/core" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../primitives/finality-grandpa" } -sp-keystore = { version = "0.13.0", path = "../../primitives/keystore" } -sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" } - -[dev-dependencies] -assert_matches = "1.3.0" -finality-grandpa = { version = "0.16.1", features = ["derive-codec", "test-helpers"] } -serde = "1.0.136" -tokio = "1.22.0" -sc-network = { version = "0.10.0-dev", path = "../network" } -sc-network-test = { version = "0.8.0", path = "../network/test" } -sp-keyring = { version = "7.0.0", path = "../../primitives/keyring" } -sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" } -substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } diff --git a/client/finality-grandpa/rpc/Cargo.toml b/client/finality-grandpa/rpc/Cargo.toml deleted file mode 100644 index e20ff174d41c5..0000000000000 --- a/client/finality-grandpa/rpc/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "sc-finality-grandpa-rpc" -version = "0.10.0-dev" -authors = ["Parity Technologies "] -description = "RPC extensions for the GRANDPA finality gadget" -repository = "https://github.com/paritytech/substrate/" -edition = "2021" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -readme = "README.md" -homepage = "https://substrate.io" - -[dependencies] -finality-grandpa = { version = "0.16.1", features = ["derive-codec"] } -futures = "0.3.16" -jsonrpsee = { version = "0.16.2", features = ["client-core", "server", "macros"] } -log = "0.4.8" -parity-scale-codec = { version = "3.2.2", features = ["derive"] } -serde = { version = "1.0.105", features = ["derive"] } -thiserror = "1.0" -sc-client-api = { version = "4.0.0-dev", path = "../../api" } -sc-finality-grandpa = { version = "0.10.0-dev", path = "../" } -sc-rpc = { version = "4.0.0-dev", path = "../../rpc" } -sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } -sp-core = { version = "7.0.0", path = "../../../primitives/core" } -sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } - -[dev-dependencies] -sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" } -sc-rpc = { version = "4.0.0-dev", features = [ - "test-helpers", -], path = "../../rpc" } -sp-core = { version = "7.0.0", path = "../../../primitives/core" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../../primitives/finality-grandpa" } -sp-keyring = { version = "7.0.0", path = "../../../primitives/keyring" } -substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" } -tokio = { version = "1.22.0", features = ["macros"] } diff --git a/client/network/README.md b/client/network/README.md index c361bc9249f71..d396747241ab1 100644 --- a/client/network/README.md +++ b/client/network/README.md @@ -190,7 +190,7 @@ The API of `sc-network` allows one to register user-defined notification protoco `sc-network` automatically tries to open a substream towards each node for which the legacy Substream substream is open. The handshake is then performed automatically. -For example, the `sc-finality-grandpa` crate registers the `/paritytech/grandpa/1` +For example, the `sc-consensus-grandpa` crate registers the `/paritytech/grandpa/1` notifications protocol. At the moment, for backwards-compatibility, notification protocols are tied to the legacy diff --git a/client/network/common/Cargo.toml b/client/network/common/Cargo.toml index 2aaada021f0fa..06ff00ef77dbc 100644 --- a/client/network/common/Cargo.toml +++ b/client/network/common/Cargo.toml @@ -32,7 +32,7 @@ sc-consensus = { version = "0.10.0-dev", path = "../../consensus/common" } sc-peerset = { version = "4.0.0-dev", path = "../../peerset" } serde = { version = "1.0.136", features = ["derive"] } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../../primitives/finality-grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../../primitives/consensus/grandpa" } sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } thiserror = "1.0" diff --git a/client/network/common/src/sync/warp.rs b/client/network/common/src/sync/warp.rs index a906091ff2a7b..5f2cacd2eeae5 100644 --- a/client/network/common/src/sync/warp.rs +++ b/client/network/common/src/sync/warp.rs @@ -16,7 +16,7 @@ use codec::{Decode, Encode}; use futures::channel::oneshot; -pub use sp_finality_grandpa::{AuthorityList, SetId}; +pub use sp_consensus_grandpa::{AuthorityList, SetId}; use sp_runtime::traits::{Block as BlockT, NumberFor}; use std::{fmt, sync::Arc}; diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 8ecb3e54902af..8714d66f1332d 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -212,7 +212,7 @@ //! `sc-network` automatically tries to open a substream towards each node for which the legacy //! Substream substream is open. The handshake is then performed automatically. //! -//! For example, the `sc-finality-grandpa` crate registers the `/paritytech/grandpa/1` +//! For example, the `sc-consensus-grandpa` crate registers the `/paritytech/grandpa/1` //! notifications protocol. //! //! At the moment, for backwards-compatibility, notification protocols are tied to the legacy diff --git a/client/network/sync/Cargo.toml b/client/network/sync/Cargo.toml index 532e873836204..bd51776d6f898 100644 --- a/client/network/sync/Cargo.toml +++ b/client/network/sync/Cargo.toml @@ -38,7 +38,7 @@ sp-arithmetic = { version = "6.0.0", path = "../../../primitives/arithmetic" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } sp-core = { version = "7.0.0", path = "../../../primitives/core" } -sp-finality-grandpa = { version = "4.0.0-dev", path = "../../../primitives/finality-grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", path = "../../../primitives/consensus/grandpa" } sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } [dev-dependencies] diff --git a/client/network/sync/src/warp.rs b/client/network/sync/src/warp.rs index 21af507877449..912ad78dfdd08 100644 --- a/client/network/sync/src/warp.rs +++ b/client/network/sync/src/warp.rs @@ -34,7 +34,7 @@ use sc_network_common::sync::{ }, }; use sp_blockchain::HeaderBackend; -use sp_finality_grandpa::{AuthorityList, SetId}; +use sp_consensus_grandpa::{AuthorityList, SetId}; use sp_runtime::traits::{Block as BlockT, Header, NumberFor, Zero}; use std::{sync::Arc, task::Poll}; diff --git a/client/sync-state-rpc/Cargo.toml b/client/sync-state-rpc/Cargo.toml index 3a964521c505b..5447c809c0795 100644 --- a/client/sync-state-rpc/Cargo.toml +++ b/client/sync-state-rpc/Cargo.toml @@ -21,6 +21,6 @@ sc-chain-spec = { version = "4.0.0-dev", path = "../chain-spec" } sc-client-api = { version = "4.0.0-dev", path = "../api" } sc-consensus-babe = { version = "0.10.0-dev", path = "../consensus/babe" } sc-consensus-epochs = { version = "0.10.0-dev", path = "../consensus/epochs" } -sc-finality-grandpa = { version = "0.10.0-dev", path = "../finality-grandpa" } +sc-consensus-grandpa = { version = "0.10.0-dev", path = "../consensus/grandpa" } sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" } sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" } diff --git a/client/sync-state-rpc/src/lib.rs b/client/sync-state-rpc/src/lib.rs index 94bf53c5ab456..78d5cafa31e26 100644 --- a/client/sync-state-rpc/src/lib.rs +++ b/client/sync-state-rpc/src/lib.rs @@ -52,7 +52,7 @@ use sp_runtime::traits::{Block as BlockT, NumberFor}; use std::sync::Arc; type SharedAuthoritySet = - sc_finality_grandpa::SharedAuthoritySet<::Hash, NumberFor>; + sc_consensus_grandpa::SharedAuthoritySet<::Hash, NumberFor>; type SharedEpochChanges = sc_consensus_epochs::SharedEpochChanges; @@ -117,7 +117,7 @@ pub struct LightSyncState { /// The authority set for grandpa. #[serde(serialize_with = "serialize_encoded")] pub grandpa_authority_set: - sc_finality_grandpa::AuthoritySet<::Hash, NumberFor>, + sc_consensus_grandpa::AuthoritySet<::Hash, NumberFor>, } /// An api for sync state RPC calls. diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS index 133ba7b094d43..4377e7ff049dc 100644 --- a/docs/CODEOWNERS +++ b/docs/CODEOWNERS @@ -41,7 +41,7 @@ # GRANDPA, BABE, consensus stuff /frame/babe/ @andresilva /frame/grandpa/ @andresilva -/client/finality-grandpa/ @andresilva +/client/consensus/grandpa/ @andresilva /client/consensus/babe/ @andresilva /client/consensus/slots/ @andresilva /client/consensus/pow/ @sorpaas diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index fa63b8427523a..3ffb516423906 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -23,7 +23,7 @@ pallet-authorship = { version = "4.0.0-dev", default-features = false, path = ". pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } sp-application-crypto = { version = "7.0.0", default-features = false, path = "../../primitives/application-crypto" } sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" } -sp-finality-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/finality-grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/grandpa" } sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" } sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" } @@ -54,7 +54,7 @@ std = [ "scale-info/std", "sp-application-crypto/std", "sp-core/std", - "sp-finality-grandpa/std", + "sp-consensus-grandpa/std", "sp-io/std", "sp-runtime/std", "sp-session/std", diff --git a/frame/grandpa/src/benchmarking.rs b/frame/grandpa/src/benchmarking.rs index 7a3849766d5ec..7a87f0c4b0788 100644 --- a/frame/grandpa/src/benchmarking.rs +++ b/frame/grandpa/src/benchmarking.rs @@ -50,14 +50,14 @@ benchmarks! { 251, 129, 29, 45, 32, 29, 6 ]; - let equivocation_proof1: sp_finality_grandpa::EquivocationProof = + let equivocation_proof1: sp_consensus_grandpa::EquivocationProof = Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap(); let equivocation_proof2 = equivocation_proof1.clone(); }: { - sp_finality_grandpa::check_equivocation_proof(equivocation_proof1); + sp_consensus_grandpa::check_equivocation_proof(equivocation_proof1); } verify { - assert!(sp_finality_grandpa::check_equivocation_proof(equivocation_proof2)); + assert!(sp_consensus_grandpa::check_equivocation_proof(equivocation_proof2)); } note_stalled { diff --git a/frame/grandpa/src/equivocation.rs b/frame/grandpa/src/equivocation.rs index 8de8d7ae68380..7d8eb6774097c 100644 --- a/frame/grandpa/src/equivocation.rs +++ b/frame/grandpa/src/equivocation.rs @@ -39,7 +39,7 @@ use sp_std::prelude::*; use codec::{self as codec, Decode, Encode}; use frame_support::traits::{Get, KeyOwnerProofSystem}; -use sp_finality_grandpa::{EquivocationProof, RoundNumber, SetId}; +use sp_consensus_grandpa::{EquivocationProof, RoundNumber, SetId}; use sp_runtime::{ transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, @@ -251,7 +251,7 @@ fn is_known_offence( key_owner_proof: &T::KeyOwnerProof, ) -> Result<(), TransactionValidityError> { // check the membership proof to extract the offender's id - let key = (sp_finality_grandpa::KEY_TYPE, equivocation_proof.offender().clone()); + let key = (sp_consensus_grandpa::KEY_TYPE, equivocation_proof.offender().clone()); let offender = T::KeyOwnerProofSystem::check_proof(key, key_owner_proof.clone()) .ok_or(InvalidTransaction::BadProof)?; diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 86751e23a31d3..85d116ee7d7e7 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -29,7 +29,7 @@ #![cfg_attr(not(feature = "std"), no_std)] // re-export since this is necessary for `impl_apis` in runtime. -pub use sp_finality_grandpa as fg_primitives; +pub use sp_consensus_grandpa as fg_primitives; use sp_std::prelude::*; @@ -555,7 +555,7 @@ impl Pallet { // validate equivocation proof (check votes are different and // signatures are valid). - if !sp_finality_grandpa::check_equivocation_proof(equivocation_proof) { + if !sp_consensus_grandpa::check_equivocation_proof(equivocation_proof) { return Err(Error::::InvalidEquivocationProof.into()) } diff --git a/frame/grandpa/src/mock.rs b/frame/grandpa/src/mock.rs index 0948be0080889..a33fbb22d6ff8 100644 --- a/frame/grandpa/src/mock.rs +++ b/frame/grandpa/src/mock.rs @@ -30,8 +30,8 @@ use frame_support::{ }, }; use pallet_session::historical as pallet_session_historical; +use sp_consensus_grandpa::{RoundNumber, SetId, GRANDPA_ENGINE_ID}; use sp_core::{crypto::KeyTypeId, H256}; -use sp_finality_grandpa::{RoundNumber, SetId, GRANDPA_ENGINE_ID}; use sp_keyring::Ed25519Keyring; use sp_runtime::{ curve::PiecewiseLinear, @@ -354,12 +354,12 @@ pub fn generate_equivocation_proof( set_id: SetId, vote1: (RoundNumber, H256, u64, &Ed25519Keyring), vote2: (RoundNumber, H256, u64, &Ed25519Keyring), -) -> sp_finality_grandpa::EquivocationProof { +) -> sp_consensus_grandpa::EquivocationProof { let signed_prevote = |round, hash, number, keyring: &Ed25519Keyring| { let prevote = finality_grandpa::Prevote { target_hash: hash, target_number: number }; let prevote_msg = finality_grandpa::Message::Prevote(prevote.clone()); - let payload = sp_finality_grandpa::localized_payload(round, set_id, &prevote_msg); + let payload = sp_consensus_grandpa::localized_payload(round, set_id, &prevote_msg); let signed = keyring.sign(&payload).into(); (prevote, signed) }; @@ -367,9 +367,9 @@ pub fn generate_equivocation_proof( let (prevote1, signed1) = signed_prevote(vote1.0, vote1.1, vote1.2, vote1.3); let (prevote2, signed2) = signed_prevote(vote2.0, vote2.1, vote2.2, vote2.3); - sp_finality_grandpa::EquivocationProof::new( + sp_consensus_grandpa::EquivocationProof::new( set_id, - sp_finality_grandpa::Equivocation::Prevote(finality_grandpa::Equivocation { + sp_consensus_grandpa::Equivocation::Prevote(finality_grandpa::Equivocation { round_number: vote1.0, identity: vote1.3.public().into(), first: (prevote1, signed1), diff --git a/frame/grandpa/src/tests.rs b/frame/grandpa/src/tests.rs index 4fd5727d54ab2..0bf3c8ddf63dc 100644 --- a/frame/grandpa/src/tests.rs +++ b/frame/grandpa/src/tests.rs @@ -355,7 +355,7 @@ fn report_equivocation_current_set_works() { // create the key ownership proof let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); // report the equivocation and the tx should be dispatched successfully assert_ok!(Grandpa::report_equivocation_unsigned( @@ -408,7 +408,7 @@ fn report_equivocation_old_set_works() { // create the key ownership proof in the "old" set let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); start_era(2); @@ -486,7 +486,7 @@ fn report_equivocation_invalid_set_id() { let equivocation_keyring = extract_keyring(equivocation_key); let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); let set_id = Grandpa::current_set_id(); @@ -524,7 +524,7 @@ fn report_equivocation_invalid_session() { // generate a key ownership proof at set id = 1 let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); start_era(2); @@ -563,7 +563,7 @@ fn report_equivocation_invalid_key_owner_proof() { // generate a key ownership proof for the authority at index 1 let invalid_key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &invalid_owner_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &invalid_owner_key)).unwrap(); let equivocation_authority_index = 0; let equivocation_key = &authorities[equivocation_authority_index].0; @@ -610,7 +610,7 @@ fn report_equivocation_invalid_equivocation_proof() { // generate a key ownership proof at set id = 1 let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); let set_id = Grandpa::current_set_id(); @@ -685,7 +685,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { ); let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); let call = Call::report_equivocation_unsigned { equivocation_proof: Box::new(equivocation_proof.clone()), @@ -873,7 +873,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // create the key ownership proof. let key_owner_proof = - Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); // check the dispatch info for the call. let info = Call::::report_equivocation_unsigned { diff --git a/primitives/finality-grandpa/Cargo.toml b/primitives/consensus/grandpa/Cargo.toml similarity index 86% rename from primitives/finality-grandpa/Cargo.toml rename to primitives/consensus/grandpa/Cargo.toml index 39bb6713a2394..7146873e0a751 100644 --- a/primitives/finality-grandpa/Cargo.toml +++ b/primitives/consensus/grandpa/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sp-finality-grandpa" +name = "sp-consensus-grandpa" version = "4.0.0-dev" authors = ["Parity Technologies "] edition = "2021" @@ -7,7 +7,7 @@ license = "Apache-2.0" homepage = "https://substrate.io" repository = "https://github.com/paritytech/substrate/" description = "Primitives for GRANDPA integration, suitable for WASM compilation." -documentation = "https://docs.rs/sp-finality-grandpa" +documentation = "https://docs.rs/sp-consensus-grandpa" readme = "README.md" [package.metadata.docs.rs] @@ -19,12 +19,12 @@ grandpa = { package = "finality-grandpa", version = "0.16.1", default-features = log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.136", features = ["derive"], optional = true } -sp-api = { version = "4.0.0-dev", default-features = false, path = "../api" } -sp-application-crypto = { version = "7.0.0", default-features = false, path = "../application-crypto" } -sp-core = { version = "7.0.0", default-features = false, path = "../core" } -sp-keystore = { version = "0.13.0", default-features = false, optional = true, path = "../keystore" } -sp-runtime = { version = "7.0.0", default-features = false, path = "../runtime" } -sp-std = { version = "5.0.0", default-features = false, path = "../std" } +sp-api = { version = "4.0.0-dev", default-features = false, path = "../../api" } +sp-application-crypto = { version = "7.0.0", default-features = false, path = "../../application-crypto" } +sp-core = { version = "7.0.0", default-features = false, path = "../../core" } +sp-keystore = { version = "0.13.0", default-features = false, optional = true, path = "../../keystore" } +sp-runtime = { version = "7.0.0", default-features = false, path = "../../runtime" } +sp-std = { version = "5.0.0", default-features = false, path = "../../std" } [features] default = ["std"] diff --git a/primitives/finality-grandpa/README.md b/primitives/consensus/grandpa/README.md similarity index 100% rename from primitives/finality-grandpa/README.md rename to primitives/consensus/grandpa/README.md diff --git a/primitives/finality-grandpa/src/lib.rs b/primitives/consensus/grandpa/src/lib.rs similarity index 100% rename from primitives/finality-grandpa/src/lib.rs rename to primitives/consensus/grandpa/src/lib.rs diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 33dbfce680d75..f3222dc15c280 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -38,7 +38,7 @@ pallet-babe = { version = "4.0.0-dev", default-features = false, path = "../../f frame-system = { version = "4.0.0-dev", default-features = false, path = "../../frame/system" } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../frame/system/rpc/runtime-api" } pallet-timestamp = { version = "4.0.0-dev", default-features = false, path = "../../frame/timestamp" } -sp-finality-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/finality-grandpa" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/grandpa" } sp-trie = { version = "7.0.0", default-features = false, path = "../../primitives/trie" } sp-transaction-pool = { version = "4.0.0-dev", default-features = false, path = "../../primitives/transaction-pool" } trie-db = { version = "0.25.1", default-features = false } @@ -97,7 +97,7 @@ std = [ "frame-system/std", "pallet-timestamp/std", "sc-service", - "sp-finality-grandpa/std", + "sp-consensus-grandpa/std", "sp-trie/std", "sp-transaction-pool/std", "trie-db/std", diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 720b0a1e06f07..9e8a4e119b293 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -945,29 +945,29 @@ cfg_if! { } } - impl sp_finality_grandpa::GrandpaApi for Runtime { - fn grandpa_authorities() -> sp_finality_grandpa::AuthorityList { + impl sp_consensus_grandpa::GrandpaApi for Runtime { + fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList { Vec::new() } - fn current_set_id() -> sp_finality_grandpa::SetId { + fn current_set_id() -> sp_consensus_grandpa::SetId { 0 } fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: sp_finality_grandpa::EquivocationProof< + _equivocation_proof: sp_consensus_grandpa::EquivocationProof< ::Hash, NumberFor, >, - _key_owner_proof: sp_finality_grandpa::OpaqueKeyOwnershipProof, + _key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof, ) -> Option<()> { None } fn generate_key_ownership_proof( - _set_id: sp_finality_grandpa::SetId, - _authority_id: sp_finality_grandpa::AuthorityId, - ) -> Option { + _set_id: sp_consensus_grandpa::SetId, + _authority_id: sp_consensus_grandpa::AuthorityId, + ) -> Option { None } }