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

Feat/remove sudo #185

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ pub mod polimec_base {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
sudo: polimec_base_runtime::SudoConfig { key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")) },
parachain_staking: polimec_base_runtime::ParachainStakingConfig {
candidates: collators::initial_authorities()
.iter()
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/src/tests/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn user_can_vote_in_election_with_staked_balance() {
/// 6. Check that the remaining candidates have their funds slashed as they did not receive any votes
#[test]
fn election_phragmen_works() {
let candidates = (1..=32)
let candidates = (1..=30)
.into_iter()
.map(|i| get_account_id_from_seed::<sr25519::Public>(format!("CANDIDATE_{}", i).as_str()))
.collect::<Vec<AccountId>>();
Expand All @@ -394,7 +394,7 @@ fn election_phragmen_works() {
assert_ok!(Elections::submit_candidacy(RuntimeOrigin::signed((*candidate).clone()), i as u32));
}

assert_eq!(Elections::candidates().len(), 32);
assert_eq!(Elections::candidates().len(), 30);

for (i, voter) in vec![ALICE, BOB, CHARLIE, DAVE, EVE, FERDIE, ALICE_STASH, BOB_STASH].into_iter().enumerate() {
let voter = PolimecBase::account_id_of(voter);
Expand All @@ -418,10 +418,10 @@ fn election_phragmen_works() {
assert_same_members(Elections::runners_up().into_iter().map(|m| m.who).collect(), &expected_runners_up);

// Check that the candidates that were not elected have their funds slashed
for candidate in &candidates[15..32] {
for candidate in &candidates[15..30] {
assert_eq!(Balances::total_balance(candidate), ED);
}
assert_eq!(Balances::balance(&Treasury::account_id()), 17 * 1000 * PLMC + ED)
assert_eq!(Balances::balance(&Treasury::account_id()), 15 * 1000 * PLMC + ED)
});
}

Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ default:
build-base-srtool:
srtool build --root -p polimec-base-runtime --runtime-dir runtimes/base --build-opts="--features=on-chain-release-build"

build-rolimec-srtool:
srtool build --root -p polimec-base-runtime --runtime-dir runtimes/base --build-opts="--features=on-chain-release-build,fast-mode"

# Build the "Testnet" Runtime using srtool

# Test the runtimes features
Expand Down
15 changes: 6 additions & 9 deletions nodes/parachain/src/chain_spec/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use base_runtime::{
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, BalancesConfig, ElectionsConfig, MinCandidateStk, ParachainInfoConfig,
ParachainStakingConfig, PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SudoConfig, SystemConfig, PLMC,
ParachainStakingConfig, PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SystemConfig, PLMC,
};

/// The default XCM version to set in genesis config.
Expand Down Expand Up @@ -106,7 +106,6 @@ pub fn get_local_base_chain_spec() -> Result<ChainSpec, String> {
(get_account_id_from_seed::<sr25519::Public>("Ferdie"), 5 * MinCandidateStk::get()),
(BLOCKCHAIN_OPERATION_TREASURY.into(), 10_000_000 * PLMC),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
DEFAULT_PARA_ID,
)
},
Expand All @@ -119,6 +118,10 @@ pub fn get_local_base_chain_spec() -> Result<ChainSpec, String> {
))
}

/// This was used to generate the original genesis config for the Polimec parachain.
/// Since then, the genesis `RuntimeGenesisConfig` has been updated.
/// This function is kept for historical purposes.
#[allow(unused)]
pub fn get_polkadot_base_chain_spec() -> Result<ChainSpec, String> {
let properties = get_properties("PLMC", 10, 41);
let wasm = base_runtime::WASM_BINARY.ok_or("No WASM")?;
Expand Down Expand Up @@ -150,7 +153,7 @@ pub fn get_polkadot_base_chain_spec() -> Result<ChainSpec, String> {
(PLMC_COL_ACC_2.into(), 4 * MinCandidateStk::get()),
(PLMC_SUDO_ACC.into(), 4 * MinCandidateStk::get()),
],
PLMC_SUDO_ACC.into(),
// PLMC_SUDO_ACC.into(),
id.into(),
)
},
Expand All @@ -169,8 +172,6 @@ pub fn get_rococo_base_chain_spec() -> Result<ChainSpec, String> {

let id: u32 = 3344;

const PLMC_SUDO_ACC: [u8; 32] =
hex_literal::hex!["d4192a54c9caa4a38eeb3199232ed0d8568b22956cafb76c7d5a1afbf4e2dc38"];
const PLMC_COL_ACC_1: [u8; 32] =
hex_literal::hex!["6603f63a4091ba074b4384e64c6bba1dd96f6af49331ebda686b0a0f27dd961c"];
const PLMC_COL_ACC_2: [u8; 32] =
Expand All @@ -192,9 +193,7 @@ pub fn get_rococo_base_chain_spec() -> Result<ChainSpec, String> {
vec![
(PLMC_COL_ACC_1.into(), 4 * MinCandidateStk::get()),
(PLMC_COL_ACC_2.into(), 4 * MinCandidateStk::get()),
(PLMC_SUDO_ACC.into(), 4 * MinCandidateStk::get()),
],
PLMC_SUDO_ACC.into(),
id.into(),
)
},
Expand All @@ -213,7 +212,6 @@ fn base_testnet_genesis(
inflation_config: InflationInfo<Balance>,
initial_authorities: Vec<AccountId>,
endowed_accounts: Vec<(AccountId, Balance)>,
sudo_account: AccountId,
id: ParaId,
) -> RuntimeGenesisConfig {
const ENDOWMENT: Balance = 10_000_000 * PLMC;
Expand Down Expand Up @@ -249,7 +247,6 @@ fn base_testnet_genesis(
.collect::<Vec<_>>(),
},
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() },
sudo: SudoConfig { key: Some(sudo_account) },
transaction_payment: Default::default(),
oracle_providers_membership: polimec_base_runtime::OracleProvidersMembershipConfig {
members: BoundedVec::truncate_from(initial_authorities),
Expand Down
44 changes: 0 additions & 44 deletions nodes/parachain/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,50 +154,6 @@ pub fn get_chain_spec_dev() -> Result<ChainSpec, String> {
))
}

