Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -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<mainnet_runtime::GenesisConfig, Extensions>;
pub type MainChainSpec = sc_service::GenericChainSpec<mainnet_runtime::GenesisConfig, Extensions>;

/// Specialized `ChainSpec` for the development parachain runtime.
pub type DevnetChainSpec =
sc_service::GenericChainSpec<devnet_runtime::GenesisConfig, Extensions>;
pub type DevnetChainSpec = sc_service::GenericChainSpec<devnet_runtime::GenesisConfig, Extensions>;

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
Expand Down Expand Up @@ -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(),
}
}
Expand Down
13 changes: 6 additions & 7 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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,
};
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,
Expand Down Expand Up @@ -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::<devnet_runtime::RuntimeApi, DevnetRuntimeExecutor, _>(
&$config,
crate::service::build_import_queue::<_, DevnetRuntimeExecutor>,
)?;
let $partials = new_partial::<devnet_runtime::RuntimeApi, DevnetRuntimeExecutor, _>(
&$config,
crate::service::build_import_queue::<_, DevnetRuntimeExecutor>,
)?;
$code
},
Runtime::Mainnet => {
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 0 additions & 2 deletions runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down
52 changes: 9 additions & 43 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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.
Expand All @@ -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<Balance> = RefTimeToFee::polynomial().into();
let proof_polynomial: FeePolynomial<Balance> = 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)
Expand Down Expand Up @@ -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<Balance> {
fn saturating_eval(&self, result: Balance, x: Balance) -> Balance;
}

impl<Balance> WeightCoefficientCalc<Balance> for WeightToFeeCoefficient<Balance>
where
Balance: BaseArithmetic + From<u32> + 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
Expand Down
2 changes: 0 additions & 2 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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",
Expand Down
52 changes: 9 additions & 43 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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.
Expand All @@ -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<Balance> = RefTimeToFee::polynomial().into();
let proof_polynomial: FeePolynomial<Balance> = 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)
Expand Down Expand Up @@ -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<Balance> {
fn saturating_eval(&self, result: Balance, x: Balance) -> Balance;
}

impl<Balance> WeightCoefficientCalc<Balance> for WeightToFeeCoefficient<Balance>
where
Balance: BaseArithmetic + From<u32> + 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
Expand Down