Compare commits
4 Commits
b5845924dc
...
39a6192d28
Author | SHA1 | Date | |
---|---|---|---|
39a6192d28 | |||
6100e79ebf | |||
99c43a0c24 | |||
417de5a7b2 |
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1186,7 +1186,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "casper-runtime"
|
||||
version = "3.5.22"
|
||||
version = "3.5.23"
|
||||
dependencies = [
|
||||
"casper-runtime-constants",
|
||||
"frame-benchmarking",
|
||||
@ -3834,7 +3834,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ghost-slow-clap"
|
||||
version = "0.3.24"
|
||||
version = "0.3.26"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-slow-clap"
|
||||
version = "0.3.24"
|
||||
version = "0.3.27"
|
||||
description = "Applause protocol for the EVM bridge"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
@ -299,6 +299,9 @@ pub mod pallet {
|
||||
#[pallet::constant]
|
||||
type UnsignedPriority: Get<TransactionPriority>;
|
||||
|
||||
#[pallet::constant]
|
||||
type HistoryDepth: Get<SessionIndex>;
|
||||
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
@ -339,11 +342,11 @@ pub mod pallet {
|
||||
pub(super) type ReceivedClaps<T: Config> = StorageNMap<
|
||||
_,
|
||||
(
|
||||
NMapKey<Twox64Concat, u32>,
|
||||
NMapKey<Twox64Concat, SessionIndex>,
|
||||
NMapKey<Twox64Concat, H256>,
|
||||
NMapKey<Twox64Concat, H256>,
|
||||
),
|
||||
BoundedBTreeSet<u32, T::MaxAuthorities>,
|
||||
BoundedBTreeSet<AuthIndex, T::MaxAuthorities>,
|
||||
ValueQuery
|
||||
>;
|
||||
|
||||
@ -352,7 +355,7 @@ pub mod pallet {
|
||||
pub(super) type ApplausesForTransaction<T: Config> = StorageNMap<
|
||||
_,
|
||||
(
|
||||
NMapKey<Twox64Concat, u32>,
|
||||
NMapKey<Twox64Concat, SessionIndex>,
|
||||
NMapKey<Twox64Concat, H256>,
|
||||
NMapKey<Twox64Concat, H256>,
|
||||
),
|
||||
@ -562,7 +565,13 @@ impl<T: Config> Pallet<T> {
|
||||
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
||||
|
||||
if enough_authorities {
|
||||
Self::try_applause(&clap, &received_claps_key)?;
|
||||
if let Err(error_msg) = Self::try_applause(&clap, &received_claps_key) {
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"👏 Could not applause because of: {:?}",
|
||||
error_msg,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -690,8 +699,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 =>
|
||||
Self::prepare_request_body_for_latest_transfers(from_block, to_block, network_data),
|
||||
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),
|
||||
_ => Self::prepare_request_body_for_latest_block(network_data),
|
||||
};
|
||||
|
||||
@ -928,10 +937,23 @@ 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()
|
||||
|
@ -187,6 +187,7 @@ 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)]
|
||||
@ -212,6 +213,7 @@ impl Config for Runtime {
|
||||
type ApplauseThreshold = ConstU32<50>;
|
||||
type OffenceThreshold = ConstU32<75>;
|
||||
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
|
||||
type HistoryDepth = HistoryDepth;
|
||||
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
@ -247,6 +247,35 @@ 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);
|
||||
@ -495,7 +524,7 @@ fn should_throw_error_if_validator_disabled_and_ignore_later() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_throw_error_on_gatekeeper_amount_overflow() {
|
||||
fn should_clap_without_applause_on_gatekeeper_amount_overflow() {
|
||||
let big_amount: u64 = u64::MAX;
|
||||
let first_receiver: u64 = 1337;
|
||||
let second_receiver: u64 = 420;
|
||||
@ -540,12 +569,7 @@ fn should_throw_error_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_ok!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature));
|
||||
}
|
||||
|
||||
assert_eq!(Balances::balance(&first_receiver), big_amount);
|
||||
@ -558,7 +582,7 @@ fn should_throw_error_on_gatekeeper_amount_overflow() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_throw_error_on_commission_overflow() {
|
||||
fn should_clap_without_applause_on_commission_overflow() {
|
||||
let big_amount: u64 = u64::MAX;
|
||||
let first_receiver: u64 = 1337;
|
||||
let second_receiver: u64 = 420;
|
||||
@ -606,19 +630,14 @@ fn should_throw_error_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_ok!(SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature));
|
||||
}
|
||||
|
||||
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), 0);
|
||||
assert_eq!(Networks::gatekeeper_amount(network_id_other), big_amount);
|
||||
assert_eq!(Networks::bridged_imbalance().bridged_in, big_amount);
|
||||
assert_eq!(Networks::bridged_imbalance().bridged_out, 0);
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "casper-runtime"
|
||||
version = "3.5.22"
|
||||
version = "3.5.23"
|
||||
build = "build.rs"
|
||||
description = "Runtime of the Casper Network"
|
||||
edition.workspace = true
|
||||
|
@ -492,6 +492,8 @@ 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 {
|
||||
@ -520,8 +522,8 @@ impl pallet_staking::Config for Runtime {
|
||||
type VoterList = VoterList;
|
||||
type TargetList = UseValidatorsMap<Self>;
|
||||
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
|
||||
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
|
||||
type HistoryDepth = frame_support::traits::ConstU32<84>;
|
||||
type MaxUnlockingChunks = MaxUnlockingChunks;
|
||||
type HistoryDepth = StakingHistoryDepth;
|
||||
type MaxControllersInDeprecationBatch = ConstU32<5314>;
|
||||
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
|
||||
type EventListeners = NominationPools;
|
||||
@ -1075,10 +1077,12 @@ impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
|
||||
|
||||
parameter_types! {
|
||||
// will be used in `Perbill::from_percent()`
|
||||
pub ApplauseThreshold: u32 = 70;
|
||||
pub const ApplauseThreshold: u32 = 70;
|
||||
// will be used in `Perbill::from_percent()`
|
||||
pub OffenceThreshold: u32 = 40;
|
||||
pub const 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 {
|
||||
@ -1096,6 +1100,7 @@ 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>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user