Skip to content

Commit

Permalink
add events for cluster management
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid5594 committed Jul 12, 2023
1 parent afee1b9 commit 01421ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ parameter_types! {
}

/// Reward points of an era. Used to split era total payout between stakers.
#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)]
pub struct EraRewardPoints<AccountId: Ord> {
/// Total number of points. Equals the sum of reward points for each staker.
pub total: RewardPoint,
Expand Down Expand Up @@ -320,6 +320,8 @@ pub mod pallet {
/// An account has declared desire to stop participating in CDN or storage network soon.
/// \[stash, cluster, era\]
ChillSoon(T::AccountId, ClusterId, EraIndex),
// Payout CDN nodes' stash accounts
PayoutNodes(EraIndex, EraRewardPoints<T::AccountId>, u128)
}

#[pallet::error]
Expand Down Expand Up @@ -804,7 +806,7 @@ pub mod pallet {
);

// Transfer a part of the budget to each CDN participant rewarded this era.
for (stash, points) in era_reward_points.individual {
for (stash, points) in era_reward_points.clone().individual {
let part = Perbill::from_rational(points, era_reward_points.total);
let reward: BalanceOf<T> = part * payout_budget;
log::debug!(
Expand All @@ -826,6 +828,8 @@ pub mod pallet {
total_rewards += reward;
<Rewards<T>>::insert(&stash, total_rewards);
}
Self::deposit_event(Event::<T>::PayoutNodes(era, era_reward_points.clone() ,price_per_byte));

log::debug!(
"Balance left on payout source account {:?}",
T::Currency::free_balance(&payout_source_account),
Expand Down
11 changes: 8 additions & 3 deletions pallets/ddc-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ pub mod pallet {
pub enum Event<T: Config>
where
<T as frame_system::Config>::AccountId: AsRef<[u8]> + UncheckedFrom<T::Hash>,
<BalanceOf<T> as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {}
<BalanceOf<T> as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {
// Validator submits decision for an era
ValidationDecision(EraIndex, T::AccountId, ValidationDecision),
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
Expand Down Expand Up @@ -635,7 +638,7 @@ pub mod pallet {
fn validate(bytes_sent: &dac::BytesSent, bytes_received: &dac::BytesReceived) -> bool {
let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32);

return if percentage_difference > 0.0 &&
return if percentage_difference >= 0.0 &&
(T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0
{
true
Expand All @@ -647,7 +650,7 @@ pub mod pallet {
fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool {
let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32);

return if percentage_difference > 0.0 &&
return if percentage_difference >= 0.0 &&
(T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0
{
true
Expand Down Expand Up @@ -919,6 +922,8 @@ pub mod pallet {
validation_decision: final_res.clone(),
});

Self::deposit_event(Event::<T>::ValidationDecision(current_era - 1, utils::string_to_account::<T>(edge.clone()), final_res.clone()));

log::info!("final_res: {:?}", final_res);
}
}
Expand Down

0 comments on commit 01421ea

Please sign in to comment.