Compare commits

...

3 Commits

Author SHA1 Message Date
cc300fefb0
apply changes to casper runtime; migrations are included
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2026-02-24 22:06:54 +03:00
c8f8ea7130
rustfmt of the chain specs
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2026-02-24 22:03:45 +03:00
93387218ec
make initialise authorities infallable and fix benchmarking
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2026-02-24 22:02:26 +03:00
9 changed files with 74 additions and 52 deletions

9
Cargo.lock generated
View File

@ -1186,7 +1186,7 @@ dependencies = [
[[package]]
name = "casper-runtime"
version = "3.5.37"
version = "3.5.38"
dependencies = [
"casper-runtime-constants",
"frame-benchmarking",
@ -3650,13 +3650,14 @@ dependencies = [
[[package]]
name = "ghost-networks"
version = "0.1.20"
version = "0.1.25"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"ghost-core-primitives",
"ghost-traits",
"log",
"num-traits",
"pallet-balances",
"pallet-staking",
@ -3837,7 +3838,7 @@ dependencies = [
[[package]]
name = "ghost-slow-clap"
version = "0.4.14"
version = "0.4.24"
dependencies = [
"frame-benchmarking",
"frame-support",
@ -3889,7 +3890,7 @@ dependencies = [
[[package]]
name = "ghost-traits"
version = "0.3.26"
version = "0.3.31"
dependencies = [
"frame-support",
"sp-runtime 31.0.1",

View File

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

View File

@ -90,11 +90,7 @@ benchmarks! {
session_index,
authority_index,
network_id,
commitment: CommitmentDetails {
last_stored_block: 69,
commits: 420,
last_updated: 1337,
}
};
let authority_id = authorities
@ -102,20 +98,21 @@ benchmarks! {
.expect("first authority should exist");
let signature = authority_id.sign(&block_commitment.encode())
.ok_or("couldn't make signature")?;
}: _(RawOrigin::None, block_commitment, signature)
verify {
let current_block_number = <Pallet<T> as BlockNumberProvider>::current_block_number();
let stored_commitment = BlockCommitments::<T>::get(&network_id)
.get(&authority_index)
.cloned()
.unwrap_or_default();
assert_eq!(stored_commitment.last_stored_block, 69);
assert_eq!(stored_commitment.commits, 1);
assert_eq!(stored_commitment.last_updated, 1337);
assert_eq!(stored_commitment.last_updated, current_block_number);
}
try_offend_validators {
let n in 4 .. T::MaxAuthorities::get();
let d in 0 .. T::MaxAuthorities::get().saturating_div(3);
let session_index = T::ValidatorSet::session_index();
let mut validators_vec = Vec::new();
@ -131,7 +128,7 @@ benchmarks! {
let offence_type = OffenceType::CommitmentOffence;
let disabled_bitmap = BitMap::new(T::MaxAuthorities::get());
let mut offence_bitmap = BitMap::new(T::MaxAuthorities::get());
for i in 0 .. (n / 3) {
for i in 0..d {
offence_bitmap.set(i);
}
}: {

View File

@ -2,10 +2,13 @@ use sp_runtime::{traits::UniqueSaturatedInto, SaturatedConversion, Saturating};
use sp_staking::SessionIndex;
use crate::{
AuthIndex, BLOCK_COMMITMENT_DELAY, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config, Decode, Deserialize, Encode, ExternalBlockNumber, H256, LOG_TARGET, NetworkIdOf, RuntimeAppPublic, RuntimeDebug, SubmitTransaction, Vec, deserialisations::{
de_string_to_bytes, de_string_to_h256, de_string_to_block_number, de_string_to_block_number_pure,
de_string_to_vec_of_bytes,
}
deserialisations::{
de_string_to_block_number, de_string_to_block_number_pure, de_string_to_bytes,
de_string_to_h256, de_string_to_vec_of_bytes,
},
AuthIndex, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config,
Decode, Deserialize, Encode, ExternalBlockNumber, NetworkIdOf, RuntimeAppPublic, RuntimeDebug,
SubmitTransaction, Vec, BLOCK_COMMITMENT_DELAY, H256, LOG_TARGET,
};
const NUMBER_OF_TOPICS: usize = 3;

View File

@ -140,7 +140,11 @@ pub struct ApplauseDetail<NetworkId, Balance> {
}
impl<NetworkId, Balance: Default> ApplauseDetail<NetworkId, Balance> {
pub fn new(network_id: NetworkId, block_number: ExternalBlockNumber, max_authorities: usize) -> Self {
pub fn new(
network_id: NetworkId,
block_number: ExternalBlockNumber,
max_authorities: usize,
) -> Self {
ApplauseDetail {
network_id,
block_number,
@ -171,7 +175,11 @@ enum OffchainErr<NetworkId> {
DifferentEvmResponseTypes,
MissingBlockNumber(u32, u32),
ContradictoryTransactionLogs(u32, u32),
ContradictoryBlockMedian(ExternalBlockNumber, ExternalBlockNumber, ExternalBlockNumber),
ContradictoryBlockMedian(
ExternalBlockNumber,
ExternalBlockNumber,
ExternalBlockNumber,
),
UnparsableRequestBody(Vec<u8>),
NoEndpointAvailable(NetworkId),
StorageRetrievalError(NetworkId),
@ -503,9 +511,8 @@ pub mod pallet {
if let Some((network_id, network_data)) =
T::NetworkDataHandler::network_for_block(converted_block)
{
weight = weight.saturating_add(T::DbWeight::get().reads_writes(3, 1));
weight.saturating_accrue(T::DbWeight::get().reads_writes(3, 1));
// TODO: put wrapper function with precalculated weight here
let session_index = T::ValidatorSet::session_index();
let block_commitments = BlockCommitments::<T>::get(&network_id);
let validators = Validators::<T>::get(&session_index);
@ -568,7 +575,7 @@ pub mod pallet {
network_id,
});
weight = weight.saturating_add(extra_weight);
weight.saturating_accrue(extra_weight);
}
weight
@ -938,7 +945,8 @@ impl<T: Config> Pallet<T> {
return Err(OffchainErr::NoEndpointAvailable(network_id));
}
let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) = StorageValueRef::persistent(&block_number_key)
let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) =
StorageValueRef::persistent(&block_number_key)
.get()
.map_err(|_| OffchainErr::StorageRetrievalError(network_id))?
.unwrap_or_default();
@ -1304,12 +1312,16 @@ impl<T: Config> Pallet<T> {
);
let authorities_len = authorities.len();
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities)
.expect("more than the maximum number of authorities");
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
authorities,
Some("slow claps reached maximum number of authorities"),
);
let validators = T::ValidatorSet::validators();
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(validators)
.expect("more than the maximum number of validators");
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
validators,
Some("slow claps reached maximum number of validators"),
);
if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) {
Self::clear_history(&target_session_index);

View File

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

View File

@ -117,11 +117,11 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("casper"),
impl_name: create_runtime_str!("casper-svengali"),
authoring_version: 0,
spec_version: 4,
impl_version: 3,
spec_version: 5,
impl_version: 4,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
state_version: 2,
};
/// The BABE epoch configuration at genesis.
@ -218,10 +218,7 @@ impl pallet_preimage::Config for Runtime {
}
parameter_types! {
pub const EpochDuration: u64 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS as u64,
2 * MINUTES as u64
);
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
pub const ReportLongevity: u64 =
BondingDuration::get() as u64 *
@ -332,14 +329,8 @@ impl pallet_session::historical::Config for Runtime {
}
parameter_types! {
pub SignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2)
);
pub UnsignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2)
);
pub SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
pub UnsignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
// signed config
pub const SignedMaxSubmissions: u32 = 16;
@ -1029,6 +1020,7 @@ impl ghost_networks::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type NetworkId = u64;
type Currency = Balances;
type MaxNetworks = ConstU32<30>;
type RegisterOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Ghosts>;
type UpdateOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
@ -1059,7 +1051,12 @@ impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
parameter_types! {
// will be used in `Perbill::from_parts()`
pub const ApplauseThreshold: u32 = 500_000_000;
pub const ApplauseThreshold: u32 = if cfg!(feature = "runtime-benchmarks") {
0
} else {
500_000_000
};
pub const MinAuthoritiesNumber: u32 = 5;
pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX;
pub const SlowClapHistoryDepth: sp_staking::SessionIndex =
@ -1083,6 +1080,7 @@ impl ghost_slow_clap::Config for Runtime {
type UnsignedPriority = SlowClapUnsignedPriority;
type HistoryDepth = SlowClapHistoryDepth;
type MinAuthoritiesNumber = MinAuthoritiesNumber;
type EpochDuration = EpochDuration;
type WeightInfo = weights::ghost_slow_clap::WeightInfo<Runtime>;
}
@ -1185,7 +1183,10 @@ pub type SignedExtra = (
/// All migrations that will run on the next runtime upgrade.
/// Should be cleared after release.
pub type Migrations = ();
pub type Migrations = (
ghost_networks::migrations::MigrateV0ToV1<Runtime>,
ghost_slow_clap::migrations::MigrateV2ToV3<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =

View File

@ -104,4 +104,8 @@ impl<T: frame_system::Config> ghost_slow_clap::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(1))
}
fn try_offend_validators(_offenders_len: u32) -> Weight {
Default::default()
}
}

View File

@ -211,10 +211,12 @@ fn casper_testnet_evm_networks() -> Vec<(u32, Vec<u8>, u128)> {
avg_block_speed: 12_000,
network_type: ghost_networks::NetworkType::Evm,
gatekeeper: "0xc85129A097773B7F8970a7364c928C05f265E6A1".into(),
topic_name: "0x7ab52ec05c331e6257a3d705d6bea6e4c27277351764ad139209e06b203811a6".into(),
topic_name: "0x7ab52ec05c331e6257a3d705d6bea6e4c27277351764ad139209e06b203811a6"
.into(),
incoming_fee: 69_000_000u32,
outgoing_fee: 0u32,
}.encode(),
}
.encode(),
2048861035254140036511u128,
),
(
@ -232,10 +234,12 @@ fn casper_testnet_evm_networks() -> Vec<(u32, Vec<u8>, u128)> {
avg_block_speed: 13_000,
network_type: ghost_networks::NetworkType::Evm,
gatekeeper: "0xA59cB4ff90bE2206121aE61eEB68d0AeC7BA095f".into(),
topic_name: "0x7ab52ec05c331e6257a3d705d6bea6e4c27277351764ad139209e06b203811a6".into(),
topic_name: "0x7ab52ec05c331e6257a3d705d6bea6e4c27277351764ad139209e06b203811a6"
.into(),
incoming_fee: 69_000_000u32,
outgoing_fee: 0u32,
}.encode(),
}
.encode(),
5100000000000000000u128,
),
]