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

pallet-broker: Small improvements to the origin checks #2656

Merged
merged 6 commits into from
Dec 8, 2023
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
10 changes: 10 additions & 0 deletions prdoc/pr_2656.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "pallet-broker: Small improvements to the origin checks"

doc:
- audience: Runtime User
description: |
Change the permissionless calls `drop_region`, `drop_contribution`, `drop_history` and
`drop_renewal` to allow any kind of origin.

crates:
- name: "pallet-broker"
20 changes: 8 additions & 12 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,55 +716,51 @@ pub mod pallet {

/// Drop an expired Region from the chain.
///
/// - `origin`: Must be a Signed origin.
/// - `origin`: Can be any kind of origin.
/// - `region_id`: The Region which has expired.
#[pallet::call_index(14)]
pub fn drop_region(
origin: OriginFor<T>,
_origin: OriginFor<T>,
region_id: RegionId,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
Self::do_drop_region(region_id)?;
Ok(Pays::No.into())
}

/// Drop an expired Instantaneous Pool Contribution record from the chain.
///
/// - `origin`: Must be a Signed origin.
/// - `origin`: Can be any kind of origin.
/// - `region_id`: The Region identifying the Pool Contribution which has expired.
#[pallet::call_index(15)]
pub fn drop_contribution(
origin: OriginFor<T>,
_origin: OriginFor<T>,
region_id: RegionId,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Self::do_drop_contribution(region_id)?;
Ok(Pays::No.into())
}

/// Drop an expired Instantaneous Pool History record from the chain.
///
/// - `origin`: Must be a Signed origin.
/// - `origin`: Can be any kind of origin.
/// - `region_id`: The time of the Pool History record which has expired.
#[pallet::call_index(16)]
pub fn drop_history(origin: OriginFor<T>, when: Timeslice) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
pub fn drop_history(_origin: OriginFor<T>, when: Timeslice) -> DispatchResultWithPostInfo {
Self::do_drop_history(when)?;
Ok(Pays::No.into())
}

/// Drop an expired Allowed Renewal record from the chain.
///
/// - `origin`: Must be a Signed origin of the account which owns the Region `region_id`.
/// - `origin`: Can be any kind of origin.
/// - `core`: The core to which the expired renewal refers.
/// - `when`: The timeslice to which the expired renewal refers. This must have passed.
#[pallet::call_index(17)]
pub fn drop_renewal(
origin: OriginFor<T>,
_origin: OriginFor<T>,
core: CoreIndex,
when: Timeslice,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Self::do_drop_renewal(core, when)?;
Ok(Pays::No.into())
}
Expand Down
29 changes: 2 additions & 27 deletions substrate/frame/broker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ use frame_support::{
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use sp_arithmetic::Perbill;
use sp_core::{ConstU16, ConstU32, ConstU64, H256};
use sp_runtime::{
traits::{BlakeTwo256, Identity, IdentityLookup},
BuildStorage, Saturating,
};
use sp_core::{ConstU32, ConstU64};
use sp_runtime::{traits::Identity, BuildStorage, Saturating};
use sp_std::collections::btree_map::BTreeMap;

type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -49,29 +46,7 @@ frame_support::construct_runtime!(

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down