update casper runtime based on ghost pallets

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2025-11-27 19:07:59 +03:00
parent c9b4325c04
commit 638d31ba28
Signed by: st1nky
GPG Key ID: 016064BD97603B40
4 changed files with 47 additions and 2 deletions

View File

@ -88,6 +88,7 @@ ghost-networks = { workspace = true }
ghost-claims = { workspace = true } ghost-claims = { workspace = true }
ghost-slow-clap = { workspace = true } ghost-slow-clap = { workspace = true }
ghost-sudo = { workspace = true } ghost-sudo = { workspace = true }
ghost-traits = { workspace = true }
casper-runtime-constants = { workspace = true } casper-runtime-constants = { workspace = true }
runtime-common = { workspace = true } runtime-common = { workspace = true }
primitives = { workspace = true } primitives = { workspace = true }

View File

@ -1,6 +1,8 @@
use super::*; use super::*;
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::PrivilegeCmp}; use frame_support::{dispatch::DispatchResultWithPostInfo, traits::PrivilegeCmp};
use ghost_traits::exposure::ExposureListener;
use pallet_alliance::{ProposalIndex, ProposalProvider}; use pallet_alliance::{ProposalIndex, ProposalProvider};
use primitives::Balance;
use sp_runtime::DispatchError; use sp_runtime::DispatchError;
use sp_std::{cmp::Ordering, marker::PhantomData}; use sp_std::{cmp::Ordering, marker::PhantomData};
@ -76,6 +78,36 @@ impl PrivilegeCmp<OriginCaller> for EqualOrGreatestRootCmp {
} }
} }
/// Used to get the exposure information out of staking pallet directly.
pub struct StakingExposureListener<T>(PhantomData<T>);
impl<T> ExposureListener<Balance, AccountIdOf<T>> for StakingExposureListener<T>
where
T: pallet_session::Config + pallet_staking::Config + frame_system::Config,
u128: From<T::CurrencyBalance>,
AccountIdOf<T>: From<<T as pallet_session::Config>::ValidatorId>,
{
fn get_account_by_index(index: usize) -> Option<AccountIdOf<T>> {
pallet_session::Pallet::<T>::validators()
.get(index)
.map(|validator| {
let account_id: AccountIdOf<T> = validator.clone().into();
account_id
})
}
fn get_total_exposure() -> Balance {
let era = pallet_staking::Pallet::<T>::current_era().unwrap_or_default();
pallet_staking::Pallet::<T>::eras_total_stake(era).into()
}
fn get_validator_exposure(validator: &AccountIdOf<T>) -> Balance {
let era = pallet_staking::Pallet::<T>::current_era().unwrap_or_default();
pallet_staking::EraInfo::<T>::get_full_exposure(era, validator)
.total
.into()
}
}
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks { pub mod benchmarks {
use super::*; use super::*;

View File

@ -78,7 +78,7 @@ mod genesis_config_presets;
mod impls; mod impls;
mod weights; mod weights;
pub use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp}; pub use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp, StakingExposureListener};
// Governance configuration. // Governance configuration.
pub mod cult; pub mod cult;
@ -1076,10 +1076,10 @@ impl ghost_slow_clap::Config for Runtime {
type BlockNumberProvider = System; type BlockNumberProvider = System;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type DisabledValidators = Session; type DisabledValidators = Session;
type ExposureListener = StakingExposureListener<Runtime>;
type MaxAuthorities = MaxAuthorities; type MaxAuthorities = MaxAuthorities;
type ApplauseThreshold = ApplauseThreshold; type ApplauseThreshold = ApplauseThreshold;
type OffenceThreshold = OffenceThreshold;
type UnsignedPriority = SlowClapUnsignedPriority; type UnsignedPriority = SlowClapUnsignedPriority;
type HistoryDepth = SlowClapHistoryDepth; type HistoryDepth = SlowClapHistoryDepth;
type MinAuthoritiesNumber = MinAuthoritiesNumber; type MinAuthoritiesNumber = MinAuthoritiesNumber;

View File

@ -191,6 +191,18 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
} }
/// Storage: `GhostNetworks::Networks` (r:1 w:1) /// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_avg_block_speed() -> Weight {
// Proof Size summary in bytes:
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_579_000 picoseconds.
Weight::from_parts(51_126_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_network() -> Weight { fn remove_network() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `302` // Measured: `302`