Skip to content

Commit

Permalink
Remove sudo from testnet genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Apr 12, 2024
1 parent cc244da commit 44d0fd4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
5 changes: 0 additions & 5 deletions node/src/chain_spec/kreivo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub fn kreivo_rococo_chain_spec_local() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
KREIVO_PARA_ID.into(),
))
.build()
Expand Down Expand Up @@ -114,7 +113,6 @@ pub fn kreivo_kusama_chain_spec_local() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
KREIVO_PARA_ID.into(),
))
.build()
Expand Down Expand Up @@ -166,7 +164,6 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
KREIVO_PARA_ID.into(),
))
.with_protocol_id(DEFAULT_PROTOCOL_ID)
Expand All @@ -181,7 +178,6 @@ pub fn kreivo_kusama_chain_spec() -> ChainSpec {
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root: AccountId,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
Expand Down Expand Up @@ -210,6 +206,5 @@ fn testnet_genesis(
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root) }
})
}
18 changes: 17 additions & 1 deletion pallets/communities/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use frame_support::{
pallet_prelude::*,
traits::{membership::GenericRank, EnsureOriginWithArg, OriginTrait},
};
use sp_runtime::Permill;
use sp_runtime::{traits::TryConvert, Permill};

pub struct EnsureCommunity<T>(PhantomData<T>);

Expand Down Expand Up @@ -117,6 +117,22 @@ pub enum DecisionMethod<AssetId> {
Rank,
}

#[cfg(feature = "xcm")]
impl<T> TryConvert<T::RuntimeOrigin, xcm::v3::MultiLocation> for RawOrigin<T>
where
T: Config,
T::RuntimeOrigin: Into<Result<RawOrigin<T>, T::RuntimeOrigin>>,
xcm::v3::Junction: TryFrom<RawOrigin<T>>,
{
fn try_convert(o: T::RuntimeOrigin) -> Result<xcm::v3::MultiLocation, T::RuntimeOrigin> {
let Ok(community @ RawOrigin { .. }) = o.clone().into() else {
return Err(o);
};
let j = xcm::v3::Junction::try_from(community).map_err(|_| o)?;
Ok(j.into())
}
}

#[cfg(feature = "xcm")]
impl<T> TryFrom<RawOrigin<T>> for xcm::v3::Junction
where
Expand Down
15 changes: 7 additions & 8 deletions runtime/kreivo/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use virto_common::AsFungibleAssetLocation;

use super::{
AccountId, AllPalletsWithSystem, Assets, Balance, Balances, FungibleAssetLocation, KreivoAssetsInstance,
ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury,
WeightToFee, XcmpQueue,
};
use virto_common::AsFungibleAssetLocation;

use crate::constants::locations::STATEMINE_PARA_ID;
use frame_support::{
Expand All @@ -24,8 +23,8 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, ConvertedConcreteId,
CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, LocalMint, MintLocation, NativeAsset,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
SignedAccountId32AsNative, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, UsingComponents,
WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::traits::JustTry;
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -230,8 +229,8 @@ impl xcm_executor::Config for XcmConfig {
type Aliasers = Nothing;
}

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
/// Only communities are allowed to dispatch xcm messages
pub type ConvertCommunityOrigin = pallet_communities::Origin<Runtime>;

/// The means for routing XCM messages which are not for local execution into
/// the right message queues.
Expand All @@ -244,9 +243,9 @@ pub type XcmRouter = (

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ConvertCommunityOrigin>;
type XcmExecuteFilter = Nothing;
// ^ Disable dispatchable execute on the XCM pallet.
type XcmExecutor = XcmExecutor<XcmConfig>;
Expand Down

0 comments on commit 44d0fd4

Please sign in to comment.