ChainSafe / ChainSafe/gossamer

(BEEFY): Implement RPCs methods

Open
#4,176 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

# Description

Implement the require RPCs methods for BEEFY, these are:

- `beefy_getFinalizedHead` - Returns the hash of the latest BEEFY finalized block
- `beefy_subscribeJustifications` - Returns the block finalized by BEEFY alongside its justification
- `beefy_unsubscribeJustifications` - Unsuscribe from beefy justifications

## Dependencies

- [ ] Beefy worker keeping beefy state from which we are going to get the data to respond in this RPCs #4177

## beefy_getFinalizedHead

1. Create beefy finality API interface `/dot/rpc/interfaces` that should be implemented by BEEFY service `/lib/beefy/beefy.go`
```go
type BeefyBlockFinalityAPI interface {
GetBeefyFinalizedHead() common.Hash
}
```
2. Create a beefy rpc module `/dot/rpc/modules/beefy.go`
```go
type BeefyModule struct {
blockAPI BlockAPI
blockFinalityAPI BlockFinalityAPI
}
```
3. Create response type
```go
type BlockHashResponse interface{}
```
4. Create RPC method
```go
func (bm *BeefyModule) GetFinalizedHead(r *http.Request, req *EmptyRequest, res *BlockHashResponse) error
```

5. Test

## beefy_subscribeJustifications & beefy_unsubscribeJustifications

1. Implement `GetBeefyFinalisedNotifierChannel` and `FreeBeefyFinalisedNotifierChannel` as part of `BlockAPI`
```go
type BlockAPI interface {
GetBeefyFinalisedNotifierChannel() chan *types.FinalisationInfo
FreeBeefyFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
}
```
2. Implement the required logic in `/dot/state/block_notify.go`
3. Create beefy listener in `/dot/rpc/subscription/listeners.go`
A quick suggestion about the implementation could be
```go
type BeefyListener struct {
Channel chan *types.FinalisationInfo
wsconn *WSConn
subID uint32
done chan struct{}
cancel chan struct{}
cancelTimeout time.Duration
}

func (l *BeefyListener) Listen() {
// Very similar than func (l *BlockFinalizedListener) Listen() but using the methods implemented in part 1.
}

```
4. Implement listener in `/dot/rpc/subscription/websocket.go`
```go
func (c *WSConn) initBeefyBlockFinalizedListener(reqID float64, _ interface{}) (Listener, error) {
// Similar than initBlockFinalizedListener but using the methods implemented in part 1
}
```
5. Register listener in `/dot/rpc/suscription/suscription.go` with method `beefy_subscribeJustifications`
6. Test

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.