0

Here's my babe pallet configuration: I suppose that for PoA we want to keep the same authority set

impl pallet_babe::Config for Runtime {
    type EpochDuration = EpochDuration;
    type ExpectedBlockTime = ExpectedBlockTime;
    type EpochChangeTrigger = pallet_babe::SameAuthoritiesForever;
    type DisabledValidators = Session;

    type KeyOwnerProofSystem = Historical;

    type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
        KeyTypeId,
        pallet_babe::AuthorityId,
    )>>::Proof;

    type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
        KeyTypeId,
        pallet_babe::AuthorityId,
    )>>::IdentificationTuple;

    type HandleEquivocation =
        pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;

    type WeightInfo = ();
    type MaxAuthorities = MaxAuthorities;
}

What would possible happen during a migration from PoA to NPoS when I change the line ExternalTrigger?

2 Answers 2

1

BABE does not really care about being PoA or NPoS.

Babe expects a set of authorities at the end of the day, and these authotities are received via implementing SessionHandler. In other words, through SessionHandler, the pallet-babe is informed of new authorities (coming from the pallet-session).

Whether those authorities are hardcoded or actually being elected via an election process determines if a chain is PoA or NPoS/DPoS.

If you want to mimic the path that Polkadot took, you can use the pallet-staking. With this pallet, you can have both PoA and NPoS (read here for more information about configuring the staking pallet). If you set the Forcing to be None, then no new eras are triggered in the staking pallet, and the initial authorities configured via genesis remain active forever, which is what a PoA chain essentially is. Once you allow new eras to be created, the staking pallet will enact new validators through whatever ElectionProvider it is given to it. You can still mimic a PoA chain by implementing a custom ElectionProvider that always elects the same set of validators.


In general, this is the structure of the Consensus/PoS pallets in substrate, in their default mode. Of course, as you see they are all connected with Rust traits so they have be swapped out when needed.

Consensus Pallets


    ┌──────────┐
    │          │
    │          │
    │          │
    │  BABE    │                  ┌─────────────────┐                 ┌──────────────────┐
    │          │                  │                 │                 │                  │
    │          │                  │                 │                 │                  │
    │          │                  │                 │                 │                  │
    │          │◄─┐               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    ├──────────┤  │               │                 │                 │                  │
    ├──────────┤  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │ SessionHandler│                 │  SessionManager │                  │
    │   AURA   ◄──┼───────────────┤    SESSION      ◄─────────────────┤     STAKING      │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    ├──────────┤  │               │                 │                 │                  │
    ├──────────┤  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │  │               │                 │                 │                  │
    │          │◄─┘               │                 │                 │                  │
    │          │                  │                 │                 │                  │
    │  GRANDPA │                  └─────────────────┘                 └──────────────────┘
    │          │
    │          │
    │          │
    │          │
    │          │
    └──────────┘
3
  • Ok so basically: 1. iniitializing (at genesis) the pallet_staking with force_era: ForceNone blocks all election eras (and so the validator set in the session pallet) to be updated, effectively ensuring PoA. 2. During a migration to NPoS should be then sufficient to call pallet_staking::force_new_era(root_origin) should re-enable normal election cycle hence enabling normal DPoS/NPoS. Is all of this correct?
    – mr_bovo
    Commented Sep 20, 2022 at 19:20
  • Yes, all correct.
    – kianenigma
    Commented Sep 21, 2022 at 10:08
  • @kianenigma hi, and how to update the BabeAuthorityWeight from a custom pallet?
    – Latte Xu
    Commented Jan 22 at 13:41
0

This is a good resource for converting POA to NPOS

https://github.com/kaichaosun/substrate-stencil/commits/master

1
  • You can remove aura from your code and use babe only . Commented Sep 19, 2022 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.