Skip to content

Commit

Permalink
Remove sudo from prod (#187)
Browse files Browse the repository at this point in the history
* Remove sudo from prod

* Add migration and update version

---------

Co-authored-by: Dmitry <[email protected]>
  • Loading branch information
vovac12 and N1ghtStorm authored Dec 1, 2023
1 parent 7c7e015 commit e0cb832
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sora2-parachain-node"
version = "2.1.0"
version = "2.2.0"
authors = ["Anonymous"]
description = "Sora2 Parachain node. Is used as a gateway to SORA2 from any relaychain ecosysytem"
license = "Unlicense"
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ fn testnet_genesis(
polkadot_xcm: sora2_parachain_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
#[cfg(feature = "rococo")]
sudo: sora2_parachain_runtime::SudoConfig { key: Some(root_key) },
technical_committee: TechnicalCommitteeConfig {
members: technical_committee_accounts,
Expand Down
Binary file modified parachain-gen/src/bytes/parachain_metadata.scale
Binary file not shown.
6 changes: 3 additions & 3 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sora2-parachain-runtime"
version = "2.1.0"
version = "2.2.0"
authors = ["Anonymous"]
description = "sora2 parachain runtime"
license = "Unlicense"
Expand Down Expand Up @@ -67,7 +67,7 @@ pallet-beefy = { git = "https://github.com/paritytech/substrate.git", default-fe
pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-mmr = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-session = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-sudo = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-sudo = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38", optional = true }
pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.38" }
Expand Down Expand Up @@ -224,7 +224,7 @@ try-runtime = ["frame-executive/try-runtime", "frame-try-runtime"]

parachain-gen = []

rococo = []
rococo = ["pallet-sudo"]

kusama = []

Expand Down
6 changes: 4 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("sora_ksm"),
impl_name: create_runtime_str!("sora_ksm"),
authoring_version: 1,
spec_version: 9,
spec_version: 10,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 9,
transaction_version: 10,
state_version: 1,
};

Expand Down Expand Up @@ -497,6 +497,7 @@ impl pallet_beefy_mmr::Config for Runtime {
type BeefyDataProvider = LeafProvider;
}

#[cfg(feature = "rococo")]
impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -1058,6 +1059,7 @@ construct_runtime!(
// ORML
XTokens: orml_xtokens::{Pallet, Storage, Event<T>} = 41,

#[cfg(feature = "rococo")]
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 100,

XCMApp: xcm_app::{Pallet, Call, Storage, Event<T>} = 101,
Expand Down
50 changes: 16 additions & 34 deletions runtime/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,30 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#[cfg(feature = "kusama")]
use crate::*;
#[cfg(feature = "kusama")]
use frame_support::{
traits::{Currency, ExistenceRequirement, LockableCurrency, OnRuntimeUpgrade, WithdrawReasons},
traits::OnRuntimeUpgrade,
weights::Weight,
};
use sp_std::collections::btree_set::BTreeSet;

pub type Migrations = (RemoveMintedAccountsBalance,);
#[cfg(feature = "kusama")]
pub type Migrations = (RemoveSudoKey,);

pub struct RemoveMintedAccountsBalance;
#[cfg(any(feature = "rococo", feature = "polkadot"))]
pub type Migrations = ();

impl OnRuntimeUpgrade for RemoveMintedAccountsBalance {
#[cfg(feature = "kusama")]
pub struct RemoveSudoKey;

#[cfg(feature = "kusama")]
impl OnRuntimeUpgrade for RemoveSudoKey {
fn on_runtime_upgrade() -> Weight {
let mut accounts_to_skip =
pallet_collator_selection::Invulnerables::<Runtime>::get().to_vec();
if let Some(sudo_key) = Sudo::key() {
// Fees was updated, so we need to update sudo account balance
// to be able to resolve possible issues after runtime upgrade.
let _ = Balances::deposit_creating(&sudo_key, UNIT * 1000);
accounts_to_skip.push(sudo_key);
}
let accounts_to_skip = BTreeSet::from_iter(accounts_to_skip.into_iter());
for (account, info) in frame_system::Account::<Runtime>::iter() {
if accounts_to_skip.contains(&account) {
continue
}
let locks = Balances::locks(&account);
for lock in locks {
Balances::remove_lock(lock.id, &account);
}
if let Err(err) = Balances::withdraw(
&account,
info.data.free - EXISTENTIAL_DEPOSIT,
WithdrawReasons::all(),
ExistenceRequirement::KeepAlive,
) {
frame_support::log::error!(
"Failed to withdraw funds from account {:?}: {:?}",
account,
err
);
}
if let Some(key) = frame_support::storage::migration::take_storage_value::<AccountId>(b"Sudo", b"Key", &[]) {
frame_support::log::error!("Sudo key removed: {:?}", key);
} else {
frame_support::log::error!("Sudo key not found in storage");
}
RuntimeBlockWeights::get().max_block
}
Expand Down

0 comments on commit e0cb832

Please sign in to comment.