Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All] Split up manta_primitives lib.rs & [Manta&Calamari] Port parity's fast-runtime cargo feature #383

Merged
merged 25 commits into from Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1566b0f
Initial port of fast runtime feature to manta/calamari RT
Feb 6, 2022
4b5a494
fix whitespace
Feb 6, 2022
3d7de22
Refactor primitives crate, have types in a submodule
Feb 7, 2022
e68ebab
Readd the header to lib.rs
Feb 7, 2022
b1529b0
Shorten SpendPeriod of pallet_treasury to 2min
Feb 7, 2022
84ea84a
Fixup: Shorten SpendPeriod of pallet_treasury to 2min
Feb 7, 2022
5daae50
Whitespace
Feb 7, 2022
347b2bf
Merge remote-tracking branch 'origin/manta' into garandor/fast-runtime
Feb 8, 2022
d3938cf
de-const SpendPeriod
Feb 8, 2022
3fb1739
merge v0.9.15 manta
Feb 14, 2022
96746dd
fixup: cargo fmt from dolphinv2 merge
Feb 14, 2022
eac9a20
Adapt new dolphin RT to primitives::types change
Feb 14, 2022
68e570d
Resolve v9.16 conflicts
Feb 15, 2022
d307b5c
cargo fmt --all
Feb 15, 2022
e8c2944
fix command.rs mentions of AuraId
Feb 16, 2022
414b3d9
Changelog
Feb 19, 2022
0e9b3b9
Merge remote-tracking branch 'origin/manta' into garandor/fast-runtime
Feb 23, 2022
6399e48
Merge remote-tracking branch 'origin/manta' into garandor/fast-runtime
Feb 24, 2022
e8d2853
Merge remote-tracking branch 'origin/manta' into garandor/fast-runtime
Mar 2, 2022
341a1dd
Adapt pallet_asset_manager to consts/types change
Mar 2, 2022
ad457d3
fixup for xcm_tests
Mar 2, 2022
9b9a2aa
Refactor xcm primitives to use pub mod instead of re-exporting
Mar 2, 2022
bf28bdd
Merge remote-tracking branch 'origin/manta' into garandor/fast-runtime
Mar 2, 2022
d3c748d
fixup helpers.rs
Mar 2, 2022
d390ccc
Update check_tests.yml
Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions node/Cargo.toml
Expand Up @@ -95,3 +95,7 @@ runtime-benchmarks = [
'polkadot-service/runtime-benchmarks',
'manta-runtime/runtime-benchmarks',
]
fast-runtime = [
"manta-runtime/fast-runtime",
"calamari-runtime/fast-runtime",
]
2 changes: 1 addition & 1 deletion node/src/chain_specs/mod.rs
Expand Up @@ -18,7 +18,7 @@
#![allow(dead_code)]
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use manta_primitives::{constants, AccountId, AuraId, Balance, Signature};
use manta_primitives::{constants, types::{AccountId, AuraId, Balance, Signature}};
Garandor marked this conversation as resolved.
Show resolved Hide resolved
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Expand Up @@ -24,7 +24,7 @@ use codec::Encode;
use cumulus_client_service::genesis::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use log::info;
use manta_primitives::Header;
use manta_primitives::types::Header;
use polkadot_parachain::primitives::AccountIdConversion;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc.rs
Expand Up @@ -25,7 +25,7 @@ use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

