Skip to content

Commit 8f13194

Browse files
authored
Merge pull request #2335 from opentensor/raise-fee-announce-next-key
Higher fee for `announce_next_key`
2 parents c6bcbbd + 4a1a5bf commit 8f13194

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

pallets/shield/src/benchmarking.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@ use super::*;
33
use frame_benchmarking::v2::*;
44
use frame_support::{BoundedVec, pallet_prelude::ConstU32};
55
use frame_system::{RawOrigin, pallet_prelude::BlockNumberFor};
6-
use sp_core::{crypto::KeyTypeId, sr25519};
7-
use sp_io::crypto::sr25519_generate;
8-
use sp_runtime::{AccountId32, traits::Hash as HashT};
6+
use sp_core::sr25519;
7+
use sp_runtime::traits::Hash as HashT;
98
use sp_std::vec;
109

11-
/// Helper to build bounded bytes (public key) of a given length.
12-
fn bounded_pk<const N: u32>(len: usize) -> BoundedVec<u8, ConstU32<N>> {
13-
let v = vec![7u8; len];
14-
BoundedVec::<u8, ConstU32<N>>::try_from(v).expect("within bound; qed")
15-
}
10+
// /// Helper to build bounded bytes (public key) of a given length.
11+
// fn bounded_pk<const N: u32>(len: usize) -> BoundedVec<u8, ConstU32<N>> {
12+
// let v = vec![7u8; len];
13+
// BoundedVec::<u8, ConstU32<N>>::try_from(v).expect("within bound; qed")
14+
// }
1615

1716
/// Helper to build bounded bytes (ciphertext) of a given length.
1817
fn bounded_ct<const N: u32>(len: usize) -> BoundedVec<u8, ConstU32<N>> {
1918
let v = vec![0u8; len];
2019
BoundedVec::<u8, ConstU32<N>>::try_from(v).expect("within bound; qed")
2120
}
2221

23-
/// Seed Aura authorities so `EnsureAuraAuthority` passes for a given sr25519 pubkey.
24-
///
25-
/// We avoid requiring `ByteArray` on `AuthorityId` by relying on:
26-
/// `<T as pallet_aura::Config>::AuthorityId: From<sr25519::Public>`.
27-
fn seed_aura_authority_from_sr25519<T>(pubkey: &sr25519::Public)
28-
where
29-
T: pallet::Config + pallet_aura::Config,
30-
<T as pallet_aura::Config>::AuthorityId: From<sr25519::Public>,
31-
{
32-
let auth_id: <T as pallet_aura::Config>::AuthorityId = (*pubkey).into();
33-
pallet_aura::Authorities::<T>::mutate(|auths| {
34-
let _ = auths.try_push(auth_id);
35-
});
36-
}
22+
// /// Seed Aura authorities so `EnsureAuraAuthority` passes for a given sr25519 pubkey.
23+
// ///
24+
// /// We avoid requiring `ByteArray` on `AuthorityId` by relying on:
25+
// /// `<T as pallet_aura::Config>::AuthorityId: From<sr25519::Public>`.
26+
// fn seed_aura_authority_from_sr25519<T>(pubkey: &sr25519::Public)
27+
// where
28+
// T: pallet::Config + pallet_aura::Config,
29+
// <T as pallet_aura::Config>::AuthorityId: From<sr25519::Public>,
30+
// {
31+
// let auth_id: <T as pallet_aura::Config>::AuthorityId = (*pubkey).into();
32+
// pallet_aura::Authorities::<T>::mutate(|auths| {
33+
// let _ = auths.try_push(auth_id);
34+
// });
35+
// }
3736

3837
#[benchmarks(
3938
where
@@ -45,30 +44,31 @@ where
4544
mod benches {
4645
use super::*;
4746

48-
/// Benchmark `announce_next_key`.
49-
#[benchmark]
50-
fn announce_next_key() {
51-
// Generate a deterministic dev key in the host keystore (for benchmarks).
52-
// Any 4-byte KeyTypeId works for generation; it does not affect AccountId derivation.
53-
const KT: KeyTypeId = KeyTypeId(*b"benc");
54-
let alice_pub: sr25519::Public = sr25519_generate(KT, Some("//Alice".as_bytes().to_vec()));
55-
let alice_acc: AccountId32 = alice_pub.into();
56-
57-
// Make this account an Aura authority for the generic runtime.
58-
seed_aura_authority_from_sr25519::<T>(&alice_pub);
59-
60-
// Valid Kyber768 public key length per pallet check.
61-
const KYBER768_PK_LEN: usize = 1184;
62-
let public_key: BoundedVec<u8, ConstU32<2048>> = bounded_pk::<2048>(KYBER768_PK_LEN);
63-
64-
// Measure: dispatch the extrinsic.
65-
#[extrinsic_call]
66-
announce_next_key(RawOrigin::Signed(alice_acc.clone()), public_key.clone());
67-
68-
// Assert: NextKey should be set exactly.
69-
let stored = NextKey::<T>::get().expect("must be set by announce_next_key");
70-
assert_eq!(stored, public_key);
71-
}
47+
// We use the custom value for announce_next_key to charge a higher fee, not the benchmark result.
48+
// /// Benchmark `announce_next_key`.
49+
// #[benchmark]
50+
// fn announce_next_key() {
51+
// // Generate a deterministic dev key in the host keystore (for benchmarks).
52+
// // Any 4-byte KeyTypeId works for generation; it does not affect AccountId derivation.
53+
// const KT: KeyTypeId = KeyTypeId(*b"benc");
54+
// let alice_pub: sr25519::Public = sr25519_generate(KT, Some("//Alice".as_bytes().to_vec()));
55+
// let alice_acc: AccountId32 = alice_pub.into();
56+
57+
// // Make this account an Aura authority for the generic runtime.
58+
// seed_aura_authority_from_sr25519::<T>(&alice_pub);
59+
60+
// // Valid Kyber768 public key length per pallet check.
61+
// const KYBER768_PK_LEN: usize = 1184;
62+
// let public_key: BoundedVec<u8, ConstU32<2048>> = bounded_pk::<2048>(KYBER768_PK_LEN);
63+
64+
// // Measure: dispatch the extrinsic.
65+
// #[extrinsic_call]
66+
// announce_next_key(RawOrigin::Signed(alice_acc.clone()), public_key.clone());
67+
68+
// // Assert: NextKey should be set exactly.
69+
// let stored = NextKey::<T>::get().expect("must be set by announce_next_key");
70+
// assert_eq!(stored, public_key);
71+
// }
7272

7373
/// Benchmark `submit_encrypted`.
7474
#[benchmark]

pallets/shield/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub mod pallet {
247247
/// the following block.
248248
#[pallet::call_index(0)]
249249
#[pallet::weight((
250-
Weight::from_parts(9_979_000, 0)
250+
Weight::from_parts(20_999_999_999, 0)
251251
.saturating_add(T::DbWeight::get().reads(1_u64))
252252
.saturating_add(T::DbWeight::get().writes(1_u64)),
253253
DispatchClass::Operational,

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
241241
// `spec_version`, and `authoring_version` are the same between Wasm and native.
242242
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
243243
// the compatible custom types.
244-
spec_version: 366,
244+
spec_version: 367,
245245
impl_version: 1,
246246
apis: RUNTIME_API_VERSIONS,
247247
transaction_version: 1,

0 commit comments

Comments
 (0)