Compare commits

..

No commits in common. "39a6192d2856f17ed8f553ea599174c7af24aab8" and "b5845924dcdb3668ac9edc951999f64bea350015" have entirely different histories.

7 changed files with 29 additions and 77 deletions

4
Cargo.lock generated
View File

@ -1186,7 +1186,7 @@ dependencies = [
[[package]]
name = "casper-runtime"
version = "3.5.23"
version = "3.5.22"
dependencies = [
"casper-runtime-constants",
"frame-benchmarking",
@ -3834,7 +3834,7 @@ dependencies = [
[[package]]
name = "ghost-slow-clap"
version = "0.3.26"
version = "0.3.24"
dependencies = [
"frame-benchmarking",
"frame-support",

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-slow-clap"
version = "0.3.27"
version = "0.3.24"
description = "Applause protocol for the EVM bridge"
license.workspace = true
authors.workspace = true

View File

@ -299,9 +299,6 @@ pub mod pallet {
#[pallet::constant]
type UnsignedPriority: Get<TransactionPriority>;
#[pallet::constant]
type HistoryDepth: Get<SessionIndex>;
type WeightInfo: WeightInfo;
}
@ -342,11 +339,11 @@ pub mod pallet {
pub(super) type ReceivedClaps<T: Config> = StorageNMap<
_,
(
NMapKey<Twox64Concat, SessionIndex>,
NMapKey<Twox64Concat, u32>,
NMapKey<Twox64Concat, H256>,
NMapKey<Twox64Concat, H256>,
),
BoundedBTreeSet<AuthIndex, T::MaxAuthorities>,
BoundedBTreeSet<u32, T::MaxAuthorities>,
ValueQuery
>;
@ -355,7 +352,7 @@ pub mod pallet {
pub(super) type ApplausesForTransaction<T: Config> = StorageNMap<
_,
(
NMapKey<Twox64Concat, SessionIndex>,
NMapKey<Twox64Concat, u32>,
NMapKey<Twox64Concat, H256>,
NMapKey<Twox64Concat, H256>,
),
@ -565,13 +562,7 @@ impl<T: Config> Pallet<T> {
) > Perbill::from_percent(T::ApplauseThreshold::get());
if enough_authorities {
if let Err(error_msg) = Self::try_applause(&clap, &received_claps_key) {
log::info!(
target: LOG_TARGET,
"👏 Could not applause because of: {:?}",
error_msg,
);
}
Self::try_applause(&clap, &received_claps_key)?;
}
Ok(())
@ -699,8 +690,8 @@ impl<T: Config> Pallet<T> {
match result_block_range {
Ok(maybe_block_range) => {
let request_body = match maybe_block_range {
Some((from_block, to_block)) if from_block < to_block.saturating_sub(1) =>
Self::prepare_request_body_for_latest_transfers(from_block, to_block.saturating_sub(1), network_data),
Some((from_block, to_block)) if from_block < to_block =>
Self::prepare_request_body_for_latest_transfers(from_block, to_block, network_data),
_ => Self::prepare_request_body_for_latest_block(network_data),
};
@ -937,23 +928,10 @@ impl<T: Config> Pallet<T> {
assert!(Authorities::<T>::get(&session_index).is_empty(), "Authorities are already initilized!");
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities)
.expect("more than the maximum number of authorities");
if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) {
Self::clear_history(&target_session_index);
}
Authorities::<T>::set(&session_index, bounded_authorities);
ClapsInSession::<T>::set(&session_index, Default::default());
}
fn clear_history(target_session_index: &SessionIndex) {
ClapsInSession::<T>::remove(target_session_index);
let mut cursor = ReceivedClaps::<T>::clear_prefix((target_session_index,), u32::MAX, None);
debug_assert!(cursor.maybe_cursor.is_none());
cursor = ApplausesForTransaction::<T>::clear_prefix((target_session_index,), u32::MAX, None);
debug_assert!(cursor.maybe_cursor.is_none());
}
fn calculate_median_claps(session_index: &SessionIndex) -> u32 {
let mut claps_in_session = ClapsInSession::<T>::get(session_index)
.values()

View File

@ -187,7 +187,6 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub static ExistentialDeposit: u64 = 2;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const HistoryDepth: u32 = 10;
}
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
@ -213,7 +212,6 @@ impl Config for Runtime {
type ApplauseThreshold = ConstU32<50>;
type OffenceThreshold = ConstU32<75>;
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
type HistoryDepth = HistoryDepth;
type WeightInfo = ();
}

View File

@ -247,35 +247,6 @@ fn should_make_http_call_and_parse_logs() {
});
}
#[test]
fn should_clear_sesions_based_on_history_depth() {
let (network_id, transaction_hash, unique_transaction_hash) =
generate_unique_hash(None, None, None, None);
new_test_ext().execute_with(|| {
let session_index = advance_session_and_get_index();
let history_depth = HistoryDepth::get();
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
assert_claps_info_correct(&storage_key, &session_index, 0);
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
assert_ok!(do_clap_from(session_index, network_id, 0, false));
assert_ok!(do_clap_from(session_index, network_id, 1, false));
assert_ok!(do_clap_from(session_index, network_id, 2, false));
assert_claps_info_correct(&storage_key, &session_index, 3);
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), true);
for _ in 0..history_depth {
advance_session();
}
assert_claps_info_correct(&storage_key, &session_index, 0);
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
});
}
#[test]
fn should_collect_commission_accordingly() {
let (network_id, _, _) = generate_unique_hash(None, None, None, None);
@ -524,7 +495,7 @@ fn should_throw_error_if_validator_disabled_and_ignore_later() {
}
#[test]
fn should_clap_without_applause_on_gatekeeper_amount_overflow() {
fn should_throw_error_on_gatekeeper_amount_overflow() {
let big_amount: u64 = u64::MAX;
let first_receiver: u64 = 1337;
let second_receiver: u64 = 420;
@ -569,7 +540,12 @@ fn should_clap_without_applause_on_gatekeeper_amount_overflow() {
};
let authority = UintAuthorityId::from((authority_index + 1) as u64);
let signature = authority.sign(&clap.encode()).unwrap();
if authority_index == 0 {
assert_ok!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature));
} else {
assert_err!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature),
Error::<Runtime>::CouldNotIncreaseGatekeeperAmount);
}
}
assert_eq!(Balances::balance(&first_receiver), big_amount);
@ -582,7 +558,7 @@ fn should_clap_without_applause_on_gatekeeper_amount_overflow() {
}
#[test]
fn should_clap_without_applause_on_commission_overflow() {
fn should_throw_error_on_commission_overflow() {
let big_amount: u64 = u64::MAX;
let first_receiver: u64 = 1337;
let second_receiver: u64 = 420;
@ -630,14 +606,19 @@ fn should_clap_without_applause_on_commission_overflow() {
};
let authority = UintAuthorityId::from((authority_index + 1) as u64);
let signature = authority.sign(&clap.encode()).unwrap();
if authority_index == 0 {
assert_ok!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature));
} else {
assert_err!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature),
Error::<Runtime>::CouldNotAccumulateIncomingImbalance);
}
}
assert_eq!(Balances::balance(&first_receiver), big_amount);
assert_eq!(Balances::balance(&second_receiver), 0);
assert_eq!(Networks::gatekeeper_amount(network_id), big_amount);
assert_eq!(Networks::gatekeeper_amount(network_id_other), big_amount);
assert_eq!(Networks::gatekeeper_amount(network_id_other), 0);
assert_eq!(Networks::bridged_imbalance().bridged_in, big_amount);
assert_eq!(Networks::bridged_imbalance().bridged_out, 0);
});

