diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e2a0299..d5137c4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ At the moment this project **does not** adhere to - Add `blake2` as built in hash function and make `HashingAlgorithm` non-exhaustive ([#881](https://github.com/entropyxyz/entropy-core/pull/881)) - Add sort to subgroup signer selection ([#900](https://github.com/entropyxyz/entropy-core/pull/900)) - Create four node Docker Compose chainspec ([#902](https://github.com/entropyxyz/entropy-core/pull/902)) +- Oracle data integration ([#922](https://github.com/entropyxyz/entropy-core/pull/922)) ### Changed - Move TSS mnemonic out of keystore ([#853](https://github.com/entropyxyz/entropy-core/pull/853)) diff --git a/Cargo.lock b/Cargo.lock index df486da62..df9b2fe72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2639,6 +2639,7 @@ dependencies = [ "pallet-nomination-pools-benchmarking", "pallet-offences", "pallet-offences-benchmarking", + "pallet-oracle", "pallet-parameters", "pallet-preimage", "pallet-programs", @@ -7081,6 +7082,21 @@ dependencies = [ "sp-std 14.0.0", ] +[[package]] +name = "pallet-oracle" +version = "0.2.0-rc.1" +dependencies = [ + "frame-benchmarking", + "frame-support 29.0.2", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core 29.0.0", + "sp-io 31.0.0", + "sp-runtime 32.0.0", + "sp-std 14.0.0", +] + [[package]] name = "pallet-parameters" version = "0.2.0" diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 7efb92da8..421e53253 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/helpers/substrate.rs b/crates/threshold-signature-server/src/helpers/substrate.rs index 0b836844b..55fcb6772 100644 --- a/crates/threshold-signature-server/src/helpers/substrate.rs +++ b/crates/threshold-signature-server/src/helpers/substrate.rs @@ -19,7 +19,7 @@ use crate::{ entropy::{ self, runtime_types::{ - bounded_collections::bounded_vec::BoundedVec, + bounded_collections::bounded_vec::BoundedVec, pallet_programs::pallet::ProgramInfo, pallet_registry::pallet::RegisteredInfo, }, }, @@ -52,13 +52,24 @@ pub async fn get_program( api: &OnlineClient, rpc: &LegacyRpcMethods, program_pointer: &::Hash, -) -> Result, UserErr> { +) -> Result, UserErr> { let bytecode_address = entropy::storage().programs().programs(program_pointer); - - Ok(query_chain(api, rpc, bytecode_address, None) + let program_info = query_chain(api, rpc, bytecode_address, None) .await? - .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))? - .bytecode) + .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))?; + Ok(program_info) +} + +/// Queries the oracle data needed for the program +pub async fn get_oracle_data( + api: &OnlineClient, + rpc: &LegacyRpcMethods, + program_oracle_data: Vec, +) -> Result, UserErr> { + let oracle_data_call = entropy::storage().oracle().oracle_data(BoundedVec(program_oracle_data)); + let oracle_info = + query_chain(api, rpc, oracle_data_call, None).await?.unwrap_or(BoundedVec(vec![])); + Ok(oracle_info.0) } /// Returns a registered user's key visibility diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 79226ee35..bb5906f41 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -41,6 +41,7 @@ use entropy_kvdb::{encrypted_sled::PasswordMethod, get_db_path, kv_manager::KvMa use entropy_protocol::PartyId; use entropy_shared::{DAVE_VERIFYING_KEY, EVE_VERIFYING_KEY, NETWORK_PARENT_KEY}; use std::time::Duration; + use subxt::{ backend::legacy::LegacyRpcMethods, ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32 as SubxtAccountId32, Config, OnlineClient, diff --git a/crates/threshold-signature-server/src/helpers/user.rs b/crates/threshold-signature-server/src/helpers/user.rs index 28d8ba03a..263aac1e9 100644 --- a/crates/threshold-signature-server/src/helpers/user.rs +++ b/crates/threshold-signature-server/src/helpers/user.rs @@ -154,8 +154,8 @@ pub async fn compute_hash( }, HashingAlgorithm::Blake2_256 => Ok(blake2_256(message)), HashingAlgorithm::Custom(i) => { - let program = get_program(api, rpc, &programs_data[*i].program_pointer).await?; - runtime.custom_hash(program.as_slice(), message).map_err(|e| e.into()) + let program_info = get_program(api, rpc, &programs_data[*i].program_pointer).await?; + runtime.custom_hash(program_info.bytecode.as_slice(), message).map_err(|e| e.into()) }, _ => Err(UserErr::UnknownHashingAlgorithm), } diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index 9fb374ce8..ef75bea2d 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -68,7 +68,8 @@ use crate::{ launch::LATEST_BLOCK_NUMBER_NEW_USER, signing::{do_signing, Hasher}, substrate::{ - get_program, get_registered_details, get_stash_address, query_chain, submit_transaction, + get_oracle_data, get_program, get_registered_details, get_stash_address, query_chain, + submit_transaction, }, user::{check_in_registration_group, compute_hash, do_dkg}, validator::{get_signer, get_signer_and_x25519_secret}, @@ -183,11 +184,17 @@ pub async fn sign_tx( let mut runtime = Runtime::new(ProgramConfig { fuel }); - for (i, program_info) in user_details.programs_data.0.iter().enumerate() { - let program = get_program(&api, &rpc, &program_info.program_pointer).await?; + for (i, program_data) in user_details.programs_data.0.iter().enumerate() { + let program_info = get_program(&api, &rpc, &program_data.program_pointer).await?; + let oracle_data = get_oracle_data(&api, &rpc, program_info.oracle_data_pointer).await?; let auxilary_data = auxilary_data_vec[i].as_ref().map(hex::decode).transpose()?; let signature_request = SignatureRequest { message: message.clone(), auxilary_data }; - runtime.evaluate(&program, &signature_request, Some(&program_info.program_config), None)?; + runtime.evaluate( + &program_info.bytecode, + &signature_request, + Some(&program_data.program_config), + Some(&oracle_data), + )?; } let with_parent_key = user_details.derivation_path.is_some(); diff --git a/crates/threshold-signature-server/src/user/errors.rs b/crates/threshold-signature-server/src/user/errors.rs index 61c43fe24..386f8e43d 100644 --- a/crates/threshold-signature-server/src/user/errors.rs +++ b/crates/threshold-signature-server/src/user/errors.rs @@ -121,6 +121,8 @@ pub enum UserErr { ValidationErr(#[from] crate::validation::errors::ValidationErr), #[error("No program set at: {0}")] NoProgramDefined(String), + #[error("No oracle data for pointer: {0}")] + NoOracleDataForPointer(String), #[error("No program pointer defined for account")] NoProgramPointerDefined(), #[error("Runtime error: {0:?}")] diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index f564932b6..98c6e31c6 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -117,7 +117,7 @@ use crate::{ DEFAULT_ENDPOINT, DEFAULT_MNEMONIC, }, signing::Hasher, - substrate::{query_chain, submit_transaction}, + substrate::{get_oracle_data, query_chain, submit_transaction}, tests::{ check_has_confirmation, check_if_confirmation, create_clients, initialize_test_logger, remove_program, run_to_block, setup_client, spawn_testing_validators, unsafe_get, @@ -1682,6 +1682,25 @@ async fn test_increment_or_wipe_request_limit() { clean_tests(); } +#[tokio::test] +#[serial_test::serial] +async fn test_get_oracle_data() { + initialize_test_logger().await; + let cxt = testing_context().await; + setup_client().await; + let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); + let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); + run_to_block(&rpc, 1).await; + + let oracle_data = get_oracle_data(&api, &rpc, "block_number_entropy".encode()).await.unwrap(); + let current_block = rpc.chain_get_header(None).await.unwrap().unwrap().number; + assert_eq!(current_block.encode(), oracle_data); + + // fails gracefully + let oracle_data_fail = get_oracle_data(&api, &rpc, "random_heading".encode()).await.unwrap(); + assert_eq!(oracle_data_fail.len(), 0); +} + pub async fn submit_transaction_requests( validator_urls_and_keys: Vec<(String, [u8; 32])>, signature_request: UserSignatureRequest, diff --git a/pallets/oracle/Cargo.toml b/pallets/oracle/Cargo.toml new file mode 100644 index 000000000..1067fb6fa --- /dev/null +++ b/pallets/oracle/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name ="pallet-oracle" +version ='0.2.0-rc.1' +authors =['Entropy Cryptography '] +homepage ='https://entropy.xyz/' +license ='AGPL-3.0-or-later' +repository='https://github.com/entropyxyz/entropy-core' +edition ='2021' +publish =false + +[dependencies] +codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } +scale-info={ version="2.11", default-features=false, features=["derive"] } + +frame-benchmarking={ version="29.0.0", default-features=false, optional=true } +frame-support ={ version="29.0.0", default-features=false } +frame-system ={ version="29.0.0", default-features=false } +sp-runtime ={ version="32.0.0", default-features=false } +sp-std ={ version="14.0.0", default-features=false } + +[dev-dependencies] +sp-core={ version="29.0.0" } +sp-io ={ version="31.0.0" } + +[features] +default=["std"] +runtime-benchmarks=[ + 'frame-benchmarking', + 'frame-support/runtime-benchmarks', + 'frame-system/runtime-benchmarks', +] +std=[ + "frame-support/std", + "frame-system/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", + 'frame-benchmarking/std', +] +try-runtime=["frame-support/try-runtime"] diff --git a/pallets/oracle/src/benchmarking.rs b/pallets/oracle/src/benchmarking.rs new file mode 100644 index 000000000..3f3713c6b --- /dev/null +++ b/pallets/oracle/src/benchmarking.rs @@ -0,0 +1,33 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// //! Benchmarking setup for pallet-oracle + +use super::*; + +#[allow(unused)] +use crate::Pallet as Oracle; +use frame_benchmarking::benchmarks; + +benchmarks! { + on_initialize { + }: { + Oracle::::on_initialize(50u32.into()); + } verify { + assert_eq!(OracleData::::get(BoundedVec::try_from("block_number_entropy".encode()).unwrap()).unwrap()[0], 50); + } + + impl_benchmark_test_suite!(Oracle, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs new file mode 100644 index 000000000..ec1898f03 --- /dev/null +++ b/pallets/oracle/src/lib.rs @@ -0,0 +1,110 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +//! # Programs Oracle +//! +//! ## Overview +//! +//! A pallet to manage oracle data for programs. +//! +//! Oracle data is stored in OracleData storage and can be pointed to and pulled in for programs +//! +#![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::unused_unit)] + +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; +pub mod weights; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +pub use module::*; + +#[frame_support::pallet] +pub mod module { + use super::*; + pub use crate::weights::WeightInfo; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The maximum amount of owned programs. + type MaxOracleKeyLength: Get; + /// The maximum amount of owned programs. + type MaxOracleValueLength: Get; + /// Weight information for the extrinsics in this module. + type WeightInfo: WeightInfo; + } + + #[pallet::storage] + #[pallet::getter(fn oracle_data)] + pub type OracleData = StorageMap< + _, + Blake2_128Concat, + BoundedVec, + BoundedVec, + OptionQuery, + >; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] + pub struct GenesisConfig { + #[serde(skip)] + _config: sp_std::marker::PhantomData, + } + + #[pallet::genesis_build] + impl BuildGenesisConfig for GenesisConfig { + fn build(&self) { + // Makes sure key chosen can fit in bounded vec + assert!("block_number_entropy".encode().len() as u32 <= T::MaxOracleKeyLength::get()); + // Makes sure block number can fit in bounded vec + assert!(u64::MAX.encode().len() as u32 <= T::MaxOracleKeyLength::get()); + } + } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(block_number: BlockNumberFor) -> Weight { + OracleData::::insert( + BoundedVec::try_from("block_number_entropy".encode()) + .expect("Key fits in bounded vec; qed"), + BoundedVec::try_from(block_number.encode()) + .expect("Block number fits in bounded vec; qed"), + ); + T::WeightInfo::on_initialize() + } + } + + #[pallet::error] + pub enum Error {} + + #[pallet::event] + pub enum Event {} + + #[pallet::call] + impl Pallet {} +} diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs new file mode 100644 index 000000000..81745833f --- /dev/null +++ b/pallets/oracle/src/mock.rs @@ -0,0 +1,85 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +//! Mocks for the parameters pallet. + +#![cfg(test)] + +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ConstU64, Everything}, +}; +use sp_core::H256; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; + +use super::*; + +pub type AccountId = u128; + +use crate as pallet_oracle; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Test { + type AccountData = (); + type AccountId = AccountId; + type BaseCallFilter = Everything; + type Block = Block; + type BlockHashCount = ConstU64<250>; + type BlockLength = (); + type BlockWeights = (); + type DbWeight = (); + type Hash = H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type Lookup = IdentityLookup; + type MaxConsumers = frame_support::traits::ConstU32<16>; + type Nonce = u64; + type OnKilledAccount = (); + type OnNewAccount = (); + type OnSetCode = (); + type PalletInfo = PalletInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type SS58Prefix = (); + type SystemWeightInfo = (); + type Version = (); +} + +parameter_types! { + pub const MaxOracleKeyLength: u32 = 100; + pub const MaxOracleValueLength: u32 = 100; +} + +impl Config for Test { + type RuntimeEvent = RuntimeEvent; + type MaxOracleKeyLength = MaxOracleKeyLength; + type MaxOracleValueLength = MaxOracleValueLength; + type WeightInfo = (); +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Test + { + System: frame_system, + Oracle: pallet_oracle, + } +); + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::::default().build_storage().unwrap().into() +} diff --git a/pallets/oracle/src/tests.rs b/pallets/oracle/src/tests.rs new file mode 100644 index 000000000..b823ed013 --- /dev/null +++ b/pallets/oracle/src/tests.rs @@ -0,0 +1,40 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +//! Unit tests for the parameters pallet. + +#![cfg(test)] +use frame_support::traits::OnInitialize; +use mock::*; + +use super::*; + +#[test] +fn test_set_block_number() { + new_test_ext().execute_with(|| { + assert_eq!( + Oracle::oracle_data(BoundedVec::try_from("block_number_entropy".encode()).unwrap()), + None + ); + + >::on_initialize(50); + + assert_eq!( + Oracle::oracle_data(BoundedVec::try_from("block_number_entropy".encode()).unwrap()) + .unwrap()[0], + 50 + ); + }); +} diff --git a/pallets/oracle/src/weights.rs b/pallets/oracle/src/weights.rs new file mode 100644 index 000000000..c8f5e7990 --- /dev/null +++ b/pallets/oracle/src/weights.rs @@ -0,0 +1,89 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +//! Autogenerated weights for pallet_oracle +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `hcastano`, CPU: `` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/entropy +// benchmark +// pallet +// --chain +// dev +// --wasm-execution=compiled +// --pallet +// pallet_oracle +// --extrinsic +// * +// --steps +// 5 +// --repeat +// 2 +// --template +// .maintain/frame-weight-template.hbs +// --output +// pallets/oracle/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for pallet_oracle. +pub trait WeightInfo { + fn on_initialize() -> Weight; +} + +/// Weights for pallet_oracle using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `Oracle::OracleData` (r:0 w:1) + /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(2_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + +} + +// For backwards compatibility and tests +impl WeightInfo for () { + /// Storage: `Oracle::OracleData` (r:0 w:1) + /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(2_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f79a12e3b..869769e5c 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -102,6 +102,7 @@ pallet-slashing ={ version='0.2.0', path='../pallets/slashing', default- pallet-staking-extension={ version='0.2.0', path='../pallets/staking', default-features=false } pallet-transaction-pause={ version='0.2.0', path='../pallets/transaction-pause', default-features=false } pallet-parameters ={ version='0.2.0', path='../pallets/parameters', default-features=false } +pallet-oracle ={ version='0.2.0-rc.1', path='../pallets/oracle', default-features=false } entropy-shared={ version="0.2.0", path="../crates/shared", default-features=false, features=[ "wasm-no-std", @@ -141,6 +142,7 @@ std=[ "pallet-nomination-pools-benchmarking?/std", "pallet-nomination-pools/std", "pallet-offences/std", + "pallet-oracle/std", "pallet-preimage/std", "pallet-parameters/std", "pallet-programs/std", @@ -207,6 +209,7 @@ runtime-benchmarks=[ "pallet-multisig/runtime-benchmarks", "pallet-nomination-pools-benchmarking/runtime-benchmarks", "pallet-offences-benchmarking/runtime-benchmarks", + "pallet-oracle/runtime-benchmarks", "pallet-parameters/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-programs/runtime-benchmarks", @@ -249,6 +252,7 @@ try-runtime=[ "pallet-multisig/try-runtime", "pallet-nomination-pools/try-runtime", "pallet-offences/try-runtime", + "pallet-oracle/try-runtime", "pallet-preimage/try-runtime", "pallet-propagation/try-runtime", "pallet-proxy/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ad26f4020..5cb70651c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1493,6 +1493,18 @@ impl pallet_parameters::Config for Runtime { type WeightInfo = weights::pallet_parameters::WeightInfo; } +parameter_types! { + pub const MaxOracleKeyLength: u32 = 100; + pub const MaxOracleValueLength: u32 = 100; +} + +impl pallet_oracle::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MaxOracleKeyLength = MaxOracleKeyLength; + type MaxOracleValueLength = MaxOracleValueLength; + type WeightInfo = weights::pallet_oracle::WeightInfo; +} + construct_runtime!( pub enum Runtime { @@ -1545,6 +1557,7 @@ construct_runtime!( TransactionPause: pallet_transaction_pause = 54, Propagation: pallet_propagation = 55, Parameters: pallet_parameters = 56, + Oracle: pallet_oracle = 57, } ); @@ -1621,6 +1634,7 @@ mod benches { [pallet_nomination_pools, NominationPoolsBench::] [pallet_multisig, Multisig] [pallet_offences, OffencesBench::] + [pallet_oracle, Oracle] [pallet_preimage, Preimage] [pallet_parameters, Parameters] [pallet_proxy, Proxy] diff --git a/runtime/src/weights/mod.rs b/runtime/src/weights/mod.rs index 396fd88c6..8b73af704 100644 --- a/runtime/src/weights/mod.rs +++ b/runtime/src/weights/mod.rs @@ -43,6 +43,7 @@ pub mod pallet_indices; pub mod pallet_membership; pub mod pallet_multisig; pub mod pallet_nomination_pools; +pub mod pallet_oracle; pub mod pallet_parameters; pub mod pallet_preimage; pub mod pallet_programs; diff --git a/runtime/src/weights/pallet_oracle.rs b/runtime/src/weights/pallet_oracle.rs new file mode 100644 index 000000000..24cd1c8db --- /dev/null +++ b/runtime/src/weights/pallet_oracle.rs @@ -0,0 +1,59 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +//! Autogenerated weights for `pallet_oracle` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 +//! DATE: 2024-08-15, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/entropy +// benchmark +// pallet +// --chain +// dev +// --pallet=pallet_oracle +// --extrinsic=* +// --steps=5 +// --repeat=2 +// --header=.maintain/AGPL-3.0-header.txt +// --output=./runtime/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_oracle`. +pub struct WeightInfo(PhantomData); +impl pallet_oracle::WeightInfo for WeightInfo { + /// Storage: `Oracle::OracleData` (r:0 w:1) + /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(2_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } +}