Skip to content

Commit dc2e341

Browse files
authored
0.7.0 weight (#233)
* feat: use new weight, template save * feat: file bank weights * style: DispatchResultWithPostInfo * style: generate new weight * feat: DispatchResultWithPostInfo error * fix: chain_spec update, and fix challenge proposal * fix: build error * test: test data
1 parent ab177cd commit dc2e341

18 files changed

+957
-1771
lines changed

.maintain/frame-weight-template.hbs

+23-30
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
// This file is part of Substrate.
2-
3-
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
4-
// SPDX-License-Identifier: Apache-2.0
5-
6-
// Licensed under the Apache License, Version 2.0 (the "License");
7-
// you may not use this file except in compliance with the License.
8-
// You may obtain a copy of the License at
9-
//
10-
// http://www.apache.org/licenses/LICENSE-2.0
11-
//
12-
// Unless required by applicable law or agreed to in writing, software
13-
// distributed under the License is distributed on an "AS IS" BASIS,
14-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
// See the License for the specific language governing permissions and
16-
// limitations under the License.
17-
1+
{{header}}
182
//! Autogenerated weights for {{pallet}}
193
//!
204
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
215
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
6+
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
227
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
238

249
// Executed Command:
@@ -55,27 +40,31 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
5540
{{#each benchmark.comments as |comment|}}
5641
// {{comment}}
5742
{{/each}}
43+
{{#each benchmark.component_ranges as |range|}}
44+
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
45+
{{/each}}
5846
fn {{benchmark.name~}}
5947
(
6048
{{~#each benchmark.components as |c| ~}}
6149
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
6250
) -> Weight {
63-
({{underscore benchmark.base_weight}} as Weight)
51+
// Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds.
52+
Weight::from_ref_time({{underscore benchmark.base_weight}})
6453
{{#each benchmark.component_weight as |cw|}}
6554
// Standard Error: {{underscore cw.error}}
66-
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
55+
.saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into()))
6756
{{/each}}
6857
{{#if (ne benchmark.base_reads "0")}}
69-
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
58+
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
7059
{{/if}}
7160
{{#each benchmark.component_reads as |cr|}}
72-
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
61+
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
7362
{{/each}}
7463
{{#if (ne benchmark.base_writes "0")}}
75-
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
64+
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
7665
{{/if}}
7766
{{#each benchmark.component_writes as |cw|}}
78-
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
67+
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
7968
{{/each}}
8069
}
8170
{{/each}}
@@ -87,28 +76,32 @@ impl WeightInfo for () {
8776
{{#each benchmark.comments as |comment|}}
8877
// {{comment}}
8978
{{/each}}
79+
{{#each benchmark.component_ranges as |range|}}
80+
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
81+
{{/each}}
9082
fn {{benchmark.name~}}
9183
(
9284
{{~#each benchmark.components as |c| ~}}
9385
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
9486
) -> Weight {
95-
({{underscore benchmark.base_weight}} as Weight)
87+
// Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds.
88+
Weight::from_ref_time({{underscore benchmark.base_weight}})
9689
{{#each benchmark.component_weight as |cw|}}
9790
// Standard Error: {{underscore cw.error}}
98-
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
91+
.saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into()))
9992
{{/each}}
10093
{{#if (ne benchmark.base_reads "0")}}
101-
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
94+
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}))
10295
{{/if}}
10396
{{#each benchmark.component_reads as |cr|}}
104-
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
97+
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
10598
{{/each}}
10699
{{#if (ne benchmark.base_writes "0")}}
107-
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
100+
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}))
108101
{{/if}}
109102
{{#each benchmark.component_writes as |cw|}}
110-
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
103+
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
111104
{{/each}}
112105
}
113106
{{/each}}
114-
}
107+
}

c-pallets/audit/src/lib.rs

+53-29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub use pallet::*;
5656
#[cfg(feature = "runtime-benchmarks")]
5757
pub mod benchmarking;
5858

59+
pub mod weights;
60+
5961
use sp_runtime::{
6062
traits::{CheckedAdd, SaturatedConversion},
6163
RuntimeDebug, Permill,
@@ -94,7 +96,6 @@ use sp_std::{
9496
};
9597
use cp_enclave_verify::verify_rsa;
9698
use cp_cess_common::*;
97-
pub mod weights;
9899
pub use weights::WeightInfo;
99100
use cp_bloom_filter::BloomFilter;
100101
use cp_scheduler_credit::SchedulerCreditCounter;
@@ -152,7 +153,7 @@ pub mod pallet {
152153
use super::*;
153154
// use frame_benchmarking::baseline::Config;
154155
use frame_support::{traits::Get};
155-
use frame_system::{ensure_signed, pallet_prelude::*};
156+
use frame_system::{ensure_signed, pallet_prelude::{*, OriginFor}};
156157

157158
///18446744073709551615
158159
pub const LIMIT: u64 = u64::MAX;
@@ -353,6 +354,10 @@ pub mod pallet {
353354
#[pallet::getter(fn verify_reassign_count)]
354355
pub(super) type VerifyReassignCount<T: Config> = StorageValue<_, u8, ValueQuery>;
355356

357+
#[pallet::storage]
358+
#[pallet::getter(fn exec_block)]
359+
pub(super) type ExecBlock<T: Config> = StorageValue<_, BlockNumberOf<T>, ValueQuery>;
360+
356361
// FOR TESTING
357362
#[pallet::storage]
358363
#[pallet::getter(fn lock)]
@@ -380,6 +385,8 @@ pub mod pallet {
380385
if now > deadline {
381386
//Determine whether to trigger a challenge
382387
// if Self::trigger_challenge(now) {
388+
let exec_block = <ExecBlock<T>>::get();
389+
if now == exec_block {
383390
log::info!("offchain worker random challenge start");
384391
if let Err(e) = Self::offchain_work_start(now) {
385392
match e {
@@ -388,6 +395,7 @@ pub mod pallet {
388395
};
389396
}
390397
log::info!("offchain worker random challenge end");
398+
}
391399
// }
392400
}
393401
}
@@ -418,31 +426,36 @@ pub mod pallet {
418426
.checked_mul(2).ok_or(Error::<T>::Overflow)?
419427
.checked_div(3).ok_or(Error::<T>::Overflow)?;
420428
let now = <frame_system::Pallet<T>>::block_number();
429+
430+
let cur_block = <VerifyDuration<T>>::get();
431+
432+
if now <= cur_block {
433+
return Ok(());
434+
}
421435

422436
if ChallengeProposal::<T>::contains_key(&hash) {
423-
let proposal = ChallengeProposal::<T>::get(&hash).unwrap();
424-
if proposal.0 + 1 >= limit {
425-
let cur_blcok = <ChallengeDuration<T>>::get();
426-
427-
if now > cur_blcok {
428-
let duration = now.checked_add(&proposal.1.net_snap_shot.life).ok_or(Error::<T>::Overflow)?;
429-
<ChallengeDuration<T>>::put(duration);
430-
let idle_duration = duration;
431-
let one_hour = T::OneHours::get();
432-
let tee_length = T::TeeWorkerHandler::get_controller_list().len();
433-
let duration: u32 = (proposal.1.net_snap_shot.total_idle_space
434-
.checked_add(proposal.1.net_snap_shot.total_service_space).ok_or(Error::<T>::Overflow)?
435-
.checked_div(IDLE_VERIFY_RATE).ok_or(Error::<T>::Overflow)?
436-
.checked_div(tee_length as u128).ok_or(Error::<T>::Overflow)?
437-
) as u32;
438-
let v_duration = idle_duration
439-
.checked_add(&duration.saturated_into()).ok_or(Error::<T>::Overflow)?
440-
.checked_add(&one_hour).ok_or(Error::<T>::Overflow)?;
441-
<VerifyDuration<T>>::put(v_duration);
442-
<ChallengeSnapShot<T>>::put(proposal.1);
443-
let _ = ChallengeProposal::<T>::clear(ChallengeProposal::<T>::count(), None);
444-
Self::deposit_event(Event::<T>::GenerateChallenge);
445-
}
437+
let mut proposal = ChallengeProposal::<T>::get(&hash).unwrap();
438+
proposal.0 += 1;
439+
if proposal.0 >= limit {
440+
let duration = now.checked_add(&proposal.1.net_snap_shot.life).ok_or(Error::<T>::Overflow)?;
441+
<ChallengeDuration<T>>::put(duration);
442+
let idle_duration = duration;
443+
let one_hour = T::OneHours::get();
444+
let tee_length = T::TeeWorkerHandler::get_controller_list().len();
445+
let duration: u32 = (proposal.1.net_snap_shot.total_idle_space
446+
.checked_add(proposal.1.net_snap_shot.total_service_space).ok_or(Error::<T>::Overflow)?
447+
.checked_div(IDLE_VERIFY_RATE).ok_or(Error::<T>::Overflow)?
448+
.checked_div(tee_length as u128).ok_or(Error::<T>::Overflow)?
449+
) as u32;
450+
let v_duration = idle_duration
451+
.checked_add(&duration.saturated_into()).ok_or(Error::<T>::Overflow)?
452+
.checked_add(&one_hour).ok_or(Error::<T>::Overflow)?;
453+
<VerifyDuration<T>>::put(v_duration);
454+
<ChallengeSnapShot<T>>::put(proposal.1);
455+
let _ = ChallengeProposal::<T>::clear(ChallengeProposal::<T>::count(), None);
456+
Self::deposit_event(Event::<T>::GenerateChallenge);
457+
} else {
458+
ChallengeProposal::<T>::insert(&hash, proposal);
446459
}
447460
} else {
448461
if ChallengeProposal::<T>::count() > count {
@@ -461,7 +474,7 @@ pub mod pallet {
461474

462475
#[pallet::call_index(1)]
463476
#[transactional]
464-
#[pallet::weight(100_000_000)]
477+
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_idle_proof())]
465478
pub fn submit_idle_proof(
466479
origin: OriginFor<T>,
467480
idle_prove: BoundedVec<u8, T::IdleTotalHashLength>,
@@ -516,7 +529,7 @@ pub mod pallet {
516529

517530
#[pallet::call_index(2)]
518531
#[transactional]
519-
#[pallet::weight(100_000_000)]
532+
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_service_proof())]
520533
pub fn submit_service_proof(
521534
origin: OriginFor<T>,
522535
service_prove: BoundedVec<u8, T::SigmaMax>,
@@ -573,7 +586,7 @@ pub mod pallet {
573586

574587
#[pallet::call_index(3)]
575588
#[transactional]
576-
#[pallet::weight(100_000_000)]
589+
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_verify_idle_result())]
577590
pub fn submit_verify_idle_result(
578591
origin: OriginFor<T>,
579592
total_prove_hash: BoundedVec<u8, T::IdleTotalHashLength>,
@@ -657,7 +670,7 @@ pub mod pallet {
657670

658671
#[pallet::call_index(4)]
659672
#[transactional]
660-
#[pallet::weight(100_000_000)]
673+
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_verify_service_result())]
661674
pub fn submit_verify_service_result(
662675
origin: OriginFor<T>,
663676
service_result: bool,
@@ -789,6 +802,17 @@ pub mod pallet {
789802

790803
Ok(())
791804
}
805+
806+
#[pallet::call_index(9)]
807+
#[transactional]
808+
#[pallet::weight(100_000_000)]
809+
pub fn update_exec_block(origin: OriginFor<T>, target: BlockNumberOf<T>) -> DispatchResult {
810+
let _ = ensure_root(origin)?;
811+
812+
<ExecBlock<T>>::put(target);
813+
814+
Ok(())
815+
}
792816
}
793817

794818
#[pallet::validate_unsigned]

0 commit comments

Comments
 (0)