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

Add LatestHead relayer method to gRPC client and server implementations #767

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading