Skip to content

Commit

Permalink
0.7.4 test (#246)
Browse files Browse the repository at this point in the history
* fix: verify clear bug

* update: miner base limit 4000

* feat: Increase miner registration and pledge requirements

* test: for test

* test: for test

* fix: verify clear
  • Loading branch information
ytqaljn authored Oct 20, 2023
1 parent ee20fda commit 757b44f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
97 changes: 54 additions & 43 deletions c-pallets/audit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ impl sp_std::fmt::Debug for AuditErr {
fn fmt(&self, fmt: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
match *self {
AuditErr::RandomErr => write!(fmt, "Unexpected error in generating random numbers!"),
AuditErr::QElementErr => write!(fmt, ""),
AuditErr::SpaceParamErr => write!(fmt, ""),
AuditErr::QElementErr => write!(fmt, "qelement generation failed"),
AuditErr::SpaceParamErr => write!(fmt, "Spatial parameter generation failed!"),
}
}
}
Expand Down Expand Up @@ -286,11 +286,6 @@ pub mod pallet {
UnSubmitted,
}

//Relevant time nodes for storage challenges
#[pallet::storage]
#[pallet::getter(fn challenge_duration)]
pub(super) type ChallengeDuration<T: Config> = StorageValue<_, BlockNumberOf<T>, ValueQuery>;

//Relevant time nodes for storage challenges
#[pallet::storage]
#[pallet::getter(fn verify_duration)]
Expand All @@ -305,11 +300,6 @@ pub mod pallet {
pub(super) type Keys<T: Config> =
StorageValue<_, WeakBoundedVec<T::AuthorityId, T::SessionKeyMax>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn challenge_proposal)]
pub(super) type ChallengeProposal<T: Config> =
CountedStorageMap<_, Blake2_128Concat, [u8; 32], (u32, ChallengeInfo<T>)>;

#[pallet::storage]
#[pallet::getter(fn counted_idle_failed)]
pub(super) type CountedIdleFailed<T: Config> =
Expand All @@ -329,26 +319,6 @@ pub mod pallet {
#[pallet::getter(fn challenge_era)]
pub(super) type ChallengeEra<T: Config> = StorageValue<_, u32, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn unverify_idle_proof)]
pub(super) type UnverifyIdleProof<T: Config> = StorageMap<
_,
Blake2_128Concat,
AccountOf<T>,
BoundedVec<IdleProveInfo<T>, T::VerifyMissionMax>,
ValueQuery,
>;

#[pallet::storage]
#[pallet::getter(fn unverify_service_proof)]
pub(super) type UnverifyServiceProof<T: Config> = StorageMap<
_,
Blake2_128Concat,
AccountOf<T>,
BoundedVec<ServiceProveInfo<T>, T::VerifyMissionMax>,
ValueQuery,
>;

