Skip to content

Commit

Permalink
add sudo and dev pallets under alphanet feature (#195)
Browse files Browse the repository at this point in the history
* add sudo

* fix tests

* fmt
  • Loading branch information
N1ghtStorm committed Feb 6, 2024
1 parent 04f2583 commit f9c3a82
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 28 deletions.
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test-polkadot:
test-rococo:
cargo test --release --features rococo

test-alpha:
cargo test --release --features alphanet

test-all:
cargo test --release -p sora2-parachain-runtime --features rococo
cargo test --release -p sora2-parachain-runtime --features kusama
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 @@ -667,7 +667,7 @@ fn testnet_genesis(
polkadot_xcm: sora2_parachain_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
#[cfg(any(feature = "rococo", feature = "polkadot"))]
#[cfg(any(feature = "rococo", feature = "polkadot", feature = "alphanet"))]
sudo: sora2_parachain_runtime::SudoConfig { key: Some(root_key) },
technical_committee: TechnicalCommitteeConfig {
members: technical_committee_accounts,
Expand Down
2 changes: 1 addition & 1 deletion pallets/xcm-app-sudo-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
WrongXCMVersion
WrongXCMVersion,
}

#[pallet::hooks]
Expand Down
Binary file modified parachain-gen/src/bytes/parachain_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ kusama = []

polkadot = []

alphanet = []
alphanet = ["pallet-sudo"]
48 changes: 24 additions & 24 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use frame_system::{
EnsureRoot,
};
pub use sp_beefy::crypto::AuthorityId as BeefyId;
#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
use sp_beefy::mmr::MmrLeafVersion;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_mmr_primitives as mmr;
Expand Down Expand Up @@ -452,7 +452,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
impl parachain_info::Config for Runtime {}

/// Configure Merkle Mountain Range pallet.
#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr";
type Hashing = Keccak256;
Expand All @@ -465,13 +465,13 @@ impl pallet_mmr::Config for Runtime {
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
type OnNewValidatorSet = BeefyMmr;
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
type OnNewValidatorSet = ();
}

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
parameter_types! {
/// Version of the produced MMR leaf.
///
Expand All @@ -489,15 +489,15 @@ parameter_types! {
pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0);
}

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
impl pallet_beefy_mmr::Config for Runtime {
type LeafVersion = LeafVersion;
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
type LeafExtra = bridge_types::types::LeafExtraData<H256, H256>;
type BeefyDataProvider = LeafProvider;
}

#[cfg(any(feature = "rococo", feature = "polkadot"))]
#[cfg(any(feature = "rococo", feature = "polkadot", feature = "alphanet"))]
impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -625,7 +625,7 @@ impl xcm_app::XcmSender<Runtime> for XCMSenderWrapper {
}
}

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

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

XCMApp: xcm_app::{Pallet, Call, Storage, Event<T>} = 101,
Expand All @@ -1071,10 +1071,10 @@ construct_runtime!(
MultisigVerifier: multisig_verifier::{Pallet, Storage, Event<T>, Call} = 109,

// Beefy pallets should be placed after channels
#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
Mmr: pallet_mmr = 4,
Beefy: pallet_beefy = 5,
#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
BeefyMmr: pallet_beefy_mmr = 6,

TechnicalCommittee: pallet_collective::<Instance1>::{Pallet, Call, Storage, Origin<T>, Event<T>, Config<T>} = 110,
Expand All @@ -1085,7 +1085,7 @@ construct_runtime!(
ElectionsPhragmen: pallet_elections_phragmen::{Pallet, Call, Storage, Event<T>, Config<T>} = 115,
Utility: pallet_utility::{Pallet, Call, Event} = 116,

#[cfg(any(feature = "rococo"))]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
XCMAppSudoWrapper: xcm_app_sudo_wrapper::{Pallet, Call, Storage, Event<T>} = 150,
}
);
Expand Down Expand Up @@ -1190,39 +1190,39 @@ impl_runtime_apis! {

impl sp_beefy::BeefyApi<Block> for Runtime {
fn validator_set() -> Option<sp_beefy::ValidatorSet<BeefyId>> {
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return None;

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
Beefy::validator_set()
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn mmr_root() -> Result<Hash, mmr::Error> {
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return Err(mmr::Error::PalletNotIncluded);

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
Ok(Mmr::mmr_root())
}

fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return Err(mmr::Error::PalletNotIncluded);

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
Ok(Mmr::mmr_leaves())
}

fn generate_proof(
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: Option<BlockNumber>,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return Err(mmr::Error::PalletNotIncluded);

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
Mmr::generate_proof(_block_numbers, _best_known_block_number).map(
|(leaves, proof)| {
(
Expand All @@ -1239,10 +1239,10 @@ impl_runtime_apis! {
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
-> Result<(), mmr::Error>
{
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return Err(mmr::Error::PalletNotIncluded);

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
{
pub type MmrLeaf = <<Runtime as pallet_mmr::Config>::LeafData as mmr::LeafDataProvider>::LeafData;
let leaves = _leaves.into_iter().map(|leaf|
Expand All @@ -1258,10 +1258,10 @@ impl_runtime_apis! {
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
_proof: mmr::Proof<Hash>
) -> Result<(), mmr::Error> {
#[cfg(not(feature = "rococo"))]
#[cfg(not(any(feature = "rococo", feature = "alphanet")))]
return Err(mmr::Error::PalletNotIncluded);

#[cfg(feature = "rococo")]
#[cfg(any(feature = "rococo", feature = "alphanet"))]
{
let nodes = _leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
pallet_mmr::verify_leaves_proof::<<Runtime as pallet_mmr::Config>::Hashing, _>(_root, nodes, _proof)
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
#[cfg(feature = "kusama")]
pub type Migrations = (RemoveSudoKey,);

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

#[cfg(feature = "polkadot")]
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/xcm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Rococo;
}

#[cfg(feature = "alphanet")]
parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Westend;
}

#[cfg(feature = "polkadot")]
parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
Expand Down

0 comments on commit f9c3a82

Please sign in to comment.