ChainSafe / gossamer

🕸️ Go Implementation of the Polkadot Host
https://chainsafe.github.io/gossamer
GNU Lesser General Public License v3.0
432 stars 117 forks source link

create inherent provider interface #4242

Open EclesioMeloJunior opened 1 month ago

EclesioMeloJunior commented 1 month ago

Description

Here is the part that connects BABE with Provisioner subsystem. Currently, Gossamer does not have a specific struct for inherents, we only define inherents at the moment of block building.

To have a better separation of responsibility we can define an interface InherentProvider and the block builder can have a set of InherentProvider.

We can define the interface in the packagelib/babe, also we can make it generic over the type of inherent it will return.

type InherentProvider interface {
    // Provide will add the data to `out`
    Provide(out *types.InherentData) T
}

type TimestampInherentProvider struct {}
// slot inherent provider might need timestamp as depedency provider
type SlotInherentProvider struct {}
// needs the overseer and state as depedencies
type ParachainsInherentProvider struct {}

go create_inherent_data()

select { case id := <- inherentDataCh: // happy path, we got the inherents in time case remainingTime.C: // timeout! inherents not provided in time }



### Reference
https://github.com/paritytech/polkadot-sdk/blob/c0b734336a68b6f48ac70a9b9507d8ddb9fed57e/polkadot/node/service/src/lib.rs#L1245
https://github.com/paritytech/polkadot-sdk/blob/c0b734336a68b6f48ac70a9b9507d8ddb9fed57e/substrate/client/consensus/slots/src/lib.rs#L250