Skip to content

Commit 66a18a9

Browse files
committed
replace aura-compat feature with generic tools
1 parent b5fbd7b commit 66a18a9

File tree

6 files changed

+43
-37
lines changed

6 files changed

+43
-37
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ frame-benchmarking = { workspace = true, optional = true }
7272
frame-system-benchmarking = { workspace = true, optional = true }
7373

7474
# Local Dependencies
75-
pallet-block-production-log = { workspace = true, features = ["block-participation", "aura-compat"] }
75+
pallet-block-production-log = { workspace = true, features = ["block-participation"] }
7676
sp-sidechain = { workspace = true }
7777
pallet-sidechain = { workspace = true }
7878
pallet-session-validator-management = { workspace = true }

demo/runtime/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use frame_support::{
2929
use frame_system::EnsureRoot;
3030
use opaque::SessionKeys;
3131
use pallet_block_producer_metadata;
32+
use pallet_block_production_log::{FromFindAuthorIndex, FromStorage};
3233
use pallet_grandpa::AuthorityId as GrandpaId;
3334
use pallet_session_validator_management::CommitteeMemberOf;
3435
use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier};
@@ -500,8 +501,8 @@ impl pallet_block_production_log::Config for Runtime {
500501

501502
type Moment = Slot;
502503

503-
type GetMoment = Aura;
504-
type GetAuthor = Aura;
504+
type GetMoment = FromStorage<pallet_aura::CurrentSlot<Runtime>>;
505+
type GetAuthor = FromFindAuthorIndex<Runtime, Aura, u32>;
505506
}
506507