#[pallet::storage]
#[pallet::getter(fn verify_result)]
pub(super) type VerifyResult<T: Config> =
Expand All @@ -372,7 +342,7 @@ pub mod pallet {
// FOR TEST
#[pallet::storage]
#[pallet::getter(fn test_option_storage)]
pub(super) type TestOptionStorageV2<T: Config> = StorageMap<_, Blake2_128Concat, u32, ProveInfo<T>>;
pub(super) type TestOptionStorageV3<T: Config> = StorageMap<_, Blake2_128Concat, u32, ProveInfoV2<T>>;

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -713,11 +683,35 @@ pub mod pallet {
#[pallet::call_index(8)]
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn test_insert_option(origin: OriginFor<T>, key: u32, value: ProveInfo<T> ) -> DispatchResult {
pub fn test_insert_option(origin: OriginFor<T>, key: u32, value: ProveInfoV2<T> ) -> DispatchResult {
let _sender = ensure_signed(origin)?;

TestOptionStorageV2::insert(key, value);
TestOptionStorageV3::insert(key, value);

Ok(())
}
// FOR TEST
#[pallet::call_index(9)]
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn test_update_clear_slip(origin: OriginFor<T>, old: BlockNumberOf<T>, new: BlockNumberOf<T>, miner: AccountOf<T> ) -> DispatchResult {
let _ = ensure_root(origin)?;

ChallengeSlip::<T>::remove(&old, &miner);
ChallengeSlip::<T>::insert(&new, &miner, true);

Ok(())
}
// FOR TEST
#[pallet::call_index(10)]
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn test_update_verify_slip(origin: OriginFor<T>, old: BlockNumberOf<T>, new: BlockNumberOf<T>, miner: AccountOf<T> ) -> DispatchResult {
let _ = ensure_root(origin)?;

VerifySlip::<T>::remove(&old, &miner);
VerifySlip::<T>::insert(&new, &miner, true);

Ok(())
}
}
Expand Down Expand Up @@ -800,14 +794,28 @@ pub mod pallet {
let mut flag = false;
if let Ok(challenge_info) = <ChallengeSnapShot<T>>::try_get(&miner) {
weight = weight.saturating_add(T::DbWeight::get().reads(1));
if challenge_info.prove_info.assign == 2 {
if let Some(idle_prove) = &challenge_info.prove_info.idle_prove {
if idle_prove.verify_result.is_some() {
flag = true;
}
} else {
flag = true;
}

if let Some(service_prove) = &challenge_info.prove_info.service_prove {
if service_prove.verify_result.is_none() {
flag = false;
}
}

if challenge_info.prove_info.assign >= 2 {
flag = true;
}

if challenge_info.prove_info.idle_prove.is_none()
&& challenge_info.prove_info.service_prove.is_none()
{
flag = true;
flag = true
}
}

Expand Down Expand Up @@ -842,10 +850,11 @@ pub mod pallet {

let one_hour: u32 = T::OneHours::get().saturated_into();
let verify_life: u32 = max_space
.saturating_add(one_hour as u128)
.saturating_div(IDLE_VERIFY_RATE) as u32;
.saturating_div(IDLE_VERIFY_RATE)
.saturating_add(one_hour as u128) as u32;

let new_slip = now.saturating_add(verify_life.saturated_into());
challenge_info.challenge_element.verify_slip = new_slip;

<VerifySlip<T>>::remove(&now, &miner);
<VerifySlip<T>>::insert(&new_slip, &miner, true);
Expand Down Expand Up @@ -903,6 +912,10 @@ pub mod pallet {

let (idle_space, service_space, service_bloom_filter, space_proof_info, tee_signature) = miner_snapshot;

if idle_space + service_space == 0 {
return weight;
}

let service_param = match Self::generate_miner_qelement(now.saturated_into()) {
Ok(service_param) => service_param,
Err(e) => {log::info!("audit: {:?}", e); return weight},
Expand Down Expand Up @@ -1035,7 +1048,6 @@ pub mod pallet {
return Err(AuditErr::QElementErr);
}
}

let mut counter: u32 = 0;
while random_list.len() < random_index_list.len() {
seed = seed.checked_add(1).ok_or(AuditErr::QElementErr)?;
Expand All @@ -1048,7 +1060,6 @@ pub mod pallet {
return Err(AuditErr::QElementErr);
}
}

Ok(QElement{random_index_list, random_list})
}

Expand All @@ -1073,13 +1084,14 @@ pub mod pallet {
let mut repeat_filter: Vec<u64> = Default::default();
let seed_multi: u32 = 5;
let mut seed: u32 = seed.checked_mul(seed_multi).ok_or(AuditErr::SpaceParamErr)?;
let limit = space_challenge_param.len();
for elem in &mut space_challenge_param {
let mut counter: usize = 0;
loop {
let random = Self::random_number(seed.checked_add(1).ok_or(AuditErr::SpaceParamErr)?)? % n;
counter = counter.checked_add(1).ok_or(AuditErr::SpaceParamErr)?;

if counter > repeat_filter.len() * 3 {
if counter > limit * 3 {
return Err(AuditErr::SpaceParamErr);
}

Expand All @@ -1095,7 +1107,6 @@ pub mod pallet {
break;
}
}

Ok(space_challenge_param)
}

Expand Down
10 changes: 10 additions & 0 deletions c-pallets/audit/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ pub struct ProveInfo<T: pallet::Config> {
pub(super) service_prove: Option<ServiceProveInfo<T>>,
}

#[derive(PartialEq, Eq, Encode, Decode, Clone, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct ProveInfoV2<T: pallet::Config> {
pub(super) idle_prove: Option<IdleProveInfo<T>>,
pub(super) assign: u8,
pub(super) service_prove: Option<ServiceProveInfo<T>>,
}


#[derive(PartialEq, Eq, Encode, Decode, Clone, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
Expand Down
2 changes: 1 addition & 1 deletion c-pallets/sminer/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ pub(super) const IDLE_PUNI_MUTI: Perbill = Perbill::from_percent(10);

pub(super) const SERVICE_PUNI_MUTI: Perbill = Perbill::from_percent(25);

pub(super) const BASE_LIMIT: u128 = 2_000_000_000_000_000;
pub(super) const BASE_LIMIT: u128 = 4_000_000_000_000_000;
2 changes: 1 addition & 1 deletion c-pallets/sminer/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<T: Config> Pallet<T> {
// FOR TESTING
let punish_amount = match level {
1 => Perbill::from_percent(30).mul_floor(limit),
2 => Perbill::from_percent(60).mul_floor(limit),
2 => Perbill::from_percent(50).mul_floor(limit),
3 | 4 | 5 | 6 => limit,
_ => return Err(Error::<T>::Unexpected)?,
};
Expand Down
3 changes: 3 additions & 0 deletions c-pallets/sminer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ pub mod pallet {
StateError,

BloomElemPushError,

CollateralNotUp,
}

/// The hashmap for info of storage miners.
Expand Down Expand Up @@ -320,6 +322,7 @@ pub mod pallet {
) -> DispatchResult {
let sender = ensure_signed(origin)?;
ensure!(!(<MinerItems<T>>::contains_key(&sender)), Error::<T>::AlreadyRegistered);
ensure!(staking_val >= BASE_LIMIT.try_into().map_err(|_| Error::<T>::Overflow)?, Error::<T>::CollateralNotUp);
T::Currency::reserve(&sender, staking_val)?;

let space_proof_info = SpaceProofInfo::<AccountOf<T>> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 103,
spec_version: 115,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 757b44f

Please sign in to comment.