View File

@ -1,6 +1,6 @@
[package]
name = "casper-runtime"
version = "3.5.23"
version = "3.5.22"
build = "build.rs"
description = "Runtime of the Casper Network"
edition.workspace = true

View File

@ -492,8 +492,6 @@ parameter_types! {
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxNominations: u32 =
<NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub const StakingHistoryDepth: u32 = 84;
pub const MaxUnlockingChunks: u32 = 32;
}
impl pallet_staking::Config for Runtime {
@ -522,8 +520,8 @@ impl pallet_staking::Config for Runtime {
type VoterList = VoterList;
type TargetList = UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
type MaxUnlockingChunks = MaxUnlockingChunks;
type HistoryDepth = StakingHistoryDepth;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxControllersInDeprecationBatch = ConstU32<5314>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type EventListeners = NominationPools;
@ -1077,12 +1075,10 @@ impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
parameter_types! {
// will be used in `Perbill::from_percent()`
pub const ApplauseThreshold: u32 = 70;
pub ApplauseThreshold: u32 = 70;
// will be used in `Perbill::from_percent()`
pub const OffenceThreshold: u32 = 40;
pub OffenceThreshold: u32 = 40;
pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX;
pub const SlowClapHistoryDepth: sp_staking::SessionIndex =
StakingHistoryDepth::get() * SessionsPerEra::get();
}
impl ghost_slow_clap::Config for Runtime {
@ -1100,7 +1096,6 @@ impl ghost_slow_clap::Config for Runtime {
type ApplauseThreshold = ApplauseThreshold;
type OffenceThreshold = OffenceThreshold;
type UnsignedPriority = SlowClapUnsignedPriority;
type HistoryDepth = SlowClapHistoryDepth;
type WeightInfo = weights::ghost_slow_clap::WeightInfo<Runtime>;
}