Skip to content

Commit

Permalink
Merge pull request #3063 from autonomys/remove-disabling-of-non-root-…
Browse files Browse the repository at this point in the history
…calls

Remove support for disabling of non-root calls
  • Loading branch information
nazar-pc authored Sep 25, 2024
2 parents b7bb137 + 0fc5a42 commit 8dd4d9c
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 113 deletions.
8 changes: 0 additions & 8 deletions crates/pallet-runtime-configs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,4 @@ mod benchmarks {

assert!(Pallet::<T>::enable_balance_transfers());
}

#[benchmark]
fn set_enable_non_root_calls() {
#[extrinsic_call]
_(RawOrigin::Root, true);

assert!(Pallet::<T>::enable_non_root_calls());
}
}
26 changes: 0 additions & 26 deletions crates/pallet-runtime-configs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ mod pallet {
#[pallet::getter(fn enable_balance_transfers)]
pub type EnableBalanceTransfers<T> = StorageValue<_, bool, ValueQuery>;

/// Whether to enable calls from non-root account.
// TODO: Find a way to work around `Sudo::key()`
// (https://github.com/paritytech/polkadot-sdk/pull/3370) or remove this feature
#[pallet::storage]
#[pallet::getter(fn enable_non_root_calls)]
pub type EnableNonRootCalls<T> = StorageValue<_, bool, ValueQuery>;

#[pallet::storage]
pub type ConfirmationDepthK<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;

Expand All @@ -77,8 +70,6 @@ mod pallet {
pub enable_dynamic_cost_of_storage: bool,
/// Whether to enable balance transfers
pub enable_balance_transfers: bool,
/// Whether to enable calls from non-root account
pub enable_non_root_calls: bool,
/// Confirmation depth k to use in the archiving process
pub confirmation_depth_k: BlockNumberFor<T>,
/// Council and democracy config params.
Expand All @@ -92,7 +83,6 @@ mod pallet {
enable_domains: false,
enable_dynamic_cost_of_storage: false,
enable_balance_transfers: false,
enable_non_root_calls: false,
confirmation_depth_k: BlockNumberFor::<T>::from(100u32),
council_democracy_config_params:
CouncilDemocracyConfigParams::<BlockNumberFor<T>>::default(),
Expand All @@ -107,7 +97,6 @@ mod pallet {
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params,
} = self;
Expand All @@ -120,7 +109,6 @@ mod pallet {
<EnableDomains<T>>::put(enable_domains);
<EnableDynamicCostOfStorage<T>>::put(enable_dynamic_cost_of_storage);
<EnableBalanceTransfers<T>>::put(enable_balance_transfers);
<EnableNonRootCalls<T>>::put(enable_non_root_calls);
<ConfirmationDepthK<T>>::put(confirmation_depth_k);
CouncilDemocracyConfig::<T>::put(council_democracy_config_params);
}
Expand Down Expand Up @@ -166,19 +154,5 @@ mod pallet {

Ok(())
}

/// Enable or disable calls from non-root users.
#[pallet::call_index(3)]
#[pallet::weight(< T as Config >::WeightInfo::set_enable_non_root_calls())]
pub fn set_enable_non_root_calls(
origin: OriginFor<T>,
enable_non_root_calls: bool,
) -> DispatchResult {
ensure_root(origin)?;

EnableNonRootCalls::<T>::put(enable_non_root_calls);

Ok(())
}
}
}
21 changes: 0 additions & 21 deletions crates/pallet-runtime-configs/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub trait WeightInfo {
fn set_enable_domains() -> Weight;
fn set_enable_dynamic_cost_of_storage() -> Weight;
fn set_enable_balance_transfers() -> Weight;
fn set_enable_non_root_calls() -> Weight;
}

/// Weights for pallet_runtime_configs using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -70,16 +69,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_parts(3_216_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `RuntimeConfigs::EnableNonRootCalls` (r:0 w:1)
/// Proof: `RuntimeConfigs::EnableNonRootCalls` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn set_enable_non_root_calls() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_095_000 picoseconds.
Weight::from_parts(3_249_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -114,14 +103,4 @@ impl WeightInfo for () {
Weight::from_parts(3_216_000, 0)
.saturating_add(ParityDbWeight::get().writes(1_u64))
}
/// Storage: `RuntimeConfigs::EnableNonRootCalls` (r:0 w:1)
/// Proof: `RuntimeConfigs::EnableNonRootCalls` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn set_enable_non_root_calls() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_095_000 picoseconds.
Weight::from_parts(3_249_000, 0)
.saturating_add(ParityDbWeight::get().writes(1_u64))
}
}
4 changes: 0 additions & 4 deletions crates/subspace-malicious-operator/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ struct GenesisParams {
enable_domains: bool,
enable_dynamic_cost_of_storage: bool,
enable_balance_transfers: bool,
enable_non_root_calls: bool,
confirmation_depth_k: u32,
rewards_config: RewardsConfig,
}
Expand Down Expand Up @@ -179,7 +178,6 @@ pub fn dev_config() -> Result<GenericChainSpec, String> {
enable_domains: true,
enable_dynamic_cost_of_storage: false,
enable_balance_transfers: true,
enable_non_root_calls: true,
confirmation_depth_k: 5,
rewards_config: RewardsConfig {
remaining_issuance: 1_000_000 * SSC,
Expand Down Expand Up @@ -215,7 +213,6 @@ fn subspace_genesis_config(
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
rewards_config,
} = genesis_params;
Expand All @@ -241,7 +238,6 @@ fn subspace_genesis_config(
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params:
CouncilDemocracyConfigParams::<BlockNumber>::fast_params(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use std::error::Error;
use std::sync::Arc;
use subspace_core_primitives::PotOutput;
use subspace_runtime::{
CheckStorageAccess, DisablePallets, Runtime, RuntimeCall, SignedExtra, UncheckedExtrinsic,
};
use subspace_runtime::{DisablePallets, Runtime, RuntimeCall, SignedExtra, UncheckedExtrinsic};
use subspace_runtime_primitives::opaque::Block as CBlock;
use subspace_runtime_primitives::{AccountId, Balance, Nonce};

Expand Down Expand Up @@ -427,7 +425,6 @@ pub fn construct_signed_extrinsic(
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0u128),
CheckStorageAccess,
DisablePallets,
);
let raw_payload = generic::SignedPayload::<RuntimeCall, SignedExtra>::from_raw(
Expand All @@ -443,7 +440,6 @@ pub fn construct_signed_extrinsic(
(),
(),
(),
(),
),
);

Expand Down
6 changes: 0 additions & 6 deletions crates/subspace-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ struct GenesisParams {
enable_domains: bool,
enable_dynamic_cost_of_storage: bool,
enable_balance_transfers: bool,
enable_non_root_calls: bool,
confirmation_depth_k: u32,
rewards_config: RewardsConfig,
}
Expand Down Expand Up @@ -105,7 +104,6 @@ pub fn gemini_3h_compiled() -> Result<GenericChainSpec, String> {
enable_domains: false,
enable_dynamic_cost_of_storage: false,
enable_balance_transfers: true,
enable_non_root_calls: false,
// TODO: Proper value here
confirmation_depth_k: 100,
// TODO: Proper value here
Expand Down Expand Up @@ -275,7 +273,6 @@ pub fn devnet_config_compiled() -> Result<GenericChainSpec, String> {
enable_domains: true,
enable_dynamic_cost_of_storage: false,
enable_balance_transfers: true,
enable_non_root_calls: false,
// TODO: Proper value here
confirmation_depth_k: 100,
// TODO: Proper value here
Expand Down Expand Up @@ -338,7 +335,6 @@ pub fn dev_config() -> Result<GenericChainSpec, String> {
enable_domains: true,
enable_dynamic_cost_of_storage: false,
enable_balance_transfers: true,
enable_non_root_calls: true,
confirmation_depth_k: 5,
rewards_config: RewardsConfig {
remaining_issuance: 1_000_000 * SSC,
Expand Down Expand Up @@ -379,7 +375,6 @@ fn subspace_genesis_config(
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
rewards_config,
} = genesis_params;
Expand Down Expand Up @@ -435,7 +430,6 @@ fn subspace_genesis_config(
enable_domains,
enable_dynamic_cost_of_storage,
enable_balance_transfers,
enable_non_root_calls,
confirmation_depth_k,
council_democracy_config_params,
},
Expand Down
3 changes: 1 addition & 2 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use crate::fees::{OnChargeTransaction, TransactionByteFee};
use crate::object_mapping::extract_block_object_mapping;
pub use crate::signed_extensions::{CheckStorageAccess, DisablePallets};
pub use crate::signed_extensions::DisablePallets;
use codec::{Decode, Encode, MaxEncodedLen};
use core::num::NonZeroU64;
use domain_runtime_primitives::opaque::Header as DomainHeader;
Expand Down Expand Up @@ -976,7 +976,6 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
CheckStorageAccess,
DisablePallets,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down
41 changes: 0 additions & 41 deletions crates/subspace-runtime/src/signed_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,6 @@ use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
};
use sp_std::prelude::*;
/// Controls non-root access to feeds and object store
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)]
pub struct CheckStorageAccess;

impl SignedExtension for CheckStorageAccess {
const IDENTIFIER: &'static str = "CheckStorageAccess";
type AccountId = <Runtime as frame_system::Config>::AccountId;
type Call = <Runtime as frame_system::Config>::RuntimeCall;
type AdditionalSigned = ();
type Pre = ();

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}

fn validate(
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
// TODO: Find a way to work around `Sudo::key()`
// (https://github.com/paritytech/polkadot-sdk/pull/3370) or remove this feature
// if RuntimeConfigs::enable_non_root_calls() || Some(who) == Sudo::key().as_ref() {
Ok(ValidTransaction::default())
// } else {
// InvalidTransaction::BadSigner.into()
// }
}

fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}

/// Disable specific pallets.
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)]
Expand Down

0 comments on commit 8dd4d9c

Please sign in to comment.