Skip to content

Commit

Permalink
remove points after some time
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Nov 5, 2024
1 parent 774f412 commit a5ef43b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 13 additions & 0 deletions pallets/external-validators-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
type EraIndexProvider: EraIndexProvider;

type HistoryDepth: Get<EraIndex>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -78,6 +80,16 @@ pub mod pallet {
})
}
}

impl<T: Config> tp_traits::OnEraStart for Pallet<T> {
fn on_era_start(era_index: EraIndex, _session_start: u32) {
let Some(era_index_to_delete) = era_index.checked_sub(T::HistoryDepth::get()) else {
return;
};

ErasRewardPoints::<T>::remove(era_index_to_delete);
}
}
}

/// The amount of era points given by backing a candidate that is included.
Expand Down Expand Up @@ -144,3 +156,4 @@ where
Self::reward_only_active(session, validators, DISPUTE_STATEMENT_POINTS);
}
}

9 changes: 2 additions & 7 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,21 +1227,16 @@ impl pallet_external_validators::Config for Runtime {
type ValidatorRegistration = Session;
type UnixTime = Timestamp;
type SessionsPerEra = SessionsPerEra;
type OnEraStart = ();
type OnEraStart = (ExternalValidatorsRewards,);
type OnEraEnd = ();
type WeightInfo = weights::pallet_external_validators::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Currency = Balances;
}

parameter_types! {
pub CurrentEra: Option<pallet_external_validators_rewards::EraIndex> =
pallet_external_validators::ActiveEra::<Runtime>::get().map(|info| info.index);
// pub const CurrentEra: Option<pallet_external_validators_rewards::EraIndex> = None;
}

impl pallet_external_validators_rewards::Config for Runtime {
type EraIndexProvider = ExternalValidators;
type HistoryDepth = ConstU32<64>;
}

impl pallet_sudo::Config for Runtime {
Expand Down

0 comments on commit a5ef43b

Please sign in to comment.