-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use frame umbrella crate in pallet-babe
& pallet-staking-reward-curve
#6412
base: master
Are you sure you want to change the base?
Changes from all commits
f2bcae7
7c81ee7
aaf16a7
b6bfd0a
84ee9b1
5cc0904
3c6fcf7
0f25d98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: Use frame umbrella crate in pallet-babe and pallet-staking-reward-curve | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
Extends the FRAME umbrella crate and uses it in pallet-babe and pallet-staking-reward-curve. | ||
Migrates benchmarking from v1 to v2 for pallet-babe. | ||
|
||
crates: | ||
- name: polkadot-sdk-frame | ||
bump: minor | ||
- name: pallet-babe | ||
bump: patch | ||
- name: pallet-staking-reward-curve | ||
bump: patch |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,16 @@ | |
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use frame_benchmarking::v1::benchmarks; | ||
use frame::benchmarking::prelude::*; | ||
|
||
type Header = sp_runtime::generic::Header<u64, sp_runtime::traits::BlakeTwo256>; | ||
|
||
benchmarks! { | ||
check_equivocation_proof { | ||
let x in 0 .. 1; | ||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn check_equivocation_proof(x: Linear<0, 1>) -> Result<(), BenchmarkError> { | ||
// 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. | ||
|
@@ -53,22 +55,21 @@ benchmarks! { | |
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 | ||
175, 145, 255, 7, 121, 133, | ||
]; | ||
|
||
let equivocation_proof1: sp_consensus_babe::EquivocationProof<Header> = | ||
Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap(); | ||
|
||
let equivocation_proof2 = equivocation_proof1.clone(); | ||
}: { | ||
sp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof1); | ||
} verify { | ||
|
||
#[extrinsic_call] | ||
_(equivocation_proof1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
assert!(sp_consensus_babe::check_equivocation_proof::<Header>(equivocation_proof2)); | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::mock::new_test_ext(3), | ||
crate::mock::Test, | ||
) | ||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(3), crate::mock::Test,); | ||
|
||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,26 +25,20 @@ extern crate alloc; | |
|
||
use alloc::{boxed::Box, vec, vec::Vec}; | ||
use codec::{Decode, Encode}; | ||
use frame_support::{ | ||
dispatch::{DispatchResultWithPostInfo, Pays}, | ||
ensure, | ||
traits::{ConstU32, DisabledValidators, FindAuthor, Get, OnTimestampSet, OneSessionHandler}, | ||
weights::Weight, | ||
BoundedVec, WeakBoundedVec, | ||
use frame::{ | ||
deps::sp_runtime::generic::DigestItem, | ||
prelude::*, | ||
traits::{ | ||
DisabledValidators, EstimateNextSessionRotation, FindAuthor, IsMember, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few of these seems general enough to go to prelude:
Rule of thumb: If you can foresee it being useful in any pallet, then prelude. Else, domain specifc mod (e.g. |
||
Lateness as LatenessT, OnTimestampSet, OneSessionHandler, StorageInstance, | ||
}, | ||
}; | ||
use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; | ||
use sp_consensus_babe::{ | ||
digests::{NextConfigDescriptor, NextEpochDescriptor, PreDigest}, | ||
AllowedSlots, BabeAuthorityWeight, BabeEpochConfiguration, ConsensusLog, Epoch, | ||
EquivocationProof, Randomness as BabeRandomness, Slot, BABE_ENGINE_ID, RANDOMNESS_LENGTH, | ||
RANDOMNESS_VRF_CONTEXT, | ||
}; | ||
use sp_core::crypto::Wraps; | ||
use sp_runtime::{ | ||
generic::DigestItem, | ||
traits::{IsMember, One, SaturatedConversion, Saturating, Zero}, | ||
ConsensusEngineId, Permill, | ||
}; | ||
use sp_session::{GetSessionNumber, GetValidatorCount}; | ||
use sp_staking::{offence::OffenceReportSystem, SessionIndex}; | ||
|
||
|
@@ -109,11 +103,9 @@ impl EpochChangeTrigger for SameAuthoritiesForever { | |
|
||
const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256; | ||
|
||
#[frame_support::pallet] | ||
#[frame::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
/// The BABE Pallet | ||
#[pallet::pallet] | ||
|
@@ -311,7 +303,7 @@ pub mod pallet { | |
pub type SkippedEpochs<T> = | ||
StorageValue<_, BoundedVec<(u64, SessionIndex), ConstU32<100>>, ValueQuery>; | ||
|
||
#[derive(frame_support::DefaultNoBound)] | ||
#[derive(frame::prelude::DefaultNoBound)] | ||
#[pallet::genesis_config] | ||
pub struct GenesisConfig<T: Config> { | ||
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>, | ||
|
@@ -369,7 +361,6 @@ pub mod pallet { | |
// execution. We don't run the verification again here to avoid slowing | ||
// down the runtime. | ||
debug_assert!({ | ||
use sp_core::crypto::VrfPublic; | ||
public.vrf_verify(&transcript.clone().into_sign_data(), &signature) | ||
}); | ||
|
||
|
@@ -943,9 +934,7 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> { | |
} | ||
} | ||
|
||
impl<T: Config> frame_support::traits::EstimateNextSessionRotation<BlockNumberFor<T>> | ||
for Pallet<T> | ||
{ | ||
impl<T: Config> EstimateNextSessionRotation<BlockNumberFor<T>> for Pallet<T> { | ||
fn average_session_length() -> BlockNumberFor<T> { | ||
T::EpochDuration::get().saturated_into() | ||
} | ||
|
@@ -971,13 +960,13 @@ impl<T: Config> frame_support::traits::EstimateNextSessionRotation<BlockNumberFo | |
} | ||
} | ||
|
||
impl<T: Config> frame_support::traits::Lateness<BlockNumberFor<T>> for Pallet<T> { | ||
impl<T: Config> LatenessT<BlockNumberFor<T>> for Pallet<T> { | ||
fn lateness(&self) -> BlockNumberFor<T> { | ||
Lateness::<T>::get() | ||
} | ||
} | ||
|
||
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> { | ||
impl<T: Config> BoundToRuntimeAppPublic for Pallet<T> { | ||
type Public = AuthorityId; | ||
} | ||
|
||
|
@@ -1045,20 +1034,19 @@ fn compute_randomness( | |
s.extend_from_slice(&vrf_output[..]); | ||
} | ||
|
||
sp_io::hashing::blake2_256(&s) | ||
blake2_256(&s) | ||
} | ||
|
||
pub mod migrations { | ||
use super::*; | ||
use frame_support::pallet_prelude::{StorageValue, ValueQuery}; | ||
|
||
/// Something that can return the storage prefix of the `Babe` pallet. | ||
pub trait BabePalletPrefix: Config { | ||
fn pallet_prefix() -> &'static str; | ||
} | ||
|
||
struct __OldNextEpochConfig<T>(core::marker::PhantomData<T>); | ||
impl<T: BabePalletPrefix> frame_support::traits::StorageInstance for __OldNextEpochConfig<T> { | ||
impl<T: BabePalletPrefix> StorageInstance for __OldNextEpochConfig<T> { | ||
fn pallet_prefix() -> &'static str { | ||
T::pallet_prefix() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be needed if these pallets are only needed for tests.