From 767e53a00e5c13c15376de0d778f4f5cf5d5d8cc Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 15 Nov 2022 13:11:04 +0200 Subject: [PATCH 1/6] Add currently failing test case for https://github.com/arkworks-rs/algebra/issues/516 --- .../src/sector_codec/tests.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/subspace-core-primitives/src/sector_codec/tests.rs b/crates/subspace-core-primitives/src/sector_codec/tests.rs index 8103a5cae4..654a461420 100644 --- a/crates/subspace-core-primitives/src/sector_codec/tests.rs +++ b/crates/subspace-core-primitives/src/sector_codec/tests.rs @@ -28,3 +28,32 @@ fn basic() { assert_eq!(sector, decoded); } + +// TODO: Unlock this test once https://github.com/arkworks-rs/algebra/issues/516 is resolved +#[test] +#[ignore] +fn two_way_transformation_works() { + let rows_columns_count = 4_usize; + let sector_size = rows_columns_count.pow(2) * Scalar::SAFE_BYTES; + + let mut scalars = { + let mut sector = Vec::with_capacity(sector_size / Scalar::SAFE_BYTES); + + for _ in 0..sector.capacity() { + sector.push(Scalar::try_from(rand::random::<[u8; 31]>().as_slice()).unwrap()); + } + + sector + }; + + let codec = SectorCodec::new(sector_size).unwrap(); + + codec.encode(&mut scalars).unwrap(); + + let new_scalars = scalars + .iter() + .map(|scalar| Scalar::from(&scalar.to_bytes())) + .collect::>(); + + assert_eq!(scalars, new_scalars); +} From e02f06d4f773878acc3b18339476d6127b64ef14 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Nov 2022 07:58:47 +0200 Subject: [PATCH 2/6] Move `FarmerProtocolInfo` into `subspace-farmer-components` --- Cargo.lock | 4 +++- crates/sc-consensus-subspace-rpc/Cargo.toml | 1 + crates/sc-consensus-subspace-rpc/src/lib.rs | 3 ++- crates/subspace-farmer-components/Cargo.toml | 3 ++- .../benches/auditing.rs | 2 +- .../benches/plotting.rs | 2 +- .../benches/proving.rs | 3 +-- .../subspace-farmer-components/src/farming.rs | 3 +-- crates/subspace-farmer-components/src/lib.rs | 22 ++++++++++++++++++- .../src/plotting.rs | 3 +-- crates/subspace-farmer/src/rpc_client.rs | 3 ++- .../src/rpc_client/bench_rpc_client.rs | 3 ++- .../src/rpc_client/node_rpc_client.rs | 3 ++- crates/subspace-rpc-primitives/src/lib.rs | 22 +------------------ 14 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2805727f83..0573e36dc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6348,6 +6348,7 @@ dependencies = [ "sp-runtime", "subspace-archiving", "subspace-core-primitives", + "subspace-farmer-components", "subspace-rpc-primitives", ] @@ -8461,16 +8462,17 @@ dependencies = [ "criterion", "fs2", "futures 0.3.21", + "hex", "libc", "memmap2", "parity-scale-codec", "rand 0.8.5", "rayon", "schnorrkel", + "serde", "static_assertions", "subspace-archiving", "subspace-core-primitives", - "subspace-rpc-primitives", "subspace-solving", "subspace-verification", "thiserror", diff --git a/crates/sc-consensus-subspace-rpc/Cargo.toml b/crates/sc-consensus-subspace-rpc/Cargo.toml index 5c06036706..a015933505 100644 --- a/crates/sc-consensus-subspace-rpc/Cargo.toml +++ b/crates/sc-consensus-subspace-rpc/Cargo.toml @@ -33,4 +33,5 @@ sp-core = { version = "6.0.0", git = "https://github.com/subspace/substrate", re sp-runtime = { version = "6.0.0", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" } subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" } +subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" } subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" } diff --git a/crates/sc-consensus-subspace-rpc/src/lib.rs b/crates/sc-consensus-subspace-rpc/src/lib.rs index e9c348331c..506e01f99a 100644 --- a/crates/sc-consensus-subspace-rpc/src/lib.rs +++ b/crates/sc-consensus-subspace-rpc/src/lib.rs @@ -51,8 +51,9 @@ use subspace_core_primitives::{ Piece, PieceIndex, RecordsRoot, SegmentIndex, Solution, RECORDED_HISTORY_SEGMENT_SIZE, RECORD_SIZE, }; +use subspace_farmer_components::FarmerProtocolInfo; use subspace_rpc_primitives::{ - FarmerProtocolInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, + RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, MAX_SEGMENT_INDEXES_PER_REQUEST, }; diff --git a/crates/subspace-farmer-components/Cargo.toml b/crates/subspace-farmer-components/Cargo.toml index 1a4da86178..3643a12ae9 100644 --- a/crates/subspace-farmer-components/Cargo.toml +++ b/crates/subspace-farmer-components/Cargo.toml @@ -20,14 +20,15 @@ async-trait = "0.1.57" bitvec = "1.0.1" blake2-rfc = "0.2.18" fs2 = "0.4.3" +hex = { version = "0.4.3", features = ["serde"] } libc = "0.2.131" parity-scale-codec = "3.1.5" rand = "0.8.5" schnorrkel = "0.9.1" +serde = { version = "1.0.143", features = ["derive"] } static_assertions = "1.1.0" subspace-solving = { version = "0.1.0", path = "../subspace-solving" } subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" } -subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" } subspace-verification = { version = "0.1.0", path = "../subspace-verification" } thiserror = "1.0.32" tracing = "0.1.36" diff --git a/crates/subspace-farmer-components/benches/auditing.rs b/crates/subspace-farmer-components/benches/auditing.rs index a415579873..db9de839b6 100644 --- a/crates/subspace-farmer-components/benches/auditing.rs +++ b/crates/subspace-farmer-components/benches/auditing.rs @@ -17,7 +17,7 @@ use subspace_core_primitives::{ use subspace_farmer_components::farming::audit_sector; use subspace_farmer_components::file_ext::FileExt; use subspace_farmer_components::plotting::plot_sector; -use subspace_rpc_primitives::FarmerProtocolInfo; +use subspace_farmer_components::FarmerProtocolInfo; use utils::BenchPieceReceiver; mod utils; diff --git a/crates/subspace-farmer-components/benches/plotting.rs b/crates/subspace-farmer-components/benches/plotting.rs index 41631698a5..6482106183 100644 --- a/crates/subspace-farmer-components/benches/plotting.rs +++ b/crates/subspace-farmer-components/benches/plotting.rs @@ -14,7 +14,7 @@ use subspace_core_primitives::{ Piece, PublicKey, PIECES_IN_SEGMENT, PLOT_SECTOR_SIZE, RECORD_SIZE, }; use subspace_farmer_components::plotting::plot_sector; -use subspace_rpc_primitives::FarmerProtocolInfo; +use subspace_farmer_components::FarmerProtocolInfo; use utils::BenchPieceReceiver; mod utils; diff --git a/crates/subspace-farmer-components/benches/proving.rs b/crates/subspace-farmer-components/benches/proving.rs index cfeb27c307..72ab6f1a0d 100644 --- a/crates/subspace-farmer-components/benches/proving.rs +++ b/crates/subspace-farmer-components/benches/proving.rs @@ -18,8 +18,7 @@ use subspace_core_primitives::{ use subspace_farmer_components::farming::audit_sector; use subspace_farmer_components::file_ext::FileExt; use subspace_farmer_components::plotting::plot_sector; -use subspace_farmer_components::SectorMetadata; -use subspace_rpc_primitives::FarmerProtocolInfo; +use subspace_farmer_components::{FarmerProtocolInfo, SectorMetadata}; use utils::BenchPieceReceiver; mod utils; diff --git a/crates/subspace-farmer-components/src/farming.rs b/crates/subspace-farmer-components/src/farming.rs index bf17c74e66..222131d7b6 100644 --- a/crates/subspace-farmer-components/src/farming.rs +++ b/crates/subspace-farmer-components/src/farming.rs @@ -1,4 +1,4 @@ -use crate::SectorMetadata; +use crate::{FarmerProtocolInfo, SectorMetadata}; use bitvec::prelude::*; use parity_scale_codec::{Decode, IoReader}; use schnorrkel::Keypair; @@ -10,7 +10,6 @@ use subspace_core_primitives::{ Blake2b256Hash, Chunk, Piece, PublicKey, SectorId, SectorIndex, Solution, SolutionRange, PIECE_SIZE, }; -use subspace_rpc_primitives::FarmerProtocolInfo; use subspace_solving::{create_chunk_signature, derive_chunk_otp}; use subspace_verification::is_within_solution_range; use thiserror::Error; diff --git a/crates/subspace-farmer-components/src/lib.rs b/crates/subspace-farmer-components/src/lib.rs index 0a775e2b68..f5592af0dc 100644 --- a/crates/subspace-farmer-components/src/lib.rs +++ b/crates/subspace-farmer-components/src/lib.rs @@ -7,14 +7,34 @@ pub mod file_ext; pub mod plotting; use parity_scale_codec::{Decode, Encode}; +use serde::{Deserialize, Serialize}; use static_assertions::const_assert; -use std::num::NonZeroU64; +use std::num::{NonZeroU16, NonZeroU32, NonZeroU64}; use subspace_core_primitives::SegmentIndex; // Refuse to compile on non-64-bit platforms, offsets may fail on those when converting from u64 to // usize depending on chain parameters const_assert!(std::mem::size_of::() >= std::mem::size_of::()); +/// Information about the protocol necessary for farmer operation +#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FarmerProtocolInfo { + /// Genesis hash of the chain + #[serde(with = "hex::serde")] + pub genesis_hash: [u8; 32], + /// The size of data in one piece (in bytes). + pub record_size: NonZeroU32, + /// Recorded history is encoded and plotted in segments of this size (in bytes). + pub recorded_history_segment_size: u32, + /// Total number of pieces stored on the network + pub total_pieces: NonZeroU64, + /// Space parameter for proof-of-replication in bits + pub space_l: NonZeroU16, + /// Number of segments after which sector expires + pub sector_expiration: SegmentIndex, +} + /// Metadata of the plotted sector #[doc(hidden)] #[derive(Debug, Encode, Decode, Clone)] diff --git a/crates/subspace-farmer-components/src/plotting.rs b/crates/subspace-farmer-components/src/plotting.rs index c837fde5f5..60ec36a718 100644 --- a/crates/subspace-farmer-components/src/plotting.rs +++ b/crates/subspace-farmer-components/src/plotting.rs @@ -1,4 +1,4 @@ -use crate::SectorMetadata; +use crate::{FarmerProtocolInfo, SectorMetadata}; use async_trait::async_trait; use bitvec::order::Lsb0; use bitvec::prelude::*; @@ -9,7 +9,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; use subspace_core_primitives::{ Piece, PieceIndex, PublicKey, SectorId, SectorIndex, PIECE_SIZE, PLOT_SECTOR_SIZE, }; -use subspace_rpc_primitives::FarmerProtocolInfo; use subspace_solving::derive_chunk_otp; use thiserror::Error; use tracing::debug; diff --git a/crates/subspace-farmer/src/rpc_client.rs b/crates/subspace-farmer/src/rpc_client.rs index e29fcd8234..c5bc3ec21b 100644 --- a/crates/subspace-farmer/src/rpc_client.rs +++ b/crates/subspace-farmer/src/rpc_client.rs @@ -6,8 +6,9 @@ use futures::Stream; use std::pin::Pin; use subspace_archiving::archiver::ArchivedSegment; use subspace_core_primitives::{Piece, PieceIndex, RecordsRoot, SegmentIndex}; +use subspace_farmer_components::FarmerProtocolInfo; use subspace_rpc_primitives::{ - FarmerProtocolInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, + RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, }; /// To become error type agnostic diff --git a/crates/subspace-farmer/src/rpc_client/bench_rpc_client.rs b/crates/subspace-farmer/src/rpc_client/bench_rpc_client.rs index c769b821d1..919e53f395 100644 --- a/crates/subspace-farmer/src/rpc_client/bench_rpc_client.rs +++ b/crates/subspace-farmer/src/rpc_client/bench_rpc_client.rs @@ -8,8 +8,9 @@ use std::pin::Pin; use std::sync::Arc; use subspace_archiving::archiver::ArchivedSegment; use subspace_core_primitives::{Piece, PieceIndex, RecordsRoot, SegmentIndex}; +use subspace_farmer_components::FarmerProtocolInfo; use subspace_rpc_primitives::{ - FarmerProtocolInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, + RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, }; use tokio::sync::Mutex; diff --git a/crates/subspace-farmer/src/rpc_client/node_rpc_client.rs b/crates/subspace-farmer/src/rpc_client/node_rpc_client.rs index 6019e86f17..73d7bcf655 100644 --- a/crates/subspace-farmer/src/rpc_client/node_rpc_client.rs +++ b/crates/subspace-farmer/src/rpc_client/node_rpc_client.rs @@ -9,8 +9,9 @@ use std::pin::Pin; use std::sync::Arc; use subspace_archiving::archiver::ArchivedSegment; use subspace_core_primitives::{Piece, PieceIndex, RecordsRoot, SegmentIndex}; +use subspace_farmer_components::FarmerProtocolInfo; use subspace_rpc_primitives::{ - FarmerProtocolInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, + RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse, }; // Defines max_concurrent_requests constant in the node rpc client. diff --git a/crates/subspace-rpc-primitives/src/lib.rs b/crates/subspace-rpc-primitives/src/lib.rs index c40ec69c58..0fb02c072a 100644 --- a/crates/subspace-rpc-primitives/src/lib.rs +++ b/crates/subspace-rpc-primitives/src/lib.rs @@ -16,33 +16,13 @@ //! Primitives for Subspace RPC. use serde::{Deserialize, Serialize}; -use std::num::{NonZeroU16, NonZeroU32, NonZeroU64}; use subspace_core_primitives::{ - Blake2b256Hash, PublicKey, RewardSignature, SegmentIndex, SlotNumber, Solution, SolutionRange, + Blake2b256Hash, PublicKey, RewardSignature, SlotNumber, Solution, SolutionRange, }; /// Defines a limit for segment indexes array. It affects storage access on the runtime side. pub const MAX_SEGMENT_INDEXES_PER_REQUEST: usize = 300; -/// Information about the protocol necessary for farmer operation -#[derive(Debug, Copy, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct FarmerProtocolInfo { - /// Genesis hash of the chain - #[serde(with = "hex::serde")] - pub genesis_hash: [u8; 32], - /// The size of data in one piece (in bytes). - pub record_size: NonZeroU32, - /// Recorded history is encoded and plotted in segments of this size (in bytes). - pub recorded_history_segment_size: u32, - /// Total number of pieces stored on the network - pub total_pieces: NonZeroU64, - /// Space parameter for proof-of-replication in bits - pub space_l: NonZeroU16, - /// Number of segments after which sector expires - pub sector_expiration: SegmentIndex, -} - /// Information about new slot that just arrived #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] From 1d5b4a3365c7283e71e5badf732211b3bf059537 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Nov 2022 12:54:14 +0200 Subject: [PATCH 3/6] Sort dependencies alphabetically in `subspace-runtime` and `system-domain-runtime` --- crates/subspace-runtime/Cargo.toml | 12 ++---- domains/runtime/system/Cargo.toml | 67 +++++++++++++----------------- 2 files changed, 34 insertions(+), 45 deletions(-) diff --git a/crates/subspace-runtime/Cargo.toml b/crates/subspace-runtime/Cargo.toml index 0a814ec51c..7da691ee17 100644 --- a/crates/subspace-runtime/Cargo.toml +++ b/crates/subspace-runtime/Cargo.toml @@ -18,9 +18,12 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } domain-runtime-primitives = { version = "0.1.0", default-features = false, path = "../../domains/primitives/runtime" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", optional = true } frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", optional = true } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } hex-literal = { version = "0.3.3", optional = true } orml-vesting = { version = "0.4.1-dev", default-features = false, path = "../../orml/vesting" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } @@ -36,6 +39,7 @@ pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https:// pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } pallet-transaction-fees = { version = "0.1.0", default-features = false, path = "../pallet-transaction-fees" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } @@ -57,14 +61,6 @@ subspace-runtime-primitives = { version = "0.1.0", default-features = false, pat subspace-verification = { version = "0.1.0", default-features = false, path = "../subspace-verification" } system-domain-runtime = { version = "0.1.0", default-features = false, path = "../../domains/runtime/system" } -# Used for the node template's RPCs -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } - -# Used for runtime benchmarking -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", optional = true } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", optional = true } - [build-dependencies] subspace-wasm-tools = { version = "0.1.0", default-features = false, path = "../subspace-wasm-tools" } substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } diff --git a/domains/runtime/system/Cargo.toml b/domains/runtime/system/Cargo.toml index f49438daba..adc7cd24c0 100644 --- a/domains/runtime/system/Cargo.toml +++ b/domains/runtime/system/Cargo.toml @@ -13,16 +13,27 @@ links = "system-domain-runtime" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -hex-literal = { version = '0.3.1', optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} +core-payments-domain-runtime = { path = "../../runtime/core-payments", default-features = false } +domain-pallet-executive = { path = "../../pallets/executive", default-features = false } +domain-runtime-primitives = { path = "../../primitives/runtime", default-features = false } +frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +frame-support = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +frame-system = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +frame-system-benchmarking = { default-features = false, optional = true, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +hex-literal = { version = '0.3.1', optional = true } log = { version = "0.4.17", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +pallet-domain-registry = { path = "../../pallets/domain-registry", default-features = false } +pallet-executor-registry = { path = "../../pallets/executor-registry", default-features = false } +pallet-transaction-payment = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } - -# Substrate Dependencies -## Substrate Primitive Dependencies sp-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-block-builder = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-core = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } +sp-domains = { path = "../../../crates/sp-domains", default-features = false } sp-inherents = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-io = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-offchain = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } @@ -31,25 +42,6 @@ sp-session = { default-features = false, git = "https://github.com/subspace/subs sp-std = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } sp-version = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } - -## Substrate FRAME Dependencies -frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -frame-support = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -frame-system = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -frame-system-benchmarking = { default-features = false, optional = true, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } - -## Substrate Pallet Dependencies -pallet-balances = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -pallet-transaction-payment = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } - -core-payments-domain-runtime = { path = "../../runtime/core-payments", default-features = false } -domain-pallet-executive = { path = "../../pallets/executive", default-features = false } -domain-runtime-primitives = { path = "../../primitives/runtime", default-features = false } -pallet-domain-registry = { path = "../../pallets/domain-registry", default-features = false } -pallet-executor-registry = { path = "../../pallets/executor-registry", default-features = false } -sp-domains = { path = "../../../crates/sp-domains", default-features = false } subspace-runtime-primitives = { path = "../../../crates/subspace-runtime-primitives", default-features = false } system-runtime-primitives = { path = "../../primitives/system-runtime", default-features = false } @@ -63,8 +55,20 @@ default = [ ] std = [ "codec/std", - "scale-info/std", + "core-payments-domain-runtime/std", + "domain-pallet-executive/std", + "domain-runtime-primitives/std", + "frame-support/std", + "frame-system/std", + "frame-system-benchmarking?/std", + "frame-system-rpc-runtime-api/std", "log/std", + "pallet-balances/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-domain-registry/std", + "pallet-executor-registry/std", + "scale-info/std", "sp-api/std", "sp-block-builder/std", "sp-core/std", @@ -76,17 +80,6 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", - "frame-support/std", - "frame-system/std", - "frame-system-rpc-runtime-api/std", - "pallet-balances/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "core-payments-domain-runtime/std", - "domain-pallet-executive/std", - "domain-runtime-primitives/std", - "pallet-domain-registry/std", - "pallet-executor-registry/std", "sp-domains/std", "subspace-runtime-primitives/std", "system-runtime-primitives/std", @@ -94,11 +87,11 @@ std = [ # Internal implementation detail, enabled during building of wasm blob. wasm-builder = [] runtime-benchmarks = [ - 'hex-literal', - "sp-runtime/runtime-benchmarks", "frame-benchmarking", "frame-system-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + 'hex-literal', "pallet-balances/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] From 19ffd826f911256dfcdac206c9dec47c2548457c Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Nov 2022 13:04:03 +0200 Subject: [PATCH 4/6] Update `std` feature in dependencies of `subspace-runtime` and `system-domain-runtime` --- crates/subspace-runtime/Cargo.toml | 4 +++- domains/runtime/system/Cargo.toml | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/subspace-runtime/Cargo.toml b/crates/subspace-runtime/Cargo.toml index 7da691ee17..10bc5286f1 100644 --- a/crates/subspace-runtime/Cargo.toml +++ b/crates/subspace-runtime/Cargo.toml @@ -73,9 +73,11 @@ default = ["std"] std = [ "codec/std", "domain-runtime-primitives/std", + "frame-benchmarking?/std", "frame-executive/std", "frame-support/std", "frame-system/std", + "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", "orml-vesting/std", "pallet-balances/std", @@ -90,8 +92,8 @@ std = [ "pallet-sudo/std", "pallet-timestamp/std", "pallet-transaction-fees/std", - "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", + "pallet-transaction-payment-rpc-runtime-api/std", "pallet-utility/std", "scale-info/std", "sp-api/std", diff --git a/domains/runtime/system/Cargo.toml b/domains/runtime/system/Cargo.toml index adc7cd24c0..8bff6124a2 100644 --- a/domains/runtime/system/Cargo.toml +++ b/domains/runtime/system/Cargo.toml @@ -58,20 +58,22 @@ std = [ "core-payments-domain-runtime/std", "domain-pallet-executive/std", "domain-runtime-primitives/std", + "frame-benchmarking?/std", "frame-support/std", "frame-system/std", "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", "log/std", "pallet-balances/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", "pallet-domain-registry/std", "pallet-executor-registry/std", + "pallet-transaction-payment/std", + "pallet-transaction-payment-rpc-runtime-api/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", "sp-core/std", + "sp-domains/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", @@ -80,7 +82,6 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", - "sp-domains/std", "subspace-runtime-primitives/std", "system-runtime-primitives/std", ] From 43b5c2c4bc19b6eca1362ff71ba4b05587af3501 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Nov 2022 14:26:45 +0200 Subject: [PATCH 5/6] Make project compilable with `runtime-benchmarks` feature (not fully functional yet though, see https://substrate.stackexchange.com/questions/5927/assimilate-storage-not-implemented-for-chainspec) --- Cargo.lock | 3 +- crates/subspace-node/Cargo.toml | 7 ++-- crates/subspace-runtime/Cargo.toml | 6 ++-- crates/subspace-runtime/src/lib.rs | 50 +++++++++++---------------- domains/runtime/system/Cargo.toml | 8 ++--- domains/runtime/system/src/lib.rs | 4 +++ domains/runtime/system/src/runtime.rs | 34 +++++++++--------- 7 files changed, 51 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0573e36dc2..135688c577 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8547,6 +8547,7 @@ dependencies = [ "core-payments-domain-runtime", "dirs", "domain-service", + "frame-benchmarking", "frame-benchmarking-cli", "frame-support", "futures 0.3.21", @@ -9106,8 +9107,6 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", - "hex-literal", - "log", "pallet-balances", "pallet-domain-registry", "pallet-executor-registry", diff --git a/crates/subspace-node/Cargo.toml b/crates/subspace-node/Cargo.toml index b1ad317ba2..a4741f5381 100644 --- a/crates/subspace-node/Cargo.toml +++ b/crates/subspace-node/Cargo.toml @@ -24,7 +24,8 @@ clap = { version = "4.0.22", features = ["derive"] } core-payments-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/core-payments" } dirs = "4.0.0" domain-service = { version = "0.1.0", path = "../../domains/service" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", default-features = false, features = ["runtime-benchmarks"] } +frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", default-features = false } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", default-features = false } frame-support = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } futures = "0.3.21" log = "0.4.17" @@ -54,7 +55,7 @@ subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-p subspace-service = { version = "0.1.0", path = "../subspace-service" } system-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/system" } thiserror = "1.0.32" -tokio = { version = "1.20.1" } +tokio = "1.20.1" [build-dependencies] substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } @@ -65,6 +66,8 @@ do-not-enforce-cost-of-storage = [ "subspace-runtime/do-not-enforce-cost-of-storage" ] runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", "domain-service/runtime-benchmarks", "subspace-runtime/runtime-benchmarks", "system-domain-runtime/runtime-benchmarks", diff --git a/crates/subspace-runtime/Cargo.toml b/crates/subspace-runtime/Cargo.toml index 10bc5286f1..b062cf6c4a 100644 --- a/crates/subspace-runtime/Cargo.toml +++ b/crates/subspace-runtime/Cargo.toml @@ -24,7 +24,6 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", optional = true } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -hex-literal = { version = "0.3.3", optional = true } orml-vesting = { version = "0.4.1-dev", default-features = false, path = "../../orml/vesting" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } pallet-domains = { version = "0.1.0", default-features = false, path = "../pallet-domains" } @@ -66,7 +65,7 @@ subspace-wasm-tools = { version = "0.1.0", default-features = false, path = "../ substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } [dev-dependencies] -hex-literal = { version = "0.3.3" } +hex-literal = "0.3.3" [features] default = ["std"] @@ -118,9 +117,8 @@ std = [ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", - "frame-system-benchmarking", "frame-system/runtime-benchmarks", - "hex-literal", + "frame-system-benchmarking/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 2da66b30dd..60ae5a4662 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -31,6 +31,10 @@ include!(concat!(env!("OUT_DIR"), "/execution_wasm_bundle.rs")); #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +#[cfg(feature = "runtime-benchmarks")] +#[macro_use] +extern crate frame_benchmarking; + use crate::feed_processor::feed_processor; pub use crate::feed_processor::FeedProcessorKind; use crate::fees::{OnChargeTransaction, TransactionByteFee}; @@ -654,6 +658,16 @@ impl From for AccountId32 { } } +#[cfg(feature = "runtime-benchmarks")] +mod benches { + frame_benchmarking::define_benchmarks!( + [frame_benchmarking, BaselineBench::] + [frame_system, SystemBench::] + [pallet_balances, Balances] + [pallet_timestamp, Timestamp] + ); +} + impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -902,29 +916,23 @@ impl_runtime_apis! { Vec, Vec, ) { - use frame_benchmarking::{list_benchmark, baseline, Benchmarking, BenchmarkList}; + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; let mut list = Vec::::new(); - - list_benchmark!(list, extra, frame_benchmarking, BaselineBench::); - list_benchmark!(list, extra, frame_system, SystemBench::); - list_benchmark!(list, extra, pallet_balances, Balances); - list_benchmark!(list, extra, pallet_timestamp, Timestamp); - list_benchmark!(params, batches, pallet_utility, Utility); - list_benchmark!(list, extra, pallet_template, TemplateModule); + list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) + (list, storage_info) } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; + use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey}; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; @@ -932,28 +940,12 @@ impl_runtime_apis! { impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); - - add_benchmark!(params, batches, frame_benchmarking, BaselineBench::); - add_benchmark!(params, batches, frame_system, SystemBench::); - add_benchmark!(params, batches, pallet_balances, Balances); - add_benchmark!(params, batches, pallet_timestamp, Timestamp); - add_benchmark!(params, batches, pallet_utility, Utility); - add_benchmark!(params, batches, pallet_template, TemplateModule); + add_benchmarks!(params, batches); Ok(batches) } diff --git a/domains/runtime/system/Cargo.toml b/domains/runtime/system/Cargo.toml index 8bff6124a2..208e29a249 100644 --- a/domains/runtime/system/Cargo.toml +++ b/domains/runtime/system/Cargo.toml @@ -22,8 +22,6 @@ frame-support = { default-features = false, git = "https://github.com/subspace/s frame-system = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } frame-system-benchmarking = { default-features = false, optional = true, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } -hex-literal = { version = '0.3.1', optional = true } -log = { version = "0.4.17", default-features = false } pallet-balances = { default-features = false, git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" } pallet-domain-registry = { path = "../../pallets/domain-registry", default-features = false } pallet-executor-registry = { path = "../../pallets/executor-registry", default-features = false } @@ -63,7 +61,6 @@ std = [ "frame-system/std", "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", - "log/std", "pallet-balances/std", "pallet-domain-registry/std", "pallet-executor-registry/std", @@ -88,11 +85,10 @@ std = [ # Internal implementation detail, enabled during building of wasm blob. wasm-builder = [] runtime-benchmarks = [ - "frame-benchmarking", - "frame-system-benchmarking", + "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - 'hex-literal', + "frame-system-benchmarking/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] diff --git a/domains/runtime/system/src/lib.rs b/domains/runtime/system/src/lib.rs index ff45ffe4e9..4c717a7e7b 100644 --- a/domains/runtime/system/src/lib.rs +++ b/domains/runtime/system/src/lib.rs @@ -15,3 +15,7 @@ pub use runtime::*; // Make the WASM binary available, except in wasm builder environment. #[cfg(not(feature = "wasm-builder"))] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +#[cfg(feature = "runtime-benchmarks")] +#[macro_use] +extern crate frame_benchmarking; diff --git a/domains/runtime/system/src/runtime.rs b/domains/runtime/system/src/runtime.rs index 9df9c82479..841563b3f2 100644 --- a/domains/runtime/system/src/runtime.rs +++ b/domains/runtime/system/src/runtime.rs @@ -325,6 +325,13 @@ construct_runtime!( } ); +#[cfg(feature = "runtime-benchmarks")] +frame_benchmarking::define_benchmarks!( + [frame_benchmarking, BaselineBench::] + [frame_system, SystemBench::] + [pallet_balances, Balances] +); + impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -512,46 +519,37 @@ impl_runtime_apis! { Vec, Vec, ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; + use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; + use baseline::Pallet as BaselineBench; let mut list = Vec::::new(); - list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) + (list, storage_info) } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey}; use frame_system_benchmarking::Pallet as SystemBench; + use baseline::Pallet as BaselineBench; + impl frame_system_benchmarking::Config for Runtime {} + impl baseline::Config for Runtime {} - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); - add_benchmarks!(params, batches); - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } From 6827c2c6537206155c8e17ec40eb40dd0d0ea223 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Nov 2022 14:49:40 +0200 Subject: [PATCH 6/6] A bit saner weights for votes --- crates/pallet-subspace/src/default_weights.rs | 5 +++++ crates/pallet-subspace/src/lib.rs | 3 ++- crates/subspace-runtime/src/lib.rs | 3 ++- crates/subspace-runtime/src/weights.rs | 1 + .../subspace-runtime/src/weights/subspace.rs | 21 +++++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 crates/subspace-runtime/src/weights.rs create mode 100644 crates/subspace-runtime/src/weights/subspace.rs diff --git a/crates/pallet-subspace/src/default_weights.rs b/crates/pallet-subspace/src/default_weights.rs index 2eddbf6a21..2336a34e88 100644 --- a/crates/pallet-subspace/src/default_weights.rs +++ b/crates/pallet-subspace/src/default_weights.rs @@ -28,4 +28,9 @@ impl crate::WeightInfo for () { // TODO: Proper value Weight::from_ref_time(10_000 * (root_blocks_count as u64 + 1)) } + + fn vote() -> Weight { + // TODO: Proper value + Weight::from_ref_time(10_000) + } } diff --git a/crates/pallet-subspace/src/lib.rs b/crates/pallet-subspace/src/lib.rs index fbcd280cc5..8730bc1dd5 100644 --- a/crates/pallet-subspace/src/lib.rs +++ b/crates/pallet-subspace/src/lib.rs @@ -67,6 +67,7 @@ use subspace_verification::{ pub trait WeightInfo { fn report_equivocation() -> Weight; fn store_root_blocks(root_blocks_count: usize) -> Weight; + fn vote() -> Weight; } /// Trigger global randomness every interval. @@ -492,7 +493,7 @@ mod pallet { /// Farmer vote, currently only used for extra rewards to farmers. // TODO: Proper weight - #[pallet::weight((100_000, DispatchClass::Operational, Pays::No))] + #[pallet::weight((::WeightInfo::vote(), DispatchClass::Operational, Pays::No))] // Suppression because the custom syntax will also generate an enum and we need enum to have // boxed value. #[allow(clippy::boxed_local)] diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 60ae5a4662..790f58d4c3 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -23,6 +23,7 @@ mod feed_processor; mod fees; mod object_mapping; mod signed_extensions; +mod weights; // Make execution WASM runtime available. include!(concat!(env!("OUT_DIR"), "/execution_wasm_bundle.rs")); @@ -268,7 +269,7 @@ impl pallet_subspace::Config for Runtime { ConstU64<{ EQUIVOCATION_REPORT_LONGEVITY as u64 }>, >; - type WeightInfo = (); + type WeightInfo = weights::subspace::WeightInfo; } impl pallet_timestamp::Config for Runtime { diff --git a/crates/subspace-runtime/src/weights.rs b/crates/subspace-runtime/src/weights.rs new file mode 100644 index 0000000000..264122fb29 --- /dev/null +++ b/crates/subspace-runtime/src/weights.rs @@ -0,0 +1 @@ +pub(crate) mod subspace; diff --git a/crates/subspace-runtime/src/weights/subspace.rs b/crates/subspace-runtime/src/weights/subspace.rs new file mode 100644 index 0000000000..9ffbf0ec92 --- /dev/null +++ b/crates/subspace-runtime/src/weights/subspace.rs @@ -0,0 +1,21 @@ +use crate::SubspaceBlockWeights; +use frame_support::weights::Weight; + +pub struct WeightInfo; + +impl pallet_subspace::WeightInfo for WeightInfo { + fn report_equivocation() -> Weight { + // TODO: Proper value + Weight::from_ref_time(10_000) + } + + fn store_root_blocks(root_blocks_count: usize) -> Weight { + // TODO: Proper value + Weight::from_ref_time(10_000 * (root_blocks_count as u64 + 1)) + } + + fn vote() -> Weight { + // TODO: Proper value, allowing up to 20 votes before block is full for now + SubspaceBlockWeights::get().max_block.div(20) + } +}