Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mainnet-runtime: add full sudo replacment #1029

Merged
merged 11 commits into from
Aug 16, 2024
2,331 changes: 1,161 additions & 1,170 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"docs",
"node",
"pallets/elections",
"pallets/governance",
"pallets/members",
"pallets/networks",
"pallets/shards",
Expand Down Expand Up @@ -56,10 +57,10 @@ scale-decode = { version = "0.13.1", default-features = false, features = [ "der
scale-info = { version = "2.11.3", default-features = false, features = [ "derive" ] }

# main substrate sdk
polkadot-sdk = { git = "https://github.com/Analog-Labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
polkadot-sdk = { git = "https://github.com/Analog-Labs/polkadot-sdk", tag = "v1.14.0-anlog0", default-features = false }

# specialized wasm builder
substrate-wasm-builder = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", features = [ "metadata-hash" ] }
substrate-wasm-builder = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.14.0-anlog0", features = [ "metadata-hash" ] }

# chain connectors
rosetta-client = { git = "https://github.com/analog-labs/chain-connectors" }
Expand All @@ -71,6 +72,7 @@ time-primitives = { path = "primitives", default-features = false }

# pallets in workspace (nostd by default)
pallet-elections = { path = "pallets/elections", default-features = false }
pallet-governance = { path = "pallets/governance", default-features = false }
pallet-members = { path = "pallets/members", default-features = false }
pallet-networks = { path = "pallets/networks", default-features = false }
pallet-shards = { path = "pallets/shards", default-features = false }
Expand Down
Binary file modified config/subxt/mainnet.default.scale
Binary file not shown.
Binary file modified config/subxt/mainnet.development.scale
Binary file not shown.
Binary file modified config/subxt/testnet.default.scale
Binary file not shown.
Binary file modified config/subxt/testnet.development.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ polkadot-sdk = { workspace = true, features = [
] }

# node's rpc dependencies
jsonrpsee = { version = "0.22.1", features = [ "server" ] }
jsonrpsee = { version = "0.23.2", features = [ "server" ] }

# node's local dependencies
time-primitives.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ impl GenesisKeysConfig {

let target_patch = match runtime {
RuntimeTarget::Mainnet => serde_json::json!({
"council": {
"technicalCommittee": {
"members": Some(self.sudo.clone()).iter().chain(self.councils.iter()).collect::<Vec<_>>(),
},
}),
Expand Down
38 changes: 11 additions & 27 deletions pallets/elections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,19 @@ log.workspace = true
scale-codec.workspace = true
scale-info.workspace = true
serde.workspace = true
simple-mermaid.workspace = true

#polkadot-sdk = { workspace = true, features = [ "frame-support", "frame-system", "sp-runtime", "sp-std" ] }

frame-support = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
frame-system = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
sp-runtime = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
sp-std = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }

frame-benchmarking = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false, optional = true }
polkadot-sdk = { workspace = true, features = [ "frame-support", "frame-system", "sp-runtime", "sp-std" ] }

time-primitives = { path = "../../primitives", default-features = false }
simple-mermaid.workspace = true
time-primitives.workspace = true

[dev-dependencies]
env_logger.workspace = true
lazy_static = "1.4.0"

#polkadot-sdk = { workspace = true, features = [ "pallet-balances", "sp-core", "sp-io" ] }
polkadot-sdk = { workspace = true, features = [ "pallet-balances", "sp-core", "sp-io" ] }

pallet-balances = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
sp-core = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }
sp-io = { git = "https://github.com/analog-labs/polkadot-sdk", tag = "v1.13.0-patched2", default-features = false }

pallet-shards = { path = "../shards", default-features = false }
pallet-shards.workspace = true

[features]
default = [ "std" ]
Expand All @@ -51,20 +40,15 @@ std = [
"scale-codec/std",
"scale-info/std",
"serde/std",
#"polkadot-sdk/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"frame-benchmarking?/std",

"polkadot-sdk/std",

"time-primitives/std",
"pallet-balances/std"
]
runtime-benchmarks = [
#"polkadot-sdk/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"polkadot-sdk/runtime-benchmarks",
"polkadot-sdk/frame-benchmarking",
]
try-runtime = [
#"polkadot-sdk/try-runtime"
"frame-support/try-runtime"
"polkadot-sdk/try-runtime"
]
4 changes: 2 additions & 2 deletions pallets/elections/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;
use crate::Pallet;

//use polkadot_sdk::*;
use polkadot_sdk::frame_benchmarking::benchmarks;
use polkadot_sdk::frame_system;

use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;

benchmarks! {
Expand Down
20 changes: 11 additions & 9 deletions pallets/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,22 @@

pub use pallet::*;

//use polkadot_sdk::{frame_support, frame_system, sp_std};

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

#[frame_support::pallet]
#[polkadot_sdk::frame_support::pallet]
pub mod pallet {
use polkadot_sdk::{frame_support, frame_system, sp_std};

use frame_support::pallet_prelude::*;
use frame_support::traits::BuildGenesisConfig;
use frame_system::pallet_prelude::*;
use sp_std::marker::PhantomData;
use sp_std::vec;
use sp_std::vec::Vec;

use time_primitives::{
AccountId, ElectionsInterface, MemberEvents, MemberStorage, NetworkId, ShardsInterface,
};
Expand All @@ -73,11 +72,14 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config<AccountId = AccountId> {
pub trait Config: polkadot_sdk::frame_system::Config<AccountId = AccountId> {
/// The runtime event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as polkadot_sdk::frame_system::Config>::RuntimeEvent>;
/// The weight information for the pallet's extrinsics.
type WeightInfo: WeightInfo;
/// Ensured origin for calls changing config or electables
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// The interface for shard-related operations.
type Shards: ShardsInterface + MemberEvents;
/// The storage interface for member-related data.
Expand Down Expand Up @@ -172,7 +174,7 @@ pub mod pallet {
shard_size: u16,
shard_threshold: u16,
) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
ensure!(shard_size >= shard_threshold, Error::<T>::ThresholdLargerThanSize);
ShardSize::<T>::put(shard_size);
ShardThreshold::<T>::put(shard_threshold);
Expand All @@ -191,7 +193,7 @@ pub mod pallet {
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_shard_config())]
pub fn set_electable(origin: OriginFor<T>, electable: Vec<AccountId>) -> DispatchResult {
ensure_root(origin)?;
T::AdminOrigin::ensure_origin(origin)?;
let _ = Electable::<T>::clear(u32::MAX, None);
for account in electable {
Electable::<T>::insert(account, ());
Expand Down
4 changes: 3 additions & 1 deletion pallets/elections/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{self as pallet_elections};

//use polkadot_sdk::*;
use polkadot_sdk::*;

use frame_support::derive_impl;
use sp_core::{ConstU128, ConstU64};
Expand Down Expand Up @@ -77,13 +77,15 @@ impl pallet_balances::Config for Test {

impl pallet_elections::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
type WeightInfo = ();
type Shards = Shards;
type Members = MockMembers;
}

impl pallet_shards::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
type WeightInfo = ();
type TaskScheduler = MockTaskScheduler;
type Members = MockMembers;
Expand Down
3 changes: 2 additions & 1 deletion pallets/elections/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{mock::*, Error, Event, ShardSize, ShardThreshold, Unassigned};

//use polkadot_sdk::*;
use polkadot_sdk::*;

use frame_support::{assert_noop, assert_ok};
use frame_system::RawOrigin;

use time_primitives::{ElectionsInterface, MemberEvents, NetworkId};

const ETHEREUM: NetworkId = 0;
Expand Down
43 changes: 43 additions & 0 deletions pallets/governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "pallet-governance"
description = "Analog mainnet governance pallet."
publish = false

version.workspace = true
license.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
edition.workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
scale-codec.workspace = true
scale-info.workspace = true

polkadot-sdk = { workspace = true, features = [ "frame-support", "frame-system", "pallet-balances", "pallet-staking" ] }

time-primitives.workspace = true

[dev-dependencies]
polkadot-sdk = { workspace = true, features = [ "frame-election-provider-support", "sp-core", "sp-io", "sp-runtime", "sp-staking", "pallet-timestamp" ] }

[features]
default = ["std"]
std = [
"scale-codec/std",
"scale-info/std",

"polkadot-sdk/std",

"time-primitives/std"
]
runtime-benchmarks = [
"polkadot-sdk/runtime-benchmarks",
"polkadot-sdk/frame-benchmarking",
]
try-runtime = [
"polkadot-sdk/try-runtime",
]
100 changes: 100 additions & 0 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#![cfg_attr(not(feature = "std"), no_std)]
//! # Analog Governance Pallet
//!
//! This is custom pallet to be used for the ever extending mainnet governance.
//!
//! Currently only wraps a few important root call to lower the required privilege level
//! to a custom origin.
//!
//! See [`Calls`] for a list of wrapped extrinsics.

pub use pallet::*;

#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;

#[polkadot_sdk::frame_support::pallet]
pub mod pallet {
// Import various useful types required by all FRAME pallets.
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use polkadot_sdk::{frame_support, frame_system};

// Additional custom imports
use frame_system::{RawOrigin, WeightInfo as SystemWeights};

use pallet_staking::{ConfigOp, WeightInfo as StakingWeights};
use polkadot_sdk::{pallet_balances, pallet_staking, sp_runtime};
use sp_runtime::{Perbill, Percent};

// Useful coupling shorthands
type CurrencyBalanceOf<T> = <T as pallet_staking::Config>::CurrencyBalance;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config:
polkadot_sdk::frame_system::Config + pallet_balances::Config + pallet_staking::Config
{
/// Allowed origin for system calls
type SystemAdmin: EnsureOrigin<Self::RuntimeOrigin>;
/// Allowed origin for staking calls
type StakingAdmin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::call]
impl<T: Config> Pallet<T> {
// Wrapper around system pallet calls
#[pallet::call_index(0)]
#[pallet::weight(<T as frame_system::Config>::SystemWeightInfo::authorize_upgrade())]
pub fn authorize_upgrade(origin: OriginFor<T>, code_hash: T::Hash) -> DispatchResult {
T::SystemAdmin::ensure_origin(origin)?;
frame_system::Pallet::<T>::authorize_upgrade(RawOrigin::Root.into(), code_hash)
}

// Wrapper around staking pallet calls
#[pallet::call_index(1)]
#[pallet::weight(<T as pallet_staking::Config>::WeightInfo::set_validator_count())]
pub fn set_validator_count(
origin: OriginFor<T>,
#[pallet::compact] new: u32,
) -> DispatchResult {
T::StakingAdmin::ensure_origin(origin)?;
pallet_staking::Pallet::<T>::set_validator_count(RawOrigin::Root.into(), new)
}

#[allow(clippy::too_many_arguments)]
#[pallet::call_index(2)]
#[pallet::weight(
<T as pallet_staking::Config>::WeightInfo::set_staking_configs_all_set()
.max(<T as pallet_staking::Config>::WeightInfo::set_staking_configs_all_remove())
)]
pub fn set_staking_configs(
origin: OriginFor<T>,
min_nominator_bond: ConfigOp<CurrencyBalanceOf<T>>,
min_validator_bond: ConfigOp<CurrencyBalanceOf<T>>,
max_nominator_count: ConfigOp<u32>,
max_validator_count: ConfigOp<u32>,
chill_threshold: ConfigOp<Percent>,
min_commission: ConfigOp<Perbill>,
max_staked_rewards: ConfigOp<Percent>,
) -> DispatchResult {
T::StakingAdmin::ensure_origin(origin)?;
pallet_staking::Pallet::<T>::set_staking_configs(
RawOrigin::Root.into(),
min_nominator_bond,
min_validator_bond,
max_nominator_count,
max_validator_count,
chill_threshold,
min_commission,
max_staked_rewards,
)
}
}
}
Loading
Loading