diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c82d1b9f..d43fb075 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: contents: write strategy: matrix: - runtime: [ "devnet", "testnet" ] + runtime: [ "devnet", "testnet", "mainnet" ] steps: - name: Checkout sources uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index 9f217ed1..9bc40f16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10298,6 +10298,7 @@ dependencies = [ "parity-scale-codec", "polkadot-cli", "polkadot-primitives", + "pop-runtime", "pop-runtime-common", "pop-runtime-devnet", "pop-runtime-testnet", @@ -10346,6 +10347,81 @@ dependencies = [ "scale-info", ] +[[package]] +name = "pop-runtime" +version = "0.1.0" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", + "cumulus-primitives-core", + "cumulus-primitives-storage-weight-reclaim", + "cumulus-primitives-utility", + "enumflags2", + "env_logger 0.11.5", + "frame-benchmarking", + "frame-executive", + "frame-metadata-hash-extension", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex", + "hex-literal", + "log", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-contracts", + "pallet-message-queue", + "pallet-multisig", + "pallet-nft-fractionalization", + "pallet-nfts", + "pallet-nfts-runtime-api", + "pallet-preimage", + "pallet-proxy", + "pallet-scheduler", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-utility", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "pop-primitives", + "pop-runtime-common", + "scale-info", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "substrate-wasm-builder", +] + [[package]] name = "pop-runtime-common" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 45b67456..335fef07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ members = [ "node", "primitives", "runtime/devnet", - "runtime/live", + "runtime/mainnet", "runtime/testnet", ] @@ -53,7 +53,7 @@ substrate-wasm-builder = "23.0.0" # Local pop-primitives = { path = "./primitives", default-features = false } -pop-runtime = { path = "runtime/live", default-features = true } # default-features=true required for `-p pop-node` builds +pop-runtime = { path = "runtime/mainnet", default-features = true } # default-features=true required for `-p pop-node` builds pop-runtime-common = { path = "runtime/common", default-features = false } pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds diff --git a/networks/mainnet.toml b/networks/mainnet.toml new file mode 100644 index 00000000..414df541 --- /dev/null +++ b/networks/mainnet.toml @@ -0,0 +1,40 @@ +# pop up parachain -f ./tests/networks/pop.toml + +[relaychain] +chain = "paseo-local" + +[relaychain.runtime_genesis_patch.balances] +balances = [ + # Pop sovereign account + ["5Ec4AhPKXY9B4ayGshkz2wFMh7N8gP7XKfAvtt1cigpG9FkJ", 60000000000000000], +] + +[[relaychain.nodes]] +name = "alice" +rpc_port = 8833 +validator = true + +[[relaychain.nodes]] +name = "bob" +validator = true + +[[parachains]] +id = 4001 +chain = "mainnet" +default_command = "./target/release/pop-node" + +[parachains.genesis_overrides.balances] +balances = [ + # Dev accounts + ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 10000000000000000], + ["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", 10000000000000000], + ["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", 10000000000000000], + ["5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy", 10000000000000000], + ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", 10000000000000000], + ["5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", 10000000000000000], +] + +[[parachains.collators]] +name = "pop" +rpc_port = 9944 +args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug"] \ No newline at end of file diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 9e7820f5..e3c8da68 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -13,7 +13,7 @@ pub type DevnetChainSpec = sc_service::GenericChainSpec; pub type TestnetChainSpec = sc_service::GenericChainSpec; /// Specialized `ChainSpec` for the live parachain runtime. -pub type LiveChainSpec = sc_service::GenericChainSpec; +pub type MainnetChainSpec = sc_service::GenericChainSpec; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -81,7 +81,7 @@ pub fn pop_testnet_session_keys(keys: AuraId) -> pop_runtime_testnet::SessionKey /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn pop_live_session_keys(keys: AuraId) -> pop_runtime::SessionKeys { +pub fn pop_mainnet_session_keys(keys: AuraId) -> pop_runtime::SessionKeys { pop_runtime::SessionKeys { aura: keys } } @@ -89,12 +89,12 @@ fn configure_for_relay( relay: Relay, properties: &mut sc_chain_spec::Properties, ) -> (Extensions, u32) { - properties.insert("ss58Format".into(), 42.into()); let para_id; 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()); @@ -103,7 +103,8 @@ fn configure_for_relay( (Extensions { relay_chain, para_id }, para_id) }, Relay::Polkadot => { - para_id = 3456; + para_id = 3395; + properties.insert("ss58Format".into(), 0.into()); properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); (Extensions { relay_chain: "polkadot".into(), para_id }, para_id) @@ -189,42 +190,37 @@ pub fn testnet_config(relay: Relay) -> TestnetChainSpec { .build() } -pub fn live_config(relay: Relay) -> LiveChainSpec { +pub fn mainnet_config(relay: Relay) -> MainnetChainSpec { let mut properties = sc_chain_spec::Properties::new(); let (extensions, para_id) = configure_for_relay(relay, &mut properties); let collator_0_account_id: AccountId = - AccountId::from_ss58check("5Gn9dVgCNUYtC5JVMBheQQv2x6Lpg5sAMcQVRupG1s3tP2gR").unwrap(); + AccountId::from_ss58check("15B6eUkXgoLA3dWruCRYWeBGNC8SCwuqiMtMTM1Zh2auSg3w").unwrap(); let collator_0_aura_id: AuraId = - AuraId::from_ss58check("5Gn9dVgCNUYtC5JVMBheQQv2x6Lpg5sAMcQVRupG1s3tP2gR").unwrap(); - let collator_1_account_id: AccountId = - AccountId::from_ss58check("5FyVvcSvSXCkBwvBEHkUh1VWGGrwaR3zbYBkU3Rc5DqV75S4").unwrap(); - let collator_1_aura_id: AuraId = - AuraId::from_ss58check("5FyVvcSvSXCkBwvBEHkUh1VWGGrwaR3zbYBkU3Rc5DqV75S4").unwrap(); - let collator_2_account_id: AccountId = - AccountId::from_ss58check("5GMqrQuWpyyBBK7LAWXR5psWvKc1QMqtiyasjp23VNKZWgh6").unwrap(); - let collator_2_aura_id: AuraId = - AuraId::from_ss58check("5GMqrQuWpyyBBK7LAWXR5psWvKc1QMqtiyasjp23VNKZWgh6").unwrap(); + AuraId::from_ss58check("15B6eUkXgoLA3dWruCRYWeBGNC8SCwuqiMtMTM1Zh2auSg3w").unwrap(); + + // Multisig account for sudo, generated from the following signatories: + // - 15VPagCVayS6XvT5RogPYop3BJTJzwqR2mCGR1kVn3w58ygg + // - 142zako1kfvrpQ7pJKYR8iGUD58i4wjb78FUsmJ9WcXmkM5z + // - 15k9niqckMg338cFBoz9vWFGwnCtwPBquKvqJEfHApijZkDz + // - 14G3CUFnZUBnHZUhahexSZ6AgemaW9zMHBnGccy3df7actf4 + // - Threshold 2 let sudo_account_id: AccountId = - AccountId::from_ss58check("5FPL3ZLqUk6MyBoZrQZ1Co29WAteX6T6N68TZ6jitHvhpyuD").unwrap(); + AccountId::from_ss58check("15NMV2JX1NeMwarQiiZvuJ8ixUcvayFDcu1F9Wz1HNpSc8gP").unwrap(); #[allow(deprecated)] - LiveChainSpec::builder( + MainnetChainSpec::builder( pop_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), extensions, ) .with_name("Pop Network") .with_id("pop") .with_chain_type(ChainType::Live) - .with_genesis_config_patch(live_genesis( + .with_genesis_config_patch(mainnet_genesis( // initial collators. vec![ // POP COLLATOR 0 (collator_0_account_id, collator_0_aura_id), - // POP COLLATOR 1 - (collator_1_account_id, collator_1_aura_id), - // POP COLLATOR 2 - (collator_2_account_id, collator_2_aura_id), ], sudo_account_id, para_id.into(), @@ -234,7 +230,7 @@ pub fn live_config(relay: Relay) -> LiveChainSpec { .build() } -fn live_genesis( +fn mainnet_genesis( invulnerables: Vec<(AccountId, AuraId)>, root: AccountId, id: ParaId, @@ -260,7 +256,7 @@ fn live_genesis( ( acc.clone(), // account id acc, // validator id - pop_live_session_keys(aura), // session keys + pop_mainnet_session_keys(aura), // session keys ) }) .collect::>(), diff --git a/node/src/command.rs b/node/src/command.rs index 45bddafe..0b82edef 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -23,7 +23,7 @@ use crate::{ enum Runtime { Devnet, Testnet, - Live, + Mainnet, } trait RuntimeResolver { @@ -36,8 +36,8 @@ 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") { - Runtime::Live + } else if id.eq("pop") || id.ends_with("live") || id.ends_with("mainnet") { + Runtime::Mainnet } else { log::warn!( "No specific runtime was recognized for ChainSpec's Id: '{}', so Runtime::Devnet will \ @@ -75,15 +75,15 @@ fn load_spec(id: &str) -> std::result::Result, 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" => - Box::new(chain_spec::live_config(Relay::Polkadot)), + "pop-network" | "pop" | "pop-polkadot" | "mainnet" => + Box::new(chain_spec::mainnet_config(Relay::Polkadot)), "" | "local" => Box::new(chain_spec::development_config(Relay::PaseoLocal)), path => { let path: PathBuf = path.into(); match path.runtime() { Runtime::Devnet => Box::new(chain_spec::DevnetChainSpec::from_json_file(path)?), Runtime::Testnet => Box::new(chain_spec::TestnetChainSpec::from_json_file(path)?), - Runtime::Live => Box::new(chain_spec::LiveChainSpec::from_json_file(path)?), + Runtime::Mainnet => Box::new(chain_spec::MainnetChainSpec::from_json_file(path)?), } }, }) @@ -181,7 +181,7 @@ macro_rules! construct_async_run { { $( $code )* }.map(|v| (v, task_manager)) }) } - Runtime::Live => { + Runtime::Mainnet => { runner.async_run(|$config| { let $components = new_partial::( &$config @@ -205,7 +205,7 @@ macro_rules! construct_benchmark_partials { let $partials = new_partial::(&$config)?; $code }, - Runtime::Live => { + Runtime::Mainnet => { let $partials = new_partial::(&$config)?; $code }, @@ -381,7 +381,7 @@ pub fn run() -> Result<()> { .map(|r| r.0) .map_err(Into::into) }, - Runtime::Live => { + Runtime::Mainnet => { sp_core::crypto::set_default_ss58_version( pop_runtime::SS58Prefix::get().into(), ); diff --git a/runtime/live/src/config/assets.rs b/runtime/live/src/config/assets.rs deleted file mode 100644 index d66358a6..00000000 --- a/runtime/live/src/config/assets.rs +++ /dev/null @@ -1,122 +0,0 @@ -use frame_support::{ - parameter_types, - traits::{AsEnsureOriginWithArg, ConstU32}, - BoundedVec, PalletId, -}; -use frame_system::{EnsureRoot, EnsureSigned}; -use pallet_nfts::PalletFeatures; -use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId, Signature}; -use sp_runtime::traits::Verify; - -use crate::{ - deposit, AccountId, Assets, Balance, Balances, BlockNumber, Nfts, Runtime, RuntimeEvent, - RuntimeHoldReason, DAYS, EXISTENTIAL_DEPOSIT, UNIT, -}; - -/// We allow root to execute privileged asset operations. -pub type AssetsForceOrigin = EnsureRoot; - -parameter_types! { - pub const AssetDeposit: Balance = 10 * UNIT; - pub const AssetAccountDeposit: Balance = deposit(1, 16); - pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT; - pub const AssetsStringLimit: u32 = 50; - /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) - // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 - pub const MetadataDepositBase: Balance = deposit(1, 68); - pub const MetadataDepositPerByte: Balance = deposit(0, 1); -} - -parameter_types! { - pub NftsPalletFeatures: PalletFeatures = PalletFeatures::all_enabled(); - pub const NftsCollectionDeposit: Balance = 10 * UNIT; - pub const NftsItemDeposit: Balance = UNIT / 100; - pub const NftsMetadataDepositBase: Balance = deposit(1, 129); - pub const NftsAttributeDepositBase: Balance = deposit(1, 0); - pub const NftsDepositPerByte: Balance = deposit(0, 1); - pub const NftsMaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS; -} - -impl pallet_nfts::Config for Runtime { - // TODO: source from primitives - type ApprovalsLimit = ConstU32<20>; - type AttributeDepositBase = NftsAttributeDepositBase; - type CollectionDeposit = NftsCollectionDeposit; - // TODO: source from primitives - type CollectionId = CollectionId; - type CreateOrigin = AsEnsureOriginWithArg>; - type Currency = Balances; - type DepositPerByte = NftsDepositPerByte; - type Features = NftsPalletFeatures; - type ForceOrigin = AssetsForceOrigin; - #[cfg(feature = "runtime-benchmarks")] - type Helper = (); - type ItemAttributesApprovalsLimit = ConstU32<30>; - type ItemDeposit = NftsItemDeposit; - // TODO: source from primitives - type ItemId = ItemId; - // TODO: source from primitives - type KeyLimit = ConstU32<64>; - type Locker = (); - type MaxAttributesPerCall = ConstU32<10>; - type MaxDeadlineDuration = NftsMaxDeadlineDuration; - type MaxTips = ConstU32<10>; - type MetadataDepositBase = NftsMetadataDepositBase; - type OffchainPublic = ::Signer; - type OffchainSignature = Signature; - type RuntimeEvent = RuntimeEvent; - type StringLimit = ConstU32<256>; - type ValueLimit = ConstU32<256>; - type WeightInfo = pallet_nfts::weights::SubstrateWeight; -} - -parameter_types! { - pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction"); - pub NewAssetSymbol: BoundedVec = (*b"FRAC").to_vec().try_into().unwrap(); - pub NewAssetName: BoundedVec = (*b"Frac").to_vec().try_into().unwrap(); -} - -impl pallet_nft_fractionalization::Config for Runtime { - type AssetBalance = >::Balance; - type AssetId = >::AssetId; - type Assets = Assets; - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); - type Currency = Balances; - type Deposit = AssetDeposit; - type NewAssetName = NewAssetName; - type NewAssetSymbol = NewAssetSymbol; - type NftCollectionId = ::CollectionId; - type NftId = ::ItemId; - type Nfts = Nfts; - type PalletId = NftFractionalizationPalletId; - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = RuntimeHoldReason; - type StringLimit = AssetsStringLimit; - type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight; -} - -pub type TrustBackedAssets = pallet_assets::Instance1; -pub type TrustBackedAssetsCall = pallet_assets::Call; -impl pallet_assets::Config for Runtime { - type ApprovalDeposit = ApprovalDeposit; - type AssetAccountDeposit = AssetAccountDeposit; - type AssetDeposit = AssetDeposit; - type AssetId = AssetIdForTrustBackedAssets; - type AssetIdParameter = codec::Compact; - type Balance = Balance; - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); - type CallbackHandle = (); - type CreateOrigin = AsEnsureOriginWithArg>; - type Currency = Balances; - type Extra = (); - type ForceOrigin = AssetsForceOrigin; - type Freezer = (); - type MetadataDepositBase = MetadataDepositBase; - type MetadataDepositPerByte = MetadataDepositPerByte; - type RemoveItemsLimit = ConstU32<1000>; - type RuntimeEvent = RuntimeEvent; - type StringLimit = AssetsStringLimit; - type WeightInfo = pallet_assets::weights::SubstrateWeight; -} diff --git a/runtime/live/src/config/contracts.rs b/runtime/live/src/config/contracts.rs deleted file mode 100644 index 3222a38a..00000000 --- a/runtime/live/src/config/contracts.rs +++ /dev/null @@ -1,84 +0,0 @@ -use frame_support::{ - parameter_types, - traits::{ConstBool, ConstU32, Nothing, Randomness}, -}; -use frame_system::{pallet_prelude::BlockNumberFor, EnsureSigned}; - -use crate::{ - deposit, extensions, Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, - RuntimeEvent, RuntimeHoldReason, Timestamp, -}; - -fn schedule() -> pallet_contracts::Schedule { - pallet_contracts::Schedule { - limits: pallet_contracts::Limits { - runtime_memory: 1024 * 1024 * 1024, - ..Default::default() - }, - ..Default::default() - } -} - -// randomness-collective-flip is insecure. Provide dummy randomness as placeholder for the -// deprecated trait. https://github.com/paritytech/polkadot-sdk/blob/9bf1a5e23884921498b381728bfddaae93f83744/substrate/frame/contracts/mock-network/src/parachain/contracts_config.rs#L45 -pub struct DummyRandomness(sp_std::marker::PhantomData); - -impl Randomness> for DummyRandomness { - fn random(_subject: &[u8]) -> (T::Hash, BlockNumberFor) { - (Default::default(), Default::default()) - } -} - -parameter_types! { - pub const DepositPerItem: Balance = deposit(1, 0); - pub const DepositPerByte: Balance = deposit(0, 1); - pub Schedule: pallet_contracts::Schedule = schedule::(); - pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024); - pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0); -} - -impl pallet_contracts::Config for Runtime { - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; - type ApiVersion = (); - /// The safest default is to allow no calls at all. - /// - /// Runtimes should whitelist dispatchables that are allowed to be called from contracts - /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to - /// change because that would break already deployed contracts. The `RuntimeCall` structure - /// itself is not allowed to change the indices of existing pallets, too. - type CallFilter = Nothing; - type CallStack = [pallet_contracts::Frame; 23]; - type ChainExtension = extensions::PopApiExtension; - type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; - type Currency = Balances; - type Debug = (); - type DefaultDepositLimit = DefaultDepositLimit; - type DepositPerByte = DepositPerByte; - type DepositPerItem = DepositPerItem; - type Environment = (); - type InstantiateOrigin = EnsureSigned; - // This node is geared towards development and testing of contracts. - // We decided to increase the default allowed contract size for this - // reason (the default is `128 * 1024`). - // - // Our reasoning is that the error code `CodeTooLarge` is thrown - // if a too-large contract is uploaded. We noticed that it poses - // less friction during development when the requirement here is - // just more lax. - type MaxCodeLen = ConstU32<{ 256 * 1024 }>; - type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; - type MaxDelegateDependencies = ConstU32<32>; - type MaxStorageKeyLen = ConstU32<128>; - type Migrations = (pallet_contracts::migration::v16::Migration,); - type Randomness = DummyRandomness; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = RuntimeHoldReason; - type Schedule = Schedule; - type Time = Timestamp; - type UnsafeUnstableInterface = ConstBool; - type UploadOrigin = EnsureSigned; - type WeightInfo = pallet_contracts::weights::SubstrateWeight; - type WeightPrice = pallet_transaction_payment::Pallet; - type Xcm = pallet_xcm::Pallet; -} diff --git a/runtime/live/src/config/proxy.rs b/runtime/live/src/config/proxy.rs deleted file mode 100644 index ff70240e..00000000 --- a/runtime/live/src/config/proxy.rs +++ /dev/null @@ -1,110 +0,0 @@ -use frame_support::traits::InstanceFilter; -use pop_runtime_common::proxy::{ - AnnouncementDepositBase, AnnouncementDepositFactor, MaxPending, MaxProxies, ProxyDepositBase, - ProxyDepositFactor, ProxyType, -}; -use sp_runtime::traits::BlakeTwo256; - -use super::assets::TrustBackedAssetsCall; -use crate::{Balances, Runtime, RuntimeCall, RuntimeEvent}; - -impl InstanceFilter for ProxyType { - fn filter(&self, c: &RuntimeCall) -> bool { - match self { - ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - RuntimeCall::Balances { .. } | - RuntimeCall::Assets { .. } | - RuntimeCall::Nfts { .. } - ), - ProxyType::CancelProxy => matches!( - c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } - ), - ProxyType::Assets => { - matches!( - c, - RuntimeCall::Assets { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } - ) - }, - ProxyType::AssetOwner => matches!( - c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } - ), - ProxyType::AssetManager => matches!( - c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | - RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | - RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } - ), - ProxyType::Collator => matches!( - c, - RuntimeCall::CollatorSelection { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } - ), - } - } - - fn is_superset(&self, o: &Self) -> bool { - ProxyType::is_superset(self, o) - } -} - -impl pallet_proxy::Config for Runtime { - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; - type CallHasher = BlakeTwo256; - type Currency = Balances; - type MaxPending = MaxPending; - type MaxProxies = MaxProxies; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; - type ProxyType = ProxyType; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_proxy::weights::SubstrateWeight; -} diff --git a/runtime/live/src/extensions.rs b/runtime/live/src/extensions.rs deleted file mode 100644 index 3e84c834..00000000 --- a/runtime/live/src/extensions.rs +++ /dev/null @@ -1,195 +0,0 @@ -use frame_support::{ - dispatch::{GetDispatchInfo, RawOrigin}, - pallet_prelude::*, - traits::{Contains, OriginTrait}, -}; -use pallet_contracts::{ - chain_extension::{ - BufInBufOutState, ChainExtension, ChargedAmount, Environment, Ext, InitState, RetVal, - }, - WeightInfo, -}; -use pop_primitives::storage_keys::RuntimeStateKeys; -use sp_core::crypto::UncheckedFrom; -use sp_runtime::{traits::Dispatchable, DispatchError}; -use sp_std::vec::Vec; - -use crate::{AccountId, AllowedApiCalls, RuntimeCall, RuntimeOrigin}; - -const LOG_TARGET: &str = "pop-api::extension"; - -#[derive(Default)] -pub struct PopApiExtension; - -impl ChainExtension for PopApiExtension -where - T: pallet_contracts::Config - + frame_system::Config< - RuntimeOrigin = RuntimeOrigin, - AccountId = AccountId, - RuntimeCall = RuntimeCall, - >, - T::AccountId: UncheckedFrom + AsRef<[u8]>, -{ - fn call(&mut self, env: Environment) -> Result - where - E: Ext, - { - log::debug!(target:LOG_TARGET, " extension called "); - match v0::FuncId::try_from(env.func_id())? { - v0::FuncId::Dispatch => { - match dispatch::(env) { - Ok(()) => Ok(RetVal::Converging(0)), - Err(DispatchError::Module(error)) => { - // encode status code = pallet index in runtime + error index, allowing for - // 999 errors - Ok(RetVal::Converging( - (error.index as u32 * 1_000) + u32::from_le_bytes(error.error), - )) - }, - Err(e) => Err(e), - } - }, - v0::FuncId::ReadState => { - read_state::(env)?; - Ok(RetVal::Converging(0)) - }, - } - } -} - -pub mod v0 { - #[derive(Debug)] - pub enum FuncId { - Dispatch, - ReadState, - } -} - -impl TryFrom for v0::FuncId { - type Error = DispatchError; - - fn try_from(func_id: u16) -> Result { - let id = match func_id { - 0x0 => Self::Dispatch, - 0x1 => Self::ReadState, - _ => { - log::error!("called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("unimplemented func_id")); - }, - }; - - Ok(id) - } -} - -fn dispatch_call( - env: &mut Environment, - call: RuntimeCall, - mut origin: RuntimeOrigin, - log_prefix: &str, -) -> Result<(), DispatchError> -where - E: Ext, -{ - let charged_dispatch_weight = env.charge_weight(call.get_dispatch_info().weight)?; - - log::debug!(target:LOG_TARGET, "{} inputted RuntimeCall: {:?}", log_prefix, call); - - origin.add_filter(AllowedApiCalls::contains); - - match call.dispatch(origin) { - Ok(info) => { - log::debug!(target:LOG_TARGET, "{} success, actual weight: {:?}", log_prefix, info.actual_weight); - - // refund weight if the actual weight is less than the charged weight - if let Some(actual_weight) = info.actual_weight { - env.adjust_weight(charged_dispatch_weight, actual_weight); - } - - Ok(()) - }, - Err(err) => { - log::debug!(target:LOG_TARGET, "{} failed: error: {:?}", log_prefix, err.error); - Err(err.error) - }, - } -} - -fn charge_overhead_weight( - env: &mut Environment, - len: u32, - log_prefix: &str, -) -> Result -where - T: pallet_contracts::Config, - E: Ext, -{ - // calculate weight for reading bytes of `len` - // reference: https://github.com/paritytech/polkadot-sdk/blob/117a9433dac88d5ac00c058c9b39c511d47749d2/substrate/frame/contracts/src/wasm/runtime.rs#L267 - let base_weight: Weight = T::WeightInfo::seal_return(len); - - // debug_message weight is a good approximation of the additional overhead of going - // from contract layer to substrate layer. - // reference: https://github.com/paritytech/ink-examples/blob/b8d2caa52cf4691e0ddd7c919e4462311deb5ad0/psp22-extension/runtime/psp22-extension-example.rs#L236 - let overhead: Weight = T::WeightInfo::seal_debug_message(len); - - let charged_weight = env.charge_weight(base_weight.saturating_add(overhead))?; - log::debug!(target: LOG_TARGET, "{} charged weight: {:?}", log_prefix, charged_weight); - - Ok(charged_weight) -} - -fn dispatch(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config, - RuntimeOrigin: From>, - E: Ext, -{ - const LOG_PREFIX: &str = " dispatch |"; - - let mut env = env.buf_in_buf_out(); - let len = env.in_len(); - - charge_overhead_weight::(&mut env, len, LOG_PREFIX)?; - - // read the input as RuntimeCall - let call: RuntimeCall = env.read_as_unbounded(len)?; - - // contract is the origin by default - let origin: RuntimeOrigin = RawOrigin::Signed(env.ext().address().clone()).into(); - - dispatch_call::(&mut env, call, origin, LOG_PREFIX) -} - -fn read_state(env: Environment) -> Result<(), DispatchError> -where - T: pallet_contracts::Config, - E: Ext, -{ - const LOG_PREFIX: &str = " read_state |"; - - let mut env = env.buf_in_buf_out(); - - // To be conservative, we charge the weight for reading the input bytes of a fixed-size type. - let base_weight: Weight = T::WeightInfo::seal_return(env.in_len()); - let charged_weight = env.charge_weight(base_weight)?; - - log::debug!(target:LOG_TARGET, "{} charged weight: {:?}", LOG_PREFIX, charged_weight); - - let key: RuntimeStateKeys = env.read_as()?; - - let result = match key { - _ => Vec::::default(), - } - .encode(); - - log::trace!( - target:LOG_TARGET, - "{} result: {:?}.", LOG_PREFIX, result - ); - env.write(&result, false, None).map_err(|e| { - log::trace!(target: LOG_TARGET, "{:?}", e); - DispatchError::Other("unable to write results to contract memory") - }) -} diff --git a/runtime/live/Cargo.toml b/runtime/mainnet/Cargo.toml similarity index 100% rename from runtime/live/Cargo.toml rename to runtime/mainnet/Cargo.toml diff --git a/runtime/live/build.rs b/runtime/mainnet/build.rs similarity index 100% rename from runtime/live/build.rs rename to runtime/mainnet/build.rs diff --git a/runtime/live/src/config/mod.rs b/runtime/mainnet/src/config/mod.rs similarity index 70% rename from runtime/live/src/config/mod.rs rename to runtime/mainnet/src/config/mod.rs index a3a64c92..a866ca8a 100644 --- a/runtime/live/src/config/mod.rs +++ b/runtime/mainnet/src/config/mod.rs @@ -1,5 +1,3 @@ -mod assets; -mod contracts; mod proxy; // Public due to integration tests crate. pub mod xcm; diff --git a/runtime/mainnet/src/config/proxy.rs b/runtime/mainnet/src/config/proxy.rs new file mode 100644 index 00000000..0b8ab9b9 --- /dev/null +++ b/runtime/mainnet/src/config/proxy.rs @@ -0,0 +1,57 @@ +use frame_support::traits::InstanceFilter; +use pop_runtime_common::proxy::{ + AnnouncementDepositBase, AnnouncementDepositFactor, MaxPending, MaxProxies, ProxyDepositBase, + ProxyDepositFactor, ProxyType, +}; +use sp_runtime::traits::BlakeTwo256; + +use crate::{Balances, Runtime, RuntimeCall, RuntimeEvent}; + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }), + ProxyType::CancelProxy => matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } + ), + ProxyType::Assets => { + matches!(c, RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. }) + }, + ProxyType::AssetOwner => { + matches!(c, RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. }) + }, + ProxyType::AssetManager => { + matches!(c, RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. }) + }, + ProxyType::Collator => matches!( + c, + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } + ), + } + } + + fn is_superset(&self, o: &Self) -> bool { + ProxyType::is_superset(self, o) + } +} + +impl pallet_proxy::Config for Runtime { + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; + type CallHasher = BlakeTwo256; + type Currency = Balances; + type MaxPending = MaxPending; + type MaxProxies = MaxProxies; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type ProxyType = ProxyType; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; +} diff --git a/runtime/live/src/config/xcm.rs b/runtime/mainnet/src/config/xcm.rs similarity index 100% rename from runtime/live/src/config/xcm.rs rename to runtime/mainnet/src/config/xcm.rs diff --git a/runtime/live/src/lib.rs b/runtime/mainnet/src/lib.rs similarity index 87% rename from runtime/live/src/lib.rs rename to runtime/mainnet/src/lib.rs index c247420c..2d107331 100644 --- a/runtime/live/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -7,7 +7,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod config; -mod extensions; mod weights; use config::xcm::{RelayLocation, XcmOriginToTransactDispatchOrigin}; @@ -19,9 +18,9 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - fungible::HoldConsideration, tokens::nonfungibles_v2::Inspect, ConstBool, ConstU32, - ConstU64, ConstU8, Contains, EitherOfDiverse, EqualPrivilegeOnly, EverythingBut, - LinearStoragePrice, TransformOrigin, VariantCountOf, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, Contains, + EitherOfDiverse, EqualPrivilegeOnly, EverythingBut, LinearStoragePrice, TransformOrigin, + VariantCountOf, }, weights::{ ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -103,11 +102,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = ( - pallet_contracts::Migration, - cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, - pallet_xcm::migration::MigrateToLatestXcmVersion, -); +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -188,18 +183,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { state_version: 1, }; -type EventRecord = frame_system::EventRecord< - ::RuntimeEvent, - ::Hash, ->; - -// Prints debug output of the `contracts` pallet to stdout if the node is -// started with `-lruntime::contracts=debug`. -const CONTRACTS_DEBUG_OUTPUT: pallet_contracts::DebugInfo = - pallet_contracts::DebugInfo::UnsafeDebug; -const CONTRACTS_EVENTS: pallet_contracts::CollectEvents = - pallet_contracts::CollectEvents::UnsafeCollect; - /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -233,7 +216,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. @@ -425,11 +408,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmpQueue = TransformOrigin; } -impl cumulus_pallet_xcmp_queue::migration::v5::V5Config for Runtime { - // This must be the same as the `ChannelInfo` from the `Config`: - type ChannelList = ParachainSystem; -} - parameter_types! { pub const Period: u32 = 6 * HOURS; pub const Offset: u32 = 0; @@ -618,10 +596,6 @@ mod runtime { #[runtime::pallet_index(33)] pub type MessageQueue = pallet_message_queue::Pallet; - // Contracts - #[runtime::pallet_index(40)] - pub type Contracts = pallet_contracts::Pallet; - // Proxy #[runtime::pallet_index(41)] pub type Proxy = pallet_proxy::Pallet; @@ -631,14 +605,6 @@ mod runtime { // Utility #[runtime::pallet_index(43)] pub type Utility = pallet_utility::Pallet; - - // Assets - #[runtime::pallet_index(50)] - pub type Nfts = pallet_nfts::Pallet; - #[runtime::pallet_index(51)] - pub type NftFractionalization = pallet_nft_fractionalization::Pallet; - #[runtime::pallet_index(52)] - pub type Assets = pallet_assets::Pallet; } #[cfg(feature = "runtime-benchmarks")] @@ -795,73 +761,6 @@ impl_runtime_apis! { } } - impl pallet_contracts::ContractsApi - for Runtime - { - fn call( - origin: AccountId, - dest: AccountId, - value: Balance, - gas_limit: Option, - storage_deposit_limit: Option, - input_data: Vec, - ) -> pallet_contracts::ContractExecResult { - let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call( - origin, - dest, - value, - gas_limit, - storage_deposit_limit, - input_data, - CONTRACTS_DEBUG_OUTPUT, - CONTRACTS_EVENTS, - pallet_contracts::Determinism::Enforced, - ) - } - - fn instantiate( - origin: AccountId, - value: Balance, - gas_limit: Option, - storage_deposit_limit: Option, - code: pallet_contracts::Code, - data: Vec, - salt: Vec, - ) -> pallet_contracts::ContractInstantiateResult - { - let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate( - origin, - value, - gas_limit, - storage_deposit_limit, - code, - data, - salt, - CONTRACTS_DEBUG_OUTPUT, - CONTRACTS_EVENTS, - ) - } - - fn upload_code( - origin: AccountId, - code: Vec, - storage_deposit_limit: Option, - determinism: pallet_contracts::Determinism, - ) -> pallet_contracts::CodeUploadResult - { - Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism) - } - - fn get_storage( - address: AccountId, - key: Vec, - ) -> pallet_contracts::GetStorageResult { - Contracts::get_storage(address, key) - } - } - impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { fn can_build_upon( included_hash: ::Hash, @@ -877,50 +776,6 @@ impl_runtime_apis! { } } - impl pallet_nfts_runtime_api::NftsApi for Runtime { - fn owner(collection: u32, item: u32) -> Option { - >::owner(&collection, &item) - } - - fn collection_owner(collection: u32) -> Option { - >::collection_owner(&collection) - } - - fn attribute( - collection: u32, - item: u32, - key: Vec, - ) -> Option> { - >::attribute(&collection, &item, &key) - } - - fn custom_attribute( - account: AccountId, - collection: u32, - item: u32, - key: Vec, - ) -> Option> { - >::custom_attribute( - &account, - &collection, - &item, - &key, - ) - } - - fn system_attribute( - collection: u32, - item: Option, - key: Vec, - ) -> Option> { - >::system_attribute(&collection, item.as_ref(), &key) - } - - fn collection_attribute(collection: u32, key: Vec) -> Option> { - >::collection_attribute(&collection, &key) - } - } - #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/runtime/live/src/weights/block_weights.rs b/runtime/mainnet/src/weights/block_weights.rs similarity index 100% rename from runtime/live/src/weights/block_weights.rs rename to runtime/mainnet/src/weights/block_weights.rs diff --git a/runtime/live/src/weights/extrinsic_weights.rs b/runtime/mainnet/src/weights/extrinsic_weights.rs similarity index 100% rename from runtime/live/src/weights/extrinsic_weights.rs rename to runtime/mainnet/src/weights/extrinsic_weights.rs diff --git a/runtime/live/src/weights/mod.rs b/runtime/mainnet/src/weights/mod.rs similarity index 100% rename from runtime/live/src/weights/mod.rs rename to runtime/mainnet/src/weights/mod.rs diff --git a/runtime/live/src/weights/paritydb_weights.rs b/runtime/mainnet/src/weights/paritydb_weights.rs similarity index 100% rename from runtime/live/src/weights/paritydb_weights.rs rename to runtime/mainnet/src/weights/paritydb_weights.rs diff --git a/runtime/live/src/weights/rocksdb_weights.rs b/runtime/mainnet/src/weights/rocksdb_weights.rs similarity index 100% rename from runtime/live/src/weights/rocksdb_weights.rs rename to runtime/mainnet/src/weights/rocksdb_weights.rs