Skip to content

Commit

Permalink
Merge branch 'master' into vstakhov-network-bridge-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Sep 6, 2023
2 parents fe159d3 + 68ab943 commit b27a8ad
Show file tree
Hide file tree
Showing 34 changed files with 366 additions and 127 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/check-prdoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check PRdoc

on:
pull_request:
types: [labeled, opened, synchronize, unlabeled]

env:
# todo: switch to paritytech/prdoc once the container is built & published
# see https://github.com/paritytech/scripts/pull/595
IMAGE: chevdor/prdoc:v0.0.4
API_BASE: https://api.github.com/repos
REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR: ${{ github.event.pull_request.number }}
MOUNT: /prdoc
ENGINE: docker

jobs:
check-prdoc:
runs-on: ubuntu-latest
steps:
- name: Pull image
run: |
echo "Pulling $IMAGE"
docker pull $IMAGE
docker run --rm $IMAGE --version
- name: Check if PRdoc is required
id: get-labels
run: |
# Fetch the labels for the PR under test
echo "Fetch the labels for $API_BASE/${REPO}/pulls/${GITHUB_PR}"
labels=$( curl -H "Authorization: token ${GITHUB_TOKEN}" -s "$API_BASE/${REPO}/pulls/${GITHUB_PR}" | jq '.labels | .[] | .name' | tr "\n" ",")
echo "Labels: ${labels}"
echo "labels=${labels}" >> "$GITHUB_OUTPUT"
- name: No PRdoc required
if: ${{ contains(steps.get-labels.outputs.labels, 'R0') }}
run: |
echo "PR detected as silent, no PRdoc is required, exiting..."
exit 0
- name: Checkout repo
if: ${{ !contains(steps.get-labels.outputs.labels, 'R0') }}
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0

- name: PRdoc check for PR#${{ github.event.pull_request.number }}
if: ${{ !contains(steps.get-labels.outputs.labels, 'R0') }}
run: |
echo "Checking for PR#${GITHUB_PR} in $MOUNT"
$ENGINE run --rm -v $PWD/prdoc:/doc $IMAGE check -n ${GITHUB_PR}
2 changes: 1 addition & 1 deletion cumulus/scripts/ci/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ all the labels that are used, search for `meta` in the templates. Currently, the
Note that labels with the same letter are mutually exclusive. A PR should not have both `B0` and `B5`, or both `C1` and
`C9`. In case of conflicts, the template will decide which label will be considered.

## Dev and debuggin
## Dev and debugging

### Hot Reload

Expand Down
32 changes: 25 additions & 7 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,36 @@ Reviews should finish with approval unless there are issues that would result in

The reviewers are also responsible to check:

a) if a changelog is necessary and attached

b) the quality of information in the changelog file

c) the PR has an impact on docs

d) that the docs team was included in the review process of a docs update
1. if a changelog is necessary and attached
1. the quality of information in the changelog file
1. the PR has an impact on docs
1. that the docs team was included in the review process of a docs update

**Reviews may not be used as an effective veto for a PR because**:
1. There exists a somewhat cleaner/better/faster way of accomplishing the same feature/fix.
2. It does not fit well with some other contributors' longer-term vision for the project.

## Documentation

All Pull Requests must contain proper title & description.

