Compare commits
No commits in common. "75268b4c0a48fb250431bc7895c5d78aa4e96492" and "fc2e4e6bffcd76454938af3ab03c351819f37df1" have entirely different histories.
75268b4c0a
...
fc2e4e6bff
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1186,7 +1186,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "casper-runtime"
|
name = "casper-runtime"
|
||||||
version = "3.5.34"
|
version = "3.5.33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"casper-runtime-constants",
|
"casper-runtime-constants",
|
||||||
"frame-benchmarking",
|
"frame-benchmarking",
|
||||||
@ -3836,7 +3836,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.3.51"
|
version = "0.3.47"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"frame-benchmarking",
|
"frame-benchmarking",
|
||||||
"frame-support",
|
"frame-support",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.3.51"
|
version = "0.3.47"
|
||||||
description = "Applause protocol for the EVM bridge"
|
description = "Applause protocol for the EVM bridge"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use frame_support::{
|
|||||||
pallet_prelude::*,
|
pallet_prelude::*,
|
||||||
traits::{
|
traits::{
|
||||||
tokens::fungible::{Inspect, Mutate},
|
tokens::fungible::{Inspect, Mutate},
|
||||||
DisabledValidators, EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet,
|
EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet,
|
||||||
ValidatorSetWithIdentification,
|
ValidatorSetWithIdentification,
|
||||||
},
|
},
|
||||||
WeakBoundedVec,
|
WeakBoundedVec,
|
||||||
@ -36,7 +36,7 @@ use sp_staking::{
|
|||||||
SessionIndex,
|
SessionIndex,
|
||||||
};
|
};
|
||||||
use sp_std::{
|
use sp_std::{
|
||||||
collections::btree_map::BTreeMap,
|
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
@ -118,7 +118,6 @@ enum OffchainErr<NetworkId> {
|
|||||||
UnknownNetworkType(NetworkId),
|
UnknownNetworkType(NetworkId),
|
||||||
OffchainTimeoutPeriod(NetworkId),
|
OffchainTimeoutPeriod(NetworkId),
|
||||||
TooManyRequests(NetworkId),
|
TooManyRequests(NetworkId),
|
||||||
AuthorityDisabled(AuthIndex),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<NetworkId: core::fmt::Debug> core::fmt::Debug for OffchainErr<NetworkId> {
|
impl<NetworkId: core::fmt::Debug> core::fmt::Debug for OffchainErr<NetworkId> {
|
||||||
@ -144,7 +143,7 @@ impl<NetworkId: core::fmt::Debug> core::fmt::Debug for OffchainErr<NetworkId> {
|
|||||||
OffchainErr::UnknownNetworkType(ref network_id) => write!(fmt, "Unknown type for network #{:?}.", network_id),
|
OffchainErr::UnknownNetworkType(ref network_id) => write!(fmt, "Unknown type for network #{:?}.", network_id),
|
||||||
OffchainErr::OffchainTimeoutPeriod(ref network_id) => write!(fmt, "Offchain request should be in-flight for network #{:?}.", network_id),
|
OffchainErr::OffchainTimeoutPeriod(ref network_id) => write!(fmt, "Offchain request should be in-flight for network #{:?}.", network_id),
|
||||||
OffchainErr::TooManyRequests(ref network_id) => write!(fmt, "Too many requests over RPC endpoint for network #{:?}.", network_id),
|
OffchainErr::TooManyRequests(ref network_id) => write!(fmt, "Too many requests over RPC endpoint for network #{:?}.", network_id),
|
||||||
OffchainErr::AuthorityDisabled(ref authority_index) => write!(fmt, "Authority index {:?} is disabled in current session.", authority_index),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +199,6 @@ pub mod pallet {
|
|||||||
IdentificationTuple<Self>,
|
IdentificationTuple<Self>,
|
||||||
ThrottlingOffence<IdentificationTuple<Self>>,
|
ThrottlingOffence<IdentificationTuple<Self>>,
|
||||||
>;
|
>;
|
||||||
type DisabledValidators: DisabledValidators;
|
|
||||||
|
|
||||||
#[pallet::constant]
|
#[pallet::constant]
|
||||||
type MaxAuthorities: Get<u32>;
|
type MaxAuthorities: Get<u32>;
|
||||||
@ -244,6 +242,7 @@ pub mod pallet {
|
|||||||
#[pallet::error]
|
#[pallet::error]
|
||||||
pub enum Error<T> {
|
pub enum Error<T> {
|
||||||
NotEnoughClaps,
|
NotEnoughClaps,
|
||||||
|
CurrentValidatorIsDisabled,
|
||||||
AlreadyClapped,
|
AlreadyClapped,
|
||||||
UnregisteredClapRemove,
|
UnregisteredClapRemove,
|
||||||
TooMuchAuthorities,
|
TooMuchAuthorities,
|
||||||
@ -399,14 +398,6 @@ pub mod pallet {
|
|||||||
None => return InvalidTransaction::BadSigner.into(),
|
None => return InvalidTransaction::BadSigner.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if ClapsInSession::<T>::get(&session_index)
|
|
||||||
.get(&clap.authority_index)
|
|
||||||
.map(|info| info.disabled)
|
|
||||||
.unwrap_or_default()
|
|
||||||
{
|
|
||||||
return InvalidTransaction::BadSigner.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
let signature_valid =
|
let signature_valid =
|
||||||
clap.using_encoded(|encoded_clap| authority.verify(&encoded_clap, signature));
|
clap.using_encoded(|encoded_clap| authority.verify(&encoded_clap, signature));
|
||||||
|
|
||||||
@ -507,14 +498,22 @@ impl<T: Config> Pallet<T> {
|
|||||||
let (session_index, clap_unique_hash) = Self::mended_session_index(&clap);
|
let (session_index, clap_unique_hash) = Self::mended_session_index(&clap);
|
||||||
let mut claps_in_session = ClapsInSession::<T>::get(&session_index);
|
let mut claps_in_session = ClapsInSession::<T>::get(&session_index);
|
||||||
|
|
||||||
let disabled_authorities = claps_in_session
|
ensure!(
|
||||||
|
claps_in_session
|
||||||
|
.get(&clap.authority_index)
|
||||||
|
.map(|info| !info.disabled)
|
||||||
|
.unwrap_or(true),
|
||||||
|
Error::<T>::CurrentValidatorIsDisabled
|
||||||
|
);
|
||||||
|
|
||||||
|
let disabled_authorites = claps_in_session
|
||||||
.values()
|
.values()
|
||||||
.filter(|info| info.disabled)
|
.filter(|info| info.disabled)
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
let active_authorities = Authorities::<T>::get(&session_index)
|
let active_authorities = Authorities::<T>::get(&session_index)
|
||||||
.len()
|
.len()
|
||||||
.saturating_sub(disabled_authorities);
|
.saturating_sub(disabled_authorites);
|
||||||
|
|
||||||
let received_claps_key = (session_index, &clap.transaction_hash, &clap_unique_hash);
|
let received_claps_key = (session_index, &clap.transaction_hash, &clap_unique_hash);
|
||||||
|
|
||||||
@ -619,53 +618,34 @@ impl<T: Config> Pallet<T> {
|
|||||||
let curr_session_index = prev_session_index.saturating_add(1);
|
let curr_session_index = prev_session_index.saturating_add(1);
|
||||||
let clap_unique_hash = Self::generate_unique_hash(&receiver, &amount, &network_id);
|
let clap_unique_hash = Self::generate_unique_hash(&receiver, &amount, &network_id);
|
||||||
|
|
||||||
let prev_authorities = Authorities::<T>::get(&prev_session_index)
|
let prev_authorities = Authorities::<T>::get(&prev_session_index);
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, auth)| (auth, i as AuthIndex))
|
|
||||||
.collect::<BTreeMap<T::AuthorityId, AuthIndex>>();
|
|
||||||
let curr_authorities = Authorities::<T>::get(&curr_session_index);
|
let curr_authorities = Authorities::<T>::get(&curr_session_index);
|
||||||
|
|
||||||
let prev_received_claps_key = (prev_session_index, &transaction_hash, &clap_unique_hash);
|
let prev_received_claps_key = (prev_session_index, &transaction_hash, &clap_unique_hash);
|
||||||
let curr_received_claps_key = (curr_session_index, &transaction_hash, &clap_unique_hash);
|
let curr_received_claps_key = (curr_session_index, &transaction_hash, &clap_unique_hash);
|
||||||
|
|
||||||
let mut previous_claps = ClapsInSession::<T>::get(&prev_session_index);
|
let prev_received_claps = ReceivedClaps::<T>::get(&prev_received_claps_key)
|
||||||
let mut total_received_claps = ReceivedClaps::<T>::get(&prev_received_claps_key).into_inner();
|
.into_iter()
|
||||||
|
.filter_map(|auth_index| prev_authorities.get(auth_index as usize))
|
||||||
|
.cloned()
|
||||||
|
.collect::<BTreeSet<T::AuthorityId>>();
|
||||||
|
|
||||||
for (auth_index, info) in ClapsInSession::<T>::get(&curr_session_index).iter() {
|
let curr_received_claps = ReceivedClaps::<T>::get(&curr_received_claps_key)
|
||||||
if !info.disabled {
|
.into_iter()
|
||||||
continue;
|
.filter_map(|auth_index| curr_authorities.get(auth_index as usize))
|
||||||
}
|
.cloned()
|
||||||
|
.collect::<BTreeSet<T::AuthorityId>>();
|
||||||
|
|
||||||
if let Some(curr_authority) = curr_authorities.get(*auth_index as usize) {
|
let disabled_authorites = ClapsInSession::<T>::get(&prev_session_index)
|
||||||
if let Some(prev_position) = prev_authorities.get(&curr_authority) {
|
|
||||||
previous_claps
|
|
||||||
.entry(*prev_position as AuthIndex)
|
|
||||||
.and_modify(|individual| (*individual).disabled = true)
|
|
||||||
.or_insert(SessionAuthorityInfo {
|
|
||||||
claps: 0u32,
|
|
||||||
disabled: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for auth_index in ReceivedClaps::<T>::get(&curr_received_claps_key).into_iter() {
|
|
||||||
if let Some(curr_authority) = curr_authorities.get(auth_index as usize) {
|
|
||||||
if let Some(prev_position) = prev_authorities.get(&curr_authority) {
|
|
||||||
let _ = total_received_claps.insert(*prev_position as AuthIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let disabled_authorities = previous_claps
|
|
||||||
.values()
|
.values()
|
||||||
.filter(|info| info.disabled)
|
.filter(|info| info.disabled)
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
let active_authorities = prev_authorities
|
let active_authorities = prev_authorities.len().saturating_sub(disabled_authorites);
|
||||||
.len()
|
|
||||||
.saturating_sub(disabled_authorities);
|
let summary_authority_claps_length = curr_received_claps
|
||||||
|
.symmetric_difference(&prev_received_claps)
|
||||||
|
.count();
|
||||||
|
|
||||||
let clap = Clap {
|
let clap = Clap {
|
||||||
authority_index: Default::default(),
|
authority_index: Default::default(),
|
||||||
@ -679,7 +659,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let enough_authorities = Perbill::from_rational(
|
let enough_authorities = Perbill::from_rational(
|
||||||
total_received_claps.len() as u32,
|
summary_authority_claps_length as u32,
|
||||||
active_authorities as u32,
|
active_authorities as u32,
|
||||||
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
||||||
|
|
||||||
@ -768,14 +748,6 @@ impl<T: Config> Pallet<T> {
|
|||||||
network_id: NetworkIdOf<T>,
|
network_id: NetworkIdOf<T>,
|
||||||
network_data: &NetworkData,
|
network_data: &NetworkData,
|
||||||
) -> OffchainResult<T, ()> {
|
) -> OffchainResult<T, ()> {
|
||||||
if ClapsInSession::<T>::get(&session_index)
|
|
||||||
.get(&authority_index)
|
|
||||||
.map(|info| info.disabled)
|
|
||||||
.unwrap_or_default()
|
|
||||||
{
|
|
||||||
return Err(OffchainErr::AuthorityDisabled(authority_index));
|
|
||||||
}
|
|
||||||
|
|
||||||
let network_id_encoded = network_id.encode();
|
let network_id_encoded = network_id.encode();
|
||||||
|
|
||||||
let block_number_key = Self::create_storage_key(b"block-", &network_id_encoded);
|
let block_number_key = Self::create_storage_key(b"block-", &network_id_encoded);
|
||||||
@ -1132,18 +1104,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
|
|
||||||
Validators::<T>::insert(&session_index, bounded_validators);
|
Validators::<T>::insert(&session_index, bounded_validators);
|
||||||
Authorities::<T>::set(&session_index, bounded_authorities);
|
Authorities::<T>::set(&session_index, bounded_authorities);
|
||||||
|
ClapsInSession::<T>::set(&session_index, Default::default());
|
||||||
let mut disabled_validators: BTreeMap<AuthIndex, SessionAuthorityInfo> = Default::default();
|
|
||||||
for disabled_index in T::DisabledValidators::disabled_validators().iter() {
|
|
||||||
let _ = disabled_validators.insert(
|
|
||||||
*disabled_index,
|
|
||||||
SessionAuthorityInfo {
|
|
||||||
claps: 0u32,
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ClapsInSession::<T>::set(&session_index, disabled_validators);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_history(target_session_index: &SessionIndex) {
|
fn clear_history(target_session_index: &SessionIndex) {
|
||||||
|
|||||||
@ -206,7 +206,6 @@ impl Config for Runtime {
|
|||||||
type NetworkDataHandler = Networks;
|
type NetworkDataHandler = Networks;
|
||||||
type BlockNumberProvider = System;
|
type BlockNumberProvider = System;
|
||||||
type ReportUnresponsiveness = OffenceHandler;
|
type ReportUnresponsiveness = OffenceHandler;
|
||||||
type DisabledValidators = Session;
|
|
||||||
|
|
||||||
type MaxAuthorities = ConstU32<5>;
|
type MaxAuthorities = ConstU32<5>;
|
||||||
type ApplauseThreshold = ConstU32<50>;
|
type ApplauseThreshold = ConstU32<50>;
|
||||||
|
|||||||
@ -710,7 +710,7 @@ fn should_throw_error_if_validator_disabled_and_ignore_later() {
|
|||||||
assert_eq!(Session::disable_index(0), true);
|
assert_eq!(Session::disable_index(0), true);
|
||||||
assert_err!(
|
assert_err!(
|
||||||
do_clap_from(session_index, network_id, 0, false),
|
do_clap_from(session_index, network_id, 0, false),
|
||||||
DispatchError::Other("Invalid signing address")
|
Error::<Runtime>::CurrentValidatorIsDisabled
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(pallet::ReceivedClaps::<Runtime>::get(&storage_key).len(), 0);
|
assert_eq!(pallet::ReceivedClaps::<Runtime>::get(&storage_key).len(), 0);
|
||||||
@ -944,74 +944,6 @@ fn should_avoid_applause_during_nullification_period() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn should_self_applause_after_diabled() {
|
|
||||||
let zero = 0u64;
|
|
||||||
let (network_id, transaction_hash, unique_transaction_hash) =
|
|
||||||
generate_unique_hash(None, None, None, None);
|
|
||||||
let (_, receiver, amount) = get_mocked_metadata();
|
|
||||||
|
|
||||||
new_test_ext().execute_with(|| {
|
|
||||||
let _ = prepare_evm_network(Some(network_id), Some(0));
|
|
||||||
let session_index = advance_session_and_get_index();
|
|
||||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
|
||||||
|
|
||||||
assert_err!(
|
|
||||||
SlowClap::self_applause(
|
|
||||||
RuntimeOrigin::signed(receiver),
|
|
||||||
network_id,
|
|
||||||
session_index,
|
|
||||||
transaction_hash,
|
|
||||||
receiver,
|
|
||||||
amount,
|
|
||||||
),
|
|
||||||
Error::<Runtime>::NotEnoughClaps,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
assert_eq!(Balances::balance(&receiver), zero);
|
|
||||||
|
|
||||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
|
||||||
advance_session();
|
|
||||||
let curr_session_index = Session::session_index();
|
|
||||||
|
|
||||||
pallet::ClapsInSession::<Runtime>::mutate(&session_index, |claps| {
|
|
||||||
claps.entry(1 as AuthIndex)
|
|
||||||
.and_modify(|individual| (*individual).disabled = true)
|
|
||||||
.or_insert(SessionAuthorityInfo {
|
|
||||||
claps: 0u32,
|
|
||||||
disabled: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
pallet::ClapsInSession::<Runtime>::mutate(&curr_session_index, |claps| {
|
|
||||||
claps.entry(2 as AuthIndex)
|
|
||||||
.and_modify(|individual| (*individual).disabled = true)
|
|
||||||
.or_insert(SessionAuthorityInfo {
|
|
||||||
claps: 0u32,
|
|
||||||
disabled: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_ok!(SlowClap::self_applause(
|
|
||||||
RuntimeOrigin::signed(receiver),
|
|
||||||
network_id,
|
|
||||||
session_index,
|
|
||||||
transaction_hash,
|
|
||||||
receiver,
|
|
||||||
amount,
|
|
||||||
));
|
|
||||||
assert_eq!(
|
|
||||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
assert_eq!(Balances::balance(&receiver), amount);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_self_applause_if_enough_claps() {
|
fn should_self_applause_if_enough_claps() {
|
||||||
let zero = 0u64;
|
let zero = 0u64;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "casper-runtime"
|
name = "casper-runtime"
|
||||||
version = "3.5.34"
|
version = "3.5.33"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
description = "Runtime of the Casper Network"
|
description = "Runtime of the Casper Network"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
|||||||
@ -117,8 +117,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
spec_name: create_runtime_str!("casper"),
|
spec_name: create_runtime_str!("casper"),
|
||||||
impl_name: create_runtime_str!("casper-svengali"),
|
impl_name: create_runtime_str!("casper-svengali"),
|
||||||
authoring_version: 0,
|
authoring_version: 0,
|
||||||
spec_version: 4,
|
spec_version: 3,
|
||||||
impl_version: 2,
|
impl_version: 1,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
transaction_version: 1,
|
transaction_version: 1,
|
||||||
state_version: 1,
|
state_version: 1,
|
||||||
@ -1059,9 +1059,9 @@ impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
|
|||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
// will be used in `Perbill::from_percent()`
|
// will be used in `Perbill::from_percent()`
|
||||||
pub const ApplauseThreshold: u32 = 66;
|
pub const ApplauseThreshold: u32 = 70;
|
||||||
// will be used in `Perbill::from_percent()`
|
// will be used in `Perbill::from_percent()`
|
||||||
pub const OffenceThreshold: u32 = 5;
|
pub const OffenceThreshold: u32 = 40;
|
||||||
pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX;
|
pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX;
|
||||||
pub const SlowClapHistoryDepth: sp_staking::SessionIndex =
|
pub const SlowClapHistoryDepth: sp_staking::SessionIndex =
|
||||||
StakingHistoryDepth::get() * SessionsPerEra::get();
|
StakingHistoryDepth::get() * SessionsPerEra::get();
|
||||||
@ -1077,7 +1077,6 @@ impl ghost_slow_clap::Config for Runtime {
|
|||||||
type NetworkDataHandler = GhostNetworks;
|
type NetworkDataHandler = GhostNetworks;
|
||||||
type BlockNumberProvider = System;
|
type BlockNumberProvider = System;
|
||||||
type ReportUnresponsiveness = Offences;
|
type ReportUnresponsiveness = Offences;
|
||||||
type DisabledValidators = Session;
|
|
||||||
|
|
||||||
type MaxAuthorities = MaxAuthorities;
|
type MaxAuthorities = MaxAuthorities;
|
||||||
type ApplauseThreshold = ApplauseThreshold;
|
type ApplauseThreshold = ApplauseThreshold;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user