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
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::*;
7251use 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
0 commit comments