feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Benchmarks for the BABE Pallet.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use pezframe_benchmarking::v2::*;
|
||||
|
||||
type Header = pezsp_runtime::generic::Header<u64, pezsp_runtime::traits::BlakeTwo256>;
|
||||
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn check_equivocation_proof(x: Linear<0, 1>) {
|
||||
// NOTE: generated with the test below `test_generate_equivocation_report_blob`.
|
||||
// the output is not deterministic since keys are generated randomly (and therefore
|
||||
// signature content changes). it should not affect the benchmark.
|
||||
// with the current benchmark setup it is not possible to generate this programmatically
|
||||
// from the benchmark setup.
|
||||
const EQUIVOCATION_PROOF_BLOB: [u8; 416] = [
|
||||
222, 241, 46, 66, 243, 228, 135, 233, 177, 64, 149, 170, 141, 92, 193, 106, 51, 73, 31,
|
||||
27, 80, 218, 220, 248, 129, 29, 20, 128, 243, 250, 134, 39, 11, 0, 0, 0, 0, 0, 0, 0,
|
||||
158, 4, 7, 240, 67, 153, 134, 190, 251, 196, 229, 95, 136, 165, 234, 228, 255, 18, 2,
|
||||
187, 76, 125, 108, 50, 67, 33, 196, 108, 38, 115, 179, 86, 40, 36, 27, 5, 105, 58, 228,
|
||||
94, 198, 65, 212, 218, 213, 61, 170, 21, 51, 249, 182, 121, 101, 91, 204, 25, 31, 87,
|
||||
219, 208, 43, 119, 211, 185, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65, 66, 69, 52, 2, 0, 0, 0, 0, 11,
|
||||
0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 188, 192, 217, 91, 138, 78, 217, 80, 8,
|
||||
29, 140, 55, 242, 210, 170, 184, 73, 98, 135, 212, 236, 209, 115, 52, 200, 79, 175,
|
||||
172, 242, 161, 199, 47, 236, 93, 101, 95, 43, 34, 141, 16, 247, 220, 33, 59, 31, 197,
|
||||
27, 7, 196, 62, 12, 238, 236, 124, 136, 191, 29, 36, 22, 238, 242, 202, 57, 139, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 40, 23, 175, 153, 83, 6, 33, 65, 123, 51, 80, 223, 126, 186, 226, 225, 240, 105, 28,
|
||||
169, 9, 54, 11, 138, 46, 194, 201, 250, 48, 242, 125, 117, 116, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65,
|
||||
66, 69, 52, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 142, 12,
|
||||
124, 11, 167, 227, 103, 88, 78, 23, 228, 33, 96, 41, 207, 183, 227, 189, 114, 70, 254,
|
||||
30, 128, 243, 233, 83, 214, 45, 74, 182, 120, 119, 64, 243, 219, 119, 63, 240, 205,
|
||||
123, 231, 82, 205, 174, 143, 70, 2, 86, 182, 20, 16, 141, 145, 91, 116, 195, 58, 223,
|
||||
175, 145, 255, 7, 121, 133,
|
||||
];
|
||||
|
||||
let equivocation_proof1: pezsp_consensus_babe::EquivocationProof<Header> =
|
||||
Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap();
|
||||
|
||||
let equivocation_proof2 = equivocation_proof1.clone();
|
||||
|
||||
#[block]
|
||||
{
|
||||
pezsp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof1);
|
||||
}
|
||||
|
||||
assert!(pezsp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof2));
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(3), crate::mock::Test,);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Default weights for the Babe Pallet
|
||||
//! This file was not auto-generated.
|
||||
|
||||
use pezframe_support::weights::{
|
||||
constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS},
|
||||
Weight,
|
||||
};
|
||||
|
||||
impl crate::WeightInfo for () {
|
||||
fn plan_config_change() -> Weight {
|
||||
DbWeight::get().writes(1)
|
||||
}
|
||||
|
||||
fn report_equivocation(validator_count: u32, max_nominators_per_validator: u32) -> Weight {
|
||||
// we take the validator set count from the membership proof to
|
||||
// calculate the weight but we set a floor of 100 validators.
|
||||
let validator_count = validator_count.max(100) as u64;
|
||||
|
||||
// checking membership proof
|
||||
Weight::from_parts(35u64 * WEIGHT_REF_TIME_PER_MICROS, 0)
|
||||
.saturating_add(
|
||||
Weight::from_parts(175u64 * WEIGHT_REF_TIME_PER_NANOS, 0)
|
||||
.saturating_mul(validator_count),
|
||||
)
|
||||
.saturating_add(DbWeight::get().reads(5))
|
||||
// check equivocation proof
|
||||
.saturating_add(Weight::from_parts(110u64 * WEIGHT_REF_TIME_PER_MICROS, 0))
|
||||
// report offence
|
||||
.saturating_add(Weight::from_parts(110u64 * WEIGHT_REF_TIME_PER_MICROS, 0))
|
||||
.saturating_add(Weight::from_parts(
|
||||
25u64 * WEIGHT_REF_TIME_PER_MICROS * max_nominators_per_validator as u64,
|
||||
0,
|
||||
))
|
||||
.saturating_add(DbWeight::get().reads(14 + 3 * max_nominators_per_validator as u64))
|
||||
.saturating_add(DbWeight::get().writes(10 + 3 * max_nominators_per_validator as u64))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! An opt-in utility module for reporting equivocations.
|
||||
//!
|
||||
//! This module defines an offence type for BABE equivocations
|
||||
//! and some utility traits to wire together:
|
||||
//! - a system for reporting offences;
|
||||
//! - a system for submitting unsigned transactions;
|
||||
//! - a way to get the current block author;
|
||||
//!
|
||||
//! These can be used in an offchain context in order to submit equivocation
|
||||
//! reporting extrinsics (from the client that's import BABE blocks).
|
||||
//! And in a runtime context, so that the BABE pallet can validate the
|
||||
//! equivocation proofs in the extrinsic and report the offences.
|
||||
//!
|
||||
//! IMPORTANT:
|
||||
//! When using this module for enabling equivocation reporting it is required
|
||||
//! that the `ValidateUnsigned` for the BABE pallet is used in the runtime
|
||||
//! definition.
|
||||
|
||||
use alloc::{boxed::Box, vec, vec::Vec};
|
||||
use pezframe_support::traits::{Get, KeyOwnerProofSystem};
|
||||
use pezframe_system::pezpallet_prelude::HeaderFor;
|
||||
use log::{error, info};
|
||||
|
||||
use pezsp_consensus_babe::{AuthorityId, EquivocationProof, Slot, KEY_TYPE};
|
||||
use pezsp_runtime::{
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
|
||||
TransactionValidityError, ValidTransaction,
|
||||
},
|
||||
DispatchError, KeyTypeId, Perbill,
|
||||
};
|
||||
use pezsp_session::{GetSessionNumber, GetValidatorCount};
|
||||
use pezsp_staking::{
|
||||
offence::{Kind, Offence, OffenceReportSystem, ReportOffence},
|
||||
SessionIndex,
|
||||
};
|
||||
|
||||
use crate::{Call, Config, Error, Pallet, LOG_TARGET};
|
||||
|
||||
/// BABE equivocation offence report.
|
||||
///
|
||||
/// When a validator released two or more blocks at the same slot.
|
||||
pub struct EquivocationOffence<Offender> {
|
||||
/// A babe slot in which this incident happened.
|
||||
pub slot: Slot,
|
||||
/// The session index in which the incident happened.
|
||||
pub session_index: SessionIndex,
|
||||
/// The size of the validator set at the time of the offence.
|
||||
pub validator_set_count: u32,
|
||||
/// The authority that produced the equivocation.
|
||||
pub offender: Offender,
|
||||
}
|
||||
|
||||
impl<Offender: Clone> Offence<Offender> for EquivocationOffence<Offender> {
|
||||
const ID: Kind = *b"babe:equivocatio";
|
||||
type TimeSlot = Slot;
|
||||
|
||||
fn offenders(&self) -> Vec<Offender> {
|
||||
vec![self.offender.clone()]
|
||||
}
|
||||
|
||||
fn session_index(&self) -> SessionIndex {
|
||||
self.session_index
|
||||
}
|
||||
|
||||
fn validator_set_count(&self) -> u32 {
|
||||
self.validator_set_count
|
||||
}
|
||||
|
||||
fn time_slot(&self) -> Self::TimeSlot {
|
||||
self.slot
|
||||
}
|
||||
|
||||
// The formula is min((3k / n)^2, 1)
|
||||
// where k = offenders_number and n = validators_number
|
||||
fn slash_fraction(&self, offenders_count: u32) -> Perbill {
|
||||
// Perbill type domain is [0, 1] by definition
|
||||
Perbill::from_rational(3 * offenders_count, self.validator_set_count).square()
|
||||
}
|
||||
}
|
||||
|
||||
/// BABE equivocation offence report system.
|
||||
///
|
||||
/// This type implements `OffenceReportSystem` such that:
|
||||
/// - Equivocation reports are published on-chain as unsigned extrinsic via
|
||||
/// `offchain::CreateTransactionBase`.
|
||||
/// - On-chain validity checks and processing are mostly delegated to the user provided generic
|
||||
/// types implementing `KeyOwnerProofSystem` and `ReportOffence` traits.
|
||||
/// - Offence reporter for unsigned transactions is fetched via the the authorship pallet.
|
||||
pub struct EquivocationReportSystem<T, R, P, L>(core::marker::PhantomData<(T, R, P, L)>);
|
||||
|
||||
impl<T, R, P, L>
|
||||
OffenceReportSystem<Option<T::AccountId>, (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof)>
|
||||
for EquivocationReportSystem<T, R, P, L>
|
||||
where
|
||||
T: Config + pezpallet_authorship::Config + pezframe_system::offchain::CreateBare<Call<T>>,
|
||||
R: ReportOffence<
|
||||
T::AccountId,
|
||||
P::IdentificationTuple,
|
||||
EquivocationOffence<P::IdentificationTuple>,
|
||||
>,
|
||||
P: KeyOwnerProofSystem<(KeyTypeId, AuthorityId), Proof = T::KeyOwnerProof>,
|
||||
P::IdentificationTuple: Clone,
|
||||
L: Get<u64>,
|
||||
{
|
||||
type Longevity = L;
|
||||
|
||||
fn publish_evidence(
|
||||
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
|
||||
) -> Result<(), ()> {
|
||||
use pezframe_system::offchain::SubmitTransaction;
|
||||
let (equivocation_proof, key_owner_proof) = evidence;
|
||||
|
||||
let call = Call::report_equivocation_unsigned {
|
||||
equivocation_proof: Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
};
|
||||
let xt = T::create_bare(call.into());
|
||||
let res = SubmitTransaction::<T, Call<T>>::submit_transaction(xt);
|
||||
match res {
|
||||
Ok(_) => info!(target: LOG_TARGET, "Submitted equivocation report"),
|
||||
Err(e) => error!(target: LOG_TARGET, "Error submitting equivocation report: {:?}", e),
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn check_evidence(
|
||||
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
let (equivocation_proof, key_owner_proof) = evidence;
|
||||
|
||||
// Check the membership proof to extract the offender's id
|
||||
let key = (pezsp_consensus_babe::KEY_TYPE, equivocation_proof.offender.clone());
|
||||
let offender =
|
||||
P::check_proof(key, key_owner_proof.clone()).ok_or(InvalidTransaction::BadProof)?;
|
||||
|
||||
// Check if the offence has already been reported, and if so then we can discard the report.
|
||||
if R::is_known_offence(&[offender], &equivocation_proof.slot) {
|
||||
Err(InvalidTransaction::Stale.into())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn process_evidence(
|
||||
reporter: Option<T::AccountId>,
|
||||
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
|
||||
) -> Result<(), DispatchError> {
|
||||
let (equivocation_proof, key_owner_proof) = evidence;
|
||||
let reporter = reporter.or_else(|| <pezpallet_authorship::Pallet<T>>::author());
|
||||
let offender = equivocation_proof.offender.clone();
|
||||
let slot = equivocation_proof.slot;
|
||||
|
||||
// Validate the equivocation proof (check votes are different and signatures are valid)
|
||||
if !pezsp_consensus_babe::check_equivocation_proof(equivocation_proof) {
|
||||
return Err(Error::<T>::InvalidEquivocationProof.into());
|
||||
}
|
||||
|
||||
let validator_set_count = key_owner_proof.validator_count();
|
||||
let session_index = key_owner_proof.session();
|
||||
|
||||
let epoch_index =
|
||||
*slot.saturating_sub(crate::GenesisSlot::<T>::get()) / T::EpochDuration::get();
|
||||
|
||||
// Check that the slot number is consistent with the session index
|
||||
// in the key ownership proof (i.e. slot is for that epoch)
|
||||
if Pallet::<T>::session_index_for_epoch(epoch_index) != session_index {
|
||||
return Err(Error::<T>::InvalidKeyOwnershipProof.into());
|
||||
}
|
||||
|
||||
// Check the membership proof and extract the offender's id
|
||||
let offender = P::check_proof((KEY_TYPE, offender), key_owner_proof)
|
||||
.ok_or(Error::<T>::InvalidKeyOwnershipProof)?;
|
||||
|
||||
let offence = EquivocationOffence { slot, validator_set_count, offender, session_index };
|
||||
|
||||
R::report_offence(reporter.into_iter().collect(), offence)
|
||||
.map_err(|_| Error::<T>::DuplicateOffenceReport)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Methods for the `ValidateUnsigned` implementation:
|
||||
/// It restricts calls to `report_equivocation_unsigned` to local calls (i.e. extrinsics generated
|
||||
/// on this node) or that already in a block. This guarantees that only block authors can include
|
||||
/// unsigned equivocation reports.
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn validate_unsigned(source: TransactionSource, call: &Call<T>) -> TransactionValidity {
|
||||
if let Call::report_equivocation_unsigned { equivocation_proof, key_owner_proof } = call {
|
||||
// discard equivocation report not coming from the local node
|
||||
match source {
|
||||
TransactionSource::Local | TransactionSource::InBlock => { /* allowed */ },
|
||||
_ => {
|
||||
log::warn!(
|
||||
target: LOG_TARGET,
|
||||
"rejecting unsigned report equivocation transaction because it is not local/in-block.",
|
||||
);
|
||||
|
||||
return InvalidTransaction::Call.into();
|
||||
},
|
||||
}
|
||||
|
||||
// Check report validity
|
||||
let evidence = (*equivocation_proof.clone(), key_owner_proof.clone());
|
||||
T::EquivocationReportSystem::check_evidence(evidence)?;
|
||||
|
||||
let longevity =
|
||||
<T::EquivocationReportSystem as OffenceReportSystem<_, _>>::Longevity::get();
|
||||
|
||||
ValidTransaction::with_tag_prefix("BabeEquivocation")
|
||||
// We assign the maximum priority for any equivocation report.
|
||||
.priority(TransactionPriority::max_value())
|
||||
// Only one equivocation report for the same offender at the same slot.
|
||||
.and_provides((equivocation_proof.offender.clone(), *equivocation_proof.slot))
|
||||
.longevity(longevity)
|
||||
// We don't propagate this. This can never be included on a remote node.
|
||||
.propagate(false)
|
||||
.build()
|
||||
} else {
|
||||
InvalidTransaction::Call.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pre_dispatch(call: &Call<T>) -> Result<(), TransactionValidityError> {
|
||||
if let Call::report_equivocation_unsigned { equivocation_proof, key_owner_proof } = call {
|
||||
let evidence = (*equivocation_proof.clone(), key_owner_proof.clone());
|
||||
T::EquivocationReportSystem::check_evidence(evidence)
|
||||
} else {
|
||||
Err(InvalidTransaction::Call.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,415 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Test utilities
|
||||
|
||||
use crate::{self as pezpallet_babe, Config, CurrentSlot};
|
||||
use codec::Encode;
|
||||
use pezframe_election_provider_support::{
|
||||
bounds::{ElectionBounds, ElectionBoundsBuilder},
|
||||
onchain, SequentialPhragmen,
|
||||
};
|
||||
use pezframe_support::{
|
||||
derive_impl, parameter_types,
|
||||
traits::{ConstU128, ConstU32, ConstU64, OnInitialize},
|
||||
};
|
||||
use pezpallet_session::historical as pezpallet_session_historical;
|
||||
use pezsp_consensus_babe::{AuthorityId, AuthorityPair, Randomness, Slot, VrfSignature};
|
||||
use pezsp_core::{
|
||||
crypto::{Pair, VrfSecret},
|
||||
ConstBool, U256,
|
||||
};
|
||||
use pezsp_io;
|
||||
use pezsp_runtime::{
|
||||
curve::PiecewiseLinear,
|
||||
impl_opaque_keys,
|
||||
testing::{Digest, DigestItem, Header, TestXt},
|
||||
traits::{Header as _, OpaqueKeys},
|
||||
BuildStorage, DispatchError, Perbill,
|
||||
};
|
||||
use pezsp_staking::{EraIndex, SessionIndex};
|
||||
|
||||
type DummyValidatorId = u64;
|
||||
|
||||
type Block = pezframe_system::mocking::MockBlock<Test>;
|
||||
|
||||
pezframe_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: pezframe_system,
|
||||
Authorship: pezpallet_authorship,
|
||||
Balances: pezpallet_balances,
|
||||
Historical: pezpallet_session_historical,
|
||||
Offences: pezpallet_offences,
|
||||
Babe: pezpallet_babe,
|
||||
Staking: pezpallet_staking,
|
||||
Session: pezpallet_session,
|
||||
Timestamp: pezpallet_timestamp,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Test {
|
||||
type Block = Block;
|
||||
type AccountData = pezpallet_balances::AccountData<u128>;
|
||||
}
|
||||
|
||||
impl<C> pezframe_system::offchain::CreateTransactionBase<C> for Test
|
||||
where
|
||||
RuntimeCall: From<C>,
|
||||
{
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Extrinsic = TestXt<RuntimeCall, ()>;
|
||||
}
|
||||
|
||||
impl<C> pezframe_system::offchain::CreateBare<C> for Test
|
||||
where
|
||||
RuntimeCall: From<C>,
|
||||
{
|
||||
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
|
||||
TestXt::new_bare(call)
|
||||
}
|
||||
}
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct MockSessionKeys {
|
||||
pub babe_authority: super::Pallet<Test>,
|
||||
}
|
||||
}
|
||||
|
||||
impl pezpallet_session::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ValidatorId = <Self as pezframe_system::Config>::AccountId;
|
||||
type ValidatorIdOf = pezsp_runtime::traits::ConvertInto;
|
||||
type ShouldEndSession = Babe;
|
||||
type NextSessionRotation = Babe;
|
||||
type SessionManager = pezpallet_session::historical::NoteHistoricalRoot<Self, Staking>;
|
||||
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = MockSessionKeys;
|
||||
type DisablingStrategy = ();
|
||||
type WeightInfo = ();
|
||||
type Currency = Balances;
|
||||
type KeyDeposit = ();
|
||||
}
|
||||
|
||||
impl pezpallet_session::historical::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type FullIdentification = ();
|
||||
type FullIdentificationOf = pezpallet_staking::UnitIdentificationOf<Self>;
|
||||
}
|
||||
|
||||
impl pezpallet_authorship::Config for Test {
|
||||
type FindAuthor = pezpallet_session::FindAccountFromAuthorIndex<Self, Babe>;
|
||||
type EventHandler = ();
|
||||
}
|
||||
|
||||
impl pezpallet_timestamp::Config for Test {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Babe;
|
||||
type MinimumPeriod = ConstU64<1>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type Balance = u128;
|
||||
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
|
||||
impl pezpallet_balances::Config for Test {
|
||||
type Balance = Balance;
|
||||
type ExistentialDeposit = ConstU128<1>;
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
pezpallet_staking_reward_curve::build! {
|
||||
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
|
||||
min_inflation: 0_025_000u64,
|
||||
max_inflation: 0_100_000,
|
||||
ideal_stake: 0_500_000,
|
||||
falloff: 0_050_000,
|
||||
max_piece_count: 40,
|
||||
test_precision: 0_005_000,
|
||||
);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const SessionsPerEra: SessionIndex = 3;
|
||||
pub const BondingDuration: EraIndex = 3;
|
||||
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
|
||||
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
|
||||
}
|
||||
|
||||
pub struct OnChainSeqPhragmen;
|
||||
impl onchain::Config for OnChainSeqPhragmen {
|
||||
type System = Test;
|
||||
type Solver = SequentialPhragmen<DummyValidatorId, Perbill>;
|
||||
type DataProvider = Staking;
|
||||
type WeightInfo = ();
|
||||
type MaxWinnersPerPage = ConstU32<100>;
|
||||
type MaxBackersPerWinner = ConstU32<100>;
|
||||
type Sort = ConstBool<true>;
|
||||
type Bounds = ElectionsBounds;
|
||||
}
|
||||
|
||||
#[derive_impl(pezpallet_staking::config_preludes::TestDefaultConfig)]
|
||||
impl pezpallet_staking::Config for Test {
|
||||
type OldCurrency = Balances;
|
||||
type Currency = Balances;
|
||||
type SessionsPerEra = SessionsPerEra;
|
||||
type BondingDuration = BondingDuration;
|
||||
type AdminOrigin = pezframe_system::EnsureRoot<Self::AccountId>;
|
||||
type SessionInterface = Self;
|
||||
type UnixTime = pezpallet_timestamp::Pallet<Test>;
|
||||
type EraPayout = pezpallet_staking::ConvertCurve<RewardCurve>;
|
||||
type NextNewSession = Session;
|
||||
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
|
||||
type GenesisElectionProvider = Self::ElectionProvider;
|
||||
type VoterList = pezpallet_staking::UseNominatorsAndValidatorsMap<Self>;
|
||||
type TargetList = pezpallet_staking::UseValidatorsMap<Self>;
|
||||
}
|
||||
|
||||
impl pezpallet_offences::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type IdentificationTuple = pezpallet_session::historical::IdentificationTuple<Self>;
|
||||
type OnOffenceHandler = Staking;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = 3;
|
||||
pub const ReportLongevity: u64 =
|
||||
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ConstU64<1>;
|
||||
type EpochChangeTrigger = crate::ExternalTrigger;
|
||||
type DisabledValidators = Session;
|
||||
type WeightInfo = ();
|
||||
type MaxAuthorities = ConstU32<10>;
|
||||
type MaxNominators = ConstU32<100>;
|
||||
type KeyOwnerProof = pezsp_session::MembershipProof;
|
||||
type EquivocationReportSystem =
|
||||
super::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
|
||||
}
|
||||
|
||||
pub fn go_to_block(n: u64, s: u64) {
|
||||
use pezframe_support::traits::OnFinalize;
|
||||
|
||||
Babe::on_finalize(System::block_number());
|
||||
Session::on_finalize(System::block_number());
|
||||
Staking::on_finalize(System::block_number());
|
||||
|
||||
let parent_hash = if System::block_number() > 1 {
|
||||
let hdr = System::finalize();
|
||||
hdr.hash()
|
||||
} else {
|
||||
System::parent_hash()
|
||||
};
|
||||
|
||||
let pre_digest = make_secondary_plain_pre_digest(0, s.into());
|
||||
|
||||
System::reset_events();
|
||||
System::initialize(&n, &parent_hash, &pre_digest);
|
||||
|
||||
Babe::on_initialize(n);
|
||||
Session::on_initialize(n);
|
||||
Staking::on_initialize(n);
|
||||
}
|
||||
|
||||
/// Slots will grow accordingly to blocks
|
||||
pub fn progress_to_block(n: u64) {
|
||||
let mut slot = u64::from(CurrentSlot::<Test>::get()) + 1;
|
||||
for i in System::block_number() + 1..=n {
|
||||
go_to_block(i, slot);
|
||||
slot += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Progress to the first block at the given session
|
||||
pub fn start_session(session_index: SessionIndex) {
|
||||
let missing = (session_index - Session::current_index()) * 3;
|
||||
progress_to_block(System::block_number() + missing as u64 + 1);
|
||||
assert_eq!(Session::current_index(), session_index);
|
||||
}
|
||||
|
||||
/// Progress to the first block at the given era
|
||||
pub fn start_era(era_index: EraIndex) {
|
||||
start_session((era_index * 3).into());
|
||||
assert_eq!(pezpallet_staking::CurrentEra::<Test>::get(), Some(era_index));
|
||||
}
|
||||
|
||||
pub fn make_primary_pre_digest(
|
||||
authority_index: pezsp_consensus_babe::AuthorityIndex,
|
||||
slot: pezsp_consensus_babe::Slot,
|
||||
vrf_signature: VrfSignature,
|
||||
) -> Digest {
|
||||
let digest_data = pezsp_consensus_babe::digests::PreDigest::Primary(
|
||||
pezsp_consensus_babe::digests::PrimaryPreDigest { authority_index, slot, vrf_signature },
|
||||
);
|
||||
let log = DigestItem::PreRuntime(pezsp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
|
||||
Digest { logs: vec![log] }
|
||||
}
|
||||
|
||||
pub fn make_secondary_plain_pre_digest(
|
||||
authority_index: pezsp_consensus_babe::AuthorityIndex,
|
||||
slot: pezsp_consensus_babe::Slot,
|
||||
) -> Digest {
|
||||
let digest_data = pezsp_consensus_babe::digests::PreDigest::SecondaryPlain(
|
||||
pezsp_consensus_babe::digests::SecondaryPlainPreDigest { authority_index, slot },
|
||||
);
|
||||
let log = DigestItem::PreRuntime(pezsp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
|
||||
Digest { logs: vec![log] }
|
||||
}
|
||||
|
||||
pub fn make_secondary_vrf_pre_digest(
|
||||
authority_index: pezsp_consensus_babe::AuthorityIndex,
|
||||
slot: pezsp_consensus_babe::Slot,
|
||||
vrf_signature: VrfSignature,
|
||||
) -> Digest {
|
||||
let digest_data = pezsp_consensus_babe::digests::PreDigest::SecondaryVRF(
|
||||
pezsp_consensus_babe::digests::SecondaryVRFPreDigest { authority_index, slot, vrf_signature },
|
||||
);
|
||||
let log = DigestItem::PreRuntime(pezsp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
|
||||
Digest { logs: vec![log] }
|
||||
}
|
||||
|
||||
pub fn make_vrf_signature_and_randomness(
|
||||
slot: Slot,
|
||||
pair: &pezsp_consensus_babe::AuthorityPair,
|
||||
) -> (VrfSignature, Randomness) {
|
||||
let transcript =
|
||||
pezsp_consensus_babe::make_vrf_transcript(&pezpallet_babe::Randomness::<Test>::get(), slot, 0);
|
||||
|
||||
let randomness =
|
||||
pair.as_ref().make_bytes(pezsp_consensus_babe::RANDOMNESS_VRF_CONTEXT, &transcript);
|
||||
|
||||
let signature = pair.as_ref().vrf_sign(&transcript.into());
|
||||
|
||||
(signature, randomness)
|
||||
}
|
||||
|
||||
pub fn new_test_ext(authorities_len: usize) -> pezsp_io::TestExternalities {
|
||||
new_test_ext_with_pairs(authorities_len).1
|
||||
}
|
||||
|
||||
pub fn new_test_ext_with_pairs(
|
||||
authorities_len: usize,
|
||||
) -> (Vec<AuthorityPair>, pezsp_io::TestExternalities) {
|
||||
let pairs = (0..authorities_len)
|
||||
.map(|i| AuthorityPair::from_seed(&U256::from(i).to_little_endian()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let public = pairs.iter().map(|p| p.public()).collect();
|
||||
|
||||
(pairs, new_test_ext_raw_authorities(public))
|
||||
}
|
||||
|
||||
pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> pezsp_io::TestExternalities {
|
||||
pezsp_tracing::try_init_simple();
|
||||
let mut t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
|
||||
let balances: Vec<_> = (0..authorities.len()).map(|i| (i as u64, 10_000_000)).collect();
|
||||
|
||||
pezpallet_balances::GenesisConfig::<Test> { balances, ..Default::default() }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
// stashes are the index.
|
||||
let session_keys: Vec<_> = authorities
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, k)| {
|
||||
(i as u64, i as u64, MockSessionKeys { babe_authority: AuthorityId::from(k.clone()) })
|
||||
})
|
||||
.collect();
|
||||
|
||||
// NOTE: this will initialize the babe authorities
|
||||
// through OneSessionHandler::on_genesis_session
|
||||
pezpallet_session::GenesisConfig::<Test> { keys: session_keys, ..Default::default() }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
// controllers are same as stash
|
||||
let stakers: Vec<_> = (0..authorities.len())
|
||||
.map(|i| (i as u64, i as u64, 10_000, pezpallet_staking::StakerStatus::<u64>::Validator))
|
||||
.collect();
|
||||
|
||||
let staking_config = pezpallet_staking::GenesisConfig::<Test> {
|
||||
stakers,
|
||||
validator_count: 8,
|
||||
force_era: pezpallet_staking::Forcing::ForceNew,
|
||||
minimum_validator_count: 0,
|
||||
invulnerables: vec![],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
staking_config.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
t.into()
|
||||
}
|
||||
|
||||
/// Creates an equivocation at the current block, by generating two headers.
|
||||
pub fn generate_equivocation_proof(
|
||||
offender_authority_index: u32,
|
||||
offender_authority_pair: &AuthorityPair,
|
||||
slot: Slot,
|
||||
) -> pezsp_consensus_babe::EquivocationProof<Header> {
|
||||
use pezsp_consensus_babe::digests::CompatibleDigestItem;
|
||||
|
||||
let current_block = System::block_number();
|
||||
let current_slot = CurrentSlot::<Test>::get();
|
||||
|
||||
let make_header = || {
|
||||
// We don't want to change any state, so we build the headers in a transaction and revert it
|
||||
// afterward.
|
||||
pezframe_support::storage::with_transaction(|| {
|
||||
let parent_hash = System::parent_hash();
|
||||
let pre_digest = make_secondary_plain_pre_digest(offender_authority_index, slot);
|
||||
System::reset_events();
|
||||
System::set_block_number(System::block_number() - 1);
|
||||
System::initialize(¤t_block, &parent_hash, &pre_digest);
|
||||
System::set_block_number(current_block);
|
||||
Timestamp::set_timestamp(*current_slot * Babe::slot_duration());
|
||||
let header = System::finalize();
|
||||
|
||||
pezsp_runtime::TransactionOutcome::Rollback(Ok::<_, DispatchError>(header))
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
// Sign the header prehash and sign it, adding it to the block as the seal
|
||||
// digest item
|
||||
let seal_header = |header: &mut Header| {
|
||||
let prehash = header.hash();
|
||||
let seal = <DigestItem as CompatibleDigestItem>::babe_seal(
|
||||
offender_authority_pair.sign(prehash.as_ref()),
|
||||
);
|
||||
header.digest_mut().push(seal);
|
||||
};
|
||||
|
||||
// Generate two headers at the current block
|
||||
let mut h1 = make_header();
|
||||
let mut h2 = make_header();
|
||||
|
||||
seal_header(&mut h1);
|
||||
seal_header(&mut h2);
|
||||
|
||||
pezsp_consensus_babe::EquivocationProof {
|
||||
slot,
|
||||
offender: offender_authority_pair.public(),
|
||||
first_header: h1,
|
||||
second_header: h2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Provides multiple implementations of the randomness trait based on the on-chain epoch
|
||||
//! randomness collected from VRF outputs.
|
||||
|
||||
use super::{
|
||||
AuthorVrfRandomness, Config, EpochStart, NextRandomness, Randomness, RANDOMNESS_LENGTH,
|
||||
};
|
||||
use pezframe_support::traits::Randomness as RandomnessT;
|
||||
use pezframe_system::pezpallet_prelude::BlockNumberFor;
|
||||
use pezsp_runtime::traits::{Hash, One, Saturating};
|
||||
|
||||
/// Randomness usable by consensus protocols that **depend** upon finality and take action
|
||||
/// based upon on-chain commitments made during the epoch before the previous epoch.
|
||||
///
|
||||
/// An off-chain consensus protocol requires randomness be finalized before usage, but one
|
||||
/// extra epoch delay beyond `RandomnessFromOneEpochAgo` suffices, under the assumption
|
||||
/// that finality never stalls for longer than one epoch.
|
||||
///
|
||||
/// All randomness is relative to commitments to any other inputs to the computation: If
|
||||
/// Alice samples randomness near perfectly using radioactive decay, but then afterwards
|
||||
/// Eve selects an arbitrary value with which to xor Alice's randomness, then Eve always
|
||||
/// wins whatever game they play.
|
||||
///
|
||||
/// All input commitments used with `RandomnessFromTwoEpochsAgo` should come from at least
|
||||
/// three epochs ago. We require BABE session keys be registered at least three epochs
|
||||
/// before being used to derive `ParentBlockRandomness` for example.
|
||||
///
|
||||
/// All users learn `RandomnessFromTwoEpochsAgo` when epoch `current_epoch - 1` starts,
|
||||
/// although some learn it a few block earlier inside epoch `current_epoch - 2`.
|
||||
///
|
||||
/// Adversaries with enough block producers could bias this randomness by choosing upon
|
||||
/// what their block producers build at the end of epoch `current_epoch - 2` or the
|
||||
/// beginning epoch `current_epoch - 1`, or skipping slots at the end of epoch
|
||||
/// `current_epoch - 2`.
|
||||
///
|
||||
/// Adversaries should not possess many block production slots towards the beginning or
|
||||
/// end of every epoch, but they possess some influence over when they possess more slots.
|
||||
pub struct RandomnessFromTwoEpochsAgo<T>(core::marker::PhantomData<T>);
|
||||
|
||||
/// Randomness usable by on-chain code that **does not depend** upon finality and takes
|
||||
/// action based upon on-chain commitments made during the previous epoch.
|
||||
///
|
||||
/// All randomness is relative to commitments to any other inputs to the computation: If
|
||||
/// Alice samples randomness near perfectly using radioactive decay, but then afterwards
|
||||
/// Eve selects an arbitrary value with which to xor Alice's randomness, then Eve always
|
||||
/// wins whatever game they play.
|
||||
///
|
||||
/// All input commitments used with `RandomnessFromOneEpochAgo` should come from at least
|
||||
/// two epochs ago, although the previous epoch might work in special cases under
|
||||
/// additional assumption.
|
||||
///
|
||||
/// All users learn `RandomnessFromOneEpochAgo` at the end of the previous epoch, although
|
||||
/// some block producers learn it several block earlier.
|
||||
///
|
||||
/// Adversaries with enough block producers could bias this randomness by choosing upon
|
||||
/// what their block producers build at either the end of the previous epoch or the
|
||||
/// beginning of the current epoch, or electing to skipping some of their own block
|
||||
/// production slots towards the end of the previous epoch.
|
||||
///
|
||||
/// Adversaries should not possess many block production slots towards the beginning or
|
||||
/// end of every epoch, but they possess some influence over when they possess more slots.
|
||||
///
|
||||
/// As an example usage, we determine teyrchain auctions ending times in Pezkuwi using
|
||||
/// `RandomnessFromOneEpochAgo` because it reduces bias from `ParentBlockRandomness` and
|
||||
/// does not require the extra finality delay of `RandomnessFromTwoEpochsAgo`.
|
||||
pub struct RandomnessFromOneEpochAgo<T>(core::marker::PhantomData<T>);
|
||||
|
||||
/// Randomness produced semi-freshly with each block, but inherits limitations of
|
||||
/// `RandomnessFromTwoEpochsAgo` from which it derives.
|
||||
///
|
||||
/// All randomness is relative to commitments to any other inputs to the computation: If
|
||||
/// Alice samples randomness near perfectly using radioactive decay, but then afterwards
|
||||
/// Eve selects an arbitrary value with which to xor Alice's randomness, then Eve always
|
||||
/// wins whatever game they play.
|
||||
///
|
||||
/// As with `RandomnessFromTwoEpochsAgo`, all input commitments combined with
|
||||
/// `ParentBlockRandomness` should come from at least two epoch ago, except preferably
|
||||
/// not near epoch ending, and thus ideally three epochs ago.
|
||||
///
|
||||
/// Almost all users learn this randomness for a given block by the time they receive it's
|
||||
/// parent block, which makes this randomness appear fresh enough. Yet, the block producer
|
||||
/// themselves learned this randomness at the beginning of epoch `current_epoch - 2`, at
|
||||
/// the same time as they learn `RandomnessFromTwoEpochsAgo`.
|
||||
///
|
||||
/// Aside from just biasing `RandomnessFromTwoEpochsAgo`, adversaries could also bias
|
||||
/// `ParentBlockRandomness` by never announcing their block if doing so yields an
|
||||
/// unfavorable randomness. As such, `ParentBlockRandomness` should be considered weaker
|
||||
/// than both other randomness sources provided by BABE, but `ParentBlockRandomness`
|
||||
/// remains constrained by declared staking, while a randomness source like block hash is
|
||||
/// only constrained by adversaries' unknowable computational power.
|
||||
///
|
||||
/// As an example use, teyrchains could assign block production slots based upon the
|
||||
/// `ParentBlockRandomness` of their relay parent or relay parent's parent, provided the
|
||||
/// teyrchain registers collators but avoids censorship sensitive functionality like
|
||||
/// slashing. Any teyrchain with slashing could operate BABE itself or perhaps better yet
|
||||
/// a BABE-like approach that derives its `ParentBlockRandomness`, and authorizes block
|
||||
/// production, based upon the relay parent's `ParentBlockRandomness` or more likely the
|
||||
/// relay parent's `RandomnessFromTwoEpochsAgo`.
|
||||
///
|
||||
/// NOTE: there is some nuance here regarding what is current and parent randomness. If
|
||||
/// you are using this trait from within the runtime (i.e. as part of block execution)
|
||||
/// then the randomness provided here will always be generated from the parent block. If
|
||||
/// instead you are using this randomness externally, i.e. after block execution, then
|
||||
/// this randomness will be provided by the "current" block (this stems from the fact that
|
||||
/// we process VRF outputs on block execution finalization, i.e. `on_finalize`).
|
||||
pub struct ParentBlockRandomness<T>(core::marker::PhantomData<T>);
|
||||
|
||||
/// Randomness produced semi-freshly with each block, but inherits limitations of
|
||||
/// `RandomnessFromTwoEpochsAgo` from which it derives.
|
||||
///
|
||||
/// See [`ParentBlockRandomness`].
|
||||
#[deprecated(note = "Should not be relied upon for correctness, \
|
||||
will not provide fresh randomness for the current block. \
|
||||
Please use `ParentBlockRandomness` instead.")]
|
||||
pub struct CurrentBlockRandomness<T>(core::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config> RandomnessT<T::Hash, BlockNumberFor<T>> for RandomnessFromTwoEpochsAgo<T> {
|
||||
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
|
||||
let mut subject = subject.to_vec();
|
||||
subject.reserve(RANDOMNESS_LENGTH);
|
||||
subject.extend_from_slice(&Randomness::<T>::get()[..]);
|
||||
|
||||
(T::Hashing::hash(&subject[..]), EpochStart::<T>::get().0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> RandomnessT<T::Hash, BlockNumberFor<T>> for RandomnessFromOneEpochAgo<T> {
|
||||
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
|
||||
let mut subject = subject.to_vec();
|
||||
subject.reserve(RANDOMNESS_LENGTH);
|
||||
subject.extend_from_slice(&NextRandomness::<T>::get()[..]);
|
||||
|
||||
(T::Hashing::hash(&subject[..]), EpochStart::<T>::get().1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> RandomnessT<Option<T::Hash>, BlockNumberFor<T>> for ParentBlockRandomness<T> {
|
||||
fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>) {
|
||||
let random = AuthorVrfRandomness::<T>::get().map(|random| {
|
||||
let mut subject = subject.to_vec();
|
||||
subject.reserve(RANDOMNESS_LENGTH);
|
||||
subject.extend_from_slice(&random);
|
||||
|
||||
T::Hashing::hash(&subject[..])
|
||||
});
|
||||
|
||||
(random, <pezframe_system::Pallet<T>>::block_number().saturating_sub(One::one()))
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<T: Config> RandomnessT<Option<T::Hash>, BlockNumberFor<T>> for CurrentBlockRandomness<T> {
|
||||
fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>) {
|
||||
let (random, _) = ParentBlockRandomness::<T>::random(subject);
|
||||
(random, <pezframe_system::Pallet<T>>::block_number())
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,101 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Autogenerated weights for `pezpallet_babe`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024`
|
||||
|
||||
// Executed Command:
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/kitchensink-runtime/kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_babe
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/babe/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --heap-pages=4096
|
||||
// --template=bizinikiwi/.maintain/frame-weight-template.hbs
|
||||
// --no-storage-info
|
||||
// --no-min-squares
|
||||
// --no-median-slopes
|
||||
// --genesis-builder-policy=none
|
||||
// --exclude-pallets=pezpallet_xcm,pezpallet_xcm_benchmarks::fungible,pezpallet_xcm_benchmarks::generic,pezpallet_nomination_pools,pezpallet_remark,pezpallet_transaction_storage,pezpallet_election_provider_multi_block,pezpallet_election_provider_multi_block::signed,pezpallet_election_provider_multi_block::unsigned,pezpallet_election_provider_multi_block::verifier
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use pezframe_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for `pezpallet_babe`.
|
||||
pub trait WeightInfo {
|
||||
fn check_equivocation_proof(x: u32, ) -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pezpallet_babe` using the Bizinikiwi node and recommended hardware.
|
||||
pub struct BizinikiwiWeight<T>(PhantomData<T>);
|
||||
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
|
||||
/// The range of component `x` is `[0, 1]`.
|
||||
fn check_equivocation_proof(_x: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 86_746_000 picoseconds.
|
||||
Weight::from_parts(88_013_048, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
/// The range of component `x` is `[0, 1]`.
|
||||
fn check_equivocation_proof(_x: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 86_746_000 picoseconds.
|
||||
Weight::from_parts(88_013_048, 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user