Skip to content

Commit

Permalink
style: update event name and idle prove rate (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytqaljn committed Sep 5, 2023
1 parent 40c7e2b commit ddbf3bf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
7 changes: 4 additions & 3 deletions c-pallets/audit/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub(super) const SERVICE_PROVE_RATE: u128 = 50_331_648;

pub(super) const IDLE_PROVE_RATE: u128 = 143_165_576;
// miner cpu use 50%.
pub(super) const SERVICE_PROVE_RATE: u128 = 25_165_824;
// miner cpu use 50%.
pub(super) const IDLE_PROVE_RATE: u128 = 71_582_788;

pub(super) const IDLE_VERIFY_RATE: u128 = 2_147_483_648;

Expand Down
11 changes: 7 additions & 4 deletions c-pallets/audit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,12 @@ pub mod pallet {
<ChallengeDuration<T>>::put(duration);
let idle_duration = duration;
let one_hour = T::OneHours::get();
let tee_length = T::TeeWorkerHandler::get_controller_list().len();
let duration: u32 = (proposal.1.net_snap_shot.total_idle_space
.checked_add(proposal.1.net_snap_shot.total_service_space).ok_or(Error::<T>::Overflow)?
.checked_div(IDLE_VERIFY_RATE).ok_or(Error::<T>::Overflow)?) as u32;
.checked_div(IDLE_VERIFY_RATE).ok_or(Error::<T>::Overflow)?
.checked_div(tee_length as u128).ok_or(Error::<T>::Overflow)?
) as u32;
let v_duration = idle_duration
.checked_add(&duration.saturated_into()).ok_or(Error::<T>::Overflow)?
.checked_add(&one_hour).ok_or(Error::<T>::Overflow)?;
Expand Down Expand Up @@ -819,7 +822,7 @@ pub mod pallet {
weight = weight.saturating_add(T::DbWeight::get().reads(1));
for miner_snapshot in snap_shot.miner_snapshot_list.iter() {
// unwrap_or(3) 3 Need to match the maximum number of consecutive penalties.
let count = <CountedClear<T>>::get(&miner_snapshot.miner).checked_add(1).unwrap_or(3);
let count = <CountedClear<T>>::get(&miner_snapshot.miner).checked_add(1).unwrap_or(6);
weight = weight.saturating_add(T::DbWeight::get().reads(1));

let _ = T::MinerControl::clear_punish(
Expand All @@ -829,8 +832,8 @@ pub mod pallet {
miner_snapshot.service_space
);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));

if count >= 3 {
//For Testing
if count >= 6 {
let result = T::MinerControl::force_miner_exit(&miner_snapshot.miner);
if result.is_err() {
log::info!("force clear miner: {:?} failed", miner_snapshot.miner);
Expand Down
2 changes: 1 addition & 1 deletion c-pallets/file-bank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub mod pallet {
let _ = ensure_root(origin)?;

if count < 20 {
if let Err(e) = <DealMap<T>>::try_mutate(&deal_hash, |opt| -> DispatchResult {
if let Err(_e) = <DealMap<T>>::try_mutate(&deal_hash, |opt| -> DispatchResult {
let deal_info = opt.as_mut().ok_or(Error::<T>::NonExistent)?;
// unlock mienr space
let mut needed_list: BoundedVec<MinerTaskList<T>, T::FragmentCount> = Default::default();
Expand Down
4 changes: 2 additions & 2 deletions c-pallets/sminer/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ impl<T: Config> Pallet<T> {
pub(super) fn clear_punish(miner: &AccountOf<T>, level: u8, idle_space: u128, service_space: u128) -> DispatchResult {
let power = Self::calculate_power(idle_space, service_space);
let limit = Self::check_collateral_limit(power)?;

// FOR TESTING
let punish_amount = match level {
1 => Perbill::from_percent(30).mul_floor(limit),
2 => Perbill::from_percent(60).mul_floor(limit),
3 => limit,
3 | 4 | 5 | 6 => limit,
_ => return Err(Error::<T>::Unexpected)?,
};

Expand Down
14 changes: 7 additions & 7 deletions c-pallets/sminer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ pub mod pallet {
Deposit {
balance: BalanceOf<T>,
},
UpdataBeneficiary {
UpdateBeneficiary {
acc: AccountOf<T>,
new: AccountOf<T>,
},
UpdataIp {
UpdatePeerId {
acc: AccountOf<T>,
old: PeerId,
new: PeerId,
Expand Down Expand Up @@ -412,7 +412,7 @@ pub mod pallet {
<CurrencyReward<T>>::mutate(|reward| -> DispatchResult {
*reward = reward.checked_add(&miner_info.debt).ok_or(Error::<T>::Overflow)?;
Ok(())
});
})?;
miner_info.debt = BalanceOf::<T>::zero();
}
}
Expand All @@ -439,7 +439,7 @@ pub mod pallet {
Ok(())
}

/// updata miner beneficiary.
/// update miner beneficiary.
///
/// Parameters:
/// - `beneficiary`: The beneficiary related to signer account.
Expand All @@ -459,11 +459,11 @@ pub mod pallet {
Ok(())
})?;

Self::deposit_event(Event::<T>::UpdataBeneficiary { acc: sender, new: beneficiary });
Self::deposit_event(Event::<T>::UpdateBeneficiary { acc: sender, new: beneficiary });
Ok(())
}

/// updata miner IP.
/// update miner IP.
///
/// Parameters:
/// - `ip`: The registered IP of storage miner.
Expand All @@ -481,7 +481,7 @@ pub mod pallet {
Ok(old)
})?;

Self::deposit_event(Event::<T>::UpdataIp { acc: sender, old, new: peer_id.into() });
Self::deposit_event(Event::<T>::UpdatePeerId { acc: sender, old, new: peer_id.into() });
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions c-pallets/sminer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn miner_register_works() {
let event =
Sys::events().pop().expect("Expected at least one Registered to be found").event;
assert_eq!(
mock::RuntimeEvent::from(Event::UpdataBeneficiary { acc: ACCOUNT1.0, new: beneficiary_new }),
mock::RuntimeEvent::from(Event::UpdateBeneficiary { acc: ACCOUNT1.0, new: beneficiary_new }),
event
);

Expand All @@ -86,7 +86,7 @@ fn miner_register_works() {
let event =
Sys::events().pop().expect("Expected at least one Registered to be found").event;
assert_eq!(
mock::RuntimeEvent::from(Event::UpdataIp { acc: ACCOUNT1.0, old: ip, new: ip_new }),
mock::RuntimeEvent::from(Event::UpdatePeerId { acc: ACCOUNT1.0, old: ip, new: ip_new }),
event
);
});
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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: 101,
spec_version: 102,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit ddbf3bf

Please sign in to comment.