From 394b1d1ad192cfcaf7cf0b19295e13e463c2dacf Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Wed, 3 Jul 2024 15:01:11 -0400 Subject: [PATCH 01/13] Integrate oracle pallet --- Cargo.lock | 16 +++++ crates/client/entropy_metadata.scale | Bin 204305 -> 204881 bytes pallets/oracle/Cargo.toml | 40 ++++++++++++ pallets/oracle/src/benchmarking.rs | 35 ++++++++++ pallets/oracle/src/lib.rs | 92 +++++++++++++++++++++++++++ pallets/oracle/src/mock.rs | 83 ++++++++++++++++++++++++ pallets/oracle/src/tests.rs | 43 +++++++++++++ pallets/oracle/src/weights.rs | 66 +++++++++++++++++++ runtime/Cargo.toml | 4 ++ runtime/src/lib.rs | 7 ++ 10 files changed, 386 insertions(+) create mode 100644 pallets/oracle/Cargo.toml create mode 100644 pallets/oracle/src/benchmarking.rs create mode 100644 pallets/oracle/src/lib.rs create mode 100644 pallets/oracle/src/mock.rs create mode 100644 pallets/oracle/src/tests.rs create mode 100644 pallets/oracle/src/weights.rs diff --git a/Cargo.lock b/Cargo.lock index 007c8434f..43c03d547 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2583,6 +2583,7 @@ dependencies = [ "pallet-nomination-pools-benchmarking", "pallet-offences", "pallet-offences-benchmarking", + "pallet-oracle", "pallet-parameters", "pallet-preimage", "pallet-programs", @@ -6988,6 +6989,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-rc.1" diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index dd72dae04a71b3d00562a9364cf6aea3a12fd6fc..0230459b46ec88a495d993e8b6b96fba295d8d48 100644 GIT binary patch delta 13833 zcmcJ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$4HRkJ!NPp`Ggvl*uNZ>l_sh4si8 zYu$AvaEsm5C6(fHRH3~{|1LmY#Hd)G6(n~m=p}xrJOiu2HB`=4+;-(C|9YrAioZEj zj>Inha;UsB2WW&OP'] +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..ec7c24e38 --- /dev/null +++ b/pallets/oracle/src/benchmarking.rs @@ -0,0 +1,35 @@ +// 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 . + +use frame_benchmarking::benchmarks; +use frame_support::assert_ok; +use frame_system::EventRecord; + +use super::*; +#[allow(unused)] +use crate::Pallet as Parameters; + +fn assert_last_event(generic_event: ::RuntimeEvent) { + let events = frame_system::Pallet::::events(); + let system_event: ::RuntimeEvent = generic_event.into(); + // compare to the last event record + let EventRecord { event, .. } = &events[events.len() - 1]; + assert_eq!(event, &system_event); +} + +benchmarks! { + + impl_benchmark_test_suite!(Parameters, crate::mock::ExtBuilder::default().build(), crate::mock::Runtime); +} diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs new file mode 100644 index 000000000..6e5a1181f --- /dev/null +++ b/pallets/oracle/src/lib.rs @@ -0,0 +1,92 @@ +// 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::*; +use sp_runtime::DispatchResult; + +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +pub mod weights; + +pub use module::*; +pub use weights::WeightInfo; + +#[frame_support::pallet] +pub mod module { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// Weight information for the extrinsics in this module. + type WeightInfo: WeightInfo; + } + + #[pallet::storage] + #[pallet::getter(fn oracle_data)] + // TODO: parameterize bounded vec constants + pub type OracleData = StorageMap< + _, + Blake2_128Concat, + BoundedVec>, + BoundedVec>, + OptionQuery, + >; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(block_number: BlockNumberFor) -> Weight { + OracleData::::insert( + BoundedVec::try_from("block_number_entropy".encode()).unwrap(), + BoundedVec::try_from(block_number.encode()).unwrap(), + ); + T::DbWeight::get().writes(1) + } + } + + #[pallet::error] + pub enum Error {} + + #[pallet::event] + #[pallet::generate_deposit(fn deposit_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..26738f73c --- /dev/null +++ b/pallets/oracle/src/mock.rs @@ -0,0 +1,83 @@ +// 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, ord_parameter_types, + traits::{ConstU64, Everything}, +}; +use frame_system::EnsureRoot; +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 Runtime { + 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 = (); +} + +ord_parameter_types! { + pub const One: AccountId = 1; +} + +impl Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime + { + 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..82a2500e7 --- /dev/null +++ b/pallets/oracle/src/tests.rs @@ -0,0 +1,43 @@ +// 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 crate as pallet_oracle; +use frame_support::{assert_noop, assert_ok, traits::OnInitialize}; +use mock::*; +use sp_runtime::traits::BadOrigin; + +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..2d9fdd410 --- /dev/null +++ b/pallets/oracle/src/weights.rs @@ -0,0 +1,66 @@ +// 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_transaction_pause +//! +//! 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_transaction_pause +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --template +// .maintain/frame-weight-template.hbs +// --output +// pallets/transaction-pause/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_transaction_pause. +pub trait WeightInfo { + +} + +/// Weights for pallet_transaction_pause using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + +} + +// For backwards compatibility and tests +impl WeightInfo for () { + +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 32d68a77e..0e3de0b2c 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -102,6 +102,7 @@ pallet-slashing ={ version='0.2.0-rc.1', path='../pallets/slashing', def pallet-staking-extension={ version='0.2.0-rc.1', path='../pallets/staking', default-features=false } pallet-transaction-pause={ version='0.2.0-rc.1', path='../pallets/transaction-pause', default-features=false } pallet-parameters ={ version='0.2.0-rc.1', 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-rc.1", 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 4ec9533de..3c86954c3 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1495,6 +1495,11 @@ impl pallet_parameters::Config for Runtime { type WeightInfo = weights::pallet_parameters::WeightInfo; } +impl pallet_oracle::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { @@ -1547,6 +1552,7 @@ construct_runtime!( TransactionPause: pallet_transaction_pause = 54, Propagation: pallet_propagation = 55, Parameters: pallet_parameters = 56, + Oracle: pallet_oracle = 57, } ); @@ -1625,6 +1631,7 @@ mod benches { [pallet_offences, OffencesBench::] [pallet_preimage, Preimage] [pallet_parameters, Parameters] + [pallet_oracle, Oracle] [pallet_proxy, Proxy] [pallet_recovery, Recovery] [pallet_registry, Registry] From 565bd795a69d7770524e57f75ae2f96b028ff1d4 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Wed, 3 Jul 2024 17:08:15 -0400 Subject: [PATCH 02/13] integrate oracle data to core --- .../src/helpers/substrate.rs | 20 +++++++++++++++---- .../src/helpers/tests.rs | 6 ++++++ .../src/helpers/user.rs | 5 +++-- .../src/user/api.rs | 16 +++++++++++---- .../src/user/errors.rs | 2 ++ 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/substrate.rs b/crates/threshold-signature-server/src/helpers/substrate.rs index 60aef4fb6..4bb35322f 100644 --- a/crates/threshold-signature-server/src/helpers/substrate.rs +++ b/crates/threshold-signature-server/src/helpers/substrate.rs @@ -83,13 +83,25 @@ pub async fn get_program( api: &OnlineClient, rpc: &LegacyRpcMethods, program_pointer: &::Hash, -) -> Result, UserErr> { +) -> Result<(Vec, Vec), UserErr> { let bytecode_address = entropy::storage().programs().programs(program_pointer); + let program_info = query_chain(api, rpc, bytecode_address, None) + .await? + .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))?; + Ok((program_info.bytecode, program_info.oracle_data_pointer)) +} - Ok(query_chain(api, rpc, bytecode_address, None) +/// 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? - .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))? - .bytecode) + .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 92634e094..7c1b79542 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -291,3 +291,9 @@ async fn test_get_signing_group() { clean_tests(); } + +#[tokio::test] +#[serial] +async fn test_get_oracle_data() { + //TODO +} \ No newline at end of file diff --git a/crates/threshold-signature-server/src/helpers/user.rs b/crates/threshold-signature-server/src/helpers/user.rs index 8da19671d..8cb544874 100644 --- a/crates/threshold-signature-server/src/helpers/user.rs +++ b/crates/threshold-signature-server/src/helpers/user.rs @@ -214,8 +214,9 @@ 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_bytecode, _) = + get_program(api, rpc, &programs_data[*i].program_pointer).await?; + runtime.custom_hash(program_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 9f3f6fb0f..386bb0912 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -70,8 +70,8 @@ use crate::{ launch::LATEST_BLOCK_NUMBER_NEW_USER, signing::{do_signing, Hasher}, substrate::{ - get_program, get_registered_details, get_stash_address, get_subgroup, query_chain, - return_all_addresses_of_subgroup, submit_transaction, + get_oracle_data, get_program, get_registered_details, get_stash_address, get_subgroup, + query_chain, return_all_addresses_of_subgroup, submit_transaction, }, user::{check_in_registration_group, compute_hash, do_dkg, send_key}, validator::{get_signer, get_signer_and_x25519_secret}, @@ -172,10 +172,18 @@ 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?; + let (program_bytecode, program_oracle_data) = + get_program(&api, &rpc, &program_info.program_pointer).await?; + let oracle_data = + get_oracle_data(&api, &rpc, program_oracle_data).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_bytecode, + &signature_request, + Some(&program_info.program_config), + Some(&oracle_data), + )?; } // We decided to do Keccak for subgroup selection for frontend compatability let message_hash_keccak = diff --git a/crates/threshold-signature-server/src/user/errors.rs b/crates/threshold-signature-server/src/user/errors.rs index 8ad8cc04b..15d0ab787 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:?}")] From 9d06af4815cd2f791c2593da438d7a65270904ec Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 14:24:17 -0400 Subject: [PATCH 03/13] test oracle data fetch --- .../src/helpers/substrate.rs | 5 ++--- .../src/helpers/tests.rs | 20 ++++++++++++++++--- .../src/user/api.rs | 3 +-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/substrate.rs b/crates/threshold-signature-server/src/helpers/substrate.rs index 4bb35322f..4ebec89d7 100644 --- a/crates/threshold-signature-server/src/helpers/substrate.rs +++ b/crates/threshold-signature-server/src/helpers/substrate.rs @@ -98,9 +98,8 @@ pub async fn get_oracle_data( 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![])); + let oracle_info = + query_chain(api, rpc, oracle_data_call, None).await?.unwrap_or(BoundedVec(vec![])); Ok(oracle_info.0) } diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 7c1b79542..6df6f2660 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -34,7 +34,7 @@ use crate::{ }, logger::Instrumentation, logger::Logger, - substrate::{get_subgroup, query_chain, submit_transaction}, + substrate::{get_oracle_data, get_subgroup, query_chain, submit_transaction}, validator::get_signer_and_x25519_secret_from_mnemonic, }, signing_client::ListenerState, @@ -47,6 +47,7 @@ use entropy_kvdb::{ use entropy_protocol::{KeyParams, PartyId}; use entropy_shared::{KeyVisibility, DETERMINISTIC_KEY_SHARE}; use entropy_testing_utils::substrate_context::testing_context; +use parity_scale_codec::Encode; use rand_core::OsRng; use serial_test::serial; use subxt::{ @@ -295,5 +296,18 @@ async fn test_get_signing_group() { #[tokio::test] #[serial] async fn test_get_oracle_data() { - //TODO -} \ No newline at end of file + 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); +} diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index 386bb0912..14efc37bc 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -174,8 +174,7 @@ pub async fn sign_tx( for (i, program_info) in user_details.programs_data.0.iter().enumerate() { let (program_bytecode, program_oracle_data) = get_program(&api, &rpc, &program_info.program_pointer).await?; - let oracle_data = - get_oracle_data(&api, &rpc, program_oracle_data).await?; + let oracle_data = get_oracle_data(&api, &rpc, program_oracle_data).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( From b44931aaf07dc561e3ed811200d3bc03fe6fcc49 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 14:39:05 -0400 Subject: [PATCH 04/13] parameterized bounded vecs --- pallets/oracle/src/benchmarking.rs | 1 - pallets/oracle/src/lib.rs | 11 ++++++----- pallets/oracle/src/mock.rs | 10 ++++++---- pallets/oracle/src/tests.rs | 5 +---- runtime/src/lib.rs | 7 +++++++ 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pallets/oracle/src/benchmarking.rs b/pallets/oracle/src/benchmarking.rs index ec7c24e38..ce4368edd 100644 --- a/pallets/oracle/src/benchmarking.rs +++ b/pallets/oracle/src/benchmarking.rs @@ -30,6 +30,5 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { } benchmarks! { - impl_benchmark_test_suite!(Parameters, crate::mock::ExtBuilder::default().build(), crate::mock::Runtime); } diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 6e5a1181f..5418af979 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -26,7 +26,6 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use sp_runtime::DispatchResult; #[cfg(test)] mod mock; @@ -49,7 +48,10 @@ pub mod module { #[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; } @@ -60,8 +62,8 @@ pub mod module { pub type OracleData = StorageMap< _, Blake2_128Concat, - BoundedVec>, - BoundedVec>, + BoundedVec, + BoundedVec, OptionQuery, >; @@ -84,7 +86,6 @@ pub mod module { pub enum Error {} #[pallet::event] - #[pallet::generate_deposit(fn deposit_event)] pub enum Event {} #[pallet::call] diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs index 26738f73c..7fc597aad 100644 --- a/pallets/oracle/src/mock.rs +++ b/pallets/oracle/src/mock.rs @@ -18,10 +18,9 @@ #![cfg(test)] use frame_support::{ - construct_runtime, derive_impl, ord_parameter_types, + construct_runtime, derive_impl, parameter_types, traits::{ConstU64, Everything}, }; -use frame_system::EnsureRoot; use sp_core::H256; use sp_runtime::{traits::IdentityLookup, BuildStorage}; @@ -58,12 +57,15 @@ impl frame_system::Config for Runtime { type Version = (); } -ord_parameter_types! { - pub const One: AccountId = 1; +parameter_types! { + pub const MaxOracleKeyLength: u32 = 100; + pub const MaxOracleValueLength: u32 = 100; } impl Config for Runtime { type RuntimeEvent = RuntimeEvent; + type MaxOracleKeyLength = MaxOracleKeyLength; + type MaxOracleValueLength = MaxOracleValueLength; type WeightInfo = (); } diff --git a/pallets/oracle/src/tests.rs b/pallets/oracle/src/tests.rs index 82a2500e7..9cae65535 100644 --- a/pallets/oracle/src/tests.rs +++ b/pallets/oracle/src/tests.rs @@ -16,11 +16,8 @@ //! Unit tests for the parameters pallet. #![cfg(test)] - -use crate as pallet_oracle; -use frame_support::{assert_noop, assert_ok, traits::OnInitialize}; +use frame_support::{traits::OnInitialize}; use mock::*; -use sp_runtime::traits::BadOrigin; use super::*; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3c86954c3..01e9790ec 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1495,8 +1495,15 @@ 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 = (); } From 5874a64e0b6cf18d01faf6a57524decdf5ca7459 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 14:42:03 -0400 Subject: [PATCH 05/13] fmt --- pallets/oracle/src/tests.rs | 2 +- runtime/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/oracle/src/tests.rs b/pallets/oracle/src/tests.rs index 9cae65535..b823ed013 100644 --- a/pallets/oracle/src/tests.rs +++ b/pallets/oracle/src/tests.rs @@ -16,7 +16,7 @@ //! Unit tests for the parameters pallet. #![cfg(test)] -use frame_support::{traits::OnInitialize}; +use frame_support::traits::OnInitialize; use mock::*; use super::*; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 0e3de0b2c..3d0eed915 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -102,7 +102,7 @@ pallet-slashing ={ version='0.2.0-rc.1', path='../pallets/slashing', def pallet-staking-extension={ version='0.2.0-rc.1', path='../pallets/staking', default-features=false } pallet-transaction-pause={ version='0.2.0-rc.1', path='../pallets/transaction-pause', default-features=false } pallet-parameters ={ version='0.2.0-rc.1', path='../pallets/parameters', default-features=false } -pallet-oracle ={ version='0.2.0-rc.1', path='../pallets/oracle', default-features=false } +pallet-oracle ={ version='0.2.0-rc.1', path='../pallets/oracle', default-features=false } entropy-shared={ version="0.2.0-rc.1", path="../crates/shared", default-features=false, features=[ "wasm-no-std", @@ -142,7 +142,7 @@ std=[ "pallet-nomination-pools-benchmarking?/std", "pallet-nomination-pools/std", "pallet-offences/std", - "pallet-oracle/std", + "pallet-oracle/std", "pallet-preimage/std", "pallet-parameters/std", "pallet-programs/std", From 2304d4c58ffc601d99b6875b69a7e2d0d1150d25 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 14:48:34 -0400 Subject: [PATCH 06/13] clean --- pallets/oracle/src/benchmarking.rs | 34 --------------- pallets/oracle/src/lib.rs | 8 +--- pallets/oracle/src/weights.rs | 66 ------------------------------ runtime/src/lib.rs | 1 - 4 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 pallets/oracle/src/benchmarking.rs delete mode 100644 pallets/oracle/src/weights.rs diff --git a/pallets/oracle/src/benchmarking.rs b/pallets/oracle/src/benchmarking.rs deleted file mode 100644 index ce4368edd..000000000 --- a/pallets/oracle/src/benchmarking.rs +++ /dev/null @@ -1,34 +0,0 @@ -// 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 . - -use frame_benchmarking::benchmarks; -use frame_support::assert_ok; -use frame_system::EventRecord; - -use super::*; -#[allow(unused)] -use crate::Pallet as Parameters; - -fn assert_last_event(generic_event: ::RuntimeEvent) { - let events = frame_system::Pallet::::events(); - let system_event: ::RuntimeEvent = generic_event.into(); - // compare to the last event record - let EventRecord { event, .. } = &events[events.len() - 1]; - assert_eq!(event, &system_event); -} - -benchmarks! { - impl_benchmark_test_suite!(Parameters, crate::mock::ExtBuilder::default().build(), crate::mock::Runtime); -} diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 5418af979..11235681c 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -25,7 +25,7 @@ #![allow(clippy::unused_unit)] use frame_support::pallet_prelude::*; -use frame_system::pallet_prelude::*; +use frame_system::{pallet_prelude::*, WeightInfo}; #[cfg(test)] mod mock; @@ -33,13 +33,7 @@ mod mock; #[cfg(test)] mod tests; -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -pub mod weights; - pub use module::*; -pub use weights::WeightInfo; #[frame_support::pallet] pub mod module { diff --git a/pallets/oracle/src/weights.rs b/pallets/oracle/src/weights.rs deleted file mode 100644 index 2d9fdd410..000000000 --- a/pallets/oracle/src/weights.rs +++ /dev/null @@ -1,66 +0,0 @@ -// 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_transaction_pause -//! -//! 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_transaction_pause -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --template -// .maintain/frame-weight-template.hbs -// --output -// pallets/transaction-pause/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_transaction_pause. -pub trait WeightInfo { - -} - -/// Weights for pallet_transaction_pause using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - -} - -// For backwards compatibility and tests -impl WeightInfo for () { - -} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 01e9790ec..8a0506f65 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1638,7 +1638,6 @@ mod benches { [pallet_offences, OffencesBench::] [pallet_preimage, Preimage] [pallet_parameters, Parameters] - [pallet_oracle, Oracle] [pallet_proxy, Proxy] [pallet_recovery, Recovery] [pallet_registry, Registry] From 9bc94f06bd655dddb140693872b1f4e9359015b6 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 17:27:30 -0400 Subject: [PATCH 07/13] remove unwrap --- pallets/oracle/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 11235681c..19543f63d 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -69,8 +69,10 @@ pub mod module { impl Hooks> for Pallet { fn on_initialize(block_number: BlockNumberFor) -> Weight { OracleData::::insert( - BoundedVec::try_from("block_number_entropy".encode()).unwrap(), - BoundedVec::try_from(block_number.encode()).unwrap(), + 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::DbWeight::get().writes(1) } From 697443a7fa7fd938aa2d53499a00bd87e8e073a4 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 17:51:40 -0400 Subject: [PATCH 08/13] add build checks --- pallets/oracle/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 19543f63d..02e27e094 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -65,6 +65,23 @@ pub mod module { #[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 { From 7205737cb6189570131f4e36bbb41be5be0ae596 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 4 Jul 2024 17:52:51 -0400 Subject: [PATCH 09/13] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4749114c1..e95f529c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,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)) From 8828ef249471fc46e3cbda96075e2c4692473323 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 15 Aug 2024 14:28:13 -0400 Subject: [PATCH 10/13] merge --- crates/client/entropy_metadata.scale | Bin 204881 -> 207917 bytes .../src/user/tests.rs | 21 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 0230459b46ec88a495d993e8b6b96fba295d8d48..421e532537576eba98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`l%8|P9#36q;47i`0^Zqov{4VODePO@b25UZ@B_%W+IQ!cP1^AD}^ z?I8&kD^!lNz)}j+T<(o5vzQw;CRrw~5rNZ+8mGS|wLGwNq&$a_EAUXHJdW8e%ee?~ zRCqUdT)v8Waf0o#xC8$&N-ky)8>6G;3knt?#mh4xX=cUC^I)lMjhE-(^SgL?%g8#G z>eM~{hNcR4m76tjRGJ^yHAX(eY) rYh51ecK%JW96bQ-;Bk}W+u;=ic1)6S>0%dezd^nem*k80Sfu{}B8b&p diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index f564932b6..1a86d07a0 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::{query_chain, submit_transaction, get_oracle_data}, 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, From dcf8152fd6ab4698f0cfedf03d268d81f4024273 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 15 Aug 2024 14:38:51 -0400 Subject: [PATCH 11/13] clean --- .../src/helpers/substrate.rs | 6 +++--- .../src/helpers/tests.rs | 3 +-- .../src/helpers/user.rs | 5 ++--- crates/threshold-signature-server/src/user/api.rs | 15 +++++++-------- .../threshold-signature-server/src/user/tests.rs | 2 +- pallets/oracle/src/lib.rs | 1 - 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/substrate.rs b/crates/threshold-signature-server/src/helpers/substrate.rs index a821409ae..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,12 +52,12 @@ pub async fn get_program( api: &OnlineClient, rpc: &LegacyRpcMethods, program_pointer: &::Hash, -) -> Result<(Vec, Vec), UserErr> { +) -> Result, UserErr> { let bytecode_address = entropy::storage().programs().programs(program_pointer); let program_info = query_chain(api, rpc, bytecode_address, None) .await? .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))?; - Ok((program_info.bytecode, program_info.oracle_data_pointer)) + Ok(program_info) } /// Queries the oracle data needed for the program diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 5185f9ffe..bb5906f41 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -31,8 +31,7 @@ use crate::{ ValidatorName, DEFAULT_ENDPOINT, }, logger::{Instrumentation, Logger}, - substrate::{get_oracle_data, query_chain, submit_transaction}, - + substrate::{query_chain, submit_transaction}, }, signing_client::ListenerState, AppState, diff --git a/crates/threshold-signature-server/src/helpers/user.rs b/crates/threshold-signature-server/src/helpers/user.rs index e27f1257c..263aac1e9 100644 --- a/crates/threshold-signature-server/src/helpers/user.rs +++ b/crates/threshold-signature-server/src/helpers/user.rs @@ -154,9 +154,8 @@ pub async fn compute_hash( }, HashingAlgorithm::Blake2_256 => Ok(blake2_256(message)), HashingAlgorithm::Custom(i) => { - let (program_bytecode, _) = - get_program(api, rpc, &programs_data[*i].program_pointer).await?; - runtime.custom_hash(program_bytecode.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 8526bab9c..ef75bea2d 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -68,8 +68,8 @@ use crate::{ launch::LATEST_BLOCK_NUMBER_NEW_USER, signing::{do_signing, Hasher}, substrate::{ - get_oracle_data, 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}, @@ -184,16 +184,15 @@ 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_bytecode, program_oracle_data) = - get_program(&api, &rpc, &program_info.program_pointer).await?; - let oracle_data = get_oracle_data(&api, &rpc, program_oracle_data).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_bytecode, + &program_info.bytecode, &signature_request, - Some(&program_info.program_config), + Some(&program_data.program_config), Some(&oracle_data), )?; } diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 1a86d07a0..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, get_oracle_data}, + 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, diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 02e27e094..a58e88fd5 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -52,7 +52,6 @@ pub mod module { #[pallet::storage] #[pallet::getter(fn oracle_data)] - // TODO: parameterize bounded vec constants pub type OracleData = StorageMap< _, Blake2_128Concat, From 5b8d80f9f745e09c08f445b903001a17cc541b23 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 15 Aug 2024 16:31:49 -0400 Subject: [PATCH 12/13] add benchmarks --- pallets/oracle/src/benchmarking.rs | 33 +++++++++++ pallets/oracle/src/lib.rs | 9 ++- pallets/oracle/src/mock.rs | 10 ++-- pallets/oracle/src/weights.rs | 89 ++++++++++++++++++++++++++++ runtime/src/lib.rs | 3 +- runtime/src/weights/pallet_oracle.rs | 59 ++++++++++++++++++ 6 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 pallets/oracle/src/benchmarking.rs create mode 100644 pallets/oracle/src/weights.rs create mode 100644 runtime/src/weights/pallet_oracle.rs 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 index a58e88fd5..ec1898f03 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -25,19 +25,24 @@ #![allow(clippy::unused_unit)] use frame_support::pallet_prelude::*; -use frame_system::{pallet_prelude::*, WeightInfo}; +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 { @@ -90,7 +95,7 @@ pub mod module { BoundedVec::try_from(block_number.encode()) .expect("Block number fits in bounded vec; qed"), ); - T::DbWeight::get().writes(1) + T::WeightInfo::on_initialize() } } diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs index 7fc597aad..81745833f 100644 --- a/pallets/oracle/src/mock.rs +++ b/pallets/oracle/src/mock.rs @@ -31,7 +31,7 @@ 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 Runtime { +impl frame_system::Config for Test { type AccountData = (); type AccountId = AccountId; type BaseCallFilter = Everything; @@ -62,17 +62,17 @@ parameter_types! { pub const MaxOracleValueLength: u32 = 100; } -impl Config for Runtime { +impl Config for Test { type RuntimeEvent = RuntimeEvent; type MaxOracleKeyLength = MaxOracleKeyLength; type MaxOracleValueLength = MaxOracleValueLength; type WeightInfo = (); } -type Block = frame_system::mocking::MockBlock; +type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum Runtime + pub enum Test { System: frame_system, Oracle: pallet_oracle, @@ -81,5 +81,5 @@ construct_runtime!( // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::::default().build_storage().unwrap().into() + frame_system::GenesisConfig::::default().build_storage().unwrap().into() } 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/src/lib.rs b/runtime/src/lib.rs index aa90f54bb..5cb70651c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1502,7 +1502,7 @@ impl pallet_oracle::Config for Runtime { type RuntimeEvent = RuntimeEvent; type MaxOracleKeyLength = MaxOracleKeyLength; type MaxOracleValueLength = MaxOracleValueLength; - type WeightInfo = (); + type WeightInfo = weights::pallet_oracle::WeightInfo; } construct_runtime!( @@ -1634,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/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)) + } +} From 9784dfb153f35a3523cdab2c3941696c31e2edd8 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 15 Aug 2024 16:38:03 -0400 Subject: [PATCH 13/13] fix --- runtime/src/weights/mod.rs | 1 + 1 file changed, 1 insertion(+) 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;