diff --git a/Cargo.lock b/Cargo.lock index d33ebe5..1020c48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2244,7 +2244,6 @@ dependencies = [ "scale-info", "smallvec", "sp-api", - "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", @@ -4999,7 +4998,6 @@ dependencies = [ "scale-info", "smallvec", "sp-api", - "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 9af2cd4..cdce776 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,18 +1,16 @@ use cumulus_primitives_core::ParaId; +use runtime_common::{AccountId, AuraId, Signature}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; -use runtime_common::{AccountId, AuraId, Signature}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type MainChainSpec = - sc_service::GenericChainSpec; +pub type MainChainSpec = sc_service::GenericChainSpec; /// Specialized `ChainSpec` for the development parachain runtime. -pub type DevnetChainSpec = - sc_service::GenericChainSpec; +pub type DevnetChainSpec = sc_service::GenericChainSpec; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -255,7 +253,9 @@ pub mod devnet { members: endowed_accounts.iter().take(4).cloned().collect(), }, parachain_system: Default::default(), - polkadot_xcm: devnet_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, + polkadot_xcm: devnet_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + }, transaction_payment: Default::default(), } } diff --git a/node/src/command.rs b/node/src/command.rs index 9ab3c8c..2dd0b2e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -5,6 +5,7 @@ use cumulus_client_cli::generate_genesis_block; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::{info, warn}; +use runtime_common::Block; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, @@ -12,7 +13,6 @@ use sc_cli::{ use sc_service::config::{BasePath, PrometheusConfig}; use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; -use runtime_common::Block; use crate::{ chain_spec, @@ -203,11 +203,10 @@ macro_rules! construct_benchmark_partials { ($config:expr, |$partials:ident| $code:expr) => { match $config.chain_spec.runtime() { Runtime::Devnet | Runtime::Default => { - let $partials = - new_partial::( - &$config, - crate::service::build_import_queue::<_, DevnetRuntimeExecutor>, - )?; + let $partials = new_partial::( + &$config, + crate::service::build_import_queue::<_, DevnetRuntimeExecutor>, + )?; $code }, Runtime::Mainnet => { @@ -338,8 +337,8 @@ pub fn run() -> Result<()> { }, #[cfg(feature = "try-runtime")] Some(Subcommand::TryRuntime(cmd)) => { - use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; use runtime_common::MILLISECS_PER_BLOCK; + use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; use try_runtime_cli::block_building_info::timestamp_with_aura_info; let runner = cli.create_runner(cmd)?; diff --git a/runtime/devnet/Cargo.toml b/runtime/devnet/Cargo.toml index fd49e83..00262d2 100644 --- a/runtime/devnet/Cargo.toml +++ b/runtime/devnet/Cargo.toml @@ -45,7 +45,6 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } -sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } @@ -116,7 +115,6 @@ std = [ "polkadot-parachain/std", "polkadot-runtime-common/std", "sp-api/std", - "sp-arithmetic/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", diff --git a/runtime/devnet/src/lib.rs b/runtime/devnet/src/lib.rs index 7e1084e..e387e9e 100644 --- a/runtime/devnet/src/lib.rs +++ b/runtime/devnet/src/lib.rs @@ -38,12 +38,12 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; -pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; -pub use sp_runtime::{MultiAddress, Perbill, Permill}; pub use runtime_common::{ AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MILLISECS_PER_BLOCK, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; +pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] @@ -106,11 +106,11 @@ pub type Executive = frame_executive::Executive< pub mod fee { use super::{Balance, ExtrinsicBaseWeight, MILLIUNIT}; use frame_support::weights::{ - Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + FeePolynomial, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, }; use smallvec::smallvec; - use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; - use sp_runtime::{Perbill, SaturatedConversion}; + use sp_runtime::Perbill; /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. @@ -127,20 +127,14 @@ pub mod fee { type Balance = Balance; fn weight_to_fee(weight: &Weight) -> Self::Balance { - let ref_time = Balance::saturated_from(weight.ref_time()); - let proof_size = Balance::saturated_from(weight.proof_size()); - - let ref_polynomial = RefTimeToFee::polynomial(); - let proof_polynomial = ProofSizeToFee::polynomial(); + let ref_polynomial: FeePolynomial = RefTimeToFee::polynomial().into(); + let proof_polynomial: FeePolynomial = ProofSizeToFee::polynomial().into(); // Get fee amount from ref_time based on the RefTime polynomial - let ref_fee: Balance = - ref_polynomial.iter().fold(0, |acc, term| term.saturating_eval(acc, ref_time)); + let ref_fee: Balance = ref_polynomial.eval(weight.ref_time()); // Get fee amount from proof_size based on the ProofSize polynomial - let proof_fee: Balance = proof_polynomial - .iter() - .fold(0, |acc, term| term.saturating_eval(acc, proof_size)); + let proof_fee: Balance = proof_polynomial.eval(weight.proof_size()); // Take the maximum instead of the sum to charge by the more scarce resource. ref_fee.max(proof_fee) @@ -182,34 +176,6 @@ pub mod fee { }] } } - - // TODO: Refactor out this code to use `FeePolynomial` on versions using polkadot-v0.9.42 and above: - pub trait WeightCoefficientCalc { - fn saturating_eval(&self, result: Balance, x: Balance) -> Balance; - } - - impl WeightCoefficientCalc for WeightToFeeCoefficient - where - Balance: BaseArithmetic + From + Copy + Unsigned + SaturatedConversion, - { - fn saturating_eval(&self, mut result: Balance, x: Balance) -> Balance { - let power = x.saturating_pow(self.degree.into()); - - let frac = self.coeff_frac * power; // Overflow safe since coeff_frac is strictly less than 1. - let integer = self.coeff_integer.saturating_mul(power); - // Do not add them together here to avoid an underflow. - - if self.negative { - result = result.saturating_sub(frac); - result = result.saturating_sub(integer); - } else { - result = result.saturating_add(frac); - result = result.saturating_add(integer); - } - - result - } - } } /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats diff --git a/runtime/mainnet/Cargo.toml b/runtime/mainnet/Cargo.toml index 554acd7..d185878 100644 --- a/runtime/mainnet/Cargo.toml +++ b/runtime/mainnet/Cargo.toml @@ -45,7 +45,6 @@ pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", d pallet-transaction-payment-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-block-builder = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} @@ -116,7 +115,6 @@ std = [ "polkadot-parachain/std", "polkadot-runtime-common/std", "sp-api/std", - "sp-arithmetic/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index d62ea27..1cb0a3a 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -38,12 +38,12 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; -pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; -pub use sp_runtime::{MultiAddress, Perbill, Permill}; pub use runtime_common::{ AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MILLISECS_PER_BLOCK, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; +pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] @@ -106,11 +106,11 @@ pub type Executive = frame_executive::Executive< pub mod fee { use super::{Balance, ExtrinsicBaseWeight, MILLIUNIT}; use frame_support::weights::{ - Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + FeePolynomial, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, }; use smallvec::smallvec; - use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; - use sp_runtime::{Perbill, SaturatedConversion}; + use sp_runtime::Perbill; /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. @@ -127,20 +127,14 @@ pub mod fee { type Balance = Balance; fn weight_to_fee(weight: &Weight) -> Self::Balance { - let ref_time = Balance::saturated_from(weight.ref_time()); - let proof_size = Balance::saturated_from(weight.proof_size()); - - let ref_polynomial = RefTimeToFee::polynomial(); - let proof_polynomial = ProofSizeToFee::polynomial(); + let ref_polynomial: FeePolynomial = RefTimeToFee::polynomial().into(); + let proof_polynomial: FeePolynomial = ProofSizeToFee::polynomial().into(); // Get fee amount from ref_time based on the RefTime polynomial - let ref_fee: Balance = - ref_polynomial.iter().fold(0, |acc, term| term.saturating_eval(acc, ref_time)); + let ref_fee: Balance = ref_polynomial.eval(weight.ref_time()); // Get fee amount from proof_size based on the ProofSize polynomial - let proof_fee: Balance = proof_polynomial - .iter() - .fold(0, |acc, term| term.saturating_eval(acc, proof_size)); + let proof_fee: Balance = proof_polynomial.eval(weight.proof_size()); // Take the maximum instead of the sum to charge by the more scarce resource. ref_fee.max(proof_fee) @@ -182,34 +176,6 @@ pub mod fee { }] } } - - // TODO: Refactor out this code to use `FeePolynomial` on versions using polkadot-v0.9.42 and above: - pub trait WeightCoefficientCalc { - fn saturating_eval(&self, result: Balance, x: Balance) -> Balance; - } - - impl WeightCoefficientCalc for WeightToFeeCoefficient - where - Balance: BaseArithmetic + From + Copy + Unsigned + SaturatedConversion, - { - fn saturating_eval(&self, mut result: Balance, x: Balance) -> Balance { - let power = x.saturating_pow(self.degree.into()); - - let frac = self.coeff_frac * power; // Overflow safe since coeff_frac is strictly less than 1. - let integer = self.coeff_integer.saturating_mul(power); - // Do not add them together here to avoid an underflow. - - if self.negative { - result = result.saturating_sub(frac); - result = result.saturating_sub(integer); - } else { - result = result.saturating_add(frac); - result = result.saturating_add(integer); - } - - result - } - } } /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats