Skip to content

Commit 0923641

Browse files
committed
tweaks and docs
1 parent 7e67bd8 commit 0923641

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

demo/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ impl pallet_block_producer_metadata::Config for Runtime {
594594
impl pallet_block_participation::Config for Runtime {
595595
type WeightInfo = pallet_block_participation::weights::SubstrateWeight<Runtime>;
596596
type DelegatorId = DelegatorKey;
597+
type BlockAuthor = BlockAuthor;
597598

598599
type Moment = Slot;
599600

toolkit/block-participation/pallet/src/lib.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
//!
1919
//! ### Adding into the runtime
2020
//!
21-
//! The pallet's configuration can be divided into three groups by purpose:
22-
//! - `BlockAuthor` and `DelegatorId` types representing block authors and their dependant block beneficiaries
23-
//! - `should_release_data` function that controls when the inherent data provider is active
24-
//! - `blocks_produced_up_to_slot` and `blocks_produced_upd_to_slot` functions that provide bindings for consuming
25-
//! (reading and clearing) block production data. Most easily these should come from `pallet_block_production_log`.
26-
//!
2721
//! Consult documentation of [pallet::Config] for details on each configuration field.
2822
//!
2923
//! Assuming that the runtime also contains the `pallet_block_production_log`, an example configuration of
@@ -36,22 +30,7 @@
3630
//! type BlockAuthor = BlockAuthor;
3731
//! type DelegatorId = DelegatorKey;
3832
//!
39-
//! // release data every `RELEASE_PERIOD` blocks, up to current slot
40-
//! fn should_release_data(slot: sidechain_slots::Slot) -> Option<sidechain_slots::Slot> {
41-
//! if System::block_number() % RELEASE_PERIOD == 0 {
42-
//! Some(slot)
43-
//! } else {
44-
//! None
45-
//! }
46-
//! }
47-
//!
48-
//! fn blocks_produced_up_to_slot(slot: Slot) -> impl Iterator<Item = (Slot, BlockAuthor)> {
49-
//! BlockProductionLog::peek_prefix(slot)
50-
//! }
51-
//!
52-
//! fn discard_blocks_produced_up_to_slot(slot: Slot) {
53-
//! BlockProductionLog::drop_prefix(&slot)
54-
//! }
33+
//! type BlockParticipationProvider = BlockProductionLog;
5534
//!
5635
//! const TARGET_INHERENT_ID: InherentIdentifier = *b"_example";
5736
//! }
@@ -72,12 +51,9 @@ pub use pallet::*;
7251
use sp_block_participation::*;
7352

7453
/// Source of block participation data
75-
pub trait BlockParticipationProvider<Moment> {
76-
/// Block participation data type
77-
type BlockData;
78-
54+
pub trait BlockParticipationProvider<Moment, BlockProducer> {
7955
/// Returns the block data for processing
80-
fn blocks_to_process(moment: &Moment) -> impl Iterator<Item = Self::BlockData>;
56+
fn blocks_to_process(moment: &Moment) -> impl Iterator<Item = (Moment, BlockProducer)>;
8157

8258
/// Discards processed data
8359
fn discard_processed_blocks(moment: &Moment);
@@ -98,10 +74,19 @@ pub mod pallet {
9874
type WeightInfo: crate::weights::WeightInfo;
9975

10076
/// Moment in time at which the participation data should be processed
77+
///
78+
/// This type should be convertible to a timestamp value. If it represents a time range,
79+
/// a representative timestamp, such as the start of the range should be computable from it.
10180
type Moment: Parameter + Default + MaxEncodedLen + PartialOrd;
10281

10382
/// Source of block participation data
104-
type BlockParticipationProvider: BlockParticipationProvider<Self::Moment>;
83+
///
84+
/// The default implementation provided by the Partner Chains toolit is the block production
85+
/// log pallet implemented by the `pallet_block_production_log` crate.
86+
type BlockParticipationProvider: BlockParticipationProvider<Self::Moment, Self::BlockAuthor>;
87+
88+
/// Type identifying the producer of a block on the Partner Chain
89+
type BlockAuthor: Member + Parameter + MaxEncodedLen;
10590

10691
/// Type identifying indirect block production participants on the Partner Chain
10792
/// This can be native stakers on Partner Chain, stakers on the main chain or other.
@@ -188,10 +173,7 @@ pub mod pallet {
188173

189174
impl<T: Config> Pallet<T> {
190175
/// Fetches all blocks to be processed
191-
pub fn blocks_to_process(
192-
moment: &T::Moment,
193-
) -> Vec<<<T as Config>::BlockParticipationProvider as BlockParticipationProvider<T::Moment>>::BlockData>
194-
{
176+
pub fn blocks_to_process(moment: &T::Moment) -> Vec<(T::Moment, T::BlockAuthor)> {
195177
<T as Config>::BlockParticipationProvider::blocks_to_process(moment).collect()
196178
}
197179

toolkit/block-participation/pallet/src/mock.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ construct_runtime! {
4141
}
4242
}
4343

44-
impl BlockParticipationProvider<u64> for Mock {
45-
type BlockData = (u64, BlockProducerId);
46-
47-
fn blocks_to_process(up_to_moment: &u64) -> impl Iterator<Item = Self::BlockData> {
44+
impl BlockParticipationProvider<u64, BlockProducerId> for Mock {
45+
fn blocks_to_process(up_to_moment: &u64) -> impl Iterator<Item = (u64, BlockProducerId)> {
4846
mock_pallet::BlockProductionLog::<Test>::get()
4947
.unwrap()
5048
.clone()
@@ -104,6 +102,7 @@ const TEST_INHERENT_ID: InherentIdentifier = [42; 8];
104102
impl crate::pallet::Config for Test {
105103
type WeightInfo = ();
106104

105+
type BlockAuthor = BlockProducerId;
107106
type DelegatorId = DelegatorId;
108107
type Moment = u64;
109108

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ pub mod pallet {
253253
mod block_participation {
254254
use pallet_block_participation::BlockParticipationProvider;
255255

256-
impl<T: crate::Config> BlockParticipationProvider<T::Moment> for crate::Pallet<T> {
257-
type BlockData = (T::Moment, T::BlockProducerId);
258-
259-
fn blocks_to_process(moment: &T::Moment) -> impl Iterator<Item = Self::BlockData> {
256+
impl<T: crate::Config> BlockParticipationProvider<T::Moment, T::BlockProducerId>
257+
for crate::Pallet<T>
258+
{
259+
fn blocks_to_process(
260+
moment: &T::Moment,
261+
) -> impl Iterator<Item = (T::Moment, T::BlockProducerId)> {
260262
Self::peek_prefix(moment)
261263
}
262264

0 commit comments

Comments
 (0)