diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c82f2ed5..a3c688f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [C] Changes is `Cere` Runtime - [D] Changes is `Cere Dev` Runtime +## [6.6.1] +- [C,D] Remove the Deprecated traits. + ## [6.6.0] - [C,D] Update Substrate from `stable2407` to `stable2409`. diff --git a/Cargo.lock b/Cargo.lock index 79eab3e82..9172a3da3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -853,7 +853,7 @@ dependencies = [ [[package]] name = "cere-cli" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-client", "cere-service", @@ -871,7 +871,7 @@ dependencies = [ [[package]] name = "cere-client" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-dev-runtime", "cere-runtime", @@ -893,6 +893,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-grandpa", "sp-inherents", + "sp-io", "sp-offchain", "sp-runtime", "sp-session", @@ -903,7 +904,7 @@ dependencies = [ [[package]] name = "cere-dev-runtime" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-runtime-common", "ddc-primitives", @@ -998,7 +999,7 @@ dependencies = [ [[package]] name = "cere-rpc" -version = "6.6.0" +version = "6.6.1" dependencies = [ "jsonrpsee", "node-primitives", @@ -1027,7 +1028,7 @@ dependencies = [ [[package]] name = "cere-runtime" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-runtime-common", "ddc-primitives", @@ -1122,7 +1123,7 @@ dependencies = [ [[package]] name = "cere-runtime-common" -version = "6.6.0" +version = "6.6.1" dependencies = [ "frame-support", "frame-system", @@ -1143,7 +1144,7 @@ dependencies = [ [[package]] name = "cere-service" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-client", "cere-dev-runtime", @@ -1833,7 +1834,7 @@ dependencies = [ [[package]] name = "ddc-primitives" -version = "6.6.0" +version = "6.6.1" dependencies = [ "frame-support", "frame-system", @@ -5648,7 +5649,7 @@ dependencies = [ [[package]] name = "pallet-chainbridge" -version = "6.6.0" +version = "6.6.1" dependencies = [ "frame-support", "frame-system", @@ -5768,7 +5769,7 @@ dependencies = [ [[package]] name = "pallet-ddc-clusters" -version = "6.6.0" +version = "6.6.1" dependencies = [ "ddc-primitives", "frame-benchmarking", @@ -5794,7 +5795,7 @@ dependencies = [ [[package]] name = "pallet-ddc-clusters-gov" -version = "6.6.0" +version = "6.6.1" dependencies = [ "ddc-primitives", "frame-benchmarking", @@ -5829,7 +5830,7 @@ dependencies = [ [[package]] name = "pallet-ddc-customers" -version = "6.6.0" +version = "6.6.1" dependencies = [ "ddc-primitives", "frame-benchmarking", @@ -5852,7 +5853,7 @@ dependencies = [ [[package]] name = "pallet-ddc-nodes" -version = "6.6.0" +version = "6.6.1" dependencies = [ "ddc-primitives", "frame-benchmarking", @@ -5873,7 +5874,7 @@ dependencies = [ [[package]] name = "pallet-ddc-payouts" -version = "6.6.0" +version = "6.6.1" dependencies = [ "byte-unit", "chrono", @@ -5897,7 +5898,7 @@ dependencies = [ [[package]] name = "pallet-ddc-staking" -version = "6.6.0" +version = "6.6.1" dependencies = [ "ddc-primitives", "frame-benchmarking", @@ -6010,7 +6011,7 @@ dependencies = [ [[package]] name = "pallet-erc20" -version = "6.6.0" +version = "6.6.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -6029,7 +6030,7 @@ dependencies = [ [[package]] name = "pallet-erc721" -version = "6.6.0" +version = "6.6.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -6268,7 +6269,7 @@ dependencies = [ [[package]] name = "pallet-origins" -version = "6.6.0" +version = "6.6.1" dependencies = [ "cere-runtime-common", "frame-benchmarking", diff --git a/Cargo.toml b/Cargo.toml index a26dbb39b..32e295da0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "6.6.0" +version = "6.6.1" authors = ["Cerebellum-Network"] edition = "2021" homepage = "https://cere.network/" diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 65fe6ff4c..5ca95ab44 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -144,8 +144,7 @@ pub fn run() -> sc_cli::Result<()> { #[cfg(feature = "cere-dev-native")] if chain_spec.is_cere_dev() { return runner.sync_run(|config| { - #[allow(deprecated)] - cmd.run::, ()>(config) + cmd.run_with_spec::, ()>(Some(config.chain_spec)) }); } diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index 95fdd6a27..cb8febb61 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -30,6 +30,7 @@ sp-consensus = { workspace = true, default-features = true } sp-consensus-babe = { workspace = true, default-features = true } sp-consensus-grandpa = { workspace = true, default-features = true } sp-inherents = { workspace = true, default-features = true } +sp-io = { workspace = true, default-features = true } sp-offchain = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } sp-session = { workspace = true, default-features = true } @@ -45,3 +46,4 @@ cere-runtime = { workspace = true, optional = true } default = ["cere"] cere = ["cere-runtime"] cere-dev = ["cere-dev-runtime"] +runtime-benchmarks = [] diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index 4b839b8cf..c476f3a10 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -6,8 +6,7 @@ use sc_client_api::{ AuxStore, Backend as BackendT, BlockchainEvents, KeysIter, MerkleValue, PairsIter, UsageProvider, }; -#[allow(deprecated)] -pub use sc_executor::NativeElseWasmExecutor; +use sc_executor::WasmExecutor; use sp_api::{CallApiAt, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; use sp_consensus::BlockStatus; @@ -19,46 +18,19 @@ use sp_runtime::{ use sp_storage::{ChildInfo, StorageData, StorageKey}; pub type FullBackend = sc_service::TFullBackend; -#[allow(deprecated)] -pub type FullClient = - sc_service::TFullClient>; -#[cfg(not(any(feature = "cere", feature = "cere-dev",)))] -compile_error!("at least one runtime feature must be enabled"); - -/// The native executor instance for Cere. -#[cfg(feature = "cere")] -pub struct CereExecutorDispatch; - -#[cfg(feature = "cere")] -impl sc_executor::NativeExecutionDispatch for CereExecutorDispatch { - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; +#[cfg(not(feature = "runtime-benchmarks"))] +pub type HostFunctions = sp_io::SubstrateHostFunctions; - fn dispatch(method: &str, data: &[u8]) -> Option> { - cere_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - cere_runtime::native_version() - } -} +#[cfg(feature = "runtime-benchmarks")] +pub type HostFunctions = + (sp_io::SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions); -/// The native executor instance for Cere Dev. -#[cfg(feature = "cere-dev")] -pub struct CereDevExecutorDispatch; +pub type ChainExecutor = WasmExecutor; +pub type FullClient = sc_service::TFullClient; -#[cfg(feature = "cere-dev")] -impl sc_executor::NativeExecutionDispatch for CereDevExecutorDispatch { - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - - fn dispatch(method: &str, data: &[u8]) -> Option> { - cere_dev_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - cere_dev_runtime::native_version() - } -} +#[cfg(not(any(feature = "cere", feature = "cere-dev",)))] +compile_error!("at least one runtime feature must be enabled"); pub trait AbstractClient: BlockchainEvents @@ -102,9 +74,9 @@ where #[derive(Clone)] pub enum Client { #[cfg(feature = "cere")] - Cere(Arc>), + Cere(Arc>), #[cfg(feature = "cere-dev")] - CereDev(Arc>), + CereDev(Arc>), } macro_rules! with_client { diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index e9d6dad1d..e0210f83b 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -5,6 +5,7 @@ use std::sync::Arc; #[cfg(not(any(feature = "cere-native", feature = "cere-dev-native",)))] compile_error!("at least one runtime feature must be enabled"); +use cere_client::ChainExecutor; #[cfg(feature = "cere-dev-native")] pub use cere_dev_runtime; #[cfg(feature = "cere-native")] @@ -22,20 +23,14 @@ use sc_service::{ use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; pub mod chain_spec; -#[cfg(feature = "cere-dev-native")] -pub use cere_client::CereDevExecutorDispatch; #[cfg(feature = "cere-native")] -pub use cere_client::CereExecutorDispatch; pub use cere_client::{ AbstractClient, Client, ClientHandle, ExecuteWithClient, FullBackend, FullClient, RuntimeApiCollection, }; pub use chain_spec::{CereChainSpec, CereDevChainSpec}; pub use node_primitives::{Block, BlockNumber}; -#[allow(deprecated)] -use sc_executor::{ - HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY, -}; +use sc_executor::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY}; pub use sc_service::ChainSpec; use sc_transaction_pool_api::OffchainTransactionPoolFactory; pub use sp_api::ConstructRuntimeApi; @@ -45,40 +40,31 @@ pub use sp_api::ConstructRuntimeApi; const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; type FullSelectChain = sc_consensus::LongestChain; -type FullGrandpaBlockImport = - sc_consensus_grandpa::GrandpaBlockImport< - FullBackend, - Block, - FullClient, - FullSelectChain, - >; - -struct Basics +type FullGrandpaBlockImport = sc_consensus_grandpa::GrandpaBlockImport< + FullBackend, + Block, + FullClient, + FullSelectChain, +>; + +struct Basics where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, - ExecutorDispatch: NativeExecutionDispatch + 'static, { task_manager: TaskManager, - client: Arc>, + client: Arc>, backend: Arc, keystore_container: KeystoreContainer, telemetry: Option, } -fn new_partial_basics( +fn new_partial_basics( config: &Configuration, -) -> Result, ServiceError> +) -> Result, ServiceError> where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, - ExecutorDispatch: NativeExecutionDispatch + 'static, { let telemetry = config .telemetry_endpoints @@ -96,15 +82,13 @@ where .default_heap_pages .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); - let wasm = WasmExecutor::builder() + let executor = ChainExecutor::builder() .with_execution_method(config.executor.wasm_method) .with_onchain_heap_alloc_strategy(heap_pages) .with_offchain_heap_alloc_strategy(heap_pages) .with_max_runtime_instances(config.executor.max_runtime_instances) .with_runtime_cache_size(config.executor.runtime_cache_size) .build(); - #[allow(deprecated)] - let executor = NativeElseWasmExecutor::::new_with_wasm_executor(wasm); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( @@ -124,19 +108,16 @@ where } #[allow(clippy::type_complexity)] -fn new_partial( +fn new_partial( config: &Configuration, - Basics { task_manager, backend, client, keystore_container, telemetry }: Basics< - RuntimeApi, - ExecutorDispatch, - >, + Basics { task_manager, backend, client, keystore_container, telemetry }: Basics, ) -> Result< sc_service::PartialComponents< - FullClient, + FullClient, FullBackend, FullSelectChain, sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool>, + sc_transaction_pool::FullPool>, ( impl Fn( sc_rpc::SubscriptionTaskExecutor, @@ -144,14 +125,10 @@ fn new_partial( ( sc_consensus_babe::BabeBlockImport< Block, - FullClient, - FullGrandpaBlockImport, - >, - sc_consensus_grandpa::LinkHalf< - Block, - FullClient, - FullSelectChain, + FullClient, + FullGrandpaBlockImport, >, + sc_consensus_grandpa::LinkHalf, FullSelectChain>, sc_consensus_babe::BabeLink, ), sc_consensus_grandpa::SharedVoterState, @@ -161,12 +138,8 @@ fn new_partial( ServiceError, > where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, - ExecutorDispatch: NativeExecutionDispatch + 'static, { let select_chain = sc_consensus::LongestChain::new(backend.clone()); @@ -283,7 +256,7 @@ pub fn build_full::Hash>>( ) -> Result, ServiceError> { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { - return new_full::( + return new_full::( config, disable_hardware_benchmarks, |_, _| (), @@ -293,12 +266,8 @@ pub fn build_full::Hash>>( #[cfg(feature = "cere-native")] { - new_full::( - config, - disable_hardware_benchmarks, - |_, _| (), - ) - .map(|full| full.with_client(Client::Cere)) + new_full::(config, disable_hardware_benchmarks, |_, _| ()) + .map(|full| full.with_client(Client::Cere)) } #[cfg(not(feature = "cere-native"))] @@ -326,25 +295,21 @@ impl NewFull { } } -pub fn new_full::Hash>>( +pub fn new_full::Hash>>( config: Configuration, disable_hardware_benchmarks: bool, with_startup_data: impl FnOnce( &sc_consensus_babe::BabeBlockImport< Block, - FullClient, - FullGrandpaBlockImport, + FullClient, + FullGrandpaBlockImport, >, &sc_consensus_babe::BabeLink, ), -) -> Result>>, ServiceError> +) -> Result>>, ServiceError> where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, - ExecutorDispatch: NativeExecutionDispatch + 'static, { let hwbench = if !disable_hardware_benchmarks { config.database.path().map(|database_path| { @@ -355,7 +320,7 @@ where None }; - let basics = new_partial_basics::(&config)?; + let basics = new_partial_basics::(&config)?; let sc_service::PartialComponents { client, @@ -630,12 +595,12 @@ impl ExecuteWithClient for RevertConsensus { } macro_rules! chain_ops { - ($config:expr; $scope:ident, $executor:ident, $variant:ident) => {{ + ($config:expr; $scope:ident, $variant:ident) => {{ let config = $config; - let basics = new_partial_basics::<$scope::RuntimeApi, $executor>(config)?; + let basics = new_partial_basics::<$scope::RuntimeApi>(config)?; let sc_service::PartialComponents { client, backend, import_queue, task_manager, .. } = - new_partial::<$scope::RuntimeApi, $executor>(&config, basics)?; + new_partial::<$scope::RuntimeApi>(&config, basics)?; Ok((Arc::new(Client::$variant(client)), backend, import_queue, task_manager)) }}; } @@ -649,12 +614,12 @@ pub fn new_chain_ops( > { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { - return chain_ops!(config; cere_dev_runtime, CereDevExecutorDispatch, CereDev); + return chain_ops!(config; cere_dev_runtime, CereDev); } #[cfg(feature = "cere-native")] { - chain_ops!(config; cere_runtime, CereExecutorDispatch, Cere) + chain_ops!(config; cere_runtime, Cere) } #[cfg(not(feature = "cere-native"))] diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index ce71d06ea..12d48340a 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -157,23 +157,19 @@ pub mod pallet { /// All whitelisted chains and their respective transaction counts #[pallet::storage] - #[pallet::getter(fn chains)] pub type ChainNonces = StorageMap<_, Blake2_256, ChainId, DepositNonce>; /// Tracks current relayer set #[pallet::storage] - #[pallet::getter(fn relayers)] pub type Relayers = StorageMap<_, Blake2_256, T::AccountId, bool>; /// Utilized by the bridge software to map resource IDs to actual methods #[pallet::storage] - #[pallet::getter(fn resources)] pub type Resources = StorageMap<_, Blake2_256, ResourceId, Vec>; /// All known proposals. /// The key is the hash of the call and the deposit ID, to ensure it's unique #[pallet::storage] - #[pallet::getter(fn votes)] pub type Votes = StorageDoubleMap< _, Blake2_256, @@ -190,7 +186,6 @@ pub mod pallet { /// Number of votes required for a proposal to execute #[pallet::storage] - #[pallet::getter(fn relayer_threshold)] pub type RelayerThreshold = StorageValue>; @@ -201,7 +196,6 @@ pub mod pallet { /// Number of relayers in set #[pallet::storage] - #[pallet::getter(fn relayer_count)] pub type RelayerCount = StorageValue>; @@ -435,7 +429,7 @@ pub mod pallet { /// Checks if who is a relayer pub fn is_relayer(who: &T::AccountId) -> bool { - Self::relayers(who).unwrap_or(false) + Relayers::::get(who).unwrap_or(false) } /// Provides an AccountId for the pallet. @@ -446,18 +440,18 @@ pub mod pallet { /// Asserts if a resource is registered pub fn resource_exists(id: ResourceId) -> bool { - Self::resources(id).is_some() + Resources::::get(id).is_some() } /// Checks if a chain exists as a whitelisted destination pub fn chain_whitelisted(id: ChainId) -> bool { - Self::chains(id).is_some() + ChainNonces::::get(id).is_some() } /// Increments the deposit nonce for the specified chain ID fn bump_nonce(id: ChainId) -> DepositNonce { - let nonce = Self::chains(id).unwrap_or_default() + 1; - >::insert(id, nonce); + let nonce = ChainNonces::::get(id).unwrap_or_default() + 1; + ChainNonces::::insert(id, nonce); nonce } diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index bf873a1da..f12f6c3eb 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -3,11 +3,7 @@ use frame_support::{ }; use frame_system::{self as system}; pub use pallet_balances as balances; -use sp_core::H256; -use sp_runtime::{ - traits::{AccountIdConversion, IdentityLookup}, - BuildStorage, Perbill, -}; +use sp_runtime::{traits::AccountIdConversion, BuildStorage, Perbill}; use crate::{self as bridge, *}; @@ -21,14 +17,9 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = u64; - type Lookup = IdentityLookup; type BlockHashCount = BlockHashCount; - // type ModuleToIndex = (); - // type MaxLocks = MaxLocks; type AccountData = pallet_balances::AccountData; type MaxConsumers = frame_support::traits::ConstU32<16>; } @@ -111,7 +102,7 @@ pub fn new_test_ext_initialized( t.execute_with(|| { // Set and check threshold assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD)); - assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD); + assert_eq!(RelayerThreshold::::get(), TEST_THRESHOLD); // Add relayers assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index 3263718b3..8c48a0166 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -82,13 +82,13 @@ fn setup_resources() { let method2 = "Pallet.do_somethingElse".as_bytes().to_vec(); assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method.clone())); - assert_eq!(Bridge::resources(id), Some(method)); + assert_eq!(Resources::::get(id), Some(method)); assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method2.clone())); - assert_eq!(Bridge::resources(id), Some(method2)); + assert_eq!(Resources::::get(id), Some(method2)); assert_ok!(Bridge::remove_resource(RuntimeOrigin::root(), id)); - assert_eq!(Bridge::resources(id), None); + assert_eq!(Resources::::get(id), None); }) } @@ -233,12 +233,12 @@ fn asset_transfer_invalid_chain() { fn add_remove_relayer() { new_test_ext().execute_with(|| { assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_eq!(Bridge::relayer_count(), 0); + assert_eq!(RelayerCount::::get(), 0); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_C)); - assert_eq!(Bridge::relayer_count(), 3); + assert_eq!(RelayerCount::::get(), 3); // Already exists assert_noop!( @@ -248,12 +248,12 @@ fn add_remove_relayer() { // Confirm removal assert_ok!(Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B)); - assert_eq!(Bridge::relayer_count(), 2); + assert_eq!(RelayerCount::::get(), 2); assert_noop!( Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B), Error::::RelayerInvalid ); - assert_eq!(Bridge::relayer_count(), 2); + assert_eq!(RelayerCount::::get(), 2); assert_events(vec![ RuntimeEvent::Bridge(Event::RelayerAdded(RELAYER_A)), @@ -285,7 +285,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -302,7 +302,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -319,7 +319,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A, RELAYER_C], votes_against: vec![RELAYER_B], @@ -355,7 +355,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -372,7 +372,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -389,7 +389,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B, RELAYER_C], @@ -427,7 +427,7 @@ fn execute_after_threshold_change() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -447,7 +447,7 @@ fn execute_after_threshold_change() { Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -485,7 +485,7 @@ fn proposal_expires() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -510,7 +510,7 @@ fn proposal_expires() { ); // Proposal state should remain unchanged - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -529,7 +529,7 @@ fn proposal_expires() { ), Error::::ProposalExpired ); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], diff --git a/pallets/ddc-clusters-gov/src/lib.rs b/pallets/ddc-clusters-gov/src/lib.rs index 788ee0656..a30f1e8e5 100644 --- a/pallets/ddc-clusters-gov/src/lib.rs +++ b/pallets/ddc-clusters-gov/src/lib.rs @@ -150,7 +150,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn proposal_of)] pub type ClusterProposal = StorageMap< _, Identity, @@ -161,13 +160,11 @@ pub mod pallet { /// Votes on a given cluster proposal, if it is ongoing. #[pallet::storage] - #[pallet::getter(fn voting)] pub type ClusterProposalVoting = StorageMap<_, Identity, ClusterId, Votes>, OptionQuery>; /// Public referendums initiated by clusters #[pallet::storage] - #[pallet::getter(fn submission_depositor)] pub type SubmissionDeposits = StorageMap<_, Identity, ReferendumIndex, SubmissionDeposit, OptionQuery>; @@ -534,7 +531,8 @@ pub mod pallet { cluster_id: ClusterId, approve: bool, ) -> Result { - let mut voting = Self::voting(cluster_id).ok_or(Error::::ProposalMissing)?; + let mut voting = + ClusterProposalVoting::::get(cluster_id).ok_or(Error::::ProposalMissing)?; let position_yes = voting.ayes.iter().position(|a| a == &voter_id); let position_no = voting.nays.iter().position(|a| a == &voter_id); @@ -579,7 +577,8 @@ pub mod pallet { /// Close a vote that is either approved, disapproved or whose voting period has ended. fn do_close(cluster_id: ClusterId, caller_id: T::AccountId) -> DispatchResultWithPostInfo { - let voting = Self::voting(cluster_id).ok_or(Error::::ProposalMissing)?; + let voting = + ClusterProposalVoting::::get(cluster_id).ok_or(Error::::ProposalMissing)?; let mut no_votes = voting.nays.len() as MemberCount; let mut yes_votes = voting.ayes.len() as MemberCount; diff --git a/pallets/ddc-clusters-gov/src/mock.rs b/pallets/ddc-clusters-gov/src/mock.rs index 7e20d0575..d89452f48 100644 --- a/pallets/ddc-clusters-gov/src/mock.rs +++ b/pallets/ddc-clusters-gov/src/mock.rs @@ -18,7 +18,6 @@ use frame_support::{ fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, EnsureOriginWithArg, EqualPrivilegeOnly, LinearStoragePrice, Nothing, }, - weights::constants::RocksDbWeight, PalletId, }; use frame_system::{ @@ -30,7 +29,6 @@ use pallet_ddc_clusters::cluster::Cluster; use pallet_ddc_nodes::StorageNode; use pallet_referenda::Curve; use parking_lot::{ReentrantMutex, ReentrantMutexGuard}; -use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ traits::{Convert, IdentifyAccount, IdentityLookup, Verify}, @@ -87,10 +85,7 @@ impl Convert> for Test { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; type Lookup = IdentityLookup; type BlockHashCount = ConstU64<250>; diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index e9c1cd123..99a93fed0 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -138,12 +138,10 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn clusters)] pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; #[pallet::storage] - #[pallet::getter(fn clusters_protocol_params)] pub type ClustersGovParams = StorageMap< _, Twox64Concat, @@ -152,7 +150,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn clusters_nodes)] pub type ClustersNodes = StorageDoubleMap< _, Blake2_128Concat, @@ -164,7 +161,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn clusters_nodes_stats)] pub type ClustersNodesStats = StorageMap<_, Twox64Concat, ClusterId, ClusterNodesStats>; diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index 19a10c745..1341766aa 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -9,14 +9,12 @@ use ddc_primitives::{ use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ConstBool, ConstU32, ConstU64, Nothing}, - weights::constants::RocksDbWeight, }; use frame_system::{ mocking::{MockBlock, MockUncheckedExtrinsic}, EnsureSigned, }; use pallet_contracts as contracts; -use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ testing::TestXt, @@ -149,20 +147,13 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; type BlockHashCount = ConstU64<250>; type AccountData = pallet_balances::AccountData; type MaxConsumers = ConstU32<16>; type Lookup = IdentityLookup; - type SingleBlockMigrations = (); - type MultiBlockMigrator = (); - type PreInherents = (); - type PostInherents = (); - type PostTransactions = (); } impl pallet_balances::Config for Test { diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index c28301e24..0a71843eb 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -50,14 +50,13 @@ fn create_cluster_works() { cluster_protocol_params.clone() )); - let created_cluster = DdcClusters::clusters(cluster_id).unwrap(); + let created_cluster = Clusters::::get(cluster_id).unwrap(); assert_eq!(created_cluster.cluster_id, cluster_id); assert_eq!(created_cluster.manager_id, cluster_manager_id); assert_eq!(created_cluster.reserve_id, cluster_reserve_id); assert_eq!(created_cluster.props.node_provider_auth_contract, Some(auth_contract.clone())); - let created_cluster_protocol_params = - DdcClusters::clusters_protocol_params(cluster_id).unwrap(); + let created_cluster_protocol_params = ClustersGovParams::::get(cluster_id).unwrap(); assert_eq!( created_cluster_protocol_params.treasury_share, cluster_protocol_params.treasury_share @@ -482,7 +481,7 @@ fn set_cluster_params_works() { }, )); - let updated_cluster = DdcClusters::clusters(cluster_id).unwrap(); + let updated_cluster = Clusters::::get(cluster_id).unwrap(); assert_eq!(updated_cluster.props.node_provider_auth_contract, Some(auth_contract_2)); assert_eq!(updated_cluster.props.erasure_coding_required, 4); assert_eq!(updated_cluster.props.erasure_coding_total, 6); diff --git a/pallets/ddc-customers/src/benchmarking.rs b/pallets/ddc-customers/src/benchmarking.rs index 59585d476..32fbccd20 100644 --- a/pallets/ddc-customers/src/benchmarking.rs +++ b/pallets/ddc-customers/src/benchmarking.rs @@ -54,7 +54,7 @@ benchmarks! { whitelist_account!(user); }: _(RawOrigin::Signed(user), cluster_id, bucket_params) verify { - assert_eq!(Pallet::::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); } deposit { diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 35fbfb4e5..f263be5e2 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -159,7 +159,6 @@ pub mod pallet { /// Map from all (unlocked) "owner" accounts to the info regarding the staking. #[pallet::storage] - #[pallet::getter(fn ledger)] pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>; #[pallet::type_value] @@ -168,13 +167,11 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn buckets_count)] pub type BucketsCount = StorageValue>; /// Map from bucket ID to the bucket structure #[pallet::storage] - #[pallet::getter(fn buckets)] pub type Buckets = StorageMap<_, Twox64Concat, BucketId, Bucket, OptionQuery>; #[pallet::event] @@ -303,7 +300,7 @@ pub mod pallet { ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = - Self::buckets_count().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + BucketsCount::::get().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; ensure!( >::cluster_exists(&cluster_id), @@ -385,7 +382,7 @@ pub mod pallet { #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -447,7 +444,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::withdraw_unlocked_deposit_kill())] pub fn withdraw_unlocked_deposit(origin: OriginFor) -> DispatchResultWithPostInfo { let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); let current_block = >::block_number(); ledger = ledger.consolidate_unlocked(current_block); @@ -507,7 +504,7 @@ pub mod pallet { bucket_params: BucketParams, ) -> DispatchResult { let owner = ensure_signed(origin)?; - let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + let mut bucket = Buckets::::get(bucket_id).ok_or(Error::::NoBucketWithId)?; ensure!(bucket.owner_id == owner, Error::::NotBucketOwner); bucket.is_public = bucket_params.is_public; @@ -631,7 +628,7 @@ pub mod pallet { amount: u128, ) -> Result { let actually_charged: BalanceOf; - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&content_owner).ok_or(Error::::NotOwner)?; let amount_to_deduct = amount.saturated_into::>(); if ledger.active >= amount_to_deduct { @@ -713,7 +710,7 @@ pub mod pallet { fn deposit_extra(owner: T::AccountId, amount: u128) -> Result<(), DispatchError> { let max_additional = amount.saturated_into::>(); - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; let owner_balance = ::Currency::free_balance(&owner); let extra = owner_balance.min(max_additional); diff --git a/pallets/ddc-customers/src/migration.rs b/pallets/ddc-customers/src/migration.rs index cd2e9c6b0..5a66c8dd9 100644 --- a/pallets/ddc-customers/src/migration.rs +++ b/pallets/ddc-customers/src/migration.rs @@ -97,7 +97,7 @@ impl OnRuntimeUpgrade for MigrateToV1 { let (prev_bucket_id, prev_count): (u64, u64) = Decode::decode(&mut &prev_state[..]).expect("pre_upgrade provides a valid state; qed"); - let post_bucket_id = Pallet::::buckets_count(); + let post_bucket_id = BucketsCount::::get(); ensure!( prev_bucket_id == post_bucket_id, "the last bucket ID before and after the migration should be the same" diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index e5578eb46..8a3c72d3e 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -9,10 +9,8 @@ use ddc_primitives::{ use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ConstU32, ConstU64}, - weights::constants::RocksDbWeight, }; use frame_system::mocking::MockBlock; -use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ traits::IdentityLookup, BuildStorage, DispatchError, DispatchResult, Perquintill, @@ -43,10 +41,7 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; type Lookup = IdentityLookup; type BlockHashCount = ConstU64<250>; diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 86d1e0bf9..d9fcd2ad1 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -21,9 +21,9 @@ fn create_bucket_works() { )); // Check storage - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -66,9 +66,9 @@ fn create_two_buckets_works() { System::assert_last_event(Event::BucketCreated { bucket_id: 2u64 }.into()); // Check storage - assert_eq!(DdcCustomers::buckets_count(), 2); + assert_eq!(BucketsCount::::get(), 2); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -78,7 +78,7 @@ fn create_two_buckets_works() { }) ); assert_eq!( - DdcCustomers::buckets(2), + Buckets::::get(2), Some(Bucket { bucket_id: 2, owner_id: account_1, @@ -116,7 +116,7 @@ fn deposit_and_deposit_extra_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_1), + Ledger::::get(account_1), Some(AccountsLedger { owner: account_1, total: amount1, @@ -154,7 +154,7 @@ fn deposit_and_deposit_extra_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_1), + Ledger::::get(account_1), Some(AccountsLedger { owner: account_1, total: amount1 + extra_amount2, @@ -190,7 +190,7 @@ fn charge_content_owner_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit, @@ -218,7 +218,7 @@ fn charge_content_owner_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit - charge1, @@ -236,7 +236,7 @@ fn charge_content_owner_works() { let charge2 = 100u128; let charge_result = DdcCustomers::charge_content_owner(account_3, vault, charge2).unwrap(); assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: 0, @@ -263,7 +263,7 @@ fn charge_content_owner_works() { assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_3), deposit)); assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit, @@ -299,7 +299,7 @@ fn unlock_and_withdraw_deposit_works() { let unlocking_chunks = vec![UnlockChunk { value: 1, block: 11 }]; // Check storage assert_eq!( - DdcCustomers::ledger(1), + Ledger::::get(1), Some(AccountsLedger { owner: account_1, total: 35_u128, @@ -326,7 +326,7 @@ fn unlock_and_withdraw_deposit_works() { assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage assert_eq!( - DdcCustomers::ledger(1), + Ledger::::get(1), Some(AccountsLedger { owner: account_1, total: 3_u128, @@ -341,7 +341,7 @@ fn unlock_and_withdraw_deposit_works() { assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage - assert_eq!(DdcCustomers::ledger(account_1), None); + assert_eq!(Ledger::::get(account_1), None); }) } @@ -373,9 +373,9 @@ fn set_bucket_params_works() { update_bucket_params.clone() )); - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id, owner_id: bucket_owner, @@ -466,9 +466,9 @@ fn remove_bucket_works() { ); // Check storage bucket is not removed - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -482,9 +482,9 @@ fn remove_bucket_works() { assert_ok!(DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_1)); // Check storage bucket is removed - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -558,7 +558,7 @@ fn remove_bucket_checks_with_multiple_buckets_works() { // Verify whether bucket has been removed assert_eq!( - DdcCustomers::buckets(bucket_id_1), + Buckets::::get(bucket_id_1), Some(Bucket { bucket_id: bucket_id_1, owner_id: account_1, @@ -569,7 +569,7 @@ fn remove_bucket_checks_with_multiple_buckets_works() { ); assert_eq!( - DdcCustomers::buckets(bucket_id_2), + Buckets::::get(bucket_id_2), Some(Bucket { bucket_id: bucket_id_2, owner_id: account_2, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 83e7ee60b..9b0517182 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -86,7 +86,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn storage_nodes)] pub type StorageNodes = StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; diff --git a/pallets/ddc-nodes/src/mock.rs b/pallets/ddc-nodes/src/mock.rs index 830ca1149..14d5cec64 100644 --- a/pallets/ddc-nodes/src/mock.rs +++ b/pallets/ddc-nodes/src/mock.rs @@ -6,12 +6,10 @@ use ddc_primitives::traits::staking::{StakingVisitor, StakingVisitorError}; use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ConstU32, ConstU64}, - weights::constants::RocksDbWeight, }; use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; -use sp_core::H256; use sp_io::TestExternalities; -use sp_runtime::{traits::IdentityLookup, BuildStorage}; +use sp_runtime::BuildStorage; use crate::{self as pallet_ddc_nodes, *}; @@ -40,15 +38,9 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; - type Lookup = IdentityLookup; - type BlockHashCount = ConstU64<250>; type AccountData = pallet_balances::AccountData; - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Test { diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index 618a01c8e..b6545708f 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -66,7 +66,7 @@ fn create_storage_node_works() { NodeParams::StorageParams(storage_node_params.clone()) )); - let created_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let created_storage_node = StorageNodes::::get(&node_pub_key).unwrap(); let expected_host: BoundedVec = storage_node_params.clone().host.try_into().unwrap(); let expected_domain: BoundedVec = @@ -91,7 +91,7 @@ fn create_storage_node_works() { { assert_eq!(cluster_id, None); } - let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let storage_node = StorageNodes::::get(&node_pub_key).unwrap(); assert_eq!(storage_node.pub_key, node_pub_key); // Node already exists @@ -143,7 +143,7 @@ fn create_storage_node_with_node_creator() { { assert_eq!(cluster_id, None); } - let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let storage_node = StorageNodes::::get(&node_pub_key).unwrap(); assert_eq!(storage_node.pub_key, node_pub_key); }) } @@ -198,7 +198,7 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(updated_params.clone()) )); - let updated_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let updated_storage_node = StorageNodes::::get(&node_pub_key).unwrap(); let expected_host: BoundedVec = updated_params.host.try_into().unwrap(); let expected_domain: BoundedVec = updated_params.domain.try_into().unwrap(); diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f543db269..34537f7a5 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -270,7 +270,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn active_billing_reports)] pub type ActiveBillingReports = StorageDoubleMap< _, Blake2_128Concat, @@ -281,16 +280,13 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn authorised_caller)] pub type AuthorisedCaller = StorageValue<_, T::AccountId>; #[pallet::storage] - #[pallet::getter(fn debtor_customers)] pub type DebtorCustomers = StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; #[pallet::storage] - #[pallet::getter(fn owing_providers)] pub type OwingProviders = StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; @@ -371,7 +367,7 @@ pub mod pallet { end_era: i64, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( ActiveBillingReports::::try_get(cluster_id, era).is_err(), @@ -403,7 +399,7 @@ pub mod pallet { max_batch_index: BatchIndex, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); @@ -431,7 +427,7 @@ pub mod pallet { payers: Vec<(T::AccountId, CustomerUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( !payers.is_empty() && payers.len() <= MaxBatchSize::get() as usize, @@ -582,7 +578,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -683,7 +679,7 @@ pub mod pallet { total_node_usage: NodeUsage, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); @@ -715,7 +711,7 @@ pub mod pallet { payees: Vec<(T::AccountId, NodeUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( !payees.is_empty() && payees.len() <= MaxBatchSize::get() as usize, @@ -827,7 +823,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -878,7 +874,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index f6ce144aa..771d88186 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -16,7 +16,6 @@ use frame_election_provider_support::SortedListProvider; use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ConstU32, ConstU64, ExistenceRequirement, Randomness}, - weights::constants::RocksDbWeight, PalletId, }; use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; @@ -75,10 +74,7 @@ impl Randomness for MockRandomness { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; type Lookup = IdentityLookup; type BlockHashCount = ConstU64<250>; diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 589e94740..e7629c0bd 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -27,7 +27,7 @@ fn set_authorised_caller_works() { Event::AuthorisedCaller { authorised_caller: dac_account }.into(), ); - assert_eq!(DdcPayouts::authorised_caller().unwrap(), dac_account); + assert_eq!(AuthorisedCaller::::get().unwrap(), dac_account); }) } @@ -98,7 +98,7 @@ fn begin_billing_report_works() { System::assert_last_event(Event::BillingReportInitialized { cluster_id, era }.into()); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_eq!(report.start_era, start_era); assert_eq!(report.end_era, end_era); @@ -182,7 +182,7 @@ fn begin_charging_customers_works() { System::assert_last_event(Event::ChargingStarted { cluster_id, era }.into()); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::ChargingCustomers); assert_eq!(report.charging_max_batch_index, max_batch_index); }) @@ -465,7 +465,7 @@ fn send_charging_customers_batch_works() { )); let usage4_charge = calculate_charge_for_month(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_month(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -477,7 +477,7 @@ fn send_charging_customers_batch_works() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_month(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -541,7 +541,7 @@ fn send_charging_customers_batch_works() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_month(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -561,7 +561,7 @@ fn send_charging_customers_batch_works() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -580,7 +580,7 @@ fn send_charging_customers_batch_works() { let user3_charge = calculate_charge_for_month(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_month(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -601,7 +601,7 @@ fn send_charging_customers_batch_works() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -687,7 +687,7 @@ fn end_charging_customers_works_small_usage_1_hour() { payers1, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let usage6_charge = calculate_charge_for_hour(cluster_id, usage6.clone()); let usage7_charge = calculate_charge_for_hour(cluster_id, usage7.clone()); let charge6 = calculate_charge_parts_for_hour(cluster_id, usage6); @@ -748,7 +748,7 @@ fn end_charging_customers_works_small_usage_1_hour() { )); System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let fees = get_fees(&cluster_id); @@ -898,7 +898,7 @@ fn send_charging_customers_batch_works_for_day() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -910,7 +910,7 @@ fn send_charging_customers_batch_works_for_day() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -974,7 +974,7 @@ fn send_charging_customers_batch_works_for_day() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -994,7 +994,7 @@ fn send_charging_customers_batch_works_for_day() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1013,7 +1013,7 @@ fn send_charging_customers_batch_works_for_day() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1034,7 +1034,7 @@ fn send_charging_customers_batch_works_for_day() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1141,7 +1141,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1153,7 +1153,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1217,7 +1217,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1237,7 +1237,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1256,7 +1256,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1277,7 +1277,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1384,7 +1384,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1396,7 +1396,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1460,7 +1460,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1480,7 +1480,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1499,7 +1499,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1520,7 +1520,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1627,7 +1627,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1639,7 +1639,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1703,7 +1703,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1723,7 +1723,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1742,7 +1742,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1763,7 +1763,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1870,7 +1870,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1882,7 +1882,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1946,7 +1946,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1966,7 +1966,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1985,7 +1985,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -2006,7 +2006,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2113,7 +2113,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -2125,7 +2125,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -2189,7 +2189,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -2209,7 +2209,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -2228,7 +2228,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -2249,7 +2249,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2321,7 +2321,7 @@ fn send_charging_customers_batch_works_zero_fees() { assert_eq!(System::events().len(), 3); // batch 1 - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let before_total_customer_charge = report.total_customer_charge; let balance_before = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_charging_customers_batch( @@ -2335,7 +2335,7 @@ fn send_charging_customers_batch_works_zero_fees() { let usage5_charge = calculate_charge_for_month(cluster_id, usage5.clone()); let charge5 = calculate_charge_parts_for_month(cluster_id, usage5); let balance = Balances::free_balance(DdcPayouts::account_id()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(balance, usage5_charge + balance_before); assert_eq!( charge5.puts + before_total_customer_charge.puts, @@ -2484,7 +2484,7 @@ fn end_charging_customers_works() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge = calculate_charge_for_month(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, batch_index, customer_id: user1, amount: charge } @@ -2522,7 +2522,7 @@ fn end_charging_customers_works() { let transfers = 3 + 3 + 3 + 3 * 3; // for Currency::transfer assert_eq!(System::events().len(), 5 + 1 + 3 + transfers); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let total_left_from_one = (get_fees(&cluster_id).treasury_share + @@ -2658,7 +2658,7 @@ fn end_charging_customers_works_zero_fees() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge = calculate_charge_for_month(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, customer_id: user1, batch_index, amount: charge } @@ -2678,7 +2678,7 @@ fn end_charging_customers_works_zero_fees() { System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); assert_eq!(System::events().len(), 5 + 1); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let fees = get_fees(&cluster_id); @@ -2888,7 +2888,7 @@ fn begin_rewarding_providers_works() { end_era, )); - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -2922,7 +2922,7 @@ fn begin_rewarding_providers_works() { System::assert_last_event(Event::RewardingStarted { cluster_id, era }.into()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::RewardingProviders); }) } @@ -3175,14 +3175,14 @@ fn send_rewarding_providers_batch_works() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_ok!(DdcPayouts::end_charging_customers( RuntimeOrigin::signed(dac_account), cluster_id, era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -3245,7 +3245,7 @@ fn send_rewarding_providers_batch_works() { let balance_node1 = Balances::free_balance(node1); assert_eq!(balance_node1, transfer_charge + storage_charge + puts_charge + gets_charge); - let mut report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report_reward = ActiveBillingReports::::get(cluster_id, era).unwrap(); System::assert_has_event( Event::ProviderRewarded { @@ -3336,7 +3336,7 @@ fn send_rewarding_providers_batch_works() { ); gets_charge = ratio3_gets * report_after.total_customer_charge.gets; - report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report_reward = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance_node3 = Balances::free_balance(node3); assert_eq!(balance_node3, transfer_charge + storage_charge + puts_charge + gets_charge); @@ -3533,7 +3533,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -3546,7 +3546,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -3807,7 +3807,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -3820,7 +3820,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4081,7 +4081,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -4094,7 +4094,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4314,7 +4314,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -4327,7 +4327,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4630,7 +4630,7 @@ fn end_rewarding_providers_works() { end_era, )); - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -4678,7 +4678,7 @@ fn end_rewarding_providers_works() { System::assert_last_event(Event::RewardingFinished { cluster_id, era }.into()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::ProvidersRewarded); }) } @@ -4858,7 +4858,7 @@ fn end_billing_report_works() { end_era, )); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -4912,7 +4912,7 @@ fn end_billing_report_works() { System::assert_last_event(Event::BillingReportFinalized { cluster_id, era }.into()); - let report_end = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_end = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert!(report_end.rewarding_processed_batches.is_empty()); assert!(report_end.charging_processed_batches.is_empty()); assert_eq!(report_end.state, State::Finalized); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ae4ae6d5f..4e8523908 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -190,44 +190,36 @@ pub mod pallet { /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] - #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] - #[pallet::getter(fn ledger)] pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; /// The map of (wannabe) Storage nodes participants stash keys to the DDC cluster ID they /// wish to participate into. #[pallet::storage] - #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// Map from DDC node ID to the node operator stash account. #[pallet::storage] - #[pallet::getter(fn nodes)] pub type Nodes = StorageMap<_, Twox64Concat, NodePubKey, T::AccountId>; /// Map from operator stash account to DDC node ID. #[pallet::storage] - #[pallet::getter(fn providers)] pub type Providers = StorageMap<_, Twox64Concat, T::AccountId, NodePubKey>; /// Map of Storage node provider stash accounts that aim to leave a cluster #[pallet::storage] - #[pallet::getter(fn leaving_storages)] pub type LeavingStorages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// Map from all clusters locked "stash" accounts to the controller account. #[pallet::storage] - #[pallet::getter(fn cluster_bonded)] pub type ClusterBonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; /// Map of all clusters staking ledgers. #[pallet::storage] - #[pallet::getter(fn cluster_ledger)] pub type ClusterLedger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; @@ -470,7 +462,7 @@ pub mod pallet { #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, @@ -490,7 +482,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let min_active_bond = if let Some(cluster_id) = Self::storages(&ledger.stash) { + let min_active_bond = if let Some(cluster_id) = Storages::::get(&ledger.stash) { let bond_size = T::ClusterProtocol::get_bond_size(&cluster_id, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; @@ -580,7 +572,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::withdraw_unbonded())] pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); let node_pub_key = >::get(stash.clone()).ok_or(Error::::BadState)?; @@ -639,7 +631,7 @@ pub mod pallet { Error::::NoCluster ); - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterProtocol::get_bond_size(&cluster_id, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; @@ -657,7 +649,7 @@ pub mod pallet { ); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::storages(stash) { + if let Some(current_cluster) = Storages::::get(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -695,11 +687,11 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; let current_block = >::block_number(); // Extract delay from the cluster settings. - let (cluster, delay) = if let Some(cluster) = Self::storages(&ledger.stash) { + let (cluster, delay) = if let Some(cluster) = Storages::::get(&ledger.stash) { let chill_delay = T::ClusterProtocol::get_chill_delay(&cluster, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; (cluster, chill_delay) @@ -749,7 +741,7 @@ pub mod pallet { controller: ::Source, ) -> DispatchResult { let stash = ensure_signed(origin)?; - let old_controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; + let old_controller = Bonded::::get(&stash).ok_or(Error::::NotStash)?; let controller = T::Lookup::lookup(controller)?; if >::contains_key(&controller) { Err(Error::::AlreadyPaired)? @@ -877,7 +869,8 @@ pub mod pallet { ensure!(controller == cluster_controller, Error::::NotController); - let mut ledger = Self::cluster_ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = + ClusterLedger::::get(&controller).ok_or(Error::::NotController)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -923,7 +916,8 @@ pub mod pallet { let controller = T::ClusterManager::get_manager_account_id(&cluster_id)?; ensure!(controller == cluster_controller, Error::::NotController); - let mut ledger = Self::cluster_ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = + ClusterLedger::::get(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); ledger = ledger.consolidate_unlocked(>::block_number()); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 982e826ad..7cf0612a5 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -9,7 +9,6 @@ use ddc_primitives::{ use frame_support::{ construct_runtime, derive_impl, traits::{ConstBool, ConstU32, ConstU64, Nothing}, - weights::constants::RocksDbWeight, }; use frame_system::{ mocking::{MockBlock, MockUncheckedExtrinsic}, @@ -17,7 +16,6 @@ use frame_system::{ }; use pallet_ddc_clusters::cluster::Cluster; use pallet_ddc_nodes::StorageNode; -use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ traits::{Convert, IdentifyAccount, IdentityLookup, Verify}, @@ -69,10 +67,7 @@ type BalanceOf = <::Currency as Currency< #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type DbWeight = RocksDbWeight; - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = AccountId; type Lookup = IdentityLookup; type BlockHashCount = ConstU64<250>; @@ -494,7 +489,7 @@ fn check_ledgers() { fn assert_ledger_consistent(controller: AccountId) { // ensures ledger.total == ledger.active + sum(ledger.unlocking). - let ledger = DdcStaking::ledger(controller.clone()).expect("Not a controller."); + let ledger = Ledger::::get(controller.clone()).expect("Not a controller."); let real_total: Balance = ledger.unlocking.iter().fold(ledger.active, |a, c| a + c.value); assert_eq!(real_total, ledger.total); assert!( diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index c48f89196..4952da4b8 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -8,7 +8,7 @@ use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; use pallet_ddc_clusters::{ cluster::{Cluster, ClusterProps}, - Error as ClustersError, + Clusters, Error as ClustersError, }; use super::{mock::*, *}; @@ -37,20 +37,20 @@ fn basic_setup_works() { ExtBuilder.build_and_execute(clusters, nodes, clusters_bonds, nodes_bondes, || { // Account 11 is stashed and locked, and account 10 is the controller assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); // Account 21 is stashed and locked, and account 20 is the controller assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_2)), + Bonded::::get(AccountId::from(NODE_STASH_2)), Some(AccountId::from(NODE_CONTROLLER_2)) ); // Account 1 is not a stashed - assert_eq!(DdcStaking::bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(Bonded::::get(AccountId::from(USER_KEY_1)), None); // Account 10 controls the stash from account 11, which is 100 units assert_eq!( - DdcStaking::ledger(AccountId::from(NODE_CONTROLLER_1)), + Ledger::::get(AccountId::from(NODE_CONTROLLER_1)), Some(StakingLedger { stash: AccountId::from(NODE_STASH_1), total: 100, @@ -61,7 +61,7 @@ fn basic_setup_works() { ); // Account 20 controls the stash from account 21, which is 100 units assert_eq!( - DdcStaking::ledger(AccountId::from(NODE_CONTROLLER_2)), + Ledger::::get(AccountId::from(NODE_CONTROLLER_2)), Some(StakingLedger { stash: AccountId::from(NODE_STASH_2), total: 100, @@ -71,7 +71,7 @@ fn basic_setup_works() { }) ); // Account 1 does not control any stash - assert_eq!(DdcStaking::ledger(AccountId::from(USER_KEY_1)), None); + assert_eq!(Ledger::::get(AccountId::from(USER_KEY_1)), None); }); } @@ -81,7 +81,7 @@ fn change_controller_works() { ExtBuilder.build_and_execute(clusters, nodes, clusters_bonds, nodes_bondes, || { // 10 and 11 are bonded as stash controller. assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); @@ -103,7 +103,7 @@ fn change_controller_works() { Error::::AlreadyPaired ); assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(USER_KEY_3)) ); @@ -250,7 +250,7 @@ fn set_node_works() { System::set_block_number(1); // 10 and 11 are bonded as stash controller. assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); @@ -427,11 +427,11 @@ fn staking_should_work() { // Account 4 controls the stash from account 3, which is 1500 units, 3 is a Storage // participant, 5 is a DDC node. assert_eq!( - DdcStaking::bonded(AccountId::from(USER_KEY_3)), + Bonded::::get(AccountId::from(USER_KEY_3)), Some(AccountId::from(USER_KEY_4)) ); assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -441,11 +441,11 @@ fn staking_should_work() { }) ); assert_eq!( - DdcStaking::storages(AccountId::from(USER_KEY_3)), + Storages::::get(AccountId::from(USER_KEY_3)), Some(ClusterId::from(CLUSTER_ID)) ); assert_eq!( - DdcStaking::nodes(NodePubKey::StoragePubKey(StorageNodePubKey::new(NODE_KEY_5))), + Nodes::::get(NodePubKey::StoragePubKey(StorageNodePubKey::new(NODE_KEY_5))), Some(AccountId::from(USER_KEY_3)) ); @@ -463,7 +463,7 @@ fn staking_should_work() { // TestClusterProtocol::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage) // .unwrap_or(10_u64); assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -499,7 +499,7 @@ fn staking_should_work() { // Ledger is not changed until we make another call to `chill`. assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -514,7 +514,7 @@ fn staking_should_work() { System::assert_last_event(Event::Chilled(AccountId::from(USER_KEY_3)).into()); // Account 3 is no longer a Storage participant. - assert_eq!(DdcStaking::storages(AccountId::from(USER_KEY_3)), None); + assert_eq!(Storages::::get(AccountId::from(USER_KEY_3)), None); }); } @@ -569,8 +569,8 @@ fn storage_full_unbonding_works() { )); System::assert_last_event(Event::Activated(provider_stash.clone()).into()); - assert_eq!(DdcStaking::storages(provider_stash.clone()), Some(cluster_id)); - assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash.clone())); + assert_eq!(Storages::::get(provider_stash.clone()), Some(cluster_id)); + assert_eq!(Nodes::::get(node_pub_key), Some(provider_stash.clone())); // Set block timestamp. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); @@ -593,7 +593,7 @@ fn storage_full_unbonding_works() { System::assert_last_event(Event::Chilled(provider_stash.clone()).into()); // Account is no longer a Storage participant. - assert_eq!(DdcStaking::storages(provider_stash.clone()), None); + assert_eq!(Storages::::get(provider_stash.clone()), None); // Start unbonding all tokens assert_ok!(DdcStaking::unbond( @@ -601,7 +601,7 @@ fn storage_full_unbonding_works() { storage_bond_size )); System::assert_has_event(Event::LeaveSoon(provider_stash.clone()).into()); - assert_eq!(DdcStaking::leaving_storages(provider_stash.clone()), Some(cluster_id)); + assert_eq!(LeavingStorages::::get(provider_stash.clone()), Some(cluster_id)); System::assert_last_event( Event::Unbonded(provider_stash.clone(), storage_bond_size).into(), ); @@ -619,7 +619,7 @@ fn storage_full_unbonding_works() { System::assert_has_event( Event::Withdrawn(provider_stash.clone(), storage_bond_size).into(), ); - assert_eq!(DdcStaking::leaving_storages(provider_stash.clone()), None); + assert_eq!(LeavingStorages::::get(provider_stash.clone()), None); System::assert_last_event(Event::Left(provider_stash).into()); }); } @@ -742,12 +742,12 @@ fn bond_cluster_works() { )); assert_eq!( - DdcStaking::cluster_bonded(AccountId::from(CLUSTER_STASH)), + ClusterBonded::::get(AccountId::from(CLUSTER_STASH)), Some(AccountId::from(CLUSTER_CONTROLLER)) ); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(CLUSTER_CONTROLLER)), + ClusterLedger::::get(AccountId::from(CLUSTER_CONTROLLER)), Some(StakingLedger { stash: AccountId::from(CLUSTER_STASH), total: 50, @@ -760,7 +760,7 @@ fn bond_cluster_works() { System::assert_has_event(Event::Bonded(AccountId::from(CLUSTER_STASH), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(CLUSTER_ID)), + Clusters::::get(ClusterId::from(CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(CLUSTER_ID), manager_id: AccountId::from(CLUSTER_CONTROLLER), @@ -896,7 +896,7 @@ fn unbond_bonded_cluster_works() { unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -909,7 +909,7 @@ fn unbond_bonded_cluster_works() { System::assert_has_event(Event::Unbonded(AccountId::from(USER_KEY_1), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(BONDED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(BONDED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(BONDED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -975,7 +975,7 @@ fn unbond_activated_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -988,7 +988,7 @@ fn unbond_activated_cluster_works() { System::assert_has_event(Event::Unbonded(AccountId::from(USER_KEY_1), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(ACTIVATED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(ACTIVATED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(ACTIVATED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -1059,7 +1059,7 @@ fn withdraw_unbonded_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -1078,11 +1078,11 @@ fn withdraw_unbonded_cluster_works() { System::assert_last_event(Event::Withdrawn(AccountId::from(USER_KEY_1), 50).into()); - assert_eq!(DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), None); - assert_eq!(DdcStaking::cluster_bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); assert_eq!( - DdcClusters::clusters(ClusterId::from(BONDED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(BONDED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(BONDED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -1145,7 +1145,7 @@ fn withdraw_activated_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -1164,11 +1164,11 @@ fn withdraw_activated_cluster_works() { System::assert_last_event(Event::Withdrawn(AccountId::from(USER_KEY_1), 50).into()); - assert_eq!(DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), None); - assert_eq!(DdcStaking::cluster_bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); assert_eq!( - DdcClusters::clusters(ClusterId::from(ACTIVATED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(ACTIVATED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(ACTIVATED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index 239251f12..da2d0ce4b 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -12,6 +12,7 @@ use frame_system::{ensure_signed, pallet_prelude::*}; pub use pallet::*; use pallet_chainbridge as bridge; use pallet_erc721 as erc721; +use pallet_erc721::Tokens; use sp_arithmetic::traits::SaturatedConversion; use sp_core::U256; use sp_std::prelude::*; @@ -121,7 +122,7 @@ pub mod pallet { ) -> DispatchResult { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - match >::tokens(token_id) { + match Tokens::::get(token_id) { Some(token) => { >::burn_token(source, token_id)?; let resource_id = T::Erc721Id::get(); diff --git a/pallets/erc20/src/mock.rs b/pallets/erc20/src/mock.rs index 914bb2f3e..fd3f7d2a5 100644 --- a/pallets/erc20/src/mock.rs +++ b/pallets/erc20/src/mock.rs @@ -23,13 +23,8 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type Origin = Origin; - type Call = Call; - type Nonce = u64; - type Block = u64; - type Hash = H256; + type Block = Block; type AccountId = u64; - type Lookup = IdentityLookup; type Event = Event; type BlockHashCount = BlockHashCount; type MaximumBlockWeight = MaximumBlockWeight; diff --git a/pallets/erc20/src/tests.rs b/pallets/erc20/src/tests.rs index 5643698da..f892b8630 100644 --- a/pallets/erc20/src/tests.rs +++ b/pallets/erc20/src/tests.rs @@ -84,7 +84,7 @@ fn transfer_erc721() { // Create a token assert_ok!(Erc721::mint(Origin::root(), RELAYER_A, token_id, metadata.clone())); assert_eq!( - Erc721::tokens(token_id).unwrap(), + Tokens::::get(token_id).unwrap(), Erc721Token { id: token_id, metadata: metadata.clone() } ); @@ -107,7 +107,7 @@ fn transfer_erc721() { )); // Ensure token no longer exists - assert_eq!(Erc721::tokens(token_id), None); + assert_eq!(Tokens::::get(token_id), None); // Transfer should fail as token doesn't exist assert_noop!( @@ -198,7 +198,7 @@ fn mint_erc721() { let bridge_id: u64 = Bridge::account_id(); // Token doesn't yet exist - assert_eq!(Erc721::tokens(token_id), None); + assert_eq!(Tokens::::get(token_id), None); // Mint assert_ok!(Example::mint_erc721( Origin::signed(bridge_id), @@ -208,7 +208,7 @@ fn mint_erc721() { )); // Ensure token exists assert_eq!( - Erc721::tokens(token_id).unwrap(), + Tokens::::get(token_id).unwrap(), Erc721Token { id: token_id, metadata: metadata.clone() } ); // Cannot mint same token diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index 655277074..e71a2fc74 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -49,12 +49,10 @@ pub mod pallet { /// Maps tokenId to Erc721 object #[pallet::storage] - #[pallet::getter(fn tokens)] pub type Tokens = StorageMap<_, Blake2_256, TokenId, Erc721Token>; /// Maps tokenId to owner #[pallet::storage] - #[pallet::getter(fn owner_of)] pub type TokenOwner = StorageMap<_, Blake2_256, TokenId, T::AccountId>; #[pallet::type_value] @@ -63,7 +61,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn token_count)] pub type TokenCount = StorageValue>; @@ -123,7 +120,7 @@ pub mod pallet { pub fn burn(origin: OriginFor, id: TokenId) -> DispatchResult { ensure_root(origin)?; - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; Self::burn_token(owner, id)?; @@ -151,7 +148,7 @@ pub mod pallet { /// Modifies ownership of a token pub fn transfer_from(from: T::AccountId, to: T::AccountId, id: TokenId) -> DispatchResult { // Check from is owner and token exists - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); // Update owner >::insert(id, to.clone()); @@ -163,7 +160,7 @@ pub mod pallet { /// Deletes a token from the system. pub fn burn_token(from: T::AccountId, id: TokenId) -> DispatchResult { - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); >::remove(id); diff --git a/pallets/erc721/src/mock.rs b/pallets/erc721/src/mock.rs index 429681476..a7ec7e8f5 100644 --- a/pallets/erc721/src/mock.rs +++ b/pallets/erc721/src/mock.rs @@ -4,8 +4,8 @@ use frame_support::{derive_impl, ord_parameter_types, parameter_types, weights:: use frame_system::{self as system}; pub use pallet_balances as balances; use pallet_chainbridge as bridge; -use sp_core::{hashing::blake2_128, H256}; -use sp_runtime::{testing::Header, traits::IdentityLookup, BuildStorage, Perbill}; +use sp_core::hashing::blake2_128; +use sp_runtime::{testing::Header, BuildStorage, Perbill}; use crate::{self as erc721, Config}; @@ -18,16 +18,8 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BlockWeights = (); - type BlockLength = (); - type Nonce = u64; type Block = Block; - type Hash = H256; type AccountId = u64; - type Lookup = IdentityLookup; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); type AccountData = balances::AccountData; type MaxConsumers = frame_support::traits::ConstU32<16>; } diff --git a/pallets/erc721/src/tests.rs b/pallets/erc721/src/tests.rs index e4bfb0ca0..e881a6679 100644 --- a/pallets/erc721/src/tests.rs +++ b/pallets/erc721/src/tests.rs @@ -18,10 +18,10 @@ fn mint_burn_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); assert_eq!( - Erc721::tokens(id_a).unwrap(), + Tokens::::get(id_a).unwrap(), Erc721Token { id: id_a, metadata: metadata_a.clone() } ); - assert_eq!(Erc721::token_count(), 1.into()); + assert_eq!(TokenCount::::get(), 1.into()); assert_noop!( Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a), Error::::TokenAlreadyExists @@ -29,22 +29,22 @@ fn mint_burn_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); assert_eq!( - Erc721::tokens(id_b).unwrap(), + Tokens::::get(id_b).unwrap(), Erc721Token { id: id_b, metadata: metadata_b.clone() } ); - assert_eq!(Erc721::token_count(), 2.into()); + assert_eq!(TokenCount::::get(), 2.into()); assert_noop!( Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b), Error::::TokenAlreadyExists ); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a)); - assert_eq!(Erc721::token_count(), 1.into()); + assert_eq!(TokenCount::::get(), 1.into()); assert!(!>::contains_key(id_a)); assert!(!>::contains_key(id_a)); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b)); - assert_eq!(Erc721::token_count(), 0.into()); + assert_eq!(TokenCount::::get(), 0.into()); assert!(!>::contains_key(id_b)); assert!(!>::contains_key(id_b)); }) @@ -62,15 +62,15 @@ fn transfer_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b)); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); + assert_eq!(TokenOwner::::get(id_a).unwrap(), USER_B); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_C, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_C); + assert_eq!(TokenOwner::::get(id_b).unwrap(), USER_C); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_B), USER_A, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_A); + assert_eq!(TokenOwner::::get(id_a).unwrap(), USER_A); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_C), USER_A, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_A); + assert_eq!(TokenOwner::::get(id_b).unwrap(), USER_A); }) } diff --git a/runtime/cere-dev/build.rs b/runtime/cere-dev/build.rs index b773ed9cf..2b3e7664a 100644 --- a/runtime/cere-dev/build.rs +++ b/runtime/cere-dev/build.rs @@ -15,12 +15,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use substrate_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3fd251215..ab6e7109e 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -28,7 +28,7 @@ use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, onchain, BalancingConfig, SequentialPhragmen, VoteWeight, }; use frame_support::{ - construct_runtime, derive_impl, + derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Get, @@ -148,7 +148,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 66000, + spec_version: 66001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 18, @@ -461,6 +461,8 @@ parameter_types! { pub MaximumMultiplier: Multiplier = Bounded::max_value(); } +// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles +// impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; #[allow(deprecated)] @@ -1285,61 +1287,164 @@ impl, T: frame_system::Config> GetDdcOrigin } } -construct_runtime!( - pub enum Runtime - { - System: frame_system, - Utility: pallet_utility, - Babe: pallet_babe, - Timestamp: pallet_timestamp, - // Authorship must be before session in order to note author in the correct session and era - // for im-online and staking. - Authorship: pallet_authorship, - Indices: pallet_indices, - Balances: pallet_balances, - TransactionPayment: pallet_transaction_payment, - ElectionProviderMultiPhase: pallet_election_provider_multi_phase, - Staking: pallet_staking, - Session: pallet_session, - Grandpa: pallet_grandpa, - Treasury: pallet_treasury, - Contracts: pallet_contracts, - Sudo: pallet_sudo, - ImOnline: pallet_im_online, - AuthorityDiscovery: pallet_authority_discovery, - Offences: pallet_offences, - Historical: pallet_session_historical::{Pallet}, - RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, - Identity: pallet_identity, - Recovery: pallet_recovery, - Vesting: pallet_vesting, - Preimage: pallet_preimage, - Scheduler: pallet_scheduler, - Proxy: pallet_proxy, - Multisig: pallet_multisig, - Bounties: pallet_bounties, - VoterList: pallet_bags_list::, - ChildBounties: pallet_child_bounties, - NominationPools: pallet_nomination_pools, - FastUnstake: pallet_fast_unstake, - ChainBridge: pallet_chainbridge::{Pallet, Call, Storage, Event}, - Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, - Erc20: pallet_erc20::{Pallet, Call, Storage, Event}, - DdcStaking: pallet_ddc_staking, - DdcCustomers: pallet_ddc_customers, - DdcNodes: pallet_ddc_nodes, - DdcClusters: pallet_ddc_clusters, - DdcPayouts: pallet_ddc_payouts, - // Start OpenGov. - ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event}, - Referenda: pallet_referenda::{Pallet, Call, Storage, Event}, - Origins: pallet_origins::{Origin}, - Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event}, - // End OpenGov. - TechComm: pallet_collective::, - DdcClustersGov: pallet_ddc_clusters_gov, - } -); +#[frame_support::runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Runtime; + + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + #[runtime::pallet_index(1)] + pub type Utility = pallet_utility::Pallet; + + #[runtime::pallet_index(2)] + pub type Babe = pallet_babe::Pallet; + + #[runtime::pallet_index(3)] + pub type Timestamp = pallet_timestamp::Pallet; + + // Authorship must be before session in order to note author in the correct session and era + // for im-online and staking. + #[runtime::pallet_index(4)] + pub type Authorship = pallet_authorship::Pallet; + + #[runtime::pallet_index(5)] + pub type Indices = pallet_indices::Pallet; + + #[runtime::pallet_index(6)] + pub type Balances = pallet_balances::Pallet; + + #[runtime::pallet_index(7)] + pub type TransactionPayment = pallet_transaction_payment::Pallet; + + #[runtime::pallet_index(8)] + pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase::Pallet; + + #[runtime::pallet_index(9)] + pub type Staking = pallet_staking::Pallet; + + #[runtime::pallet_index(10)] + pub type Session = pallet_session::Pallet; + + #[runtime::pallet_index(11)] + pub type Grandpa = pallet_grandpa::Pallet; + + #[runtime::pallet_index(12)] + pub type Treasury = pallet_treasury::Pallet; + + #[runtime::pallet_index(13)] + pub type Contracts = pallet_contracts::Pallet; + + #[runtime::pallet_index(14)] + pub type Sudo = pallet_sudo::Pallet; + + #[runtime::pallet_index(15)] + pub type ImOnline = pallet_im_online::Pallet; + + #[runtime::pallet_index(16)] + pub type AuthorityDiscovery = pallet_authority_discovery::Pallet; + + #[runtime::pallet_index(17)] + pub type Offences = pallet_offences::Pallet; + + #[runtime::pallet_index(18)] + pub type Historical = pallet_session_historical::Pallet; + + #[runtime::pallet_index(19)] + pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet; + + #[runtime::pallet_index(20)] + pub type Identity = pallet_identity::Pallet; + + #[runtime::pallet_index(21)] + pub type Recovery = pallet_recovery::Pallet; + + #[runtime::pallet_index(22)] + pub type Vesting = pallet_vesting::Pallet; + + #[runtime::pallet_index(23)] + pub type Preimage = pallet_preimage::Pallet; + + #[runtime::pallet_index(24)] + pub type Scheduler = pallet_scheduler::Pallet; + + #[runtime::pallet_index(25)] + pub type Proxy = pallet_proxy::Pallet; + + #[runtime::pallet_index(26)] + pub type Multisig = pallet_multisig::Pallet; + + #[runtime::pallet_index(27)] + pub type Bounties = pallet_bounties::Pallet; + + #[runtime::pallet_index(28)] + pub type VoterList = pallet_bags_list::Pallet; + + #[runtime::pallet_index(29)] + pub type ChildBounties = pallet_child_bounties::Pallet; + + #[runtime::pallet_index(30)] + pub type NominationPools = pallet_nomination_pools::Pallet; + + #[runtime::pallet_index(31)] + pub type FastUnstake = pallet_fast_unstake::Pallet; + + #[runtime::pallet_index(32)] + pub type ChainBridge = pallet_chainbridge::Pallet; + + #[runtime::pallet_index(33)] + pub type Erc721 = pallet_erc721::Pallet; + + #[runtime::pallet_index(34)] + pub type Erc20 = pallet_erc20::Pallet; + + #[runtime::pallet_index(35)] + pub type DdcStaking = pallet_ddc_staking::Pallet; + + #[runtime::pallet_index(36)] + pub type DdcCustomers = pallet_ddc_customers::Pallet; + + #[runtime::pallet_index(37)] + pub type DdcNodes = pallet_ddc_nodes::Pallet; + + #[runtime::pallet_index(38)] + pub type DdcClusters = pallet_ddc_clusters::Pallet; + + #[runtime::pallet_index(39)] + pub type DdcPayouts = pallet_ddc_payouts::Pallet; + + // Start OpenGov. + #[runtime::pallet_index(40)] + pub type ConvictionVoting = pallet_conviction_voting::Pallet; + + #[runtime::pallet_index(41)] + pub type Referenda = pallet_referenda::Pallet; + + #[runtime::pallet_index(42)] + pub type Origins = pallet_origins::Pallet; + + #[runtime::pallet_index(43)] + pub type Whitelist = pallet_whitelist::Pallet; + + // End OpenGov. + #[runtime::pallet_index(44)] + pub type TechComm = pallet_collective::Pallet; + + #[runtime::pallet_index(45)] + pub type DdcClustersGov = pallet_ddc_clusters_gov::Pallet; +} /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; diff --git a/runtime/cere/build.rs b/runtime/cere/build.rs index b773ed9cf..2b3e7664a 100644 --- a/runtime/cere/build.rs +++ b/runtime/cere/build.rs @@ -15,12 +15,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use substrate_wasm_builder::WasmBuilder; - fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 649a9a51f..decb24321 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -27,7 +27,7 @@ use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, onchain, BalancingConfig, SequentialPhragmen, VoteWeight, }; use frame_support::{ - construct_runtime, derive_impl, + derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Get, @@ -143,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 66000, + spec_version: 66001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 18, @@ -456,6 +456,8 @@ parameter_types! { pub MaximumMultiplier: Multiplier = Bounded::max_value(); } +// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles +// impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; #[allow(deprecated)] @@ -1288,61 +1290,164 @@ impl, T: frame_system::Config> GetDdcOrigin } } -construct_runtime!( - pub enum Runtime - { - System: frame_system, - Utility: pallet_utility, - Babe: pallet_babe, - Timestamp: pallet_timestamp, - // Authorship must be before session in order to note author in the correct session and era - // for im-online and staking. - Authorship: pallet_authorship, - Indices: pallet_indices, - Balances: pallet_balances, - TransactionPayment: pallet_transaction_payment, - ElectionProviderMultiPhase: pallet_election_provider_multi_phase, - Staking: pallet_staking, - Session: pallet_session, - Grandpa: pallet_grandpa, - Treasury: pallet_treasury, - Contracts: pallet_contracts, - Sudo: pallet_sudo, - ImOnline: pallet_im_online, - AuthorityDiscovery: pallet_authority_discovery, - Offences: pallet_offences, - Historical: pallet_session_historical::{Pallet}, - RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, - Identity: pallet_identity, - Recovery: pallet_recovery, - Vesting: pallet_vesting, - Preimage: pallet_preimage, - Scheduler: pallet_scheduler, - Proxy: pallet_proxy, - Multisig: pallet_multisig, - Bounties: pallet_bounties, - VoterList: pallet_bags_list::, - ChildBounties: pallet_child_bounties, - NominationPools: pallet_nomination_pools, - FastUnstake: pallet_fast_unstake, - ChainBridge: pallet_chainbridge::{Pallet, Call, Storage, Event}, - Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, - Erc20: pallet_erc20::{Pallet, Call, Storage, Event}, - DdcStaking: pallet_ddc_staking, - DdcCustomers: pallet_ddc_customers, - DdcNodes: pallet_ddc_nodes, - DdcClusters: pallet_ddc_clusters, - DdcPayouts: pallet_ddc_payouts, - // Start OpenGov. - ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event}, - Referenda: pallet_referenda::{Pallet, Call, Storage, Event}, - Origins: pallet_origins::{Origin}, - Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event}, - // End OpenGov. - TechComm: pallet_collective::, - DdcClustersGov: pallet_ddc_clusters_gov, - } -); +#[frame_support::runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Runtime; + + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + #[runtime::pallet_index(1)] + pub type Utility = pallet_utility::Pallet; + + #[runtime::pallet_index(2)] + pub type Babe = pallet_babe::Pallet; + + #[runtime::pallet_index(3)] + pub type Timestamp = pallet_timestamp::Pallet; + + // Authorship must be before session in order to note author in the correct session and era + // for im-online and staking. + #[runtime::pallet_index(4)] + pub type Authorship = pallet_authorship::Pallet; + + #[runtime::pallet_index(5)] + pub type Indices = pallet_indices::Pallet; + + #[runtime::pallet_index(6)] + pub type Balances = pallet_balances::Pallet; + + #[runtime::pallet_index(7)] + pub type TransactionPayment = pallet_transaction_payment::Pallet; + + #[runtime::pallet_index(8)] + pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase::Pallet; + + #[runtime::pallet_index(9)] + pub type Staking = pallet_staking::Pallet; + + #[runtime::pallet_index(10)] + pub type Session = pallet_session::Pallet; + + #[runtime::pallet_index(11)] + pub type Grandpa = pallet_grandpa::Pallet; + + #[runtime::pallet_index(12)] + pub type Treasury = pallet_treasury::Pallet; + + #[runtime::pallet_index(13)] + pub type Contracts = pallet_contracts::Pallet; + + #[runtime::pallet_index(14)] + pub type Sudo = pallet_sudo::Pallet; + + #[runtime::pallet_index(15)] + pub type ImOnline = pallet_im_online::Pallet; + + #[runtime::pallet_index(16)] + pub type AuthorityDiscovery = pallet_authority_discovery::Pallet; + + #[runtime::pallet_index(17)] + pub type Offences = pallet_offences::Pallet; + + #[runtime::pallet_index(18)] + pub type Historical = pallet_session_historical::Pallet; + + #[runtime::pallet_index(19)] + pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet; + + #[runtime::pallet_index(20)] + pub type Identity = pallet_identity::Pallet; + + #[runtime::pallet_index(21)] + pub type Recovery = pallet_recovery::Pallet; + + #[runtime::pallet_index(22)] + pub type Vesting = pallet_vesting::Pallet; + + #[runtime::pallet_index(23)] + pub type Preimage = pallet_preimage::Pallet; + + #[runtime::pallet_index(24)] + pub type Scheduler = pallet_scheduler::Pallet; + + #[runtime::pallet_index(25)] + pub type Proxy = pallet_proxy::Pallet; + + #[runtime::pallet_index(26)] + pub type Multisig = pallet_multisig::Pallet; + + #[runtime::pallet_index(27)] + pub type Bounties = pallet_bounties::Pallet; + + #[runtime::pallet_index(28)] + pub type VoterList = pallet_bags_list::Pallet; + + #[runtime::pallet_index(29)] + pub type ChildBounties = pallet_child_bounties::Pallet; + + #[runtime::pallet_index(30)] + pub type NominationPools = pallet_nomination_pools::Pallet; + + #[runtime::pallet_index(31)] + pub type FastUnstake = pallet_fast_unstake::Pallet; + + #[runtime::pallet_index(32)] + pub type ChainBridge = pallet_chainbridge::Pallet; + + #[runtime::pallet_index(33)] + pub type Erc721 = pallet_erc721::Pallet; + + #[runtime::pallet_index(34)] + pub type Erc20 = pallet_erc20::Pallet; + + #[runtime::pallet_index(35)] + pub type DdcStaking = pallet_ddc_staking::Pallet; + + #[runtime::pallet_index(36)] + pub type DdcCustomers = pallet_ddc_customers::Pallet; + + #[runtime::pallet_index(37)] + pub type DdcNodes = pallet_ddc_nodes::Pallet; + + #[runtime::pallet_index(38)] + pub type DdcClusters = pallet_ddc_clusters::Pallet; + + #[runtime::pallet_index(39)] + pub type DdcPayouts = pallet_ddc_payouts::Pallet; + + // Start OpenGov. + #[runtime::pallet_index(40)] + pub type ConvictionVoting = pallet_conviction_voting::Pallet; + + #[runtime::pallet_index(41)] + pub type Referenda = pallet_referenda::Pallet; + + #[runtime::pallet_index(42)] + pub type Origins = pallet_origins::Pallet; + + #[runtime::pallet_index(43)] + pub type Whitelist = pallet_whitelist::Pallet; + + // End OpenGov. + #[runtime::pallet_index(44)] + pub type TechComm = pallet_collective::Pallet; + + #[runtime::pallet_index(45)] + pub type DdcClustersGov = pallet_ddc_clusters_gov::Pallet; +} /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress;