Skip to content

Commit

Permalink
Add LatestHead relayer method to gRPC client and server implementatio…
Browse files Browse the repository at this point in the history
…ns (#767)

* Add LatestHead method to relayer interface

* Add LatestHead implementation to relayerset server and clients

* Fix error message
  • Loading branch information
kidambisrinivas authored Sep 16, 2024
1 parent 36cb477 commit b8f8ccc
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 114 deletions.
384 changes: 270 additions & 114 deletions pkg/loop/internal/pb/relayerset/relayerset.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pkg/loop/internal/pb/relayerset/relayerset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ message NewChainWriterResponse {
uint32 chainWriterId = 1;
}

message LatestHeadRequest {
RelayerId relayerId = 1;
}

message LatestHeadResponse {
string height = 1;
bytes hash = 2;
uint64 timestamp = 3;
}

message RelayerHealthReportResponse {
map<string, string> report = 1;
}
Expand All @@ -96,6 +106,7 @@ service RelayerSet {
rpc RelayerReady(RelayerId) returns (google.protobuf.Empty) {}
rpc RelayerHealthReport(RelayerId) returns (RelayerHealthReportResponse) {}
rpc RelayerName(RelayerId) returns (RelayerNameResponse) {}
rpc RelayerLatestHead(LatestHeadRequest) returns (LatestHeadResponse) {}
}


Expand Down
37 changes: 37 additions & 0 deletions pkg/loop/internal/pb/relayerset/relayerset_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/loop/internal/relayerset/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ func (k *Client) RelayerName(ctx context.Context, relayID types.RelayID) (string
return resp.Name, nil
}

func (k *Client) RelayerLatestHead(ctx context.Context, relayID types.RelayID) (types.Head, error) {
req := &relayerset.LatestHeadRequest{
RelayerId: &relayerset.RelayerId{ChainId: relayID.ChainID, Network: relayID.Network},
}
resp, err := k.relayerSetClient.RelayerLatestHead(ctx, req)
if err != nil {
return types.Head{}, fmt.Errorf("error getting latest head from relayerset client for relayer: %w", err)
}
return types.Head{
Height: resp.Height,
Hash: resp.Hash,
Timestamp: resp.Timestamp,
}, nil
}

func (k *Client) NewPluginProvider(ctx context.Context, relayID types.RelayID, relayArgs core.RelayArgs, pluginArgs core.PluginArgs) (uint32, error) {
// TODO at a later phase these credentials should be set as part of the relay config and not as a separate field
var mercuryCredentials *relayerset.MercuryCredentials
Expand Down
9 changes: 9 additions & 0 deletions pkg/loop/internal/relayerset/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,12 @@ func (r *relayerClient) Name() string {

return name
}

func (r *relayerClient) LatestHead(_ context.Context) (types.Head, error) {
latestHead, err := r.relayerSetClient.RelayerLatestHead(context.Background(), r.relayerID)
if err != nil {
r.log.Error("error getting latestHead", "error", err)
return types.Head{}, err
}
return latestHead, err
}
17 changes: 17 additions & 0 deletions pkg/loop/internal/relayerset/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ func (s *Server) RelayerName(ctx context.Context, relayID *relayerset.RelayerId)
return &relayerset.RelayerNameResponse{Name: relayer.Name()}, nil
}

func (s *Server) RelayerLatestHead(ctx context.Context, req *relayerset.LatestHeadRequest) (*relayerset.LatestHeadResponse, error) {
relayer, err := s.getRelayer(ctx, req.RelayerId)
if err != nil {
return nil, err
}

latestHead, err := relayer.LatestHead(ctx)
if err != nil {
return nil, err
}
return &relayerset.LatestHeadResponse{
Height: latestHead.Height,
Hash: latestHead.Hash,
Timestamp: latestHead.Timestamp,
}, nil
}

func (s *Server) getRelayer(ctx context.Context, relayerID *relayerset.RelayerId) (core.Relayer, error) {
relayer, err := s.impl.Get(ctx, types.RelayID{ChainID: relayerID.ChainId, Network: relayerID.Network})
if err != nil {
Expand Down
56 changes: 56 additions & 0 deletions pkg/types/core/mocks/relayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/types/core/relayerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ type Relayer interface {
NewPluginProvider(context.Context, RelayArgs, PluginArgs) (types.PluginProvider, error)
NewContractReader(_ context.Context, contractReaderConfig []byte) (types.ContractReader, error)
NewChainWriter(_ context.Context, chainWriterConfig []byte) (types.ChainWriter, error)
LatestHead(context.Context) (types.Head, error)
}

0 comments on commit b8f8ccc

Please sign in to comment.