Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BEEFY): Implement RPCs methods #4176

Open
1 task
dimartiro opened this issue Sep 9, 2024 · 0 comments
Open
1 task

(BEEFY): Implement RPCs methods #4176

dimartiro opened this issue Sep 9, 2024 · 0 comments

Comments

@dimartiro
Copy link
Contributor

dimartiro commented Sep 9, 2024

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_getFinalizedHead

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

beefy_subscribeJustifications & beefy_unsubscribeJustifications

  1. Implement GetBeefyFinalisedNotifierChannel and FreeBeefyFinalisedNotifierChannel as part of BlockAPI
type BlockAPI interface {
    GetBeefyFinalisedNotifierChannel() chan *types.FinalisationInfo
    FreeBeefyFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
}
  1. Implement the required logic in /dot/state/block_notify.go
  2. Create beefy listener in /dot/rpc/subscription/listeners.go
    A quick suggestion about the implementation could be
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.
}
  1. Implement listener in /dot/rpc/subscription/websocket.go
func (c *WSConn) initBeefyBlockFinalizedListener(reqID float64, _ interface{}) (Listener, error) {
	// Similar than initBlockFinalizedListener but using the methods implemented in part 1
}
  1. Register listener in /dot/rpc/suscription/suscription.go with method beefy_subscribeJustifications
  2. Test
@dimartiro dimartiro changed the title (BEEF): Implement RPCs methods (BEEFY): Implement RPCs methods Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant