From 73e83503aaf39c2421490dafcdd4710f2f308d27 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Thu, 11 Jan 2024 16:29:05 +0100 Subject: [PATCH 1/4] added storage and dispatchable for setting timestamp --- Cargo.lock | 80 ++++++++++++++++++++--------------------- parentchain/src/lib.rs | 24 +++++++++++++ parentchain/src/mock.rs | 2 ++ 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ca05c8c..ff9165c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -873,7 +873,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-support-procedural", @@ -910,7 +910,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bitflags 1.3.2", "environmental", @@ -943,7 +943,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "cfg-expr", @@ -959,7 +959,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -971,7 +971,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -981,7 +981,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "log", @@ -1786,7 +1786,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -1955,7 +1955,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -1973,7 +1973,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -2813,7 +2813,7 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db", "log", @@ -2833,7 +2833,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "blake2", @@ -2847,7 +2847,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -2860,7 +2860,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "integer-sqrt", "num-traits", @@ -2874,7 +2874,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -2887,7 +2887,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -2899,7 +2899,7 @@ dependencies = [ [[package]] name = "sp-core" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "array-bytes", "bitflags 1.3.2", @@ -2943,7 +2943,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "blake2b_simd", "byteorder", @@ -2957,7 +2957,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -2968,7 +2968,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -2978,7 +2978,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "environmental", "parity-scale-codec", @@ -2989,7 +2989,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -3004,7 +3004,7 @@ dependencies = [ [[package]] name = "sp-io" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes", "ed25519", @@ -3030,7 +3030,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "lazy_static", "sp-core", @@ -3041,7 +3041,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "futures", "parity-scale-codec", @@ -3055,7 +3055,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -3066,7 +3066,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "backtrace", "lazy_static", @@ -3076,7 +3076,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "either", "hash256-std-hasher", @@ -3098,7 +3098,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "proc-macro-crate", @@ -3128,7 +3128,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -3141,7 +3141,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db", "log", @@ -3161,12 +3161,12 @@ dependencies = [ [[package]] name = "sp-std" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" [[package]] name = "sp-storage" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -3179,7 +3179,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "futures-timer", @@ -3194,7 +3194,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-std", @@ -3206,7 +3206,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "ahash 0.8.6", "hash-db", @@ -3229,7 +3229,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -3246,7 +3246,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -3257,7 +3257,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -3271,7 +3271,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", diff --git a/parentchain/src/lib.rs b/parentchain/src/lib.rs index abb7d447..23e5f067 100644 --- a/parentchain/src/lib.rs +++ b/parentchain/src/lib.rs @@ -14,6 +14,7 @@ pub mod pallet { use crate::{weights::WeightInfo, ParentchainAccountData, ParentchainIndex}; use frame_support::{pallet_prelude::*, sp_runtime::traits::Header}; use frame_system::{pallet_prelude::*, AccountInfo}; + use sp_runtime::traits::{AtLeast32Bit, Scale}; const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::pallet] @@ -27,6 +28,15 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type WeightInfo: WeightInfo; + + /// Type used for expressing timestamp. + type Moment: Parameter + + Default + + AtLeast32Bit + + Scale + + Copy + + MaxEncodedLen + + scale_info::StaticTypeInfo; } #[pallet::event] @@ -85,6 +95,12 @@ pub mod pallet { pub(super) type Number, I: 'static = ()> = StorageValue<_, T::BlockNumber, OptionQuery>; + /// The current block timestamp. Set by `set_now`. + /// this is not guaranteed by the pallet to be consistent with block_number or hash + #[pallet::storage] + #[pallet::getter(fn now)] + pub(super) type Now, I: 'static = ()> = StorageValue<_, T::Moment, OptionQuery>; + /// Hash of the previous block. Set by `set_block`. #[pallet::storage] #[pallet::getter(fn parent_hash)] @@ -155,6 +171,14 @@ pub mod pallet { Self::deposit_event(crate::pallet::Event::AccountInfoForcedFor { account }); Ok(()) } + + #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::set_block())] + pub fn set_now(origin: OriginFor, now: T::Moment) -> DispatchResult { + ensure_root(origin)?; + >::put(now); + Ok(()) + } } } diff --git a/parentchain/src/mock.rs b/parentchain/src/mock.rs index a9280e60..ac618b0c 100644 --- a/parentchain/src/mock.rs +++ b/parentchain/src/mock.rs @@ -61,12 +61,14 @@ pub type ParentchainInstanceIntegritee = pallet_parentchain::Instance1; impl Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); + type Moment = u64; } pub type ParentchainInstanceTargetA = pallet_parentchain::Instance2; impl Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); + type Moment = u64; } parameter_types! { From cf342f1042738e6418d090f274c43240c36e07e6 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Thu, 11 Jan 2024 16:54:42 +0100 Subject: [PATCH 2/4] typo --- parentchain/src/lib.rs | 4 ++-- parentchain/src/tests.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parentchain/src/lib.rs b/parentchain/src/lib.rs index 23e5f067..bdb540b2 100644 --- a/parentchain/src/lib.rs +++ b/parentchain/src/lib.rs @@ -54,7 +54,7 @@ pub mod pallet { AccountInfoForcedFor { account: T::AccountId, }, - ParentchainGeneisInitialized { + ParentchainGenesisInitialized { hash: T::Hash, }, } @@ -155,7 +155,7 @@ pub mod pallet { Error::::GenesisAlreadyInitialized ); >::put(genesis); - Self::deposit_event(Event::ParentchainGeneisInitialized { hash: genesis }); + Self::deposit_event(Event::ParentchainGenesisInitialized { hash: genesis }); Ok(()) } diff --git a/parentchain/src/tests.rs b/parentchain/src/tests.rs index 1970369a..19b887a9 100644 --- a/parentchain/src/tests.rs +++ b/parentchain/src/tests.rs @@ -153,7 +153,7 @@ fn init_parentchain_genesis_hash_works() { assert_eq!(ParentchainIntegritee::parentchain_genesis_hash().unwrap(), genesis); System::assert_last_event(RuntimeEvent::ParentchainIntegritee( - ParentchainEvent::ParentchainGeneisInitialized { hash: genesis }, + ParentchainEvent::ParentchainGenesisInitialized { hash: genesis }, )); assert_noop!( ParentchainIntegritee::init_parentchain_genesis_hash(RuntimeOrigin::root(), genesis), From 173dac87cfc56cb1ce2ebc5398ac562c8f8c6d42 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 12 Jan 2024 09:21:37 +0100 Subject: [PATCH 3/4] add test --- parentchain/src/tests.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/parentchain/src/tests.rs b/parentchain/src/tests.rs index 19b887a9..bae7dfb8 100644 --- a/parentchain/src/tests.rs +++ b/parentchain/src/tests.rs @@ -189,3 +189,12 @@ fn force_account_info_works() { )); }) } + +#[test] +fn set_now_works() { + new_test_ext().execute_with(|| { + let now = 111u64; + assert_ok!(ParentchainIntegritee::set_now(RuntimeOrigin::root(), now)); + assert_eq!(ParentchainIntegritee::now(), Some(now)); + }) +} From 04470c60b4c2f01a8bb05a4f6542f07c73ec0b86 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 12 Jan 2024 09:26:48 +0100 Subject: [PATCH 4/4] fix weight info --- parentchain/src/lib.rs | 8 ++++---- parentchain/src/weights.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/parentchain/src/lib.rs b/parentchain/src/lib.rs index bdb540b2..3f07a373 100644 --- a/parentchain/src/lib.rs +++ b/parentchain/src/lib.rs @@ -134,7 +134,7 @@ pub mod pallet { } #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_block())] + #[pallet::weight(T::WeightInfo::init_shard_vault())] pub fn init_shard_vault(origin: OriginFor, account: T::AccountId) -> DispatchResult { ensure_root(origin)?; ensure!(Self::shard_vault().is_none(), Error::::ShardVaultAlreadyInitialized); @@ -144,7 +144,7 @@ pub mod pallet { } #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::set_block())] + #[pallet::weight(T::WeightInfo::init_parentchain_genesis_hash())] pub fn init_parentchain_genesis_hash( origin: OriginFor, genesis: T::Hash, @@ -160,7 +160,7 @@ pub mod pallet { } #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::set_block())] + #[pallet::weight(T::WeightInfo::force_account_info())] pub fn force_account_info( origin: OriginFor, account: T::AccountId, @@ -173,7 +173,7 @@ pub mod pallet { } #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::set_block())] + #[pallet::weight(T::WeightInfo::set_now())] pub fn set_now(origin: OriginFor, now: T::Moment) -> DispatchResult { ensure_root(origin)?; >::put(now); diff --git a/parentchain/src/weights.rs b/parentchain/src/weights.rs index 68052bf8..c2ebfec4 100644 --- a/parentchain/src/weights.rs +++ b/parentchain/src/weights.rs @@ -3,6 +3,10 @@ pub use frame_support::weights::{constants::RocksDbWeight, Weight}; /// Weight functions needed for pallet_parentchain. pub trait WeightInfo { fn set_block() -> Weight; + fn init_shard_vault() -> Weight; + fn init_parentchain_genesis_hash() -> Weight; + fn force_account_info() -> Weight; + fn set_now() -> Weight; } /// Weights for pallet_parentchain using the Integritee parachain node and recommended hardware. @@ -10,4 +14,16 @@ impl WeightInfo for () { fn set_block() -> Weight { Weight::from_parts(10_000, 0u64) } + fn init_shard_vault() -> Weight { + Weight::from_parts(10_000, 0u64) + } + fn init_parentchain_genesis_hash() -> Weight { + Weight::from_parts(10_000, 0u64) + } + fn force_account_info() -> Weight { + Weight::from_parts(10_000, 0u64) + } + fn set_now() -> Weight { + Weight::from_parts(10_000, 0u64) + } }