Skip to content

Commit

Permalink
Governance (Snowfork#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes authored Apr 28, 2021
1 parent 36f9f55 commit 62b4907
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 45 deletions.
9 changes: 9 additions & 0 deletions parachain/Cargo.lock

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

20 changes: 17 additions & 3 deletions parachain/pallets/incentivized-channel/src/inbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use frame_support::{
decl_error, decl_event, decl_module, decl_storage,
dispatch::DispatchResult,
traits::{Currency, Get, ExistenceRequirement::KeepAlive, WithdrawReasons, Imbalance},
traits::{
Currency, Get, ExistenceRequirement::KeepAlive,
WithdrawReasons, Imbalance,
EnsureOrigin,
},
storage::StorageValue,
log,
weights::Weight,
Expand Down Expand Up @@ -38,7 +42,6 @@ impl WeightInfo for () {
fn submit() -> Weight { 0 }
}


pub trait Config: system::Config {
type Event: From<Event> + Into<<Self as system::Config>::Event>;

Expand All @@ -58,6 +61,9 @@ pub trait Config: system::Config {

type FeeConverter: Convert<U256, BalanceOf<Self>>;

/// The origin which may update reward related params
type UpdateOrigin: EnsureOrigin<Self::Origin>;

/// Weight information for extrinsics in this pallet
type WeightInfo: WeightInfo;
}
Expand All @@ -73,7 +79,6 @@ decl_storage! {

decl_event! {
pub enum Event {

}
}

Expand Down Expand Up @@ -127,6 +132,15 @@ decl_module! {

Ok(())
}

// Weight = 0 is fine here (a single storage write). Also can only be called by governance.
#[weight = 0]
pub fn set_reward_fraction(origin, fraction: Perbill) -> DispatchResult {
T::UpdateOrigin::ensure_origin(origin)?;
RewardFraction::set(fraction);
Ok(())
}

}
}

Expand Down
14 changes: 14 additions & 0 deletions parachain/pallets/incentivized-channel/src/inbound/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl incentivized_inbound_channel::Config for Test {
type SourceAccount = SourceAccount;
type TreasuryAccount = TreasuryAccount;
type FeeConverter = FeeConverter<Self>;
type UpdateOrigin = frame_system::EnsureRoot<Self::AccountId>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -288,5 +289,18 @@ fn test_handle_fee() {
assert_eq!(Balances::free_balance(&TreasuryAccount::get()), 2000000001);
assert_eq!(Balances::free_balance(&relayer), 8000000001);
});
}

#[test]
fn test_set_reward_fraction_not_authorized() {
new_tester(SOURCE_CHANNEL_ADDR.into()).execute_with(|| {
let bob: AccountId = Keyring::Bob.into();
assert_noop!(
IncentivizedInboundChannel::set_reward_fraction(
Origin::signed(bob),
Perbill::from_percent(60)
),
DispatchError::BadOrigin
);
});
}
7 changes: 7 additions & 0 deletions parachain/runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ frame-executive = { git = "https://github.com/paritytech/substrate.git", branch
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
Expand Down Expand Up @@ -75,12 +78,15 @@ std = [
"frame-support/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"pallet-sudo/std",
"pallet-balances/std",
"pallet-randomness-collective-flip/std",
"pallet-timestamp/std",
"pallet-utility/std",
"pallet-transaction-payment/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-collective/std",
"pallet-membership/std",
"sp-api/std",
"sp-block-builder/std",
"sp-core/std",
Expand Down Expand Up @@ -121,6 +127,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
# Artemis pallets & support
"artemis-core/runtime-benchmarks",
Expand Down
82 changes: 68 additions & 14 deletions parachain/runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use sp_core::{U256, crypto::KeyTypeId, OpaqueMetadata};
use sp_core::{
U256, crypto::KeyTypeId, OpaqueMetadata,
u32_trait::{_1, _2},
};
use sp_runtime::{
ApplyExtrinsicResult, generic, create_runtime_str, impl_opaque_keys, MultiSignature,
transaction_validity::{TransactionValidity, TransactionSource},
Expand Down Expand Up @@ -39,7 +42,7 @@ pub use frame_support::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
},
};
use frame_system::EnsureRoot;
use frame_system::{EnsureRoot, EnsureOneOf};
use pallet_transaction_payment::FeeDetails;
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;

Expand Down Expand Up @@ -355,6 +358,50 @@ impl cumulus_pallet_xcm_handler::Config for Runtime {
type AccountIdConverter = LocationConverter;
}


// Governance

impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}

type EnsureRootOrHalfLocalCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, LocalCouncilInstance>,
>;

parameter_types! {
pub const LocalCouncilMotionDuration: BlockNumber = 7 * DAYS;
pub const LocalCouncilMaxProposals: u32 = 100;
pub const LocalCouncilMaxMembers: u32 = 4;
}

type LocalCouncilInstance = pallet_collective::Instance1;
impl pallet_collective::Config<LocalCouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = LocalCouncilMotionDuration;
type MaxProposals = LocalCouncilMaxProposals;
type MaxMembers = LocalCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}

