Compare commits

..

No commits in common. "da271a6f2270bad42c78c6ab4b9f53bfca042d38" and "f7b1b75d5aab7a39b9267e42370b1698d78ebb17" have entirely different histories.

10 changed files with 59 additions and 217 deletions

16
Cargo.lock generated
View File

@ -1186,7 +1186,7 @@ dependencies = [
[[package]]
name = "casper-runtime"
version = "3.5.30"
version = "3.5.29"
dependencies = [
"casper-runtime-constants",
"frame-benchmarking",
@ -3529,7 +3529,7 @@ dependencies = [
[[package]]
name = "ghost-cli"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"cfg-if",
"clap 4.5.4",
@ -3585,7 +3585,7 @@ dependencies = [
[[package]]
name = "ghost-machine-primitives"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"lazy_static",
"sc-sysinfo",
@ -3594,7 +3594,7 @@ dependencies = [
[[package]]
name = "ghost-metrics"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"assert_cmd",
"bs58 0.5.1",
@ -3668,7 +3668,7 @@ dependencies = [
[[package]]
name = "ghost-node"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"assert_cmd",
"color-eyre",
@ -3699,7 +3699,7 @@ dependencies = [
[[package]]
name = "ghost-rpc"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"ghost-core-primitives",
"jsonrpsee",
@ -3751,7 +3751,7 @@ dependencies = [
[[package]]
name = "ghost-service"
version = "0.8.1"
version = "0.8.0"
dependencies = [
"assert_matches",
"async-trait",
@ -3835,7 +3835,7 @@ dependencies = [
[[package]]
name = "ghost-slow-clap"
version = "0.3.39"
version = "0.3.35"
dependencies = [
"frame-benchmarking",
"frame-support",

View File

@ -17,7 +17,7 @@ homepage.workspace = true
[workspace.package]
license = "GPL-3.0-only"
authors = ["571nky", "57r37ch", "f4750"]
version = "0.8.1"
version = "0.8.0"
edition = "2021"
homepage = "https://ghostchain.io"
repository = "https://git.ghostchain.io/ghostchain/ghost-node"

View File

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

View File

@ -90,7 +90,7 @@ pub struct Clap<AccountId, NetworkId, Balance> {
pub amount: Balance,
}
#[derive(Default, Clone, Copy, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Default, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct SessionAuthorityInfo {
pub claps: u32,
pub disabled: bool,
@ -465,13 +465,6 @@ impl<T: Config> Pallet<T> {
authorities.get(clap.authority_index as usize).is_some(),
Error::<T>::NotAnAuthority
);
ensure!(
ClapsInSession::<T>::get(&clap.session_index)
.get(&clap.authority_index)
.map(|info| !info.disabled)
.unwrap_or(true),
Error::<T>::CurrentValidatorIsDisabled
);
let clap_unique_hash =
Self::generate_unique_hash(&clap.receiver, &clap.amount, &clap.network_id);
@ -498,7 +491,15 @@ impl<T: Config> Pallet<T> {
}
})?;
ClapsInSession::<T>::mutate(&clap.session_index, |claps_details| {
ClapsInSession::<T>::try_mutate(&clap.session_index, |claps_details| {
if claps_details
.get(&clap.authority_index)
.map(|x| x.disabled)
.unwrap_or_default()
{
return Err(Error::<T>::CurrentValidatorIsDisabled);
}
(*claps_details)
.entry(clap.authority_index)
.and_modify(|individual| (*individual).claps.saturating_inc())
@ -506,7 +507,9 @@ impl<T: Config> Pallet<T> {
claps: 1u32,
disabled: false,
});
});
Ok(())
})?;
Self::deposit_event(Event::<T>::Clapped {
authority_id: clap.authority_index,
@ -763,20 +766,23 @@ impl<T: Config> Pallet<T> {
Ok(match maybe_block_range {
Some((from_block, to_block)) => match maybe_new_evm_block {
Some(_) if from_block.le(&to_block) => {
let adjusted_to_block = estimated_block
.checked_sub(from_block)
.map(|current_distance| current_distance
.le(&max_block_distance)
.then(|| estimated_block)
)
.flatten()
.unwrap_or(from_block
.saturating_add(max_block_distance)
.min(estimated_block));
(from_block, adjusted_to_block)
Some(_) => {
match estimated_block.checked_sub(from_block) {
Some(current_distance)
if current_distance
< max_block_distance =>
{
(from_block, estimated_block)
}
_ => (
from_block,
from_block
.saturating_add(max_block_distance)
.min(estimated_block),
),
}
}
_ => (to_block, to_block),
None => (to_block, to_block),
},
None => (estimated_block, estimated_block),
})
@ -961,18 +967,10 @@ impl<T: Config> Pallet<T> {
.ok_or(OffchainErr::ErrorInEvmResponse)?)
}
fn calculate_median_claps(
actual_claps_in_session: &BTreeMap<AuthIndex, SessionAuthorityInfo>,
authorities_len: usize,
) -> u32 {
let mut claps_in_session = (0..authorities_len)
.filter_map(|authority_index| {
let clap_info = actual_claps_in_session
.get(&(authority_index as AuthIndex))
.copied()
.unwrap_or_default();
(!clap_info.disabled).then(|| clap_info.claps)
})
fn calculate_median_claps(session_index: &SessionIndex) -> u32 {
let mut claps_in_session = ClapsInSession::<T>::get(session_index)
.values()
.filter_map(|value| (!value.disabled).then(|| value.claps))
.collect::<Vec<_>>();
if claps_in_session.is_empty() {
@ -993,21 +991,17 @@ impl<T: Config> Pallet<T> {
fn is_good_actor(
authority_index: usize,
session_index: SessionIndex,
median_claps: u32,
claps_in_session: &BTreeMap<AuthIndex, SessionAuthorityInfo>,
) -> bool {
if median_claps == 0 {
return true;
}
let number_of_claps = claps_in_session
.get(&(authority_index as AuthIndex))
.copied()
.map(|info| match info.disabled {
true => median_claps,
false => info.claps,
})
.unwrap_or_default();
let number_of_claps = ClapsInSession::<T>::get(session_index)
.entry(authority_index as AuthIndex)
.or_default()
.claps;
let authority_deviation = if number_of_claps < median_claps {
Perbill::from_rational(median_claps - number_of_claps, median_claps)
@ -1089,15 +1083,14 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
fn on_before_session_ending() {
let session_index = T::ValidatorSet::session_index();
let validators = T::ValidatorSet::validators();
let authorities_len = Authorities::<T>::get(&session_index).len();
let claps_in_session = ClapsInSession::<T>::get(&session_index);
let authorities = Authorities::<T>::get(&session_index);
let median_claps = Self::calculate_median_claps(&claps_in_session, authorities_len);
let median_claps = Self::calculate_median_claps(&session_index);
let offenders = validators
.into_iter()
.enumerate()
.filter(|(index, _)| !Self::is_good_actor(*index, median_claps, &claps_in_session))
.filter(|(index, _)| !Self::is_good_actor(*index, session_index, median_claps))
.filter_map(|(_, id)| {
<T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
id.clone(),
@ -1112,7 +1105,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
throttling: offenders.clone(),
});
let validator_set_count = authorities_len as u32;
let validator_set_count = authorities.len() as u32;
let offence = ThrottlingOffence {
session_index,
validator_set_count,

View File

@ -119,157 +119,6 @@ fn test_throttling_slash_function() {
);
}
#[test]
fn test_median_calculations_are_correct() {
new_test_ext().execute_with(|| {
let data = BTreeMap::from([
(
0u32,
SessionAuthorityInfo {
claps: 0,
disabled: true,
},
),
(
3u32,
SessionAuthorityInfo {
claps: 1,
disabled: false,
},
),
]);
assert_eq!(SlowClap::calculate_median_claps(&data, 4), 0);
let data = BTreeMap::from([
(
0u32,
SessionAuthorityInfo {
claps: 0,
disabled: false,
},
),
(
1u32,
SessionAuthorityInfo {
claps: 69,
disabled: false,
},
),
(
2u32,
SessionAuthorityInfo {
claps: 69,
disabled: false,
},
),
(
3u32,
SessionAuthorityInfo {
claps: 420,
disabled: false,
},
),
]);
assert_eq!(SlowClap::calculate_median_claps(&data, 4), 69);
let data = BTreeMap::from([
(
0u32,
SessionAuthorityInfo {
claps: 31,
disabled: false,
},
),
(
1u32,
SessionAuthorityInfo {
claps: 420,
disabled: true,
},
),
(
2u32,
SessionAuthorityInfo {
claps: 69,
disabled: false,
},
),
(
3u32,
SessionAuthorityInfo {
claps: 156,
disabled: true,
},
),
]);
assert_eq!(SlowClap::calculate_median_claps(&data, 4), 50);
let data = BTreeMap::from([
(
0u32,
SessionAuthorityInfo {
claps: 0,
disabled: true,
},
),
(
1u32,
SessionAuthorityInfo {
claps: 420,
disabled: false,
},
),
(
2u32,
SessionAuthorityInfo {
claps: 0,
disabled: true,
},
),
(
3u32,
SessionAuthorityInfo {
claps: 0,
disabled: false,
},
),
]);
assert_eq!(SlowClap::calculate_median_claps(&data, 4), 210);
let data = BTreeMap::from([
(
0u32,
SessionAuthorityInfo {
claps: 0,
disabled: false,
},
),
(
1u32,
SessionAuthorityInfo {
claps: 420,
disabled: true,
},
),
(
2u32,
SessionAuthorityInfo {
claps: 69,
disabled: true,
},
),
(
3u32,
SessionAuthorityInfo {
claps: 0,
disabled: false,
},
),
]);
assert_eq!(SlowClap::calculate_median_claps(&data, 4), 0);
});
}
#[test]
fn request_body_is_correct_for_get_block_number() {
let (offchain, _) = TestOffchainExt::new();

View File

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

View File

@ -505,7 +505,7 @@ impl pallet_staking::Config for Runtime {
type SlashDeferDuration = SlashDeferDuration;
type AdminOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type SessionInterface = Self;
type EraPayout = ghost_networks::BridgedInflationCurve<RewardCurve, Self>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxExposurePageSize = MaxExposurePageSize;
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type NextNewSession = Session;

View File

@ -98,9 +98,6 @@ downgrade_compiler_if_needed() {
toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1)
rustup target add wasm32-unknown-unknown --toolchain $toolchain_name
rustup component add rust-src --toolchain $toolchain_name
cd $PROJECT_FOLDER
echo "[+] clean build cache..."
cargo clean
else
echo "[+] rustc compiler version is compatible"
fi
@ -229,6 +226,8 @@ if [[ $HARD_RESET = true ]]; then
sudo rm -rf "$BASE_PATH/chains/casper_staging_testnet"
cd $PROJECT_FOLDER
echo "[+] clean build cache..."
cargo clean
echo "[+] starting build in 3 seconds..."
sleep 3
cargo build --release

File diff suppressed because one or more lines are too long

View File

@ -198,6 +198,7 @@ fn casper_testnet_evm_networks() -> Vec<(u32, Vec<u8>)> {
"https://api.zan.top/eth-sepolia".into(),
"https://rpc.sepolia.ethpandaops.io".into(),
"https://ethereum-sepolia-rpc.publicnode.com".into(),
"https://rpc-sepolia.rockx.com".into(),
"https://1rpc.io/sepolia".into(),
"https://0xrpc.io/sep".into(),
"https://eth-sepolia.api.onfinality.io/public".into(),