ChainSafe / ChainSafe/gossamer

create inherent provider interface [BABE integration]

Open
#4,242 0 comments 0 reactions 1 assignee Claimed by @axaysagathiya View on GitHub
A-design C-complex P-high S-babe
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

### 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 package`lib/babe`, also we can make it generic over the type of inherent it will return.
```go
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 {}
```

- Change the `BlockBuilder` at `lib/babe/build.go` to have a set of `InherentProviders` and iterate over them passing a fresh `*types.InherentData` and them encode it.
- Changes might be needed to make `timestamp` and `slot` to conform with `InherentProvider interface`
- Given that we now when a slot ends (slot start + duration) set up a timeout timer to avoid going beyond the block producer time slot.
```go
endAt := slot.start + slot.duration
remainingTime := time.NewTimer(end_at - time.Now())

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
BABE
- 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

Parachain Inherent Data Creation
- https://github.com/paritytech/polkadot-sdk/blob/c0b734336a68b6f48ac70a9b9507d8ddb9fed57e/polkadot/node/core/parachains-inherent/src/lib.rs

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.