moonbeam icon indicating copy to clipboard operation
moonbeam copied to clipboard

[`Docs guide`] How to implement staking pallet

Open sudipghimire533 opened this issue 2 years ago • 1 comments

Moonbeam's pallet-staking seems to be fit in our use case as well. I would like to request you guys if you have some reference on how to implement pallet-staking in other cumulus based node as well. Currenlt we are using pallet-collator-selection

Here is my current understanding:

  1. Configure pallet-staking's Config in Runtime
  2. Add to construct runtime before session and authorship pallet
  3. Set pallet_authorship::Config::EventHandler to ParachainStaking was previously to ( CollatorSelection )
  4. Set pallet_session::Config::SessionManager to ParachainStaking was previously to ( CollatorSelection )

On step 3 & 4, I am getting these error:

  349 |     type EventHandler = ParachainStaking;
      |                         ^^^^^^^^^^^^^^^^ the trait `EventHandler<sp_runtime::AccountId32, u32>` is not implemented for `pallet_parachain_staking::Pallet<Runtime>`
      |
  note: required by a bound in `pallet_authorship::Config::EventHandler`
     --> /home/user/.cargo/git/checkouts/substrate-7e08433d4c370a21/814752f/frame/authorship/src/lib.rs:154:22
      |
  154 |         type EventHandler: EventHandler<Self::AccountId, Self::BlockNumber>;
      |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pallet_authorship::Config::EventHandler`

and

  error[E0277]: the trait bound `pallet_parachain_staking::Pallet<Runtime>: pallet_session::SessionManager<sp_runtime::AccountId32>` is not satisfied
     --> /home/user/Projects/DataHighway-Parachain/runtime/src/lib.rs:633:27
      |
  633 |     type SessionManager = ParachainStaking;
      |                           ^^^^^^^^^^^^^^^^ the trait `pallet_session::SessionManager<sp_runtime::AccountId32>` is not implemented for `pallet_parachain_staking::Pallet<Runtime>`
      |
  note: required by a bound in `pallet_session::Config::SessionManager`
     --> /home/user/.cargo/git/checkouts/substrate-7e08433d4c370a21/814752f/frame/session/src/lib.rs:405:24
      |
  405 |         type SessionManager: SessionManager<Self::ValidatorId>;
      |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pallet_session::Config::SessionManager`

If there are any other option as well please suggest so.

PS: I was looking into the moonbeam's implementation as a reference but I am not able to figure out where and how are those two unsatisfied trait being implemented

sudipghimire533 avatar Aug 11 '22 10:08 sudipghimire533

PS: I was looking into the moonbeam's implementation as a reference but I am not able to figure out where and how are those two unsatisfied trait being implemented

Hello @sudipghimire533 , they are not implemented -- moonbeam runtimes do not have pallet_authorship nor pallet_session; it has substitutes:

(3) we use nimbus::pallet_author_inherent https://github.com/PureStake/nimbus/tree/main/pallets/author-inherent instead of pallet_authorship, so there is no implementation of pallet_authorship::EventHandler for ParachainStaking

We removed the nimbus_primitives::EventHandler impl from ParachainStaking in #1701 so if you're using a recent version of ParachainStaking, it would not have this. Now ParachainStaking's Config has an associated type BlockAuthor which gets the current block author from nimbus::pallet_author_inherent storage and this is used in on_finalize to track rewards.

(4) pallet_session::Config::SessionManager is not implemented by ParachainStaking because we use the AuthorMapping pallet instead https://github.com/PureStake/moonbeam/tree/master/pallets/author-mapping

We'd accept PRs to implement these traits but that won't guarantee everything works perfectly together. It's probably easier to just use nimbus::pallet_author_inherent and pallet_author_mapping in your runtime instead.

4meta5 avatar Aug 14 '22 13:08 4meta5