use manta_primitives::{AccountId, Balance, Block, Index as Nonce};
use manta_primitives::types::{AccountId, Balance, Block, Index as Nonce};

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Expand Up @@ -31,7 +31,7 @@ use cumulus_primitives_core::{
use polkadot_service::NativeExecutionDispatch;

use crate::rpc;
pub use manta_primitives::{AccountId, Balance, Block, Hash, Header, Index as Nonce};
pub use manta_primitives::types::{AccountId, Balance, Block, Hash, Header, Index as Nonce};

use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
use futures::lock::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion pallets/pallet-tx-pause/src/mock.rs
Expand Up @@ -24,7 +24,7 @@
use super::*;
use frame_support::{construct_runtime, ord_parameter_types, parameter_types};
use frame_system::EnsureRoot;
use manta_primitives::Balance;
use manta_primitives::types::Balance;

use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
Expand Down
3 changes: 3 additions & 0 deletions runtime/calamari/Cargo.toml
Expand Up @@ -121,6 +121,9 @@ runtime-benchmarks = [
'pallet-tx-pause/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',
]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []

std = [
'codec/std',
'serde',
Expand Down
2 changes: 1 addition & 1 deletion runtime/calamari/src/currency.rs
Expand Up @@ -15,7 +15,7 @@
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

#![allow(non_upper_case_globals)]
use manta_primitives::Balance;
use manta_primitives::types::Balance;

pub const KMA: Balance = 1_000_000_000_000; // 12 decimal
pub const cKMA: Balance = KMA / 100; // 10 decimal, cent-MA
Expand Down
2 changes: 1 addition & 1 deletion runtime/calamari/src/fee.rs
Expand Up @@ -17,7 +17,7 @@
use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use manta_primitives::Balance;
use manta_primitives::types::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

Expand Down
16 changes: 9 additions & 7 deletions runtime/calamari/src/lib.rs
Expand Up @@ -52,7 +52,9 @@ use frame_system::{
EnsureOneOf, EnsureRoot,
};
use manta_primitives::{
time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
constants::time::*,
prod_or_fast,
types::{AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature},
};
use sp_runtime::{Perbill, Permill};

Expand Down Expand Up @@ -358,13 +360,13 @@ impl pallet_sudo::Config for Runtime {
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 7 * DAYS;
pub const VotingPeriod: BlockNumber = 7 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 5 * MINUTES,"CALAMARI_LAUNCHPERIOD");
pub VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 5 * MINUTES,"CALAMARI_VOTINGPERIOD");
pub FastTrackVotingPeriod: BlockNumber = prod_or_fast!(3 * HOURS, 2 * MINUTES,"CALAMARI_FASTTRACKVOTINGPERIOD");
pub const InstantAllowed: bool = true;
pub const MinimumDeposit: Balance = 20 * KMA;
pub const EnactmentPeriod: BlockNumber = 1 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub EnactmentPeriod: BlockNumber = prod_or_fast!(1 * DAYS, 2 * MINUTES,"CALAMARI_ENACTMENTPERIOD");
pub CooloffPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 2 * MINUTES,"CALAMARI_COOLOFFPERIOD");
pub const PreimageByteDeposit: Balance = deposit(0, 1);
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
Expand Down Expand Up @@ -755,7 +757,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {

parameter_types! {
// Rotate collator's spot each 6 hours.
pub const Period: u32 = 6 * HOURS;
pub Period: u32 = prod_or_fast!(6 * HOURS, 2 * MINUTES,"CALAMARI_PERIOD");
Garandor marked this conversation as resolved.
Show resolved Hide resolved
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
}
Expand Down
3 changes: 3 additions & 0 deletions runtime/manta/Cargo.toml
Expand Up @@ -107,6 +107,9 @@ runtime-benchmarks = [
'pallet-scheduler/runtime-benchmarks',
'pallet-tx-pause/runtime-benchmarks',
]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []

std = [
'codec/std',
'serde',
Expand Down
2 changes: 1 addition & 1 deletion runtime/manta/src/currency.rs
Expand Up @@ -15,7 +15,7 @@
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

#![allow(non_upper_case_globals)]
use manta_primitives::Balance;
use manta_primitives::types::Balance;

pub const MANTA: Balance = 1_000_000_000_000_000_000; // 18 decimal
pub const cMANTA: Balance = MANTA / 100; // 16 decimal, cent-MA
Expand Down
2 changes: 1 addition & 1 deletion runtime/manta/src/fee.rs
Expand Up @@ -19,7 +19,7 @@ use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use manta_primitives::Balance;
use manta_primitives::types::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

Expand Down
6 changes: 4 additions & 2 deletions runtime/manta/src/lib.rs
Expand Up @@ -51,7 +51,9 @@ use frame_system::{
EnsureOneOf, EnsureRoot,
};
use manta_primitives::{
time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
constants::time::*,
prod_or_fast,
types::{AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature},
};
use sp_runtime::Perbill;

Expand Down Expand Up @@ -509,7 +511,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
}

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub Period: u32 = prod_or_fast!(7 * HOURS, 2 * MINUTES, "MANTA_PERIOD");
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/primitives/src/constants.rs
Expand Up @@ -26,7 +26,7 @@ pub const MANTA_TOKEN_SYMBOL: &str = "MANTA";

/// Manta parachain time-related
pub mod time {
use crate::{BlockNumber, Moment};
use crate::types::{BlockNumber, Moment};
/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
Expand Down
89 changes: 34 additions & 55 deletions runtime/primitives/src/lib.rs
@@ -1,61 +1,40 @@
// Copyright 2020-2022 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.
Garandor marked this conversation as resolved.
Show resolved Hide resolved

#![allow(non_upper_case_globals)]
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::upper_case_acronyms)]
#![cfg_attr(not(feature = "std"), no_std)]

pub mod constants;
pub use constants::time;

use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, Verify};

/// An index to a block.
pub type BlockNumber = u32;

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = sp_runtime::MultiSignature;

/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
/// never know...
pub type AccountIndex = u32;

/// Balance of an account.
pub type Balance = u128;

/// Index of a transaction in the chain.
pub type Index = u32;

/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;

/// Block header type as expected by this runtime.
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;

/// Digest item type.
pub type DigestItem = sp_runtime::generic::DigestItem;

// Aura consensus authority.
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;

// Moment
pub type Moment = u64;
pub mod types;

// From https://github.com/paritytech/polkadot/pull/4332/files?diff=unified&w=1 @ runtime/common/src/lib.rs
/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value
/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected).
/// Note that the environment variable is evaluated _at compile time_.
///
/// Usage:
/// ```Rust
/// parameter_types! {
/// // Note that the env variable version parameter cannot be const.
/// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD");
/// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES);
/// }
#[macro_export]
macro_rules! prod_or_fast {
Dengjianping marked this conversation as resolved.
Show resolved Hide resolved
($prod:expr, $test:expr) => {
if cfg!(feature = "fast-runtime") {
$test
} else {
$prod
}
};
($prod:expr, $test:expr, $env:expr) => {
if cfg!(feature = "fast-runtime") {
core::option_env!($env)
.map(|s| s.parse().ok())
.flatten()
.unwrap_or($test)
} else {
$prod
}
};
}
53 changes: 53 additions & 0 deletions runtime/primitives/src/types.rs
@@ -0,0 +1,53 @@
// Copyright 2020-2022 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, Verify};

/// An index to a block.
pub type BlockNumber = u32;

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = sp_runtime::MultiSignature;

/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
/// never know...
pub type AccountIndex = u32;

/// Balance of an account.
pub type Balance = u128;

/// Index of a transaction in the chain.
pub type Index = u32;

/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;

/// Block header type as expected by this runtime.
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;

/// Digest item type.
pub type DigestItem = sp_runtime::generic::DigestItem;

// Aura consensus authority.
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;

// Moment
pub type Moment = u64;