mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-15 14:55:42 +00:00
eaf1bc5633
This PR introduces the new crate `developer_hub` into the polkadot-sdk repo. The vision for the developer-hub crate is detailed in [this document](https://docs.google.com/document/d/1XLLkFNE8v8HLvZpI2rzsa8N2IN1FcKntc8q-Sc4xBAk/edit?usp=sharing). <img width="1128" alt="Screenshot 2023-11-02 at 10 45 48" src="https://github.com/paritytech/polkadot-sdk/assets/5588131/1e12b60f-fef5-42c4-8503-a3ba234077c3"> Other than adding the new crate, it also does the following: * Remove the `substrate` crate, as there is now a unique umbrella crate for multiple things in `developer_hub::polkadot_sdk`. * (backport candidate) A minor change to `frame-support` macros that allows `T::RuntimeOrigin` to also be acceptable as the origin type. * (backport candidate) A minor change to `frame-system` that allows us to deposit events at genesis because now the real genesis config is generated via wasm, and we can safely assume `cfg!(feature = "std")` means only testing. related to #62. * (backport candidate) Introduces a small `read_events_for_pallet` to `frame_system` for easier event reading in tests. * From https://github.com/paritytech/polkadot-sdk-docs/issues/31, it takes action on improving the `pallet::call` docs. * From https://github.com/paritytech/polkadot-sdk-docs/issues/31, it takes action on improving the `UncheckedExtrinsic` docs. ## Way Forward First, a version of this is deployed temporarily [here](https://blog.kianenigma.nl/polkadot-sdk/developer_hub/index.html). I will keep it up to date on a daily basis. ### This Pull Request I see two ways forward: 1. We acknowledge that everything in `developer-hub` is going to be WIP, and merge this asap. We should not yet use links to this crate anywhere. 2. We make this be the feature branch, make PRs against this, and either gradually backport it, or only merge to master once it is done. I am personally in favor of option 1. If we stick to option 2, we need a better way to deploy a staging version of this to gh-pages. ### Issue Tracking The main issues related to the future of `developer_hub` are: - https://github.com/paritytech/polkadot-sdk-docs/issues/31 - https://github.com/paritytech/polkadot-sdk-docs/issues/4 - https://github.com/paritytech/polkadot-sdk-docs/issues/26 - https://github.com/paritytech/polkadot-sdk-docs/issues/32 - https://github.com/paritytech/polkadot-sdk-docs/issues/36 ### After This Pull Request - [ ] create a redirect for https://paritytech.github.io/polkadot-sdk/master/substrate/ - [x] analytics - [ ] link checker - [ ] the matter of publishing, and how all of these relative links for when we do, that is still an open question. There is section on this in the landing page. - [ ] updated https://paritytech.github.io/ --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Juan Girini <juangirini@gmail.com> Co-authored-by: bader y <ibnbassem@gmail.com> Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: James Wilson <james@jsdw.me> Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
108 lines
3.7 KiB
Rust
108 lines
3.7 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//! Migrations to version [`4.0.0`], as denoted by the changelog.
|
|
|
|
use super::super::LOG_TARGET;
|
|
use frame_support::{
|
|
traits::{Get, StorageVersion},
|
|
weights::Weight,
|
|
};
|
|
|
|
/// The old prefix.
|
|
pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
|
|
|
|
/// Migrate the entire storage of this pallet to a new prefix.
|
|
///
|
|
/// This new prefix must be the same as the one set in construct_runtime. For safety, use
|
|
/// `PalletInfo` to get it, as:
|
|
/// `<Runtime as frame_system::Config>::PalletInfo::name::<ElectionsPhragmenPallet>`.
|
|
///
|
|
/// The old storage prefix, `PhragmenElection` is hardcoded in the migration code.
|
|
pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
|
|
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
|
|
log::info!(
|
|
target: LOG_TARGET,
|
|
"New pallet name is equal to the old prefix. No migration needs to be done.",
|
|
);
|
|
return Weight::zero()
|
|
}
|
|
let storage_version = StorageVersion::get::<crate::Pallet<T>>();
|
|
log::info!(
|
|
target: LOG_TARGET,
|
|
"Running migration to v4 for elections-phragmen with storage version {:?}",
|
|
storage_version,
|
|
);
|
|
|
|
if storage_version <= 3 {
|
|
log::info!("new prefix: {}", new_pallet_name.as_ref());
|
|
frame_support::storage::migration::move_pallet(
|
|
OLD_PREFIX,
|
|
new_pallet_name.as_ref().as_bytes(),
|
|
);
|
|
|
|
StorageVersion::new(4).put::<crate::Pallet<T>>();
|
|
|
|
<T as frame_system::Config>::BlockWeights::get().max_block
|
|
} else {
|
|
log::warn!(
|
|
target: LOG_TARGET,
|
|
"Attempted to apply migration to v4 but failed because storage version is {:?}",
|
|
storage_version,
|
|
);
|
|
Weight::zero()
|
|
}
|
|
}
|
|
|
|
/// Some checks prior to migration. This can be linked to
|
|
/// `frame_support::traits::OnRuntimeUpgrade::pre_upgrade` for further testing.
|
|
///
|
|
/// Panics if anything goes wrong.
|
|
pub fn pre_migration<T: crate::Config, N: AsRef<str>>(new: N) {
|
|
let new = new.as_ref();
|
|
log::info!("pre-migration elections-phragmen test with new = {}", new);
|
|
|
|
// the next key must exist, and start with the hash of `OLD_PREFIX`.
|
|
let next_key = sp_io::storage::next_key(OLD_PREFIX).unwrap();
|
|
assert!(next_key.starts_with(&sp_io::hashing::twox_128(OLD_PREFIX)));
|
|
|
|
// ensure nothing is stored in the new prefix.
|
|
assert!(
|
|
sp_io::storage::next_key(new.as_bytes()).map_or(
|
|
// either nothing is there
|
|
true,
|
|
// or we ensure that it has no common prefix with twox_128(new).
|
|
|next_key| !next_key.starts_with(&sp_io::hashing::twox_128(new.as_bytes()))
|
|
),
|
|
"unexpected next_key({}) = {:?}",
|
|
new,
|
|
sp_core::hexdisplay::HexDisplay::from(&sp_io::storage::next_key(new.as_bytes()).unwrap())
|
|
);
|
|
// ensure storage version is 3.
|
|
assert_eq!(StorageVersion::get::<crate::Pallet<T>>(), 3);
|
|
}
|
|
|
|
/// Some checks for after migration. This can be linked to
|
|
/// `frame_support::traits::OnRuntimeUpgrade::post_upgrade` for further testing.
|
|
///
|
|
/// Panics if anything goes wrong.
|
|
pub fn post_migration<T: crate::Config>() {
|
|
log::info!("post-migration elections-phragmen");
|
|
// ensure we've been updated to v4 by the automatic write of crate version -> storage version.
|
|
assert_eq!(StorageVersion::get::<crate::Pallet<T>>(), 4);
|
|
}
|