Some Pull Requests can be exempt of `prdoc` documentation, those
must be labelled with
[`R0-silent`](https://github.com/paritytech/labels/blob/main/ruled_labels/specs_polkadot-sdk.yaml#L89-L91).

Non "silent" PRs must come with documentation in the form of a `.prdoc` file.
A `.prdoc` documentation is made of a text file (YAML) named `/prdoc/pr_NNNN.prdoc` where `NNNN` is the PR number.
For convenience, those file can also contain a short description/title: `/prdoc/pr_NNNN_pr-foobar.prdoc`.

The CI automation checks for the presence and validity of a `prdoc` in the `/prdoc` folder.
Those files need to comply with a specific [schema](https://github.com/paritytech/prdoc/blob/master/schema_user.json). It
is highly recommended to [make your editor aware](https://github.com/paritytech/prdoc#schemas) of the schema as it is
self-described and will assist you in writing correct content.

This schema is also embedded in the
[prdoc](https://github.com/paritytech/prdoc) utility that can also be used to generate and check the validity of a
`prdoc` locally.

## Helping out

We use [labels](https://github.com/paritytech/polkadot-sdk/labels) to manage PRs and issues and communicate
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/common/slot_range_helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license.workspace = true

[dependencies]
paste = "1.0"
enumn = "0.1.8"
enumn = "0.1.12"
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] }
sp-std = { package = "sp-std", path = "../../../../substrate/primitives/std", default-features = false }
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/assigned_slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ mod tests {
type UnsignedPriority = ParasUnsignedPriority;
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
}

impl parachains_shared::Config for Test {}
Expand Down
2 changes: 0 additions & 2 deletions polkadot/runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ pub mod pallet {
);

NextFundIndex::<T>::put(new_fund_index);
// Add a lock to the para so that the configuration cannot be changed.
T::Registrar::apply_lock(index);

Self::deposit_event(Event::<T>::Created { para_id: index });
Ok(())
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl paras::Config for Test {
type UnsignedPriority = ParasUnsignedPriority;
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
}

parameter_types! {
Expand Down
71 changes: 71 additions & 0 deletions polkadot/runtime/common/src/paras_registrar/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use frame_support::traits::{Contains, OnRuntimeUpgrade};

#[derive(Encode, Decode)]
pub struct ParaInfoV1<Account, Balance> {
manager: Account,
deposit: Balance,
locked: bool,
}

pub struct VersionUncheckedMigrateToV1<T, UnlockParaIds>(
sp_std::marker::PhantomData<(T, UnlockParaIds)>,
);
impl<T: Config, UnlockParaIds: Contains<ParaId>> OnRuntimeUpgrade
for VersionUncheckedMigrateToV1<T, UnlockParaIds>
{
fn on_runtime_upgrade() -> Weight {
let mut count = 0u64;
Paras::<T>::translate::<ParaInfoV1<T::AccountId, BalanceOf<T>>, _>(|key, v1| {
count.saturating_inc();
Some(ParaInfo {
manager: v1.manager,
deposit: v1.deposit,
locked: if UnlockParaIds::contains(&key) { None } else { Some(v1.locked) },
})
});

log::info!(target: "runtime::registrar", "Upgraded {} storages to version 1", count);
T::DbWeight::get().reads_writes(count, count)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok((Paras::<T>::iter_keys().count() as u32).encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let old_count = u32::decode(&mut &state[..]).expect("Known good");
let new_count = Paras::<T>::iter_values().count() as u32;

ensure!(old_count == new_count, "Paras count should not change");
Ok(())
}
}

#[cfg(feature = "experimental")]
pub type VersionCheckedMigrateToV1<T, UnlockParaIds> =
frame_support::migrations::VersionedMigration<
0,
1,
VersionUncheckedMigrateToV1<T, UnlockParaIds>,
super::Pallet<T>,
<T as frame_system::Config>::DbWeight,
>;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//! Pallet to handle parachain registration and related fund management.
//! In essence this is a simple wrapper around `paras`.

pub mod migration;

use frame_support::{
dispatch::DispatchResult,
ensure,
Expand All @@ -35,7 +37,7 @@ use sp_std::{prelude::*, result};
use crate::traits::{OnSwap, Registrar};
pub use pallet::*;
use parity_scale_codec::{Decode, Encode};
use runtime_parachains::paras::ParaKind;
use runtime_parachains::paras::{OnNewHead, ParaKind};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{CheckedSub, Saturating},
Expand All @@ -49,7 +51,15 @@ pub struct ParaInfo<Account, Balance> {
/// The amount reserved by the `manager` account for the registration.
deposit: Balance,
/// Whether the para registration should be locked from being controlled by the manager.
locked: bool,
/// None means the lock had not been explicitly set, and should be treated as false.
locked: Option<bool>,
}

impl<Account, Balance> ParaInfo<Account, Balance> {
/// Returns if the para is locked.
pub fn is_locked(&self) -> bool {
self.locked.unwrap_or(false)
}
}

type BalanceOf<T> =
Expand Down Expand Up @@ -96,8 +106,12 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::without_storage_info]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -446,12 +460,12 @@ impl<T: Config> Registrar for Pallet<T> {

// Apply a lock to the parachain.
fn apply_lock(id: ParaId) {
Paras::<T>::mutate(id, |x| x.as_mut().map(|info| info.locked = true));
Paras::<T>::mutate(id, |x| x.as_mut().map(|info| info.locked = Some(true)));
}

// Remove a lock from the parachain.
fn remove_lock(id: ParaId) {
Paras::<T>::mutate(id, |x| x.as_mut().map(|info| info.locked = false));
Paras::<T>::mutate(id, |x| x.as_mut().map(|info| info.locked = Some(false)));
}

// Register a Para ID under control of `manager`.
Expand Down Expand Up @@ -481,9 +495,7 @@ impl<T: Config> Registrar for Pallet<T> {
);
runtime_parachains::schedule_parathread_upgrade::<T>(id)
.map_err(|_| Error::<T>::CannotUpgrade)?;
// Once a para has upgraded to a parachain, it can no longer be managed by the owner.
// Intentionally, the flag stays with the para even after downgrade.
Self::apply_lock(id);

Ok(())
}

Expand Down Expand Up @@ -533,7 +545,7 @@ impl<T: Config> Pallet<T> {
.map_err(|e| e.into())
.and_then(|who| -> DispatchResult {
let para_info = Paras::<T>::get(id).ok_or(Error::<T>::NotRegistered)?;
ensure!(!para_info.locked, Error::<T>::ParaLocked);
ensure!(!para_info.is_locked(), Error::<T>::ParaLocked);
ensure!(para_info.manager == who, Error::<T>::NotOwner);
Ok(())
})
Expand Down Expand Up @@ -566,7 +578,7 @@ impl<T: Config> Pallet<T> {

let deposit = deposit_override.unwrap_or_else(T::ParaDeposit::get);
<T as Config>::Currency::reserve(&who, deposit)?;
let info = ParaInfo { manager: who.clone(), deposit, locked: false };
let info = ParaInfo { manager: who.clone(), deposit, locked: None };

Paras::<T>::insert(id, info);
Self::deposit_event(Event::<T>::Reserved { para_id: id, who });
Expand All @@ -585,7 +597,7 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
let deposited = if let Some(para_data) = Paras::<T>::get(id) {
ensure!(para_data.manager == who, Error::<T>::NotOwner);
ensure!(!para_data.locked, Error::<T>::ParaLocked);
ensure!(!para_data.is_locked(), Error::<T>::ParaLocked);
para_data.deposit
} else {
ensure!(!ensure_reserved, Error::<T>::NotReserved);
Expand All @@ -601,7 +613,7 @@ impl<T: Config> Pallet<T> {
} else if let Some(rebate) = deposited.checked_sub(&deposit) {
<T as Config>::Currency::unreserve(&who, rebate);
};
let info = ParaInfo { manager: who.clone(), deposit, locked: false };
let info = ParaInfo { manager: who.clone(), deposit, locked: None };

Paras::<T>::insert(id, info);
// We check above that para has no lifecycle, so this should not fail.
Expand Down Expand Up @@ -665,6 +677,21 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> OnNewHead for Pallet<T> {
fn on_new_head(id: ParaId, _head: &HeadData) -> Weight {
// mark the parachain locked if the locked value is not already set
let mut writes = 0;
if let Some(mut info) = Paras::<T>::get(id) {
if info.locked.is_none() {
info.locked = Some(true);
Paras::<T>::insert(id, info);
writes += 1;
}
}
T::DbWeight::get().reads_writes(1, writes)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -784,6 +811,7 @@ mod tests {
type UnsignedPriority = ParasUnsignedPriority;
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
}

impl configuration::Config for Test {
Expand Down Expand Up @@ -1270,8 +1298,10 @@ mod tests {
));

assert_noop!(Registrar::add_lock(RuntimeOrigin::signed(2), para_id), BadOrigin);
// Once they begin onboarding, we lock them in.
assert_ok!(Registrar::add_lock(RuntimeOrigin::signed(1), para_id));

// Once they produces new block, we lock them in.
Registrar::on_new_head(para_id, &Default::default());

// Owner cannot pass origin check when checking lock
assert_noop!(
Registrar::ensure_root_para_or_owner(RuntimeOrigin::signed(1), para_id),
Expand All @@ -1283,6 +1313,11 @@ mod tests {
assert_ok!(Registrar::remove_lock(para_origin(para_id), para_id));
// Owner can pass origin check again
assert_ok!(Registrar::ensure_root_para_or_owner(RuntimeOrigin::signed(1), para_id));

// Won't lock again after it is unlocked
Registrar::on_new_head(para_id, &Default::default());

assert_ok!(Registrar::ensure_root_para_or_owner(RuntimeOrigin::signed(1), para_id));
});
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ frame-system-benchmarking = { path = "../../../substrate/frame/system/benchmarki
pallet-election-provider-support-benchmarking = { path = "../../../substrate/frame/election-provider-support/benchmarking", default-features = false, optional = true }
hex-literal = "0.4.1"

runtime-common = { package = "polkadot-runtime-common", path = "../common", default-features = false }
runtime-common = { package = "polkadot-runtime-common", path = "../common", default-features = false, features = ["experimental"] }
runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parachains", default-features = false }
primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }

Expand Down
Loading

0 comments on commit b27a8ad

Please sign in to comment.