pub fn get_prod_chain_spec() -> Result<ChainSpec, String> {
let properties = get_properties("PLMC", 10, 41);
let wasm = polimec_parachain_runtime::WASM_BINARY.ok_or("No WASM")?;

// TODO: Update this after reserving a ParaId
let id: u32 = 4261;

const PLMC_SUDO_ACC: [u8; 32] =
hex_literal::hex!["d4192a54c9caa4a38eeb3199232ed0d8568b22956cafb76c7d5a1afbf4e2dc38"];
const PLMC_COL_ACC_1: [u8; 32] =
hex_literal::hex!["6603f63a4091ba074b4384e64c6bba1dd96f6af49331ebda686b0a0f27dd961c"];
const PLMC_COL_ACC_2: [u8; 32] =
hex_literal::hex!["ba48ab77461ef53f9ebfdc94a12c780b57354f986e31eb2504b9e3ed580fab51"];

Ok(ChainSpec::from_genesis(
"Polimec Kusama Testnet",
"polimec",
ChainType::Live,
move || {
testnet_genesis(
wasm,
vec![
(PLMC_COL_ACC_1.into(), None, 2 * MinCandidateStk::get()),
(PLMC_COL_ACC_2.into(), None, 2 * MinCandidateStk::get()),
],
polimec_inflation_config(),
vec![(PLMC_COL_ACC_1.into()), (PLMC_COL_ACC_2.into())],
vec![
(PLMC_COL_ACC_1.into(), 3 * MinCandidateStk::get()),
(PLMC_COL_ACC_2.into(), 3 * MinCandidateStk::get()),
],
PLMC_SUDO_ACC.into(),
id.into(),
)
},
vec![],
None,
Some("polimec"),
None,
Some(properties),
Extensions { relay_chain: "polkadot".into(), para_id: id },
))
}

