Skip to content

Commit

Permalink
refactor: various improvements and fixes (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilrobot-01 authored Aug 29, 2024
1 parent bec2216 commit da62fc2
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 62 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion networks/mainnet.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pop up parachain -f ./tests/networks/pop.toml
# pop up parachain -f ./networks/mainnet.toml

[relaychain]
chain = "paseo-local"
Expand Down
3 changes: 3 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ cumulus-relay-chain-interface.workspace = true
[build-dependencies]
substrate-build-script-utils.workspace = true

[dev-dependencies]
pallet-multisig.workspace = true

[features]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
Expand Down
52 changes: 48 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub type DevnetChainSpec = sc_service::GenericChainSpec<Extensions>;
/// Specialized `ChainSpec` for the testnet parachain runtime.
pub type TestnetChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Specialized `ChainSpec` for the live parachain runtime.
/// Specialized `ChainSpec` for the mainnet parachain runtime.
pub type MainnetChainSpec = sc_service::GenericChainSpec<Extensions>;

/// The default XCM version to set in genesis config.
Expand Down Expand Up @@ -94,12 +94,16 @@ fn configure_for_relay(
match relay {
Relay::Paseo | Relay::PaseoLocal => {
para_id = 4001;
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "PAS".into());
properties.insert("tokenDecimals".into(), 10.into());

let relay_chain =
if let Relay::Paseo = relay { "paseo".into() } else { "paseo-local".into() };
let relay_chain = if let Relay::Paseo = relay {
properties.insert("ss58Format".into(), 0.into());
"paseo".into()
} else {
properties.insert("ss58Format".into(), 42.into());
"paseo-local".into()
};
(Extensions { relay_chain, para_id }, para_id)
},
Relay::Polkadot => {
Expand Down Expand Up @@ -341,3 +345,43 @@ fn devnet_genesis(
"sudo": { "key": Some(root) }
})
}

#[test]
fn sudo_key_valid() {
// Source: https://github.com/paritytech/extended-parachain-template/blob/d08cec37117731953119ecaed79522a0812b46f5/node/src/chain_spec.rs#L79
fn get_multisig_sudo_key(mut authority_set: Vec<AccountId>, threshold: u16) -> AccountId {
assert!(threshold > 0, "Threshold for sudo multisig cannot be 0");
assert!(!authority_set.is_empty(), "Sudo authority set cannot be empty");
assert!(
authority_set.len() >= threshold.into(),
"Threshold must be less than or equal to authority set members"
);
// Sorting is done to deterministically order the multisig set
// So that a single authority set (A, B, C) may generate only a single unique multisig key
// Otherwise, (B, A, C) or (C, A, B) could produce different keys and cause chaos
authority_set.sort();

// Define a multisig threshold for `threshold / authority_set.len()` members
pallet_multisig::Pallet::<pop_runtime_mainnet::Runtime>::multi_account_id(
&authority_set[..],
threshold,
)
}

assert_eq!(
get_multisig_sudo_key(
vec![
AccountId::from_ss58check("15VPagCVayS6XvT5RogPYop3BJTJzwqR2mCGR1kVn3w58ygg")
.unwrap(),
AccountId::from_ss58check("142zako1kfvrpQ7pJKYR8iGUD58i4wjb78FUsmJ9WcXmkM5z")
.unwrap(),
AccountId::from_ss58check("15k9niqckMg338cFBoz9vWFGwnCtwPBquKvqJEfHApijZkDz")
.unwrap(),
AccountId::from_ss58check("14G3CUFnZUBnHZUhahexSZ6AgemaW9zMHBnGccy3df7actf4")
.unwrap(),
],
2
),
AccountId::from_ss58check("15NMV2JX1NeMwarQiiZvuJ8ixUcvayFDcu1F9Wz1HNpSc8gP").unwrap()
)
}
4 changes: 2 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn runtime(id: &str) -> Runtime {
Runtime::Devnet
} else if id.starts_with("test") || id.ends_with("testnet") {
Runtime::Testnet
} else if id.eq("pop") || id.ends_with("live") || id.ends_with("mainnet") {
} else if id.eq("pop") || id.ends_with("mainnet") {
Runtime::Mainnet
} else {
log::warn!(
Expand Down Expand Up @@ -75,7 +75,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
"dev" | "devnet" | "dev-paseo" =>
Box::new(chain_spec::development_config(Relay::PaseoLocal)),
"test" | "testnet" | "pop-paseo" => Box::new(chain_spec::testnet_config(Relay::Paseo)),
"pop-network" | "pop" | "pop-polkadot" | "mainnet" =>
"pop" | "mainnet" | "pop-polkadot" | "pop-network" =>
Box::new(chain_spec::mainnet_config(Relay::Polkadot)),
"" | "local" => Box::new(chain_spec::development_config(Relay::PaseoLocal)),
path => {
Expand Down
25 changes: 1 addition & 24 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors.workspace = true
description.workspace = true
edition.workspace = true
homepage.workspace = true
license = "Unlicense"
license.workspace = true
name = "pop-runtime-mainnet"
repository.workspace = true
version = "0.1.0"
Expand All @@ -16,13 +16,10 @@ substrate-wasm-builder.workspace = true

[dependencies]
codec.workspace = true
hex-literal.workspace = true
log.workspace = true
scale-info.workspace = true
smallvec.workspace = true

# Local
pop-primitives.workspace = true
pop-runtime-common = { workspace = true, default-features = false }

# Substrate
Expand All @@ -34,16 +31,11 @@ frame-system.workspace = true
frame-system-benchmarking.workspace = true
frame-system-rpc-runtime-api.workspace = true
frame-try-runtime.workspace = true
pallet-assets.workspace = true
pallet-aura.workspace = true
pallet-authorship.workspace = true
pallet-balances.workspace = true
pallet-contracts.workspace = true
pallet-message-queue.workspace = true
pallet-multisig.workspace = true
pallet-nft-fractionalization.workspace = true
pallet-nfts.workspace = true
pallet-nfts-runtime-api.workspace = true
pallet-preimage.workspace = true
pallet-proxy.workspace = true
pallet-scheduler.workspace = true
Expand Down Expand Up @@ -115,18 +107,12 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime/std",
"log/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-contracts/std",
"pallet-message-queue/std",
"pallet-multisig/std",
"pallet-nft-fractionalization/std",
"pallet-nfts-runtime-api/std",
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-scheduler/std",
Expand All @@ -141,7 +127,6 @@ std = [
"parachains-common/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"pop-primitives/std",
"pop-runtime-common/std",
"scale-info/std",
"sp-api/std",
Expand Down Expand Up @@ -172,14 +157,10 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nft-fractionalization/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
Expand All @@ -205,16 +186,12 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-contracts/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nft-fractionalization/try-runtime",
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-scheduler/try-runtime",
Expand Down
2 changes: 1 addition & 1 deletion runtime/mainnet/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(all(feature = "std", feature = "metadata-hash"))]
fn main() {
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("PAS", 10)
.enable_metadata_hash("DOT", 10)
.build()
}

Expand Down
3 changes: 1 addition & 2 deletions runtime/mainnet/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod proxy;
// Public due to integration tests crate.
pub mod xcm;
pub(crate) mod xcm;
80 changes: 61 additions & 19 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ impl Contains<RuntimeCall> for FilteredCalls {
}
}

/// A type to identify allowed calls to the Runtime from contracts. Used by Pop API
pub struct AllowedApiCalls;
impl Contains<RuntimeCall> for AllowedApiCalls {
fn contains(_c: &RuntimeCall) -> bool {
false
}
}

/// The default types are being injected by [`derive_impl`](`frame_support::derive_impl`) from
/// [`ParaChainDefaultConfig`](`struct@frame_system::config_preludes::ParaChainDefaultConfig`),
/// but overridden as needed.
Expand Down Expand Up @@ -364,16 +356,16 @@ impl parachain_info::Config for Runtime {}

parameter_types! {
pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
pub MessageQueueIdleServiceWeight: Weight = Perbill::from_percent(20) * RuntimeBlockWeights::get().max_block;
}

impl pallet_message_queue::Config for Runtime {
type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
type IdleMaxServiceWeight = ();
type MaxStale = sp_core::ConstU32<8>;
type HeapSize = ConstU32<{ 64 * 1024 }>;
type IdleMaxServiceWeight = MessageQueueIdleServiceWeight;
type MaxStale = ConstU32<8>;
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
cumulus_primitives_core::AggregateMessageOrigin,
>;
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = xcm_builder::ProcessXcmMessage<
AggregateMessageOrigin,
Expand All @@ -395,14 +387,14 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ChannelInfo = ParachainSystem;
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
// Limit the number of messages and signals a HRML channel can have at most
// Limit the number of messages and signals a HRMP channel can have at most
type MaxActiveOutboundChannels = ConstU32<128>;
type MaxInboundSuspended = sp_core::ConstU32<1_000>;
// Limit the number of HRML channels
type MaxInboundSuspended = ConstU32<1_000>;
// Limit the number of HRMP channels
type MaxPageSize = ConstU32<{ 103 * 1024 }>;
type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
type RuntimeEvent = RuntimeEvent;
type VersionWrapper = ();
type VersionWrapper = PolkadotXcm;
type WeightInfo = ();
// Enqueue XCMP messages from siblings for later processing.
type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
Expand Down Expand Up @@ -437,7 +429,6 @@ impl pallet_aura::Config for Runtime {

parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const SessionLength: BlockNumber = 6 * HOURS;
// StakingAdmin pluralistic body.
pub const StakingAdminBodyId: BodyId = BodyId::Defense;
}
Expand Down Expand Up @@ -864,3 +855,54 @@ cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(test)]
mod tests {
use std::any::TypeId;

use pallet_balances::AdjustmentDirection;
use BalancesCall::*;
use RuntimeCall::Balances;

use super::*;
#[test]
fn filtering_force_adjust_total_issuance_works() {
assert!(FilteredCalls::contains(&Balances(force_adjust_total_issuance {
direction: AdjustmentDirection::Increase,
delta: 0
})));
}

#[test]
fn filtering_force_set_balance_works() {
assert!(FilteredCalls::contains(&Balances(force_set_balance {
who: MultiAddress::Address32([0u8; 32]),
new_free: 0,
})));
}

#[test]
fn filtering_force_transfer_works() {
assert!(FilteredCalls::contains(&Balances(force_transfer {
source: MultiAddress::Address32([0u8; 32]),
dest: MultiAddress::Address32([0u8; 32]),
value: 0,
})));
}

#[test]
fn filtering_force_unreserve_works() {
assert!(FilteredCalls::contains(&Balances(force_unreserve {
who: MultiAddress::Address32([0u8; 32]),
amount: 0
})));
}

#[test]
fn filtering_configured() {
assert_eq!(
TypeId::of::<<Runtime as frame_system::Config>::BaseCallFilter>(),
TypeId::of::<EverythingBut<FilteredCalls>>(),
);
}
}
2 changes: 1 addition & 1 deletion runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ parameter_types! {
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
pub const SS58Prefix: u16 = 42;
pub const SS58Prefix: u16 = 0;
}

/// A type to identify filtered calls.
Expand Down

0 comments on commit da62fc2

Please sign in to comment.