Skip to content

Commit

Permalink
0.7.4 challenge punish cancel (#242)
Browse files Browse the repository at this point in the history
* feat: cancel idle punish

* feat: adding domain name fields to oss registration
  • Loading branch information
ytqaljn authored Oct 12, 2023
1 parent dbe2206 commit e548a23
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 1 addition & 12 deletions c-pallets/audit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,6 @@ pub mod pallet {
}
}

if idle_result {
<CountedIdleFailed<T>>::insert(&sender, u32::MIN);
} else {
let count = <CountedIdleFailed<T>>::get(&sender).checked_add(1).unwrap_or(IDLE_FAULT_TOLERANT as u32);
if count >= IDLE_FAULT_TOLERANT as u32 {
T::MinerControl::idle_punish(&sender, *idle_space, *service_space)?;
}
<CountedIdleFailed<T>>::insert(&sender, count);
}

let count = challenge_info.miner_snapshot.space_proof_info.rear
.checked_sub(challenge_info.miner_snapshot.space_proof_info.front).ok_or(Error::<T>::Overflow)?;
T::CreditCounter::record_proceed_block_size(&tee_acc, count)?;
Expand Down Expand Up @@ -672,8 +662,7 @@ pub mod pallet {
for (miner, _) in <ChallengeSlip<T>>::iter_prefix(&now) {
if let Ok(challenge_info) = <ChallengeSnapShot<T>>::try_get(&miner) {
weight = weight.saturating_add(T::DbWeight::get().reads(1));
if challenge_info.prove_info.idle_prove.is_none()
|| challenge_info.prove_info.service_prove.is_none() {
if challenge_info.prove_info.service_prove.is_none() {
let count = <CountedClear<T>>::get(&miner).checked_add(1).unwrap_or(6);
weight = weight.saturating_add(T::DbWeight::get().reads(1));

Expand Down
22 changes: 15 additions & 7 deletions c-pallets/oss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pub mod benchmarking;

pub mod weights;

mod types;
use types::*;

#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down Expand Up @@ -78,7 +81,7 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn oss)]
pub(super) type Oss<T: Config> = StorageMap<_, Blake2_128Concat, AccountOf<T>, PeerId>;
pub(super) type Oss<T: Config> = StorageMap<_, Blake2_128Concat, AccountOf<T>, OssInfo>;

#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
Expand Down Expand Up @@ -131,10 +134,14 @@ pub mod pallet {
#[pallet::call_index(2)]
#[transactional]
#[pallet::weight(<T as pallet::Config>::WeightInfo::register())]
pub fn register(origin: OriginFor<T>, endpoint: PeerId) -> DispatchResult {
pub fn register(origin: OriginFor<T>, endpoint: PeerId, domain: BoundedVec<u8, ConstU32<50>>) -> DispatchResult {
let sender = ensure_signed(origin)?;
ensure!(!<Oss<T>>::contains_key(&sender), Error::<T>::Registered);
<Oss<T>>::insert(&sender, endpoint.clone());
let oss_info = OssInfo {
peer_id: endpoint.clone(),
domain,
};
<Oss<T>>::insert(&sender, oss_info);

Self::deposit_event(Event::<T>::OssRegister {acc: sender, endpoint});

Expand All @@ -144,13 +151,14 @@ pub mod pallet {
#[pallet::call_index(3)]
#[transactional]
#[pallet::weight(<T as pallet::Config>::WeightInfo::update())]
pub fn update(origin: OriginFor<T>, endpoint: PeerId) -> DispatchResult {
pub fn update(origin: OriginFor<T>, endpoint: PeerId, domain: BoundedVec<u8, ConstU32<50>>) -> DispatchResult {
let sender = ensure_signed(origin)?;
ensure!(<Oss<T>>::contains_key(&sender), Error::<T>::UnRegister);

<Oss<T>>::try_mutate(&sender, |endpoint_opt| -> DispatchResult {
let p_endpoint = endpoint_opt.as_mut().ok_or(Error::<T>::OptionParseError)?;
*p_endpoint = endpoint.clone();
<Oss<T>>::try_mutate(&sender, |oss_info_opt| -> DispatchResult {
let oss_info = oss_info_opt.as_mut().ok_or(Error::<T>::OptionParseError)?;
oss_info.peer_id = endpoint;
oss_info.domain = domain;
Ok(())
})?;

Expand Down
7 changes: 7 additions & 0 deletions c-pallets/oss/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::*;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct OssInfo {
pub(super) peer_id: PeerId,
pub(super) domain: BoundedVec<u8, ConstU32<50>>,
}

0 comments on commit e548a23

Please sign in to comment.