Skip to content

Commit

Permalink
Initial Runtime (#1)
Browse files Browse the repository at this point in the history
* make devnet and mainnet runtime equal

* Set ED and Asset Deposits to Zero

* multisig deposits to zero

* explicit note on preimage deposit

* Fix integrity test failure with ED 0

* set max consumers to 1024

* Add Parent as Superuser to give Relay Chain Root Access

* use psvm to bump some deps, add FrameTransactionalProcessor

* fix merge

* Fix integrity test failure with ED 0, again

* add pallet nfts

* remove balances whitelist from tx pause and safe mode
  • Loading branch information
shawntabrizi authored Mar 27, 2024
1 parent c078b31 commit 9caa068
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 97 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ frame-system-benchmarking = { version = "31.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "29.0.0", default-features = false }
frame-try-runtime = { version = "0.37.0", default-features = false }
pallet-assets = { version = "32.0.0", default-features = false }
pallet-balances = { version = "31.0.0", default-features = false }
# AUDIT: Allowing ED to be zero.
pallet-balances = { version = "31.0.0", default-features = false, features = ["insecure_zero_ed"] }
pallet-collective = { version = "31.0.0", default-features = false }
pallet-membership = { version = "31.0.0", default-features = false }
pallet-multisig = { version = "31.0.0", default-features = false }
pallet-nfts = { version = "25.0.0", default-features = false }
pallet-preimage = { version = "31.0.0", default-features = false }
pallet-scheduler = { version = "32.0.0", default-features = false }
pallet-sudo = { version = "31.0.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ frame-try-runtime = { workspace = true, default-features = false, optional = tru
pallet-assets = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }
pallet-collective = { workspace = true, default-features = false }
pallet-nfts = { workspace = true, default-features = false }
pallet-scheduler = { workspace = true, default-features = false }
pallet-sudo = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
Expand Down Expand Up @@ -107,6 +108,7 @@ std = [
"pallet-message-queue/std",
"pallet-motion/std",
"pallet-multisig/std",
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-scheduler/std",
"pallet-sudo/std",
Expand Down Expand Up @@ -150,6 +152,7 @@ runtime-benchmarks = [
"pallet-collective/runtime-benchmarks",
"pallet-motion/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand All @@ -175,6 +178,7 @@ try-runtime = [
"pallet-message-queue/try-runtime",
"pallet-motion/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-sudo/try-runtime",
Expand Down
129 changes: 85 additions & 44 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -222,7 +222,11 @@ pub const MICROUNIT: Balance = 1_000_000;
pub const MILLIUNIT: Balance = 1_000 * MICROUNIT;
pub const UNIT: Balance = 1_000 * MILLIUNIT;

pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
// AUDIT: Existential deposit is explicitly zero.
pub const EXISTENTIAL_DEPOSIT: Balance = 0;

// AUDIT: Some pallets are given zero deposit.
pub const ZERO_DEPOSIT: Balance = 0;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance * 20 * UNIT + (bytes as Balance) * 100 * MICROUNIT) / 100
Expand Down Expand Up @@ -313,7 +317,8 @@ impl frame_system::Config for Runtime {
type SS58Prefix = SS58Prefix;
/// The action to take on a Runtime Upgrade
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
/// The maximum number of consumers allowed on a single account.
type MaxConsumers = frame_support::traits::ConstU32<1024>;
type RuntimeTask = RuntimeTask;
type SingleBlockMigrations = ();
type MultiBlockMigrator = ();
Expand Down Expand Up @@ -355,13 +360,16 @@ impl pallet_balances::Config for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
}

/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;

parameter_types! {
pub const AssetDeposit: Balance = 10 * UNIT;
pub const AssetAccountDeposit: Balance = deposit(1, 16);
pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT;
pub const AssetDeposit: Balance = ZERO_DEPOSIT;
pub const AssetAccountDeposit: Balance = ZERO_DEPOSIT;
pub const ApprovalDeposit: Balance = ZERO_DEPOSIT;
pub const StringLimit: u32 = 50;
pub const MetadataDepositBase: Balance = deposit(1, 68);
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
pub const MetadataDepositBase: Balance = ZERO_DEPOSIT;
pub const MetadataDepositPerByte: Balance = ZERO_DEPOSIT;
}

impl pallet_assets::Config for Runtime {
Expand All @@ -372,7 +380,7 @@ impl pallet_assets::Config for Runtime {
type AssetIdParameter = parity_scale_codec::Compact<u32>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type AssetAccountDeposit = AssetAccountDeposit;
type MetadataDepositBase = MetadataDepositBase;
Expand All @@ -387,6 +395,47 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = ();
}

use pallet_nfts::PalletFeatures;
parameter_types! {
pub NftsPalletFeatures: PalletFeatures = PalletFeatures::all_enabled();
pub const NftsMaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS;
// Zero Deposits for NFTs
pub const NftsCollectionDeposit: Balance = ZERO_DEPOSIT;
pub const NftsItemDeposit: Balance = ZERO_DEPOSIT;
pub const NftsMetadataDepositBase: Balance = ZERO_DEPOSIT;
pub const NftsAttributeDepositBase: Balance = ZERO_DEPOSIT;
pub const NftsDepositPerByte: Balance = ZERO_DEPOSIT;
}

impl pallet_nfts::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CollectionId = u32;
type ItemId = u32;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type Locker = ();
type CollectionDeposit = NftsCollectionDeposit;
type ItemDeposit = NftsItemDeposit;
type MetadataDepositBase = NftsMetadataDepositBase;
type AttributeDepositBase = NftsAttributeDepositBase;
type DepositPerByte = NftsDepositPerByte;
type StringLimit = ConstU32<256>;
type KeyLimit = ConstU32<64>;
type ValueLimit = ConstU32<256>;
type ApprovalsLimit = ConstU32<20>;
type ItemAttributesApprovalsLimit = ConstU32<30>;
type MaxTips = ConstU32<10>;
type MaxDeadlineDuration = NftsMaxDeadlineDuration;
type MaxAttributesPerCall = ConstU32<10>;
type Features = NftsPalletFeatures;
type OffchainSignature = Signature;
type OffchainPublic = <Signature as Verify>::Signer;
type WeightInfo = pallet_nfts::weights::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = 10 * MICROUNIT;
Expand Down Expand Up @@ -474,11 +523,6 @@ impl pallet_message_queue::Config for Runtime {
type ServiceWeight = MessageQueueServiceWeight;
}

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
RuntimeBlockWeights::get().max_block;
Expand Down Expand Up @@ -537,23 +581,24 @@ impl pallet_motion::Config for Runtime {
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
// Additional storage item size of 32 bytes.
pub const DepositFactor: Balance = deposit(0, 32);
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. But we set deposits to zero.
pub const MultisigDepositBase: Balance = ZERO_DEPOSIT;
// Additional storage item size of 32 bytes, but we set deposits to zero.
pub const MultisigDepositFactor: Balance = ZERO_DEPOSIT;
}

impl pallet_multisig::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type DepositBase = MultisigDepositBase;
type DepositFactor = MultisigDepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
// Keep preimage deposits, as these items are heavy and does not intersect with the average user experience.
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
pub const PreimageByteDeposit: Balance = deposit(0, 1);
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
Expand Down Expand Up @@ -586,10 +631,7 @@ pub struct SafeModeWhitelistedCalls;
impl Contains<RuntimeCall> for SafeModeWhitelistedCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::System(_)
| RuntimeCall::SafeMode(_)
| RuntimeCall::TxPause(_)
| RuntimeCall::Balances(_) => true,
RuntimeCall::System(_) | RuntimeCall::SafeMode(_) | RuntimeCall::TxPause(_) => true,
_ => false,
}
}
Expand All @@ -607,7 +649,6 @@ impl pallet_safe_mode::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;
// balance transfers are still allowed
type WhitelistedCalls = SafeModeWhitelistedCalls;
// Safe mode will last 4 hours
type EnterDuration = EnterDuration;
Expand All @@ -633,11 +674,10 @@ impl pallet_safe_mode::Config for Runtime {

/// Calls that cannot be paused by the tx-pause pallet.
pub struct TxPauseWhitelistedCalls;
/// Whitelist `Balances::transfer_keep_alive`, all others are pauseable.
/// All calls are paused.
impl Contains<RuntimeCallNameOf<Runtime>> for TxPauseWhitelistedCalls {
fn contains(full_name: &RuntimeCallNameOf<Runtime>) -> bool {
match (full_name.0.as_slice(), full_name.1.as_slice()) {
(b"Balances", b"transfer_keep_alive") => true,
_ => false,
}
}
Expand All @@ -650,7 +690,6 @@ impl pallet_tx_pause::Config for Runtime {
type PauseOrigin = EnsureRoot<AccountId>;
// Only root origin can unpause transactions
type UnpauseOrigin = EnsureRoot<AccountId>;
// Balance transfers will not be paused
type WhitelistedCalls = TxPauseWhitelistedCalls;
type MaxNameLen = ConstU32<256>;
type WeightInfo = pallet_tx_pause::weights::SubstrateWeight<Runtime>;
Expand All @@ -666,28 +705,29 @@ construct_runtime!(
ParachainInfo: parachain_info = 3,

// Utility
Utility: pallet_utility = 4,
Multisig: pallet_multisig = 5,
Preimage: pallet_preimage = 6,
Scheduler: pallet_scheduler = 7,
SafeMode: pallet_safe_mode = 8,
TxPause: pallet_tx_pause = 9,
Utility: pallet_utility = 10,
Multisig: pallet_multisig = 11,
Preimage: pallet_preimage = 12,
Scheduler: pallet_scheduler = 13,
SafeMode: pallet_safe_mode = 14,
TxPause: pallet_tx_pause = 15,

// Monetary stuff.
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
Balances: pallet_balances = 20,
TransactionPayment: pallet_transaction_payment = 21,
Assets: pallet_assets = 22,
Nfts: pallet_nfts = 23,

// Governance
Sudo: pallet_sudo = 15,
Council: pallet_collective::<Instance1> = 16,
Motion: pallet_motion = 17,
Sudo: pallet_sudo = 30,
Council: pallet_collective::<Instance1> = 31,
Motion: pallet_motion = 32,

// XCM helpers.
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,
XcmpQueue: cumulus_pallet_xcmp_queue = 40,
PolkadotXcm: pallet_xcm = 41,
CumulusXcm: cumulus_pallet_xcm = 42,
MessageQueue: pallet_message_queue = 43,
}
);

Expand All @@ -697,6 +737,7 @@ mod benches {
[frame_system, SystemBench::<Runtime>]
[pallet_balances, Balances]
[pallet_assets, Assets]
[pallet_nfts, Nfts]
[pallet_scheduler, Scheduler]
[pallet_timestamp, Timestamp]
[pallet_multisig, Multisig]
Expand Down
7 changes: 5 additions & 2 deletions runtime/devnet/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, WithComputedOrigin, WithUniqueTopic,
};
Expand Down Expand Up @@ -68,6 +68,9 @@ pub type XcmOriginToTransactDispatchOrigin = (
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
// recognized.
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
// transaction from the Root origin.
ParentAsSuperuser<RuntimeOrigin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `RuntimeOrigin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
Expand Down
4 changes: 4 additions & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ frame-try-runtime = { workspace = true, default-features = false, optional = tru
pallet-assets = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }
pallet-collective = { workspace = true, default-features = false }
pallet-nfts = { workspace = true, default-features = false }
pallet-scheduler = { workspace = true, default-features = false }
pallet-sudo = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
Expand Down Expand Up @@ -107,6 +108,7 @@ std = [
"pallet-message-queue/std",
"pallet-motion/std",
"pallet-multisig/std",
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-scheduler/std",
"pallet-sudo/std",
Expand Down Expand Up @@ -150,6 +152,7 @@ runtime-benchmarks = [
"pallet-collective/runtime-benchmarks",
"pallet-motion/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand All @@ -175,6 +178,7 @@ try-runtime = [
"pallet-message-queue/try-runtime",
"pallet-motion/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-sudo/try-runtime",
Expand Down
Loading

0 comments on commit 9caa068

Please sign in to comment.