Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paras-registrar: Improve error reporting #6989

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,30 +561,31 @@ impl<T: Config> Pallet<T> {
origin: <T as frame_system::Config>::RuntimeOrigin,
id: ParaId,
) -> DispatchResult {
ensure_signed(origin.clone())
.map_err(|e| e.into())
.and_then(|who| -> DispatchResult {
let para_info = Paras::<T>::get(id).ok_or(Error::<T>::NotRegistered)?;
if let Ok(who) = ensure_signed(origin.clone()) {
let para_info = Paras::<T>::get(id).ok_or(Error::<T>::NotRegistered)?;

if para_info.manager == who {
ensure!(!para_info.is_locked(), Error::<T>::ParaLocked);
ensure!(para_info.manager == who, Error::<T>::NotOwner);
Ok(())
})
.or_else(|_| -> DispatchResult { Self::ensure_root_or_para(origin, id) })
return Ok(())
}
}

Self::ensure_root_or_para(origin, id)
}

/// Ensure the origin is one of Root or the `para` itself.
fn ensure_root_or_para(
origin: <T as frame_system::Config>::RuntimeOrigin,
id: ParaId,
) -> DispatchResult {
if let Ok(caller_id) = ensure_parachain(<T as Config>::RuntimeOrigin::from(origin.clone()))
{
// Check if matching para id...
ensure!(caller_id == id, Error::<T>::NotOwner);
} else {
// Check if root...
ensure_root(origin.clone())?;
if ensure_root(origin.clone()).is_ok() {
return Ok(())
}

let caller_id = ensure_parachain(<T as Config>::RuntimeOrigin::from(origin))?;
// Check if matching para id...
ensure!(caller_id == id, Error::<T>::NotOwner);

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/common/src/paras_registrar/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ fn para_lock_works() {
// Owner cannot pass origin check when checking lock
assert_noop!(
mock::Registrar::ensure_root_para_or_owner(RuntimeOrigin::signed(1), para_id),
BadOrigin
Error::<Test>::ParaLocked,
);
// Owner cannot remove lock.
assert_noop!(mock::Registrar::remove_lock(RuntimeOrigin::signed(1), para_id), BadOrigin);
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_6989.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'paras-registrar: Improve error reporting'
doc:
- audience: Runtime User
description: |-
This pr improves the error reporting by paras registrar when an owner wants to access a locked parachain.

Closes: https://github.com/paritytech/polkadot-sdk/issues/6745
crates:
- name: polkadot-runtime-common
bump: patch
Loading