type LocalCouncilMembershipInstance = pallet_membership::Instance1;
impl pallet_membership::Config<LocalCouncilMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrHalfLocalCouncil;
type RemoveOrigin = EnsureRootOrHalfLocalCouncil;
type SwapOrigin = EnsureRootOrHalfLocalCouncil;
type ResetOrigin = EnsureRootOrHalfLocalCouncil;
type PrimeOrigin = EnsureRootOrHalfLocalCouncil;
type MembershipInitialized = LocalCouncil;
type MembershipChanged = LocalCouncil;
}

// Our pallets

// Module accounts
Expand Down Expand Up @@ -426,6 +473,7 @@ impl incentivized_channel_inbound::Config for Runtime {
type SourceAccount = SourceAccount;
type TreasuryAccount = TreasuryAccount;
type FeeConverter = FeeConverter;
type UpdateOrigin = EnsureRootOrHalfLocalCouncil;
type WeightInfo = ();
}

Expand Down Expand Up @@ -540,18 +588,24 @@ construct_runtime!(
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 5,
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 6,

BasicInboundChannel: basic_channel_inbound::{Pallet, Call, Config, Storage, Event} = 7,
BasicOutboundChannel: basic_channel_outbound::{Pallet, Storage, Event} = 8,
IncentivizedInboundChannel: incentivized_channel_inbound::{Pallet, Call, Config, Storage, Event} = 9,
IncentivizedOutboundChannel: incentivized_channel_outbound::{Pallet, Config<T>, Storage, Event} = 10,
Dispatch: dispatch::{Pallet, Call, Storage, Event<T>, Origin} = 11,
Commitments: commitments::{Pallet, Call, Config<T>, Storage, Event} = 12,
VerifierLightclient: verifier_lightclient::{Pallet, Call, Storage, Event, Config} = 13,
Assets: assets::{Pallet, Call, Config<T>, Storage, Event<T>} = 14,

LocalXcmHandler: cumulus_pallet_xcm_handler::{Pallet, Event<T>, Origin} = 15,
Transfer: artemis_transfer::{Pallet, Call, Event<T>} = 16,
Utility: pallet_utility::{Pallet, Call, Event, Storage} = 17,
LocalCouncil: pallet_collective::<Instance1>::{Pallet, Call, Storage, Origin<T>, Event<T>, Config<T>} = 7,
LocalCouncilMembership: pallet_membership::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 8,

BasicInboundChannel: basic_channel_inbound::{Pallet, Call, Config, Storage, Event} = 9,
BasicOutboundChannel: basic_channel_outbound::{Pallet, Storage, Event} = 10,
IncentivizedInboundChannel: incentivized_channel_inbound::{Pallet, Call, Config, Storage, Event} = 11,
IncentivizedOutboundChannel: incentivized_channel_outbound::{Pallet, Config<T>, Storage, Event} = 12,
Dispatch: dispatch::{Pallet, Call, Storage, Event<T>, Origin} = 13,
Commitments: commitments::{Pallet, Call, Config<T>, Storage, Event} = 14,
VerifierLightclient: verifier_lightclient::{Pallet, Call, Storage, Event, Config} = 15,
Assets: assets::{Pallet, Call, Config<T>, Storage, Event<T>} = 16,

LocalXcmHandler: cumulus_pallet_xcm_handler::{Pallet, Event<T>, Origin} = 17,
Transfer: artemis_transfer::{Pallet, Call, Event<T>} = 18,
Utility: pallet_utility::{Pallet, Call, Event, Storage} = 19,

// For dev only, will be removed in production
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20,

DOT: dot_app::{Pallet, Call, Config<T>, Storage, Event<T>} = 64,
ETH: eth_app::{Pallet, Call, Config, Storage, Event<T>} = 65,
Expand Down
7 changes: 7 additions & 0 deletions parachain/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ frame-executive = { git = "https://github.com/paritytech/substrate.git", branch
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1", default-features = false }
Expand Down Expand Up @@ -75,12 +78,15 @@ std = [
"frame-support/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"pallet-sudo/std",
"pallet-balances/std",
"pallet-randomness-collective-flip/std",
"pallet-timestamp/std",
"pallet-utility/std",
"pallet-transaction-payment/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-collective/std",
"pallet-membership/std",
"sp-api/std",
"sp-block-builder/std",
"sp-core/std",
Expand Down Expand Up @@ -121,6 +127,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
# Artemis pallets & support
"artemis-core/runtime-benchmarks",
Expand Down
Loading

0 comments on commit 62b4907

Please sign in to comment.