Skip to content

Commit

Permalink
run cargo fmt on audit pallet. (#237)
Browse files Browse the repository at this point in the history
* remove unused code and comments

* run cargo fmt on audit pallet
  • Loading branch information
yeousunn authored Oct 10, 2023
1 parent 3de648b commit 1502f48
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 237 deletions.
53 changes: 34 additions & 19 deletions c-pallets/audit/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use frame_system::RawOrigin;
// use pallet_cess_staking::{
// testing_utils, Config as StakingConfig, Pallet as Staking, RewardDestination,
// };
// use pallet_tee_worker::{Config as TeeWorkerConfig, testing_utils::add_scheduler, Pallet as TeeWorker};
// use pallet_sminer::{Config as SminerConfig, Pallet as Sminer};
// use pallet_tee_worker::{Config as TeeWorkerConfig, testing_utils::add_scheduler, Pallet as
// TeeWorker}; use pallet_sminer::{Config as SminerConfig, Pallet as Sminer};
// use sp_runtime::{
// traits::{Bounded, One, StaticLookup, TrailingZeroInput, Zero},
// Perbill, Percent,
Expand All @@ -25,7 +25,11 @@ use frame_system::RawOrigin;
// use frame_system::RawOrigin;
pub struct Pallet<T: Config>(Audit<T>);
pub trait Config:
crate::Config + pallet_cess_staking::Config + pallet_tee_worker::benchmarking::Config + pallet_sminer::benchmarking::Config + pallet_file_bank::benchmarking::Config
crate::Config
+ pallet_cess_staking::Config
+ pallet_tee_worker::benchmarking::Config
+ pallet_sminer::benchmarking::Config
+ pallet_file_bank::benchmarking::Config
{
}

Expand All @@ -34,24 +38,38 @@ const USER_SEED: u32 = 999666;
const SEED: u32 = 2190502;

const MINER_LIST: [&'static str; 30] = [
"miner1", "miner2", "miner3", "miner4", "miner5", "miner6", "miner7", "miner8", "miner9", "miner10",
"miner11", "miner12", "miner13", "miner14", "miner15", "miner16", "miner17", "miner18", "miner19", "miner20",
"miner21", "miner22", "miner23", "miner24", "miner25", "miner26", "miner27", "miner28", "miner29", "miner30",
"miner1", "miner2", "miner3", "miner4", "miner5", "miner6", "miner7", "miner8", "miner9",
"miner10", "miner11", "miner12", "miner13", "miner14", "miner15", "miner16", "miner17",
"miner18", "miner19", "miner20", "miner21", "miner22", "miner23", "miner24", "miner25",
"miner26", "miner27", "miner28", "miner29", "miner30",
];

pub fn bench_generate_challenge<T: Config>() {
let space_challenge_param = [67_549_635, 67_864_236, 67_338_392, 67_130_229, 67_369_766, 67_193_409, 67_799_602, 67_425_292];
let random_index_list = [691, 406, 838, 480, 996, 798, 362, 456, 144, 666, 1, 018, 568, 992, 650, 729, 808, 229, 623, 499, 671, 254, 24, 217, 698, 648, 781, 460, 298, 548, 742, 364, 183, 114, 309, 564, 127, 154, 815, 651, 397, 576, 697, 358, 880, 73, 629, 66];
let space_challenge_param = [
67_549_635, 67_864_236, 67_338_392, 67_130_229, 67_369_766, 67_193_409, 67_799_602,
67_425_292,
];
let random_index_list = [
691, 406, 838, 480, 996, 798, 362, 456, 144, 666, 1, 018, 568, 992, 650, 729, 808, 229,
623, 499, 671, 254, 24, 217, 698, 648, 781, 460, 298, 548, 742, 364, 183, 114, 309, 564,
127, 154, 815, 651, 397, 576, 697, 358, 880, 73, 629, 66,
];
let random_list = [[55u8; 20]; 48];

let mut miner_snapshot_list: BoundedVec<MinerSnapShot<AccountOf<T>, BlockNumberOf<T>>, <T as crate::Config>::ChallengeMinerMax> = Default::default();
let mut miner_snapshot_list: BoundedVec<
MinerSnapShot<AccountOf<T>, BlockNumberOf<T>>,
<T as crate::Config>::ChallengeMinerMax,
> = Default::default();
let mut total_idle_space: u128 = u128::MIN;
let mut total_service_space: u128 = u128::MIN;
let all_miner = <T as crate::Config>::MinerControl::get_all_miner().expect("get all miner error!");
let all_miner =
<T as crate::Config>::MinerControl::get_all_miner().expect("get all miner error!");
for miner in all_miner.into_iter() {
let (idle_space, service_space, service_bloom_filter, space_proof_info, tee_signature) = <T as crate::Config>::MinerControl::get_miner_snapshot(&miner).expect("get miner snapshot failed");
let (idle_space, service_space, service_bloom_filter, space_proof_info, tee_signature) =
<T as crate::Config>::MinerControl::get_miner_snapshot(&miner)
.expect("get miner snapshot failed");
if (idle_space == 0) && (service_space == 0) {
continue;
continue
}
total_idle_space = total_idle_space.checked_add(idle_space).expect("overflow");
total_service_space = total_service_space.checked_add(service_space).expect("overflow");
Expand Down Expand Up @@ -83,10 +101,7 @@ pub fn bench_generate_challenge<T: Config>() {
space_challenge_param,
};

let challenge_info = ChallengeInfo::<T> {
net_snap_shot,
miner_snapshot_list,
};
let challenge_info = ChallengeInfo::<T> { net_snap_shot, miner_snapshot_list };
<ChallengeSnapShot<T>>::put(challenge_info);
let duration: BlockNumberOf<T> = 5000u32.saturated_into();
<ChallengeDuration<T>>::put(duration);
Expand Down Expand Up @@ -151,15 +166,15 @@ benchmarks! {
let sigma: BoundedVec<u8, T::SigmaMax> = [5u8; 2048].to_vec().try_into().unwrap();
Audit::<T>::submit_idle_proof(RawOrigin::Signed(miner.clone()).into(), idle_total_hash.clone())?;
Audit::<T>::submit_service_proof(RawOrigin::Signed(miner.clone()).into(), sigma.clone())?;

let random_index_list = [691, 406, 838, 480, 996, 798, 362, 456, 144, 666, 1, 018, 568, 992, 650, 729, 808, 229, 623, 499, 671, 254, 24, 217, 698, 648, 781, 460, 298, 548, 742, 364, 183, 114, 309, 564, 127, 154, 815, 651, 397, 576, 697, 358, 880, 73, 629, 66];
let random_list = [[55u8; 20]; 48];
let verify_service_result = VerifyServiceResultInfo::<T>{
miner: miner.clone(),
tee_acc: controller_acc.clone(),
miner_prove: sigma.clone(),
result: true,
chal: QElement {
chal: QElement {
random_index_list: random_index_list.to_vec().try_into().unwrap(),
random_list: random_list.to_vec().try_into().unwrap(),
},
Expand Down Expand Up @@ -220,7 +235,7 @@ benchmarks! {
tee_acc: controller_acc.clone(),
miner_prove: sigma.clone(),
result: true,
chal: QElement {
chal: QElement {
random_index_list: random_index_list.to_vec().try_into().unwrap(),
random_list: random_list.to_vec().try_into().unwrap(),
},
Expand Down
2 changes: 1 addition & 1 deletion c-pallets/audit/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pub(super) const IDLE_FAULT_TOLERANT: u8 = 2;

pub(super) const SERVICE_FAULT_TOLERANT: u8 = 2;

pub(super) type SpaceChallengeParam = [u64; 8];
pub(super) type SpaceChallengeParam = [u64; 8];
Loading

0 comments on commit 1502f48

Please sign in to comment.