From b7e0518966b145f22c16137da5c9796fcdb43b73 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Tue, 28 Feb 2023 15:56:22 +0100 Subject: [PATCH] Move BEEFY code to consensus (#13484) * Move beefy primitives to consensus dir * Move beefy gadget to client consensus folder * Rename beefy crates --- Cargo.lock | 174 +++++++++--------- Cargo.toml | 6 +- client/beefy/Cargo.toml | 49 ----- client/consensus/beefy/Cargo.toml | 49 +++++ client/{ => consensus}/beefy/README.md | 0 client/{ => consensus}/beefy/rpc/Cargo.toml | 18 +- client/{ => consensus}/beefy/rpc/src/lib.rs | 12 +- .../beefy/rpc/src/notification.rs | 4 +- .../{ => consensus}/beefy/src/aux_schema.rs | 0 .../beefy/src/communication/gossip.rs | 4 +- .../beefy/src/communication/mod.rs | 0 .../beefy/src/communication/notification.rs | 0 .../beefy/src/communication/peers.rs | 0 .../incoming_requests_handler.rs | 2 +- .../src/communication/request_response/mod.rs | 0 .../outgoing_requests_engine.rs | 2 +- client/{ => consensus}/beefy/src/error.rs | 0 client/{ => consensus}/beefy/src/import.rs | 2 +- .../beefy/src/justification.rs | 10 +- client/{ => consensus}/beefy/src/keystore.rs | 8 +- client/{ => consensus}/beefy/src/lib.rs | 8 +- client/{ => consensus}/beefy/src/metrics.rs | 0 client/{ => consensus}/beefy/src/round.rs | 8 +- client/{ => consensus}/beefy/src/tests.rs | 18 +- client/{ => consensus}/beefy/src/worker.rs | 20 +- client/merkle-mountain-range/Cargo.toml | 4 +- client/merkle-mountain-range/src/lib.rs | 2 +- .../merkle-mountain-range/src/offchain_mmr.rs | 2 +- frame/beefy-mmr/Cargo.toml | 4 +- frame/beefy-mmr/src/lib.rs | 18 +- frame/beefy-mmr/src/mock.rs | 6 +- frame/beefy-mmr/src/tests.rs | 4 +- frame/beefy/Cargo.toml | 4 +- frame/beefy/src/equivocation.rs | 4 +- frame/beefy/src/lib.rs | 12 +- frame/beefy/src/mock.rs | 2 +- frame/beefy/src/tests.rs | 20 +- primitives/{ => consensus}/beefy/Cargo.toml | 18 +- .../{ => consensus}/beefy/src/commitment.rs | 0 primitives/{ => consensus}/beefy/src/lib.rs | 0 primitives/{ => consensus}/beefy/src/mmr.rs | 0 .../{ => consensus}/beefy/src/payload.rs | 0 .../{ => consensus}/beefy/src/test_utils.rs | 0 .../{ => consensus}/beefy/src/witness.rs | 0 .../beefy/test-res/large-raw-commitment | Bin test-utils/runtime/Cargo.toml | 4 +- test-utils/runtime/src/lib.rs | 24 +-- 47 files changed, 260 insertions(+), 262 deletions(-) delete mode 100644 client/beefy/Cargo.toml create mode 100644 client/consensus/beefy/Cargo.toml rename client/{ => consensus}/beefy/README.md (100%) rename client/{ => consensus}/beefy/rpc/Cargo.toml (60%) rename client/{ => consensus}/beefy/rpc/src/lib.rs (97%) rename client/{ => consensus}/beefy/rpc/src/notification.rs (90%) rename client/{ => consensus}/beefy/src/aux_schema.rs (100%) rename client/{ => consensus}/beefy/src/communication/gossip.rs (99%) rename client/{ => consensus}/beefy/src/communication/mod.rs (100%) rename client/{ => consensus}/beefy/src/communication/notification.rs (100%) rename client/{ => consensus}/beefy/src/communication/peers.rs (100%) rename client/{ => consensus}/beefy/src/communication/request_response/incoming_requests_handler.rs (99%) rename client/{ => consensus}/beefy/src/communication/request_response/mod.rs (100%) rename client/{ => consensus}/beefy/src/communication/request_response/outgoing_requests_engine.rs (99%) rename client/{ => consensus}/beefy/src/error.rs (100%) rename client/{ => consensus}/beefy/src/import.rs (99%) rename client/{ => consensus}/beefy/src/justification.rs (98%) rename client/{ => consensus}/beefy/src/keystore.rs (97%) rename client/{ => consensus}/beefy/src/lib.rs (99%) rename client/{ => consensus}/beefy/src/metrics.rs (100%) rename client/{ => consensus}/beefy/src/round.rs (99%) rename client/{ => consensus}/beefy/src/tests.rs (99%) rename client/{ => consensus}/beefy/src/worker.rs (99%) rename primitives/{ => consensus}/beefy/Cargo.toml (84%) rename primitives/{ => consensus}/beefy/src/commitment.rs (100%) rename primitives/{ => consensus}/beefy/src/lib.rs (100%) rename primitives/{ => consensus}/beefy/src/mmr.rs (100%) rename primitives/{ => consensus}/beefy/src/payload.rs (100%) rename primitives/{ => consensus}/beefy/src/test_utils.rs (100%) rename primitives/{ => consensus}/beefy/src/witness.rs (100%) rename primitives/{ => consensus}/beefy/test-res/large-raw-commitment (100%) diff --git a/Cargo.lock b/Cargo.lock index 91ae9ab422c3e..a29213b45b545 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,69 +493,6 @@ dependencies = [ "serde", ] -[[package]] -name = "beefy-gadget" -version = "4.0.0-dev" -dependencies = [ - "array-bytes", - "async-trait", - "fnv", - "futures", - "log", - "parity-scale-codec", - "parking_lot 0.12.1", - "sc-block-builder", - "sc-client-api", - "sc-consensus", - "sc-keystore", - "sc-network", - "sc-network-common", - "sc-network-gossip", - "sc-network-test", - "sc-utils", - "serde", - "sp-api", - "sp-application-crypto", - "sp-arithmetic", - "sp-beefy", - "sp-blockchain", - "sp-consensus", - "sp-consensus-grandpa", - "sp-core", - "sp-keyring", - "sp-keystore", - "sp-mmr-primitives", - "sp-runtime", - "sp-tracing", - "substrate-prometheus-endpoint", - "substrate-test-runtime-client", - "tempfile", - "thiserror", - "tokio", - "wasm-timer", -] - -[[package]] -name = "beefy-gadget-rpc" -version = "4.0.0-dev" -dependencies = [ - "beefy-gadget", - "futures", - "jsonrpsee", - "log", - "parity-scale-codec", - "parking_lot 0.12.1", - "sc-rpc", - "serde", - "serde_json", - "sp-beefy", - "sp-core", - "sp-runtime", - "substrate-test-runtime-client", - "thiserror", - "tokio", -] - [[package]] name = "binary-merkle-tree" version = "4.0.0-dev" @@ -4492,9 +4429,9 @@ dependencies = [ "sc-client-api", "sc-offchain", "sp-api", - "sp-beefy", "sp-blockchain", "sp-consensus", + "sp-consensus-beefy", "sp-core", "sp-mmr-primitives", "sp-runtime", @@ -5555,7 +5492,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-beefy", + "sp-consensus-beefy", "sp-core", "sp-io", "sp-runtime", @@ -5580,7 +5517,7 @@ dependencies = [ "scale-info", "serde", "sp-api", - "sp-beefy", + "sp-consensus-beefy", "sp-core", "sp-io", "sp-runtime", @@ -8333,6 +8270,69 @@ dependencies = [ "tokio", ] +[[package]] +name = "sc-consensus-beefy" +version = "4.0.0-dev" +dependencies = [ + "array-bytes", + "async-trait", + "fnv", + "futures", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-block-builder", + "sc-client-api", + "sc-consensus", + "sc-keystore", + "sc-network", + "sc-network-common", + "sc-network-gossip", + "sc-network-test", + "sc-utils", + "serde", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-beefy", + "sp-consensus-grandpa", + "sp-core", + "sp-keyring", + "sp-keystore", + "sp-mmr-primitives", + "sp-runtime", + "sp-tracing", + "substrate-prometheus-endpoint", + "substrate-test-runtime-client", + "tempfile", + "thiserror", + "tokio", + "wasm-timer", +] + +[[package]] +name = "sc-consensus-beefy-rpc" +version = "4.0.0-dev" +dependencies = [ + "futures", + "jsonrpsee", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-consensus-beefy", + "sc-rpc", + "serde", + "serde_json", + "sp-consensus-beefy", + "sp-core", + "sp-runtime", + "substrate-test-runtime-client", + "thiserror", + "tokio", +] + [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" @@ -9829,26 +9829,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "sp-beefy" -version = "4.0.0-dev" -dependencies = [ - "array-bytes", - "lazy_static", - "parity-scale-codec", - "scale-info", - "serde", - "sp-api", - "sp-application-crypto", - "sp-core", - "sp-io", - "sp-keystore", - "sp-mmr-primitives", - "sp-runtime", - "sp-std", - "strum", -] - [[package]] name = "sp-block-builder" version = "4.0.0-dev" @@ -9934,6 +9914,26 @@ dependencies = [ "sp-timestamp", ] +[[package]] +name = "sp-consensus-beefy" +version = "4.0.0-dev" +dependencies = [ + "array-bytes", + "lazy_static", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-core", + "sp-io", + "sp-keystore", + "sp-mmr-primitives", + "sp-runtime", + "sp-std", + "strum", +] + [[package]] name = "sp-consensus-grandpa" version = "4.0.0-dev" @@ -10837,11 +10837,11 @@ dependencies = [ "serde", "sp-api", "sp-application-crypto", - "sp-beefy", "sp-block-builder", "sp-consensus", "sp-consensus-aura", "sp-consensus-babe", + "sp-consensus-beefy", "sp-consensus-grandpa", "sp-core", "sp-externalities", diff --git a/Cargo.toml b/Cargo.toml index 88c9c1998f415..af2d8f9066fa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,6 @@ members = [ "client/api", "client/authority-discovery", "client/basic-authorship", - "client/beefy", - "client/beefy/rpc", "client/block-builder", "client/chain-spec", "client/chain-spec/derive", @@ -27,6 +25,8 @@ members = [ "client/consensus/aura", "client/consensus/babe", "client/consensus/babe/rpc", + "client/consensus/beefy", + "client/consensus/beefy/rpc", "client/consensus/common", "client/consensus/epochs", "client/consensus/grandpa", @@ -178,11 +178,11 @@ members = [ "primitives/arithmetic", "primitives/arithmetic/fuzzer", "primitives/authority-discovery", - "primitives/beefy", "primitives/block-builder", "primitives/blockchain", "primitives/consensus/aura", "primitives/consensus/babe", + "primitives/consensus/beefy", "primitives/consensus/common", "primitives/consensus/grandpa", "primitives/consensus/pow", diff --git a/client/beefy/Cargo.toml b/client/beefy/Cargo.toml deleted file mode 100644 index eb616823680aa..0000000000000 --- a/client/beefy/Cargo.toml +++ /dev/null @@ -1,49 +0,0 @@ -[package] -name = "beefy-gadget" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -repository = "https://github.com/paritytech/substrate" -description = "BEEFY Client gadget for substrate" -homepage = "https://substrate.io" - -[dependencies] -array-bytes = "4.1" -async-trait = "0.1.57" -codec = { package = "parity-scale-codec", version = "3.2.2", features = ["derive"] } -fnv = "1.0.6" -futures = "0.3" -log = "0.4" -parking_lot = "0.12.1" -thiserror = "1.0" -wasm-timer = "0.2.5" -beefy-primitives = { version = "4.0.0-dev", path = "../../primitives/beefy", package = "sp-beefy" } -prometheus = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" } -sc-client-api = { version = "4.0.0-dev", path = "../api" } -sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" } -sc-keystore = { version = "4.0.0-dev", path = "../keystore" } -sc-network = { version = "0.10.0-dev", path = "../network" } -sc-network-common = { version = "0.10.0-dev", path = "../network/common" } -sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" } -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-keystore = { version = "0.13.0", path = "../../primitives/keystore" } -sp-mmr-primitives = { version = "4.0.0-dev", path = "../../primitives/merkle-mountain-range" } -sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" } - -[dev-dependencies] -serde = "1.0.136" -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-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/beefy/Cargo.toml b/client/consensus/beefy/Cargo.toml new file mode 100644 index 0000000000000..d88c07df2612f --- /dev/null +++ b/client/consensus/beefy/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "sc-consensus-beefy" +version = "4.0.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" +repository = "https://github.com/paritytech/substrate" +description = "BEEFY Client gadget for substrate" +homepage = "https://substrate.io" + +[dependencies] +array-bytes = "4.1" +async-trait = "0.1.57" +codec = { package = "parity-scale-codec", version = "3.2.2", features = ["derive"] } +fnv = "1.0.6" +futures = "0.3" +log = "0.4" +parking_lot = "0.12.1" +thiserror = "1.0" +wasm-timer = "0.2.5" +prometheus = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" } +sc-client-api = { version = "4.0.0-dev", path = "../../api" } +sc-consensus = { version = "0.10.0-dev", path = "../../consensus/common" } +sc-keystore = { version = "4.0.0-dev", path = "../../keystore" } +sc-network = { version = "0.10.0-dev", path = "../../network" } +sc-network-common = { version = "0.10.0-dev", path = "../../network/common" } +sc-network-gossip = { version = "0.10.0-dev", path = "../../network-gossip" } +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-consensus-beefy = { version = "4.0.0-dev", path = "../../../primitives/consensus/beefy" } +sp-core = { version = "7.0.0", path = "../../../primitives/core" } +sp-keystore = { version = "0.13.0", path = "../../../primitives/keystore" } +sp-mmr-primitives = { version = "4.0.0-dev", path = "../../../primitives/merkle-mountain-range" } +sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } + +[dev-dependencies] +serde = "1.0.136" +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-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/beefy/README.md b/client/consensus/beefy/README.md similarity index 100% rename from client/beefy/README.md rename to client/consensus/beefy/README.md diff --git a/client/beefy/rpc/Cargo.toml b/client/consensus/beefy/rpc/Cargo.toml similarity index 60% rename from client/beefy/rpc/Cargo.toml rename to client/consensus/beefy/rpc/Cargo.toml index ab3e6921f3cfe..d6dfa8731a3be 100644 --- a/client/beefy/rpc/Cargo.toml +++ b/client/consensus/beefy/rpc/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "beefy-gadget-rpc" +name = "sc-consensus-beefy-rpc" version = "4.0.0-dev" authors = ["Parity Technologies "] edition = "2021" @@ -16,16 +16,14 @@ log = "0.4" parking_lot = "0.12.1" serde = { version = "1.0.136", features = ["derive"] } thiserror = "1.0" -beefy-gadget = { version = "4.0.0-dev", path = "../." } -beefy-primitives = { version = "4.0.0-dev", path = "../../../primitives/beefy", package = "sp-beefy" } -sc-rpc = { version = "4.0.0-dev", path = "../../rpc" } -sp-core = { version = "7.0.0", path = "../../../primitives/core" } -sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" } +sc-consensus-beefy = { version = "4.0.0-dev", path = "../" } +sp-consensus-beefy = { version = "4.0.0-dev", path = "../../../../primitives/consensus/beefy" } +sc-rpc = { version = "4.0.0-dev", path = "../../../rpc" } +sp-core = { version = "7.0.0", path = "../../../../primitives/core" } +sp-runtime = { version = "7.0.0", path = "../../../../primitives/runtime" } [dev-dependencies] serde_json = "1.0.85" -sc-rpc = { version = "4.0.0-dev", features = [ - "test-helpers", -], path = "../../rpc" } -substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" } +sc-rpc = { version = "4.0.0-dev", features = ["test-helpers"], path = "../../../rpc" } +substrate-test-runtime-client = { version = "2.0.0", path = "../../../../test-utils/runtime/client" } tokio = { version = "1.22.0", features = ["macros"] } diff --git a/client/beefy/rpc/src/lib.rs b/client/consensus/beefy/rpc/src/lib.rs similarity index 97% rename from client/beefy/rpc/src/lib.rs rename to client/consensus/beefy/rpc/src/lib.rs index 0a7a4de14cbcc..f5c0ff32627d5 100644 --- a/client/beefy/rpc/src/lib.rs +++ b/client/consensus/beefy/rpc/src/lib.rs @@ -35,7 +35,7 @@ use jsonrpsee::{ }; use log::warn; -use beefy_gadget::communication::notification::{ +use sc_consensus_beefy::communication::notification::{ BeefyBestBlockStream, BeefyVersionedFinalityProofStream, }; @@ -166,13 +166,13 @@ where mod tests { use super::*; - use beefy_gadget::{ + use codec::{Decode, Encode}; + use jsonrpsee::{types::EmptyServerParams as EmptyParams, RpcModule}; + use sc_consensus_beefy::{ communication::notification::BeefyVersionedFinalityProofSender, justification::BeefyVersionedFinalityProof, }; - use beefy_primitives::{known_payloads, Payload, SignedCommitment}; - use codec::{Decode, Encode}; - use jsonrpsee::{types::EmptyServerParams as EmptyParams, RpcModule}; + use sp_consensus_beefy::{known_payloads, Payload, SignedCommitment}; use sp_runtime::traits::{BlakeTwo256, Hash}; use substrate_test_runtime_client::runtime::Block; @@ -269,7 +269,7 @@ mod tests { let payload = Payload::from_single_entry(known_payloads::MMR_ROOT_ID, "Hello World!".encode()); BeefyVersionedFinalityProof::::V1(SignedCommitment { - commitment: beefy_primitives::Commitment { + commitment: sp_consensus_beefy::Commitment { payload, block_number: 5, validator_set_id: 0, diff --git a/client/beefy/rpc/src/notification.rs b/client/consensus/beefy/rpc/src/notification.rs similarity index 90% rename from client/beefy/rpc/src/notification.rs rename to client/consensus/beefy/rpc/src/notification.rs index 286385187c342..690c511b999ac 100644 --- a/client/beefy/rpc/src/notification.rs +++ b/client/consensus/beefy/rpc/src/notification.rs @@ -23,13 +23,13 @@ use sp_runtime::traits::Block as BlockT; /// An encoded finality proof proving that the given header has been finalized. /// The given bytes should be the SCALE-encoded representation of a -/// `beefy_primitives::VersionedFinalityProof`. +/// `sp_consensus_beefy::VersionedFinalityProof`. #[derive(Clone, Serialize, Deserialize)] pub struct EncodedVersionedFinalityProof(sp_core::Bytes); impl EncodedVersionedFinalityProof { pub fn new( - finality_proof: beefy_gadget::justification::BeefyVersionedFinalityProof, + finality_proof: sc_consensus_beefy::justification::BeefyVersionedFinalityProof, ) -> Self where Block: BlockT, diff --git a/client/beefy/src/aux_schema.rs b/client/consensus/beefy/src/aux_schema.rs similarity index 100% rename from client/beefy/src/aux_schema.rs rename to client/consensus/beefy/src/aux_schema.rs diff --git a/client/beefy/src/communication/gossip.rs b/client/consensus/beefy/src/communication/gossip.rs similarity index 99% rename from client/beefy/src/communication/gossip.rs rename to client/consensus/beefy/src/communication/gossip.rs index a1fb6fa26e5d4..219203ee4e173 100644 --- a/client/beefy/src/communication/gossip.rs +++ b/client/consensus/beefy/src/communication/gossip.rs @@ -29,7 +29,7 @@ use parking_lot::{Mutex, RwLock}; use wasm_timer::Instant; use crate::{communication::peers::KnownPeers, keystore::BeefyKeystore, LOG_TARGET}; -use beefy_primitives::{ +use sp_consensus_beefy::{ crypto::{Public, Signature}, VoteMessage, }; @@ -243,7 +243,7 @@ mod tests { use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use crate::keystore::BeefyKeystore; - use beefy_primitives::{ + use sp_consensus_beefy::{ crypto::Signature, known_payloads, Commitment, Keyring, MmrRootHash, Payload, VoteMessage, KEY_TYPE, }; diff --git a/client/beefy/src/communication/mod.rs b/client/consensus/beefy/src/communication/mod.rs similarity index 100% rename from client/beefy/src/communication/mod.rs rename to client/consensus/beefy/src/communication/mod.rs diff --git a/client/beefy/src/communication/notification.rs b/client/consensus/beefy/src/communication/notification.rs similarity index 100% rename from client/beefy/src/communication/notification.rs rename to client/consensus/beefy/src/communication/notification.rs diff --git a/client/beefy/src/communication/peers.rs b/client/consensus/beefy/src/communication/peers.rs similarity index 100% rename from client/beefy/src/communication/peers.rs rename to client/consensus/beefy/src/communication/peers.rs diff --git a/client/beefy/src/communication/request_response/incoming_requests_handler.rs b/client/consensus/beefy/src/communication/request_response/incoming_requests_handler.rs similarity index 99% rename from client/beefy/src/communication/request_response/incoming_requests_handler.rs rename to client/consensus/beefy/src/communication/request_response/incoming_requests_handler.rs index 3266f6dba3989..ab6c21a187c95 100644 --- a/client/beefy/src/communication/request_response/incoming_requests_handler.rs +++ b/client/consensus/beefy/src/communication/request_response/incoming_requests_handler.rs @@ -16,7 +16,6 @@ //! Helper for handling (i.e. answering) BEEFY justifications requests from a remote peer. -use beefy_primitives::BEEFY_ENGINE_ID; use codec::Decode; use futures::{ channel::{mpsc, oneshot}, @@ -26,6 +25,7 @@ use log::{debug, trace}; use sc_client_api::BlockBackend; use sc_network::{config as netconfig, config::RequestResponseConfig, PeerId, ReputationChange}; use sc_network_common::protocol::ProtocolName; +use sp_consensus_beefy::BEEFY_ENGINE_ID; use sp_runtime::traits::Block; use std::{marker::PhantomData, sync::Arc}; diff --git a/client/beefy/src/communication/request_response/mod.rs b/client/consensus/beefy/src/communication/request_response/mod.rs similarity index 100% rename from client/beefy/src/communication/request_response/mod.rs rename to client/consensus/beefy/src/communication/request_response/mod.rs diff --git a/client/beefy/src/communication/request_response/outgoing_requests_engine.rs b/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs similarity index 99% rename from client/beefy/src/communication/request_response/outgoing_requests_engine.rs rename to client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs index 0f4f07835ca82..7450d4b3239f1 100644 --- a/client/beefy/src/communication/request_response/outgoing_requests_engine.rs +++ b/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs @@ -18,7 +18,6 @@ //! Generating request logic for request/response protocol for syncing BEEFY justifications. -use beefy_primitives::{crypto::AuthorityId, ValidatorSet}; use codec::Encode; use futures::channel::{oneshot, oneshot::Canceled}; use log::{debug, warn}; @@ -28,6 +27,7 @@ use sc_network_common::{ request_responses::{IfDisconnected, RequestFailure}, service::NetworkRequest, }; +use sp_consensus_beefy::{crypto::AuthorityId, ValidatorSet}; use sp_runtime::traits::{Block, NumberFor}; use std::{collections::VecDeque, result::Result, sync::Arc}; diff --git a/client/beefy/src/error.rs b/client/consensus/beefy/src/error.rs similarity index 100% rename from client/beefy/src/error.rs rename to client/consensus/beefy/src/error.rs diff --git a/client/beefy/src/import.rs b/client/consensus/beefy/src/import.rs similarity index 99% rename from client/beefy/src/import.rs rename to client/consensus/beefy/src/import.rs index 44d30d5d7df03..177a99b1066b2 100644 --- a/client/beefy/src/import.rs +++ b/client/consensus/beefy/src/import.rs @@ -16,8 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use beefy_primitives::{BeefyApi, BEEFY_ENGINE_ID}; use log::debug; +use sp_consensus_beefy::{BeefyApi, BEEFY_ENGINE_ID}; use std::{collections::HashMap, sync::Arc}; use sp_api::{ProvideRuntimeApi, TransactionFor}; diff --git a/client/beefy/src/justification.rs b/client/consensus/beefy/src/justification.rs similarity index 98% rename from client/beefy/src/justification.rs rename to client/consensus/beefy/src/justification.rs index 6ceb3d2f5b369..1bd250b2a25f3 100644 --- a/client/beefy/src/justification.rs +++ b/client/consensus/beefy/src/justification.rs @@ -17,17 +17,17 @@ // along with this program. If not, see . use crate::keystore::BeefyKeystore; -use beefy_primitives::{ +use codec::{Decode, Encode}; +use sp_consensus::Error as ConsensusError; +use sp_consensus_beefy::{ crypto::{AuthorityId, Signature}, ValidatorSet, VersionedFinalityProof, }; -use codec::{Decode, Encode}; -use sp_consensus::Error as ConsensusError; use sp_runtime::traits::{Block as BlockT, NumberFor}; /// A finality proof with matching BEEFY authorities' signatures. pub type BeefyVersionedFinalityProof = - beefy_primitives::VersionedFinalityProof, Signature>; + sp_consensus_beefy::VersionedFinalityProof, Signature>; /// Decode and verify a Beefy FinalityProof. pub(crate) fn decode_and_verify_finality_proof( @@ -80,7 +80,7 @@ fn verify_with_validator_set( #[cfg(test)] pub(crate) mod tests { - use beefy_primitives::{ + use sp_consensus_beefy::{ known_payloads, Commitment, Keyring, Payload, SignedCommitment, VersionedFinalityProof, }; use substrate_test_runtime_client::runtime::Block; diff --git a/client/beefy/src/keystore.rs b/client/consensus/beefy/src/keystore.rs similarity index 97% rename from client/beefy/src/keystore.rs rename to client/consensus/beefy/src/keystore.rs index 3f0d8a5f316af..421f7149018c8 100644 --- a/client/beefy/src/keystore.rs +++ b/client/consensus/beefy/src/keystore.rs @@ -22,7 +22,7 @@ use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use log::warn; -use beefy_primitives::{ +use sp_consensus_beefy::{ crypto::{Public, Signature}, BeefyAuthorityId, KEY_TYPE, }; @@ -89,8 +89,8 @@ impl BeefyKeystore { Ok(sig) } - /// Returns a vector of [`beefy_primitives::crypto::Public`] keys which are currently supported - /// (i.e. found in the keystore). + /// Returns a vector of [`sp_consensus_beefy::crypto::Public`] keys which are currently + /// supported (i.e. found in the keystore). pub fn public_keys(&self) -> Result, error::Error> { let store = self.0.clone().ok_or_else(|| error::Error::Keystore("no Keystore".into()))?; @@ -123,7 +123,7 @@ pub mod tests { use sc_keystore::LocalKeystore; use sp_core::{ecdsa, Pair}; - use beefy_primitives::{crypto, Keyring}; + use sp_consensus_beefy::{crypto, Keyring}; use super::*; use crate::error::Error; diff --git a/client/beefy/src/lib.rs b/client/consensus/beefy/src/lib.rs similarity index 99% rename from client/beefy/src/lib.rs rename to client/consensus/beefy/src/lib.rs index 4f5f8b44329bf..9b627e3ff8fef 100644 --- a/client/beefy/src/lib.rs +++ b/client/consensus/beefy/src/lib.rs @@ -32,10 +32,6 @@ use crate::{ round::Rounds, worker::PersistedState, }; -use beefy_primitives::{ - crypto::AuthorityId, BeefyApi, MmrRootHash, PayloadProvider, ValidatorSet, BEEFY_ENGINE_ID, - GENESIS_AUTHORITY_SET_ID, -}; use futures::{stream::Fuse, StreamExt}; use log::{error, info}; use parking_lot::Mutex; @@ -50,6 +46,10 @@ use sp_blockchain::{ Backend as BlockchainBackend, Error as ClientError, HeaderBackend, Result as ClientResult, }; use sp_consensus::{Error as ConsensusError, SyncOracle}; +use sp_consensus_beefy::{ + crypto::AuthorityId, BeefyApi, MmrRootHash, PayloadProvider, ValidatorSet, BEEFY_ENGINE_ID, + GENESIS_AUTHORITY_SET_ID, +}; use sp_keystore::SyncCryptoStorePtr; use sp_mmr_primitives::MmrApi; use sp_runtime::traits::{Block, Zero}; diff --git a/client/beefy/src/metrics.rs b/client/consensus/beefy/src/metrics.rs similarity index 100% rename from client/beefy/src/metrics.rs rename to client/consensus/beefy/src/metrics.rs diff --git a/client/beefy/src/round.rs b/client/consensus/beefy/src/round.rs similarity index 99% rename from client/beefy/src/round.rs rename to client/consensus/beefy/src/round.rs index 142e138f599d5..64d03beeee854 100644 --- a/client/beefy/src/round.rs +++ b/client/consensus/beefy/src/round.rs @@ -18,12 +18,12 @@ use crate::LOG_TARGET; -use beefy_primitives::{ +use codec::{Decode, Encode}; +use log::debug; +use sp_consensus_beefy::{ crypto::{AuthorityId, Public, Signature}, Commitment, EquivocationProof, SignedCommitment, ValidatorSet, ValidatorSetId, VoteMessage, }; -use codec::{Decode, Encode}; -use log::debug; use sp_runtime::traits::{Block, NumberFor}; use std::collections::BTreeMap; @@ -198,7 +198,7 @@ where mod tests { use sc_network_test::Block; - use beefy_primitives::{ + use sp_consensus_beefy::{ crypto::Public, known_payloads::MMR_ROOT_ID, Commitment, EquivocationProof, Keyring, Payload, SignedCommitment, ValidatorSet, VoteMessage, }; diff --git a/client/beefy/src/tests.rs b/client/consensus/beefy/src/tests.rs similarity index 99% rename from client/beefy/src/tests.rs rename to client/consensus/beefy/src/tests.rs index 419033efe367f..e4fe16a2acfd3 100644 --- a/client/beefy/src/tests.rs +++ b/client/consensus/beefy/src/tests.rs @@ -29,14 +29,6 @@ use crate::{ load_or_init_voter_state, wait_for_runtime_pallet, BeefyRPCLinks, BeefyVoterLinks, KnownPeers, PersistedState, }; -use beefy_primitives::{ - crypto::{AuthorityId, Signature}, - known_payloads, - mmr::MmrRootProvider, - BeefyApi, Commitment, ConsensusLog, EquivocationProof, Keyring as BeefyKeyring, MmrRootHash, - OpaqueKeyOwnershipProof, Payload, SignedCommitment, ValidatorSet, ValidatorSetId, - VersionedFinalityProof, BEEFY_ENGINE_ID, KEY_TYPE as BeefyKeyType, -}; use futures::{future, stream::FuturesUnordered, Future, StreamExt}; use parking_lot::Mutex; use sc_client_api::{Backend as BackendT, BlockchainEvents, FinalityNotifications, HeaderBackend}; @@ -53,6 +45,14 @@ use sc_utils::notification::NotificationReceiver; use serde::{Deserialize, Serialize}; use sp_api::{ApiRef, ProvideRuntimeApi}; use sp_consensus::BlockOrigin; +use sp_consensus_beefy::{ + crypto::{AuthorityId, Signature}, + known_payloads, + mmr::MmrRootProvider, + BeefyApi, Commitment, ConsensusLog, EquivocationProof, Keyring as BeefyKeyring, MmrRootHash, + OpaqueKeyOwnershipProof, Payload, SignedCommitment, ValidatorSet, ValidatorSetId, + VersionedFinalityProof, BEEFY_ENGINE_ID, KEY_TYPE as BeefyKeyType, +}; use sp_core::H256; use sp_keystore::{testing::KeyStore as TestKeystore, SyncCryptoStore, SyncCryptoStorePtr}; use sp_mmr_primitives::{Error as MmrError, MmrApi}; @@ -484,7 +484,7 @@ async fn wait_for_beefy_signed_commitments( let expected = expected.next(); async move { let signed_commitment = match versioned_finality_proof { - beefy_primitives::VersionedFinalityProof::V1(sc) => sc, + sp_consensus_beefy::VersionedFinalityProof::V1(sc) => sc, }; let commitment_block_num = signed_commitment.commitment.block_number; assert_eq!(expected, Some(commitment_block_num).as_ref()); diff --git a/client/beefy/src/worker.rs b/client/consensus/beefy/src/worker.rs similarity index 99% rename from client/beefy/src/worker.rs rename to client/consensus/beefy/src/worker.rs index 439da213818df..7f3114958647f 100644 --- a/client/beefy/src/worker.rs +++ b/client/consensus/beefy/src/worker.rs @@ -29,12 +29,6 @@ use crate::{ round::{Rounds, VoteImportResult}, BeefyVoterLinks, LOG_TARGET, }; -use beefy_primitives::{ - check_equivocation_proof, - crypto::{AuthorityId, Signature}, - BeefyApi, Commitment, ConsensusLog, EquivocationProof, PayloadProvider, ValidatorSet, - VersionedFinalityProof, VoteMessage, BEEFY_ENGINE_ID, -}; use codec::{Codec, Decode, Encode}; use futures::{stream::Fuse, FutureExt, StreamExt}; use log::{debug, error, info, log_enabled, trace, warn}; @@ -45,6 +39,12 @@ use sc_utils::notification::NotificationReceiver; use sp_api::{BlockId, ProvideRuntimeApi}; use sp_arithmetic::traits::{AtLeast32Bit, Saturating}; use sp_consensus::SyncOracle; +use sp_consensus_beefy::{ + check_equivocation_proof, + crypto::{AuthorityId, Signature}, + BeefyApi, Commitment, ConsensusLog, EquivocationProof, PayloadProvider, ValidatorSet, + VersionedFinalityProof, VoteMessage, BEEFY_ENGINE_ID, +}; use sp_runtime::{ generic::OpaqueDigestItemId, traits::{Block, ConstU32, Header, NumberFor, Zero}, @@ -1062,10 +1062,6 @@ pub(crate) mod tests { }, BeefyRPCLinks, KnownPeers, }; - use beefy_primitives::{ - generate_equivocation_proof, known_payloads, known_payloads::MMR_ROOT_ID, - mmr::MmrRootProvider, Keyring, Payload, SignedCommitment, - }; use futures::{future::poll_fn, task::Poll}; use parking_lot::Mutex; use sc_client_api::{Backend as BackendT, HeaderBackend}; @@ -1073,6 +1069,10 @@ pub(crate) mod tests { use sc_network_test::TestNetFactory; use sp_api::HeaderT; use sp_blockchain::Backend as BlockchainBackendT; + use sp_consensus_beefy::{ + generate_equivocation_proof, known_payloads, known_payloads::MMR_ROOT_ID, + mmr::MmrRootProvider, Keyring, Payload, SignedCommitment, + }; use sp_runtime::traits::One; use substrate_test_runtime_client::{ runtime::{Block, Digest, DigestItem, Header, H256}, diff --git a/client/merkle-mountain-range/Cargo.toml b/client/merkle-mountain-range/Cargo.toml index 90fb65453ba12..899f4cc2e08da 100644 --- a/client/merkle-mountain-range/Cargo.toml +++ b/client/merkle-mountain-range/Cargo.toml @@ -14,10 +14,10 @@ homepage = "https://substrate.io" codec = { package = "parity-scale-codec", version = "3.2.2" } futures = "0.3" log = "0.4" -beefy-primitives = { version = "4.0.0-dev", path = "../../primitives/beefy", package = "sp-beefy" } -sc-client-api = { version = "4.0.0-dev", path = "../api" } sp-api = { version = "4.0.0-dev", path = "../../primitives/api" } sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" } +sc-client-api = { version = "4.0.0-dev", path = "../api" } +sp-consensus-beefy = { version = "4.0.0-dev", path = "../../primitives/consensus/beefy" } sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } sp-core = { version = "7.0.0", path = "../../primitives/core" } sp-mmr-primitives = { version = "4.0.0-dev", path = "../../primitives/merkle-mountain-range" } diff --git a/client/merkle-mountain-range/src/lib.rs b/client/merkle-mountain-range/src/lib.rs index de21b9b4967fb..e174af7068abb 100644 --- a/client/merkle-mountain-range/src/lib.rs +++ b/client/merkle-mountain-range/src/lib.rs @@ -43,13 +43,13 @@ mod offchain_mmr; pub mod test_utils; use crate::offchain_mmr::OffchainMmr; -use beefy_primitives::MmrRootHash; use futures::StreamExt; use log::{debug, error, trace, warn}; use sc_client_api::{Backend, BlockchainEvents, FinalityNotification, FinalityNotifications}; use sc_offchain::OffchainDb; use sp_api::ProvideRuntimeApi; use sp_blockchain::{HeaderBackend, HeaderMetadata}; +use sp_consensus_beefy::MmrRootHash; use sp_mmr_primitives::{utils, LeafIndex, MmrApi}; use sp_runtime::traits::{Block, Header, NumberFor}; use std::{marker::PhantomData, sync::Arc}; diff --git a/client/merkle-mountain-range/src/offchain_mmr.rs b/client/merkle-mountain-range/src/offchain_mmr.rs index 33d85f0cb14e3..3c3f0beb6c6a9 100644 --- a/client/merkle-mountain-range/src/offchain_mmr.rs +++ b/client/merkle-mountain-range/src/offchain_mmr.rs @@ -22,11 +22,11 @@ #![warn(missing_docs)] use crate::{aux_schema, MmrClient, LOG_TARGET}; -use beefy_primitives::MmrRootHash; use log::{debug, error, info, warn}; use sc_client_api::{Backend, FinalityNotification}; use sc_offchain::OffchainDb; use sp_blockchain::{CachedHeaderMetadata, ForkBackend}; +use sp_consensus_beefy::MmrRootHash; use sp_core::offchain::{DbExternalities, StorageKind}; use sp_mmr_primitives::{utils, utils::NodesUtils, MmrApi, NodeIndex}; use sp_runtime::{ diff --git a/frame/beefy-mmr/Cargo.toml b/frame/beefy-mmr/Cargo.toml index 1d24e821c5012..721e24282c45b 100644 --- a/frame/beefy-mmr/Cargo.toml +++ b/frame/beefy-mmr/Cargo.toml @@ -15,12 +15,12 @@ log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } binary-merkle-tree = { version = "4.0.0-dev", default-features = false, path = "../../utils/binary-merkle-tree" } -beefy-primitives = { version = "4.0.0-dev", default-features = false, path = "../../primitives/beefy", package = "sp-beefy" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-beefy = { version = "4.0.0-dev", default-features = false, path = "../beefy" } pallet-mmr = { version = "4.0.0-dev", default-features = false, path = "../merkle-mountain-range" } pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } +sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" } sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" } @@ -36,7 +36,6 @@ default = ["std"] std = [ "array-bytes", "binary-merkle-tree/std", - "beefy-primitives/std", "codec/std", "frame-support/std", "frame-system/std", @@ -46,6 +45,7 @@ std = [ "pallet-session/std", "scale-info/std", "serde", + "sp-consensus-beefy/std", "sp-core/std", "sp-io/std", "sp-runtime/std", diff --git a/frame/beefy-mmr/src/lib.rs b/frame/beefy-mmr/src/lib.rs index 8bb3aaa7e69b8..ba52be4f883f0 100644 --- a/frame/beefy-mmr/src/lib.rs +++ b/frame/beefy-mmr/src/lib.rs @@ -36,11 +36,11 @@ use sp_runtime::traits::{Convert, Member}; use sp_std::prelude::*; -use beefy_primitives::{ +use pallet_mmr::{LeafDataProvider, ParentNumberAndHash}; +use sp_consensus_beefy::{ mmr::{BeefyAuthoritySet, BeefyDataProvider, BeefyNextAuthoritySet, MmrLeaf, MmrLeafVersion}, ValidatorSet as BeefyValidatorSet, }; -use pallet_mmr::{LeafDataProvider, ParentNumberAndHash}; use frame_support::{crypto::ecdsa::ECDSAExt, traits::Get}; @@ -54,15 +54,15 @@ mod tests; /// A BEEFY consensus digest item with MMR root hash. pub struct DepositBeefyDigest(sp_std::marker::PhantomData); -impl pallet_mmr::primitives::OnNewRoot for DepositBeefyDigest +impl pallet_mmr::primitives::OnNewRoot for DepositBeefyDigest where - T: pallet_mmr::Config, + T: pallet_mmr::Config, T: pallet_beefy::Config, { fn on_new_root(root: &::Hash) { let digest = sp_runtime::generic::DigestItem::Consensus( - beefy_primitives::BEEFY_ENGINE_ID, - codec::Encode::encode(&beefy_primitives::ConsensusLog::< + sp_consensus_beefy::BEEFY_ENGINE_ID, + codec::Encode::encode(&sp_consensus_beefy::ConsensusLog::< ::BeefyId, >::MmrRoot(*root)), ); @@ -72,8 +72,8 @@ where /// Convert BEEFY secp256k1 public keys into Ethereum addresses pub struct BeefyEcdsaToEthereum; -impl Convert> for BeefyEcdsaToEthereum { - fn convert(beefy_id: beefy_primitives::crypto::AuthorityId) -> Vec { +impl Convert> for BeefyEcdsaToEthereum { + fn convert(beefy_id: sp_consensus_beefy::crypto::AuthorityId) -> Vec { sp_core::ecdsa::Public::from(beefy_id) .to_eth_address() .map(|v| v.to_vec()) @@ -156,7 +156,7 @@ impl LeafDataProvider for Pallet { } } -impl beefy_primitives::OnNewValidatorSet<::BeefyId> for Pallet +impl sp_consensus_beefy::OnNewValidatorSet<::BeefyId> for Pallet where T: pallet::Config, { diff --git a/frame/beefy-mmr/src/mock.rs b/frame/beefy-mmr/src/mock.rs index 922f882e1f1df..d31effc9ab577 100644 --- a/frame/beefy-mmr/src/mock.rs +++ b/frame/beefy-mmr/src/mock.rs @@ -17,7 +17,6 @@ use std::vec; -use beefy_primitives::mmr::MmrLeafVersion; use codec::Encode; use frame_support::{ construct_runtime, parameter_types, @@ -25,6 +24,7 @@ use frame_support::{ traits::{ConstU16, ConstU32, ConstU64, GenesisBuild, KeyOwnerProofSystem}, BasicExternalities, }; +use sp_consensus_beefy::mmr::MmrLeafVersion; use sp_core::{crypto::KeyTypeId, Hasher, H256}; use sp_runtime::{ app_crypto::ecdsa::Public, @@ -35,7 +35,7 @@ use sp_runtime::{ use crate as pallet_beefy_mmr; -pub use beefy_primitives::{ +pub use sp_consensus_beefy::{ crypto::AuthorityId as BeefyId, mmr::BeefyDataProvider, ConsensusLog, BEEFY_ENGINE_ID, }; @@ -101,7 +101,7 @@ impl pallet_session::Config for Test { type WeightInfo = (); } -pub type MmrLeaf = beefy_primitives::mmr::MmrLeaf< +pub type MmrLeaf = sp_consensus_beefy::mmr::MmrLeaf< ::BlockNumber, ::Hash, ::Hash, diff --git a/frame/beefy-mmr/src/tests.rs b/frame/beefy-mmr/src/tests.rs index af10d1127ebd7..dc2e46f31fe64 100644 --- a/frame/beefy-mmr/src/tests.rs +++ b/frame/beefy-mmr/src/tests.rs @@ -17,11 +17,11 @@ use std::vec; -use beefy_primitives::{ +use codec::{Decode, Encode}; +use sp_consensus_beefy::{ mmr::{BeefyNextAuthoritySet, MmrLeafVersion}, ValidatorSet, }; -use codec::{Decode, Encode}; use sp_core::H256; use sp_io::TestExternalities; diff --git a/frame/beefy/Cargo.toml b/frame/beefy/Cargo.toml index b2d6635377571..3778ca5f37a56 100644 --- a/frame/beefy/Cargo.toml +++ b/frame/beefy/Cargo.toml @@ -12,11 +12,11 @@ homepage = "https://substrate.io" codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -beefy-primitives = { version = "4.0.0-dev", default-features = false, path = "../../primitives/beefy", package = "sp-beefy" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } +sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" } 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" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } @@ -36,7 +36,6 @@ sp-staking = { version = "4.0.0-dev", path = "../../primitives/staking" } [features] default = ["std"] std = [ - "beefy-primitives/std", "codec/std", "frame-support/std", "frame-system/std", @@ -44,6 +43,7 @@ std = [ "pallet-session/std", "scale-info/std", "serde", + "sp-consensus-beefy/std", "sp-runtime/std", "sp-session/std", "sp-staking/std", diff --git a/frame/beefy/src/equivocation.rs b/frame/beefy/src/equivocation.rs index 19c41cbfacea5..cc04f316c3638 100644 --- a/frame/beefy/src/equivocation.rs +++ b/frame/beefy/src/equivocation.rs @@ -36,13 +36,13 @@ use sp_std::prelude::*; -use beefy_primitives::{EquivocationProof, ValidatorSetId}; use codec::{self as codec, Decode, Encode}; use frame_support::{ log, traits::{Get, KeyOwnerProofSystem}, }; use frame_system::pallet_prelude::BlockNumberFor; +use sp_consensus_beefy::{EquivocationProof, ValidatorSetId}; use sp_runtime::{ transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, @@ -271,7 +271,7 @@ fn is_known_offence( ) -> Result<(), TransactionValidityError> { // check the membership proof to extract the offender's id, // equivocation validity will be fully checked during the call. - let key = (beefy_primitives::KEY_TYPE, equivocation_proof.offender_id().clone()); + let key = (sp_consensus_beefy::KEY_TYPE, equivocation_proof.offender_id().clone()); let offender = T::KeyOwnerProofSystem::check_proof(key, key_owner_proof.clone()) .ok_or(InvalidTransaction::BadProof)?; diff --git a/frame/beefy/src/lib.rs b/frame/beefy/src/lib.rs index bcb7fc126520b..698e6e73312f1 100644 --- a/frame/beefy/src/lib.rs +++ b/frame/beefy/src/lib.rs @@ -40,7 +40,7 @@ use sp_session::{GetSessionNumber, GetValidatorCount}; use sp_staking::SessionIndex; use sp_std::prelude::*; -use beefy_primitives::{ +use sp_consensus_beefy::{ AuthorityIndex, BeefyAuthorityId, ConsensusLog, EquivocationProof, OnNewValidatorSet, ValidatorSet, BEEFY_ENGINE_ID, GENESIS_AUTHORITY_SET_ID, }; @@ -135,7 +135,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn validator_set_id)] pub(super) type ValidatorSetId = - StorageValue<_, beefy_primitives::ValidatorSetId, ValueQuery>; + StorageValue<_, sp_consensus_beefy::ValidatorSetId, ValueQuery>; /// Authorities set scheduled to be used with the next session #[pallet::storage] @@ -156,7 +156,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn session_for_set)] pub(super) type SetIdSession = - StorageMap<_, Twox64Concat, beefy_primitives::ValidatorSetId, SessionIndex>; + StorageMap<_, Twox64Concat, sp_consensus_beefy::ValidatorSetId, SessionIndex>; /// Block number where BEEFY consensus is enabled/started. /// If changing this, make sure `Self::ValidatorSetId` is also reset to @@ -280,7 +280,7 @@ impl Pallet { /// Return the current active BEEFY validator set. pub fn validator_set() -> Option> { let validators: BoundedVec = Self::authorities(); - let id: beefy_primitives::ValidatorSetId = Self::validator_set_id(); + let id: sp_consensus_beefy::ValidatorSetId = Self::validator_set_id(); ValidatorSet::::new(validators, id) } @@ -390,13 +390,13 @@ impl Pallet { // validate the key ownership proof extracting the id of the offender. let offender = T::KeyOwnerProofSystem::check_proof( - (beefy_primitives::KEY_TYPE, offender_id), + (sp_consensus_beefy::KEY_TYPE, offender_id), key_owner_proof, ) .ok_or(Error::::InvalidKeyOwnershipProof)?; // validate equivocation proof (check votes are different and signatures are valid). - if !beefy_primitives::check_equivocation_proof(&equivocation_proof) { + if !sp_consensus_beefy::check_equivocation_proof(&equivocation_proof) { return Err(Error::::InvalidEquivocationProof.into()) } diff --git a/frame/beefy/src/mock.rs b/frame/beefy/src/mock.rs index 74dba2a01b81d..72e3f83dff91c 100644 --- a/frame/beefy/src/mock.rs +++ b/frame/beefy/src/mock.rs @@ -40,7 +40,7 @@ use sp_staking::{EraIndex, SessionIndex}; use crate as pallet_beefy; -pub use beefy_primitives::{ +pub use sp_consensus_beefy::{ crypto::{AuthorityId as BeefyId, AuthoritySignature as BeefySignature}, ConsensusLog, EquivocationProof, BEEFY_ENGINE_ID, }; diff --git a/frame/beefy/src/tests.rs b/frame/beefy/src/tests.rs index 767b1e5657502..f9da20e90dc74 100644 --- a/frame/beefy/src/tests.rs +++ b/frame/beefy/src/tests.rs @@ -17,11 +17,11 @@ use std::vec; -use beefy_primitives::{ +use codec::Encode; +use sp_consensus_beefy::{ check_equivocation_proof, generate_equivocation_proof, known_payloads::MMR_ROOT_ID, Keyring as BeefyKeyring, Payload, ValidatorSet, }; -use codec::Encode; use sp_runtime::DigestItem; @@ -298,7 +298,7 @@ fn report_equivocation_current_set_works() { // create the key ownership proof let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); // report the equivocation and the tx should be dispatched successfully assert_ok!(Beefy::report_equivocation_unsigned( @@ -355,7 +355,7 @@ fn report_equivocation_old_set_works() { // create the key ownership proof in the "old" set let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); start_era(2); @@ -437,7 +437,7 @@ fn report_equivocation_invalid_set_id() { let equivocation_keyring = BeefyKeyring::from_public(equivocation_key).unwrap(); let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); let payload1 = Payload::from_single_entry(MMR_ROOT_ID, vec![42]); let payload2 = Payload::from_single_entry(MMR_ROOT_ID, vec![128]); @@ -476,7 +476,7 @@ fn report_equivocation_invalid_session() { // generate a key ownership proof at current era set id let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); start_era(2); @@ -520,7 +520,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((beefy_primitives::KEY_TYPE, &invalid_owner_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &invalid_owner_key)).unwrap(); let equivocation_authority_index = 0; let equivocation_key = &authorities[equivocation_authority_index]; @@ -569,7 +569,7 @@ fn report_equivocation_invalid_equivocation_proof() { // generate a key ownership proof at set id in era 1 let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); let assert_invalid_equivocation_proof = |equivocation_proof| { assert_err!( @@ -650,7 +650,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { ); let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); let call = Call::report_equivocation_unsigned { equivocation_proof: Box::new(equivocation_proof.clone()), @@ -756,7 +756,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // create the key ownership proof. let key_owner_proof = - Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap(); + Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap(); // check the dispatch info for the call. let info = Call::::report_equivocation_unsigned { diff --git a/primitives/beefy/Cargo.toml b/primitives/consensus/beefy/Cargo.toml similarity index 84% rename from primitives/beefy/Cargo.toml rename to primitives/consensus/beefy/Cargo.toml index 5dfda3e378fab..657569d122b05 100644 --- a/primitives/beefy/Cargo.toml +++ b/primitives/consensus/beefy/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sp-beefy" +name = "sp-consensus-beefy" version = "4.0.0-dev" authors = ["Parity Technologies "] edition = "2021" @@ -15,19 +15,19 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -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-io = { version = "7.0.0", default-features = false, path = "../io" } -sp-mmr-primitives = { version = "4.0.0-dev", default-features = false, path = "../merkle-mountain-range" } -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-io = { version = "7.0.0", default-features = false, path = "../../io" } +sp-mmr-primitives = { version = "4.0.0-dev", default-features = false, path = "../../merkle-mountain-range" } +sp-runtime = { version = "7.0.0", default-features = false, path = "../../runtime" } +sp-std = { version = "5.0.0", default-features = false, path = "../../std" } strum = { version = "0.24.1", features = ["derive"], default-features = false } lazy_static = "1.4.0" [dev-dependencies] array-bytes = "4.1" -sp-keystore = { version = "0.13.0", path = "../keystore" } +sp-keystore = { version = "0.13.0", path = "../../keystore" } [features] default = ["std"] diff --git a/primitives/beefy/src/commitment.rs b/primitives/consensus/beefy/src/commitment.rs similarity index 100% rename from primitives/beefy/src/commitment.rs rename to primitives/consensus/beefy/src/commitment.rs diff --git a/primitives/beefy/src/lib.rs b/primitives/consensus/beefy/src/lib.rs similarity index 100% rename from primitives/beefy/src/lib.rs rename to primitives/consensus/beefy/src/lib.rs diff --git a/primitives/beefy/src/mmr.rs b/primitives/consensus/beefy/src/mmr.rs similarity index 100% rename from primitives/beefy/src/mmr.rs rename to primitives/consensus/beefy/src/mmr.rs diff --git a/primitives/beefy/src/payload.rs b/primitives/consensus/beefy/src/payload.rs similarity index 100% rename from primitives/beefy/src/payload.rs rename to primitives/consensus/beefy/src/payload.rs diff --git a/primitives/beefy/src/test_utils.rs b/primitives/consensus/beefy/src/test_utils.rs similarity index 100% rename from primitives/beefy/src/test_utils.rs rename to primitives/consensus/beefy/src/test_utils.rs diff --git a/primitives/beefy/src/witness.rs b/primitives/consensus/beefy/src/witness.rs similarity index 100% rename from primitives/beefy/src/witness.rs rename to primitives/consensus/beefy/src/witness.rs diff --git a/primitives/beefy/test-res/large-raw-commitment b/primitives/consensus/beefy/test-res/large-raw-commitment similarity index 100% rename from primitives/beefy/test-res/large-raw-commitment rename to primitives/consensus/beefy/test-res/large-raw-commitment diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index f3222dc15c280..339a435ef2a04 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -13,11 +13,11 @@ publish = false targets = ["x86_64-unknown-linux-gnu"] [dependencies] -beefy-primitives = { version = "4.0.0-dev", default-features = false, path = "../../primitives/beefy", package = "sp-beefy" } pallet-beefy-mmr = { version = "4.0.0-dev", default-features = false, path = "../../frame/beefy-mmr" } sp-application-crypto = { version = "7.0.0", default-features = false, path = "../../primitives/application-crypto" } sp-consensus-aura = { version = "0.10.0-dev", default-features = false, path = "../../primitives/consensus/aura" } sp-consensus-babe = { version = "0.10.0-dev", default-features = false, path = "../../primitives/consensus/babe" } +sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" } sp-block-builder = { version = "4.0.0-dev", default-features = false, path = "../../primitives/block-builder" } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } @@ -66,11 +66,11 @@ default = [ "std", ] std = [ - "beefy-primitives/std", "pallet-beefy-mmr/std", "sp-application-crypto/std", "sp-consensus-aura/std", "sp-consensus-babe/std", + "sp-consensus-beefy/std", "sp-block-builder/std", "codec/std", "scale-info/std", diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 9e8a4e119b293..87a60acfc87ce 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -972,36 +972,36 @@ cfg_if! { } } - impl beefy_primitives::BeefyApi for Runtime { + impl sp_consensus_beefy::BeefyApi for Runtime { fn beefy_genesis() -> Option { None } - fn validator_set() -> Option> { + fn validator_set() -> Option> { None } fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: beefy_primitives::EquivocationProof< + _equivocation_proof: sp_consensus_beefy::EquivocationProof< NumberFor, - beefy_primitives::crypto::AuthorityId, - beefy_primitives::crypto::Signature + sp_consensus_beefy::crypto::AuthorityId, + sp_consensus_beefy::crypto::Signature >, - _key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof, + _key_owner_proof: sp_consensus_beefy::OpaqueKeyOwnershipProof, ) -> Option<()> { None } fn generate_key_ownership_proof( - _set_id: beefy_primitives::ValidatorSetId, - _authority_id: beefy_primitives::crypto::AuthorityId, - ) -> Option { None } + _set_id: sp_consensus_beefy::ValidatorSetId, + _authority_id: sp_consensus_beefy::crypto::AuthorityId, + ) -> Option { None } } - impl pallet_beefy_mmr::BeefyMmrApi for Runtime { - fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet { + impl pallet_beefy_mmr::BeefyMmrApi for Runtime { + fn authority_set_proof() -> sp_consensus_beefy::mmr::BeefyAuthoritySet { Default::default() } - fn next_authority_set_proof() -> beefy_primitives::mmr::BeefyNextAuthoritySet { + fn next_authority_set_proof() -> sp_consensus_beefy::mmr::BeefyNextAuthoritySet { Default::default() } }