From a6b50877f4c5fd84607493dc94d6807ba4d447e7 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 23 Aug 2021 15:19:11 +0100 Subject: [PATCH 1/3] adds treasure and other governance pallets --- Cargo.lock | 7 +- node/src/chain_spec.rs | 2 +- runtime/common/Cargo.toml | 12 +- runtime/common/src/impls.rs | 50 ++++++- runtime/common/src/lib.rs | 25 +++- runtime/picasso/Cargo.toml | 17 ++- runtime/picasso/src/lib.rs | 198 ++++++++++++++++++++++++---- scripts/polkadot-launch/config.json | 2 +- 8 files changed, 261 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54baa1312a3..8cd084c300c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6077,14 +6077,18 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-collective", + "pallet-democracy", "pallet-indices", + "pallet-membership", "pallet-oracle", "pallet-randomness-collective-flip", + "pallet-scheduler", "pallet-session", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", "pallet-xcm", "parachain-info", "parity-scale-codec", @@ -8089,6 +8093,8 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-collator-selection", + "pallet-collective", + "pallet-treasury", "parity-scale-codec", "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?tag=v0.9.8)", "polkadot-runtime-common 0.9.8 (git+https://github.com/paritytech/polkadot?tag=v0.9.8)", @@ -8098,7 +8104,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "substrate-wasm-builder", ] [[package]] diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index d5e92b956a2..229a30fdf1c 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -54,7 +54,7 @@ where pub fn picasso_dev() -> picasso::ChainSpec { //TODO check properties let mut properties = Properties::new(); - properties.insert("tokenSymbol".into(), "$PICA".into()); + properties.insert("tokenSymbol".into(), "PICA".into()); properties.insert("tokenDecimals".into(), 12.into()); picasso::ChainSpec::from_genesis( diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 7d5e63a495a..6e260a73afa 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime-common" version = "0.8.30" -authors = ["Parity Technologies "] +authors = ["Composable Developers "] edition = "2018" [package.metadata.docs.rs] @@ -15,22 +15,21 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = executive = { package = "frame-executive", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } frame-system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } frame-support = { package = "frame-support", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } -balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } node-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false } + collator-selection = { package = "pallet-collator-selection", git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } +balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +collective = { package = "pallet-collective", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } [dev-dependencies] serde = { version = "1.0.119" } authorship = { package = "pallet-authorship", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } -[build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" } - - [features] default = ["std"] std = [ @@ -43,6 +42,7 @@ std = [ 'frame-system/std', 'collator-selection/std', 'balances/std', + 'collective/std', 'node-primitives/std', 'polkadot-runtime-common/std', 'polkadot-primitives/std', diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index a0de012fc14..2cc07ef92bd 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -24,7 +24,7 @@ pub type NegativeImbalance = as Currency<(sp_std::marker::PhantomData); impl OnUnbalanced> for ToStakingPot where - R: balances::Config + collator_selection::Config, + R: balances::Config + collator_selection::Config + treasury::Config>, ::AccountId: From, ::AccountId: Into, ::Event: From>, @@ -40,11 +40,12 @@ where ); // deposit then slash the amount to burn fees if >::can_slash(&staking_pot, slash_amount) { - // TODO: enrich treasury with the negative imbalance. - let (_negative_imbalanbce, _) = >::slash( + let (imbalance, _) = >::slash( &staking_pot, slash_amount, ); + // give treasury the remaining half + as OnUnbalanced<_>>::on_unbalanced(imbalance); } >::deposit_event(balances::Event::Deposit( @@ -58,7 +59,7 @@ where pub struct DealWithFees(sp_std::marker::PhantomData); impl OnUnbalanced> for DealWithFees where - R: balances::Config + collator_selection::Config, + R: balances::Config + collator_selection::Config + treasury::Config>, ::AccountId: From, ::AccountId: Into, ::Event: From>, @@ -84,9 +85,10 @@ mod tests { use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - Perbill, + Perbill, Permill, }; use collator_selection::IdentityCollator; + use crate::{DAYS, Balance, BlockNumber, constants::PICA}; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -99,6 +101,7 @@ mod tests { { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: balances::{Pallet, Call, Storage, Config, Event}, + Treasury: treasury::{Pallet, Call, Storage, Config, Event} = 31, CollatorSelection: collator_selection::{Pallet, Call, Storage, Event}, } ); @@ -127,7 +130,7 @@ mod tests { type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = balances::AccountData; + type AccountData = balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); @@ -140,7 +143,7 @@ mod tests { } impl balances::Config for Test { - type Balance = u64; + type Balance = u128; type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; @@ -197,6 +200,36 @@ mod tests { type EventHandler = (); } + parameter_types! { + pub const TreasuryPalletId: PalletId = PalletId(*b"picatrsy"); + /// percentage of proposal that most be bonded by the proposer + pub const ProposalBond: Permill = Permill::from_percent(5); + // TODO: rationale? + pub const ProposalBondMinimum: Balance = 5 * PICA; + pub const SpendPeriod: BlockNumber = 7 * DAYS; + pub const Burn: Permill = Permill::from_percent(0); + + pub const MaxApprovals: u32 = 30; + } + + impl treasury::Config for Test { + type PalletId = TreasuryPalletId; + type Currency = Balances; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; + type Event = Event; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = Burn; + type MaxApprovals = MaxApprovals; + type BurnDestination = (); + type WeightInfo = (); + // TODO: add bounties? + type SpendFunds = (); + } + pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() @@ -220,6 +253,7 @@ mod tests { // Author gets 50% of tip and 50% of fee = 15 assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 15); + assert_eq!(Balances::free_balance(Treasury::account_id()), 15); }); } @@ -235,6 +269,7 @@ mod tests { // Author gets 50% of tip and 50% of fee = 15 assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 0); + assert_eq!(Balances::free_balance(Treasury::account_id()), 0); }); } @@ -250,6 +285,7 @@ mod tests { // Author gets 50% of tip and 50% of fee = 15 assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 0); + assert_eq!(Balances::free_balance(Treasury::account_id()), 0); }); } } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index fa8a8288095..b516dd6b728 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -51,13 +51,19 @@ mod types { // Aura consensus authority. pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; + + /// Council Instance + pub type CouncilInstance = collective::Instance1; } /// Common constants of statemint and statemine mod constants { - use super::types::BlockNumber; + use super::types::{BlockNumber, AccountId, CouncilInstance, Balance}; use sp_runtime::Perbill; use frame_support::weights::{Weight, constants::WEIGHT_PER_SECOND}; + use frame_system::{EnsureOneOf, EnsureRoot}; + use sp_core::u32_trait::{_1, _2}; + /// 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 @@ -73,14 +79,27 @@ mod constants { pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; + // PICA = 12 decimals + pub const PICA: Balance = 1_000_000_000_000; + pub const MILLI_PICA: Balance = PICA / 1_000; + pub const MICRO_PICA: Balance = MILLI_PICA / 1_000; + + /// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is /// used to limit the maximal weight of a single extrinsic. // TODO changed to be more in line with statemine pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); - /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by + /// TODO: We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by /// Operational extrinsics. pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); - /// We allow for 0.5 seconds of compute with a 6 second average block time. + /// TODO: We allow for 0.5 seconds of compute with a 6 second average block time. pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2; + + /// Origin for either root or half of general council + pub type EnsureRootOrHalfCouncil = EnsureOneOf< + AccountId, + EnsureRoot, + collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>, + >; } diff --git a/runtime/picasso/Cargo.toml b/runtime/picasso/Cargo.toml index dc2ab9b1cfe..ec7f6494f8e 100644 --- a/runtime/picasso/Cargo.toml +++ b/runtime/picasso/Cargo.toml @@ -3,7 +3,7 @@ name = "picasso-runtime" version = "0.1.0" edition = "2018" description = "Picasso, Kusama Parachain Runtime Implementation" -authors = ["Seun Lanlege"] +authors = ["Seun Lanlege "] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -32,13 +32,17 @@ authorship = { package = "pallet-authorship", git = "https://github.com/parityte balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } indices = { package = "pallet-indices", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } randomness-collective-flip = { package = "pallet-randomness-collective-flip", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } -pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true } +collective = { package = "pallet-collective", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +membership = { package = "pallet-membership", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +scheduler = { package = "pallet-scheduler", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } session = { package = "pallet-session", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } sudo = { package = "pallet-sudo", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } timestamp = { package = "pallet-timestamp", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } +democracy = { package = "pallet-democracy", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } transaction-payment = { package = "pallet-transaction-payment", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } oracle = { package = "pallet-oracle", path = "../../frame/oracle", default-features = false } -runtime-common = { path = "../common", default-features = false, version = "0.8.30" } +runtime-common = { path = "../common", default-features = false } # Used for the node template's RPCs system-rpc-runtime-api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } transaction-payment-rpc-runtime-api = { package = "pallet-transaction-payment-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } @@ -95,6 +99,11 @@ std = [ "sudo/std", "indices/std", "oracle/std", + "treasury/std", + "democracy/std", + "scheduler/std", + "runtime-common/std", + "collective/std", "transaction-payment/std", "parachain-info/std", "cumulus-pallet-aura-ext/std", @@ -120,7 +129,7 @@ runtime-benchmarks = [ "balances/runtime-benchmarks", "timestamp/runtime-benchmarks", "oracle/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", + "collective/runtime-benchmarks", "collator-selection/runtime-benchmarks", "session-benchmarking/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", diff --git a/runtime/picasso/src/lib.rs b/runtime/picasso/src/lib.rs index 882e59d5e2a..bed3683bca0 100644 --- a/runtime/picasso/src/lib.rs +++ b/runtime/picasso/src/lib.rs @@ -19,6 +19,7 @@ pub use runtime_common as common; use runtime_common::{ impls::DealWithFees, AccountId, AccountIndex, AuraId, Balance, BlockNumber, Hash, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + DAYS, EnsureRootOrHalfCouncil, CouncilInstance, PICA, MICRO_PICA, }; use sp_std::prelude::*; #[cfg(feature = "std")] @@ -43,10 +44,7 @@ use polkadot_parachain::primitives::Sibling; pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; use frame_system as system; -use system::{ - limits::{BlockLength, BlockWeights}, - EnsureOneOf, EnsureRoot, -}; +use system::{limits::{BlockLength, BlockWeights}, EnsureRoot}; use xcm::{ opaque::v0::{BodyId, Junction, MultiAsset, MultiLocation, NetworkId}, v0::Xcm, @@ -83,10 +81,6 @@ pub mod opaque { } } -// Unit = the base number of indivisible units for balances -pub const UNIT: Balance = 1_000_000_000_000; -pub const MILLIUNIT: Balance = 1_000_000_000; -pub const MICROUNIT: Balance = 1_000_000; // To learn more about runtime versioning and what each of the following value means: // https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning @@ -139,6 +133,7 @@ parameter_types! { }) .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) .build_or_panic(); + // TODO: update pub const SS58Prefix: u8 = 42; } @@ -216,11 +211,10 @@ impl timestamp::Config for Runtime { type WeightInfo = weights::timestamp::WeightInfo; } -// TODO changed to be inline with ksm -pub const EXISTENTIAL_DEPOSIT: Balance = 3333333; +/// minimum account balance is given as 0.1 PICA ~ 100 MILLI_PICA +pub const EXISTENTIAL_DEPOSIT: Balance = 100 * MILLI_PICA; parameter_types! { - //TODO set pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; pub const MaxLocks: u32 = 50; } @@ -233,14 +227,15 @@ impl balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type Event = Event; - type DustRemoval = (); + type DustRemoval = Treasury; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::balances::WeightInfo; } -//TODO set, some get burned some got to collator pot see DealWithFees in statemint repo + parameter_types! { - pub const TransactionByteFee: Balance = 1; + /// 1 milli-pica/byte should be fine + pub const TransactionByteFee: Balance = 1 * MILLI_PICA; } impl transaction_payment::Config for Runtime { @@ -256,7 +251,8 @@ impl sudo::Config for Runtime { } parameter_types! { - pub const IndexDeposit: Balance = 1 * 100000000000000; + /// Index deposit requires a 100 PICA + pub const IndexDeposit: Balance = 100 * PICA; } impl indices::Config for Runtime { @@ -337,11 +333,14 @@ where //TODO set parameter_types! { pub const StakeLock: BlockNumber = 50; - pub const MinStake: Balance = 3333333; - pub const RequestCost: Balance = 1; - pub const RewardAmount: Balance = 5; - pub const SlashAmount: Balance = 5; pub const StalePrice: BlockNumber = 5; + + /// TODO: discuss with omar/cosmin + pub const MinStake: Balance = 1000 * PICA; + pub const RequestCost: Balance = 1 * PICA; + pub const RewardAmount: Balance = 5 * PICA; + // Shouldn't this be a ratio based on locked amount? + pub const SlashAmount: Balance = 5; pub const MaxAnswerBound: u64 = 25; } @@ -353,7 +352,7 @@ impl oracle::Config for Runtime { type StakeLock = StakeLock; type MinStake = MinStake; type StalePrice = StalePrice; - type AddOracle = EnsureOneOf, EnsureRoot>; + type AddOracle = EnsureRootOrHalfCouncil; type RequestCost = RequestCost; type RewardAmount = RewardAmount; type SlashAmount = SlashAmount; @@ -441,8 +440,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate. pub UnitWeightCost: Weight = 1_000_000; - // One UNIT buys 1 second of weight. - pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::X1(Junction::Parent), UNIT); + // One PICA buys 1 second of weight. + pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::X1(Junction::Parent), PICA); } match_type! { @@ -467,7 +466,7 @@ impl xcm_executor::Config for XcmConfig { type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToTransactDispatchOrigin; type IsReserve = NativeAsset; - type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of UNIT + type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of PICA type LocationInverter = LocationInverter; type Barrier = Barrier; type Weigher = FixedWeightBounds; @@ -561,7 +560,7 @@ parameter_types! { impl collator_selection::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = EnsureOneOf, EnsureRoot>; + type UpdateOrigin = EnsureRootOrHalfCouncil; type PotId = PotId; type MaxCandidates = MaxCandidates; type MinCandidates = MinCandidates; @@ -571,8 +570,141 @@ impl collator_selection::Config for Runtime { type ValidatorId = ::AccountId; type ValidatorIdOf = collator_selection::IdentityCollator; type ValidatorRegistration = Session; + // TODO: benchmark for runtime + type WeightInfo = (); +} + +parameter_types! { + pub const TreasuryPalletId: PalletId = PalletId(*b"picatrsy"); + /// percentage of proposal that most be bonded by the proposer + pub const ProposalBond: Permill = Permill::from_percent(5); + // TODO: rationale? + pub const ProposalBondMinimum: Balance = 5 * PICA; + pub const SpendPeriod: BlockNumber = 7 * DAYS; + pub const Burn: Permill = Permill::from_percent(0); + + pub const MaxApprovals: u32 = 30; +} + +impl treasury::Config for Runtime { + type PalletId = TreasuryPalletId; + type Currency = Balances; + type ApproveOrigin = EnsureRootOrHalfCouncil; + type RejectOrigin = EnsureRootOrHalfCouncil; + type Event = Event; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = Burn; + type MaxApprovals = MaxApprovals; + type BurnDestination = (); + type WeightInfo = (); + // TODO: add bounties? + type SpendFunds = (); +} + +parameter_types! { + pub const CouncilMotionDuration: BlockNumber = 7 * DAYS; + pub const CouncilMaxProposals: u32 = 100; + pub const CouncilMaxMembers: u32 = 100; +} + +impl membership::Config for Runtime { + type Event = Event; + type AddOrigin = EnsureRootOrHalfCouncil; + type RemoveOrigin = EnsureRootOrHalfCouncil; + type SwapOrigin = EnsureRootOrHalfCouncil; + type ResetOrigin = EnsureRootOrHalfCouncil; + type PrimeOrigin = EnsureRootOrHalfCouncil; + type MembershipInitialized = Council; + type MembershipChanged = Council; + type MaxMembers = CouncilMaxMembers; + // TODO: benchmark type WeightInfo = (); } + +impl collective::Config for Runtime { + type Origin = Origin; + type Proposal = Call; + type Event = Event; + type MotionDuration = CouncilMotionDuration; + type MaxProposals = CouncilMaxProposals; + type MaxMembers = CouncilMaxMembers; + type DefaultVote = collective::PrimeDefaultVote; + // TODO: benchmark + type WeightInfo = (); +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * + RuntimeBlockWeights::get().max_block; + pub const MaxScheduledPerBlock: u32 = 50; +} + +impl scheduler::Config for Runtime { + type Event = Event; + type Origin = Origin; + type PalletsOrigin = OriginCaller; + type Call = Call; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + // TODO: benchmark for runtime + type WeightInfo = (); +} + +parameter_types! { + pub const LaunchPeriod: BlockNumber = 5 * DAYS; + pub const VotingPeriod: BlockNumber = 5 * DAYS; + pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS; + pub MinimumDeposit: Balance = 100 * PICA; + pub const EnactmentPeriod: BlockNumber = 2 * DAYS; + pub const CooloffPeriod: BlockNumber = 7 * DAYS; + // TODO: prod value + pub PreimageByteDeposit: Balance = 1 * MILLI_PICA; + pub const InstantAllowed: bool = true; + pub const MaxVotes: u32 = 100; + pub const MaxProposals: u32 = 100; +} + +impl democracy::Config for Runtime { + type Proposal = Call; + type Event = Event; + type Currency = Balances; + type EnactmentPeriod = EnactmentPeriod; + type LaunchPeriod = LaunchPeriod; + type VotingPeriod = VotingPeriod; + type MinimumDeposit = MinimumDeposit; + + // TODO: prod values + type ExternalOrigin = EnsureRootOrHalfCouncil; + type ExternalMajorityOrigin = EnsureRootOrHalfCouncil; + type ExternalDefaultOrigin = EnsureRootOrHalfCouncil; + + type FastTrackOrigin = EnsureRootOrHalfCouncil; + type InstantOrigin = EnsureRootOrHalfCouncil; + type InstantAllowed = InstantAllowed; + + type FastTrackVotingPeriod = FastTrackVotingPeriod; + type CancellationOrigin = EnsureRootOrHalfCouncil; + type BlacklistOrigin = EnsureRootOrHalfCouncil; + type CancelProposalOrigin = EnsureRootOrHalfCouncil; + type VetoOrigin = collective::EnsureMember; + type OperationalPreimageOrigin = collective::EnsureMember; + type Slash = Treasury; + + type CooloffPeriod = CooloffPeriod; + type MaxProposals = MaxProposals; + type MaxVotes = MaxVotes; + type PalletsOrigin = OriginCaller; + + type PreimageByteDeposit = PreimageByteDeposit; + type Scheduler = Scheduler; + // TODO: benchmark for runtime + type WeightInfo = (); +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -599,13 +731,21 @@ construct_runtime!( Aura: aura::{Pallet, Config} = 23, AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 24, + // Governance utilities + Council: collective::::{Pallet, Call, Storage, Origin, Event, Config} = 30, + CouncilMembership: membership::::{Pallet, Call, Storage, Event, Config} = 31, + Treasury: treasury::{Pallet, Call, Storage, Config, Event} = 32, + Democracy: democracy::{Pallet, Call, Storage, Config, Event} = 33, + Scheduler: scheduler::{Pallet, Call, Storage, Event} = 34, + + // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 30, - PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin} = 31, - CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event, Origin} = 32, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 40, + PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin} = 41, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event, Origin} = 42, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 43, - Oracle: oracle::{Pallet, Call, Storage, Event} = 40, + Oracle: oracle::{Pallet, Call, Storage, Event} = 50, } ); diff --git a/scripts/polkadot-launch/config.json b/scripts/polkadot-launch/config.json index cac8bf19da5..68fc35a474a 100644 --- a/scripts/polkadot-launch/config.json +++ b/scripts/polkadot-launch/config.json @@ -1,6 +1,6 @@ { "relaychain": { - "bin": "./bin/polkadot", + "bin": "../../../polkadot/target/release/polkadot", "chain": "rococo-local", "nodes": [ { From 6b98c4834efb6bc57da2a16edf55434c091894bf Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 23 Aug 2021 16:13:06 +0100 Subject: [PATCH 2/3] fix chainspec --- node/src/chain_spec/picasso.rs | 8 ++++++++ runtime/common/Cargo.toml | 31 ++++++++++++++++--------------- runtime/picasso/Cargo.toml | 32 ++++++++++++++++---------------- runtime/picasso/src/lib.rs | 2 +- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/node/src/chain_spec/picasso.rs b/node/src/chain_spec/picasso.rs index c4688080e4c..232ce053e71 100644 --- a/node/src/chain_spec/picasso.rs +++ b/node/src/chain_spec/picasso.rs @@ -54,5 +54,13 @@ pub fn genesis_config( candidacy_bond: existential_deposit * 16, ..Default::default() }, + council_membership: picasso_runtime::CouncilMembershipConfig { + members: vec![], + ..Default::default() + }, + // council will get its members from council_membership + council: Default::default(), + democracy: Default::default(), + treasury: Default::default(), } } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 6e260a73afa..57e3c93f2b9 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Composable Developers "] edition = "2018" [package.metadata.docs.rs] -targets = ['x86_64-unknown-linux-gnu'] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } @@ -21,7 +21,7 @@ node-primitives = { git = "https://github.com/paritytech/substrate", branch = "p polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false } -collator-selection = { package = "pallet-collator-selection", git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } +collator-selection = { package = "pallet-collator-selection", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } collective = { package = "pallet-collective", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } @@ -33,17 +33,18 @@ authorship = { package = "pallet-authorship", git = "https://github.com/parityte [features] default = ["std"] std = [ - 'codec/std', - 'sp-consensus-aura/std', - 'sp-std/std', - 'sp-io/std', - 'frame-support/std', - 'executive/std', - 'frame-system/std', - 'collator-selection/std', - 'balances/std', - 'collective/std', - 'node-primitives/std', - 'polkadot-runtime-common/std', - 'polkadot-primitives/std', + "codec/std", + "sp-consensus-aura/std", + "sp-std/std", + "sp-io/std", + "frame-support/std", + "executive/std", + "frame-system/std", + "collator-selection/std", + "balances/std", + "collective/std", + "treasury/std", + "node-primitives/std", + "polkadot-runtime-common/std", + "polkadot-primitives/std", ] diff --git a/runtime/picasso/Cargo.toml b/runtime/picasso/Cargo.toml index ec7f6494f8e..35c69c8cb43 100644 --- a/runtime/picasso/Cargo.toml +++ b/runtime/picasso/Cargo.toml @@ -54,22 +54,22 @@ hex-literal = { version = "0.3.1", optional = true } codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } # Parachain Utilities -cumulus-pallet-aura-ext = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-pallet-parachain-system = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-pallet-dmp-queue = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-pallet-xcm = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-pallet-xcmp-queue = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -collator-selection = { package = "pallet-collator-selection", git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -session-benchmarking = { package = "cumulus-pallet-session-benchmarking", git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -parachain-info = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false } -polkadot-parachain = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.8', default-features = false } -xcm = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.8', default-features = false } -xcm-builder = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.8', default-features = false } -xcm-executor = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.8', default-features = false } -pallet-xcm = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.8', default-features = false } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +collator-selection = { package = "pallet-collator-selection", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +session-benchmarking = { package = "cumulus-pallet-session-benchmarking", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8", default-features = false } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } +xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" } diff --git a/runtime/picasso/src/lib.rs b/runtime/picasso/src/lib.rs index bed3683bca0..b7df98915a0 100644 --- a/runtime/picasso/src/lib.rs +++ b/runtime/picasso/src/lib.rs @@ -19,7 +19,7 @@ pub use runtime_common as common; use runtime_common::{ impls::DealWithFees, AccountId, AccountIndex, AuraId, Balance, BlockNumber, Hash, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, - DAYS, EnsureRootOrHalfCouncil, CouncilInstance, PICA, MICRO_PICA, + DAYS, EnsureRootOrHalfCouncil, CouncilInstance, PICA, MILLI_PICA, }; use sp_std::prelude::*; #[cfg(feature = "std")] From 5d759eebc14ccf8b2edd2a40787303f3bccc1fd1 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 23 Aug 2021 18:21:18 +0100 Subject: [PATCH 3/3] =?UTF-8?q?50%=20of=20block=20reewards=20to=20collator?= =?UTF-8?q?,=2030%=20=F0=9F=94=A5,=2020%=20to=20treasury?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/common/src/impls.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index 2cc07ef92bd..c2e51432de2 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -18,8 +18,11 @@ use frame_support::traits::{Currency, Imbalance, OnUnbalanced}; use core::ops::Div; +use sp_std::ops::Mul; + pub type NegativeImbalance = as Currency<::AccountId>>::NegativeImbalance; + /// Logic for the author to get a portion of fees. pub struct ToStakingPot(sp_std::marker::PhantomData); impl OnUnbalanced> for ToStakingPot @@ -28,6 +31,7 @@ where ::AccountId: From, ::AccountId: Into, ::Event: From>, + ::Balance: From, { fn on_nonzero_unbalanced(amount: NegativeImbalance) { let numeric_amount = amount.peek(); @@ -44,25 +48,32 @@ where &staking_pot, slash_amount, ); + // this resolves to 20% of total block fees going to treasury. + let to_treasury = imbalance.peek().div(5u128.into()).mul(2u128.into()); + let (treasury_imbalance, _burn) = imbalance.split(to_treasury); // give treasury the remaining half - as OnUnbalanced<_>>::on_unbalanced(imbalance); + as OnUnbalanced<_>>::on_unbalanced(treasury_imbalance); } >::deposit_event(balances::Event::Deposit( staking_pot, slash_amount, )); - } } +/// OnUnbalanced handler for pallet-transaction-payment. pub struct DealWithFees(sp_std::marker::PhantomData); + impl OnUnbalanced> for DealWithFees where - R: balances::Config + collator_selection::Config + treasury::Config>, + R: balances::Config + + collator_selection::Config + + treasury::Config>, ::AccountId: From, ::AccountId: Into, ::Event: From>, + ::Balance: From, { fn on_unbalanceds(mut fees_then_tips: impl Iterator>) { if let Some(mut fees) = fees_then_tips.next() { @@ -253,7 +264,8 @@ mod tests { // Author gets 50% of tip and 50% of fee = 15 assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 15); - assert_eq!(Balances::free_balance(Treasury::account_id()), 15); + // Treasury gets 20% + assert_eq!(Balances::free_balance(Treasury::account_id()), 6); }); }