Skip to content

Commit

Permalink
paras-registrar: Improve error reporting (#6989)
Browse files Browse the repository at this point in the history
This pr improves the error reporting by paras registrar when an owner
wants to access a locked parachain.

Closes: #6745

---------

Co-authored-by: command-bot <>
  • Loading branch information
bkchr authored Dec 27, 2024
1 parent ca78179 commit b7afe48
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
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

0 comments on commit b7afe48

Please sign in to comment.