507508
parameter_types! {

docs/developer-guides/block-participation-rewards.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ range, a representative timestamp, such as the start of the range should be comp
104104

105105
The pallet should be added to the runtime and configured to use `BlockAuthor` type as its `BlockProducerId`
106106
and use the `Moment` type. Additionally, it must be provided a source of current block author and moment.
107-
These are provided out of the box for chains using Aura under feature flag `aura-compat`.
108107

109108
#### Address Associations
110109

toolkit/block-production-log/pallet/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ sp-std = { workspace = true }
2525
pallet-session-validator-management = { workspace = true }
2626

2727
pallet-block-participation = { workspace = true, optional = true }
28-
pallet-aura = { workspace = true, optional = true }
29-
sp-consensus-aura = { workspace = true, optional = true }
3028

3129
[dev-dependencies]
3230
sp-core = { workspace = true }
@@ -45,8 +43,6 @@ std = [
4543
"sp-std/std",
4644
"pallet-session-validator-management/std",
4745
"pallet-block-participation?/std",
48-
"pallet-aura?/std",
49-
"sp-consensus-aura?/std",
5046
]
5147
runtime-benchmarks = [
5248
"frame-benchmarking/runtime-benchmarks",
@@ -56,7 +52,3 @@ runtime-benchmarks = [
5652
block-participation = [
5753
"dep:pallet-block-participation",
5854
]
59-
aura-compat = [
60-
"dep:pallet-aura",
61-
"dep:sp-consensus-aura",
62-
]

toolkit/block-production-log/pallet/src/lib.rs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@
2828
//! impl pallet_block_production_log::Config for Runtime {
2929
//! type BlockProducerId = BlockAuthor;
3030
//!
31-
//! type Moment = Slot;
31+
//! type Moment = Slot;
3232
//!
33-
//! type GetMoment = Aura;
34-
//! type GetAuthor = Aura;
33+
//! type GetMoment = FromStorage<pallet_aura::CurrentSlot<Runtime>>;
34+
//! type GetAuthor = FromFindAuthorIndex<Runtime, Aura, u32>;
3535
//! }
3636
//! ```
3737
//!
38-
//! Implementations supporting use of Aura and SessionCommitteeManagement as sources of moment and block producer
39-
//! can be enabled using the `aura-compat` feature flag.
40-
//!
4138
//! #### Defining block producer ID
4239
//!
4340
//! The pallet expects the Partner Chain to provide a type representing its block producers.
@@ -98,26 +95,30 @@ mod mock;
9895
#[cfg(test)]
9996
mod test;
10097

98+
use core::marker::PhantomData;
99+
101100
pub use pallet::*;
102101
pub use weights::WeightInfo;
103102

104103
/// Source of the current block's author
105-
///
106-
/// An implementation that will fetch block author from `pallet_session_validator_management` based on
107-
/// an index provided by Aura pallet is provided under feature flag `aura-compat`.
108104
pub trait GetAuthor<BlockProducerId> {
109105
/// Returns the current block's author
110106
fn get_author() -> Option<BlockProducerId>;
111107
}
112108

109+
/// [GetAuthor] implementation that uses a [FindAuthor] instance to get the current block's author index
110+
/// of type `I` and uses it to read the author from `pallet_session_validator_management`.
111+
pub struct FromFindAuthorIndex<T, FA, I>(PhantomData<(T, FA, I)>);
112+
113113
/// Source of the current block's moment
114-
///
115-
/// Implementation that fetches current slot from Aura pallet is provided under feature flat `aura-compat`.
116114
pub trait GetMoment<Moment> {
117115
/// Returns the current block's moment
118116
fn get_moment() -> Option<Moment>;
119117
}
120118

119+
/// [GetMoment] implementation that fetches current block's `Moment` from storage `S`
120+
pub struct FromStorage<S>(PhantomData<S>);
121+
121122
#[frame_support::pallet]
122123
pub mod pallet {
123124
use super::*;
@@ -219,25 +220,40 @@ mod block_participation {
219220
}
220221
}
221222

222-
#[cfg(feature = "aura-compat")]
223-
mod aura_support {
224-
use crate::*;
223+
mod source_impls {
224+
use super::*;
225+
use frame_support::{
226+
pallet_prelude::StorageValue,
227+
storage::types::QueryKindTrait,
228+
traits::{FindAuthor, StorageInstance},
229+
};
225230
use pallet_session_validator_management as psvm;
226-
use sp_consensus_aura::Slot;
231+
use parity_scale_codec::FullCodec;
232+
use sp_runtime::traits::Get;
227233

228-
impl<T: crate::Config + pallet_aura::Config> GetMoment<Slot> for pallet_aura::Pallet<T> {
229-
fn get_moment() -> Option<Slot> {
230-
Some(pallet_aura::CurrentSlot::<T>::get())
234+
impl<BlockProducerId, I, FA, T> GetAuthor<BlockProducerId> for FromFindAuthorIndex<T, FA, I>
235+
where
236+
FA: FindAuthor<I>,
237+
I: TryInto<usize>,
238+
T: psvm::Config,
239+
psvm::CommitteeMemberOf<T>: Into<BlockProducerId>,
240+
{
241+
fn get_author() -> Option<BlockProducerId> {
242+
Some(psvm::Pallet::<T>::find_current_authority::<I, FA>()?.into())
231243
}
232244
}
233245

234-
impl<BlockProducerId, T> GetAuthor<BlockProducerId> for pallet_aura::Pallet<T>
246+
impl<Prefix, Value, Moment, QueryKind, OnEmpty> GetMoment<Moment>
247+
for FromStorage<StorageValue<Prefix, Value, QueryKind, OnEmpty>>
235248
where
236-
T: crate::Config + psvm::Config + pallet_aura::Config,
237-
psvm::CommitteeMemberOf<T>: Into<BlockProducerId>,
249+
Prefix: StorageInstance,
250+
Value: FullCodec,
251+
QueryKind: QueryKindTrait<Value, OnEmpty>,
252+
OnEmpty: Get<QueryKind::Query> + 'static,
253+
Option<Moment>: From<<QueryKind as QueryKindTrait<Value, OnEmpty>>::Query>,
238254
{
239-
fn get_author() -> Option<BlockProducerId> {
240-
Some(psvm::Pallet::<T>::find_current_authority::<u32, pallet_aura::Pallet<T>>()?.into())
255+
fn get_moment() -> Option<Moment> {
256+
StorageValue::<Prefix, Value, QueryKind, OnEmpty>::get().into()
241257
}
242258
}
243259
}

0 commit comments

Comments
 (0)