#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
wasm_binary: &[u8],
Expand Down
7 changes: 3 additions & 4 deletions nodes/parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ fn runtime(id: &str) -> Runtime {

fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
log::info!("Load spec id: {}", id);
let generated_chain_spec = include_bytes!("../../../chain-specs/polimec-raw-chain-spec.json").to_vec();

Ok(match id {
// Base runtime
"base-rococo-local" => Box::new(chain_spec::base::get_local_base_chain_spec()?),
"base-polkadot" => Box::new(chain_spec::base::get_polkadot_base_chain_spec()?),
"base-rococo" => Box::new(chain_spec::base::get_rococo_base_chain_spec()?),
// Testnet runtime
"polimec-polkadot" => Box::new(chain_spec::base::ChainSpec::from_json_bytes(generated_chain_spec)?),
"polimec-rococo-local" => Box::new(chain_spec::testnet::get_chain_spec_dev()?),
#[cfg(feature = "std")]
"polimec-testing" => Box::new(chain_spec::testnet::get_chain_spec_testing()?),
"polimec-rococo-local" => Box::new(chain_spec::testnet::get_chain_spec_dev()?),
"polimec-polkadot" => Box::new(chain_spec::testnet::get_prod_chain_spec()?),
// -- Fallback (generic chainspec)
"" => {
log::warn!("No ChainSpec.id specified, so using default one, based on polimec-rococo-local");
Expand Down
44 changes: 9 additions & 35 deletions runtimes/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,15 @@ pub type Migrations = migrations::Unreleased;
pub mod migrations {
// Not warn for unused imports in this module.
#![allow(unused_imports)]
use frame_support::migrations::RemovePallet;

parameter_types! {
pub const Sudo: &'static str = "Sudo";
}

use super::*;
/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
custom_migrations::InitializePallet<OracleProvidersMembership>,
custom_migrations::InitializePallet<Democracy>,
custom_migrations::InitializePallet<Council>,
custom_migrations::InitializePallet<TechnicalCommittee>,
custom_migrations::InitializePallet<Elections>,
custom_migrations::InitializePallet<Preimage>,
custom_migrations::InitializePallet<Scheduler>,
custom_migrations::InitializePallet<ForeignAssets>,
);
pub type Unreleased = (RemovePallet<Sudo, ParityDbWeight>,);
}

/// Executive: handles dispatch to the various modules.
Expand Down Expand Up @@ -198,7 +195,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polimec-mainnet"),
impl_name: create_runtime_str!("polimec-mainnet"),
authoring_version: 1,
spec_version: 0_005_001,
spec_version: 0_005_005,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand All @@ -219,23 +216,7 @@ parameter_types! {
pub struct BaseCallFilter;
impl Contains<RuntimeCall> for BaseCallFilter {
fn contains(c: &RuntimeCall) -> bool {
use pallet_balances::Call::*;
use pallet_vesting::Call::*;

match c {
// Transferability lock.
RuntimeCall::Balances(inner_call) => match inner_call {
transfer { .. } => false,
transfer_all { .. } => false,
transfer_keep_alive { .. } => false,
transfer_allow_death { .. } => false,
_ => true,
},
RuntimeCall::Vesting(inner_call) => match inner_call {
// Vested transfes are not allowed.
vested_transfer { .. } => false,
_ => true,
},
_ => true,
}
}
Expand Down Expand Up @@ -463,12 +444,6 @@ impl pallet_aura::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
}

impl pallet_sudo::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

pub struct ToTreasury;

impl tokens::imbalance::OnUnbalanced<CreditOf<Runtime>> for ToTreasury {
Expand Down Expand Up @@ -867,7 +842,7 @@ construct_runtime!(
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,
Sudo: pallet_sudo = 4,
// Index 4 used to be Sudo
Utility: pallet_utility::{Pallet, Call, Event} = 5,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 6,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 7,
Expand Down Expand Up @@ -915,7 +890,6 @@ mod benches {
// System support stuff.
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_sudo, Sudo]
[pallet_utility, Utility]
[pallet_multisig, Multisig]
[pallet_proxy, Proxy]
Expand Down