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

[BCF-3381] - Add LatestHead to ChainService #760

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1,276 changes: 701 additions & 575 deletions pkg/loop/internal/pb/relayer.pb.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pkg/loop/internal/pb/relayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ option go_package = "github.com/smartcontractkit/chainlink-common/pkg/loop/inter
package loop;

import "google/protobuf/empty.proto";
import "contract_reader.proto";

service PluginRelayer {
rpc NewRelayer (NewRelayerRequest) returns (NewRelayerReply) {}
Expand Down Expand Up @@ -46,6 +47,7 @@ service Relayer {
rpc NewConfigProvider (NewConfigProviderRequest) returns (NewConfigProviderReply) {}
rpc NewPluginProvider (NewPluginProviderRequest) returns (NewPluginProviderReply) {}

rpc LatestHead (LatestHeadRequest) returns (LatestHeadReply) {}
rpc GetChainStatus (GetChainStatusRequest) returns (GetChainStatusReply) {}
rpc ListNodeStatuses (ListNodeStatusesRequest) returns (ListNodeStatusesReply) {}
rpc Transact (TransactionRequest) returns (google.protobuf.Empty) {}
Expand Down Expand Up @@ -108,6 +110,13 @@ message NewConfigProviderReply {
uint32 configProviderID = 1;
}

message LatestHeadRequest {}

// LatestHeadReply has return arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.LatestHeadReply].
message LatestHeadReply {
Head head = 1;
}

message GetChainStatusRequest {}

// ChainStatusReply has return arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.ChainStatus].
Expand Down
37 changes: 37 additions & 0 deletions pkg/loop/internal/pb/relayer_grpc.pb.go

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

28 changes: 28 additions & 0 deletions pkg/loop/internal/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ func (r *relayerClient) NewLLOProvider(ctx context.Context, rargs types.RelayArg
return nil, fmt.Errorf("llo provider not supported: %w", errors.ErrUnsupported)
}

func (r *relayerClient) LatestHead(ctx context.Context) (types.Head, error) {
reply, err := r.relayer.LatestHead(ctx, &pb.LatestHeadRequest{})
if err != nil {
return types.Head{}, err
}

return types.Head{
Identifier: reply.Head.Identifier,
Hash: reply.Head.Hash,
Timestamp: reply.Head.Timestamp,
}, nil
}

func (r *relayerClient) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
reply, err := r.relayer.GetChainStatus(ctx, &pb.GetChainStatusRequest{})
if err != nil {
Expand Down Expand Up @@ -657,6 +670,21 @@ func (r *relayerServer) newCommitProvider(ctx context.Context, relayArgs types.R
return id, err
}

func (r *relayerServer) LatestHead(ctx context.Context, _ *pb.LatestHeadRequest) (*pb.LatestHeadReply, error) {
head, err := r.impl.LatestHead(ctx)
if err != nil {
return nil, err
}

return &pb.LatestHeadReply{
Head: &pb.Head{
Identifier: head.Identifier,
jmank88 marked this conversation as resolved.
Show resolved Hide resolved
Hash: head.Hash,
Timestamp: head.Timestamp,
},
}, nil
}

func (r *relayerServer) GetChainStatus(ctx context.Context, request *pb.GetChainStatusRequest) (*pb.GetChainStatusReply, error) {
chain, err := r.impl.GetChainStatus(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/loop/internal/relayer/test/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func (s staticPluginRelayer) NewLLOProvider(ctx context.Context, r types.RelayAr
return nil, errors.New("not implemented")
}

func (s staticPluginRelayer) LatestHead(ctx context.Context) (types.Head, error) {
return types.Head{}, errors.New("not implemented")
}

func (s staticPluginRelayer) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
return s.chainStatus, nil
}
Expand Down
56 changes: 56 additions & 0 deletions pkg/loop/mocks/relayer.go

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

7 changes: 7 additions & 0 deletions pkg/loop/relayer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func (r *RelayerService) NewLLOProvider(ctx context.Context, rargs types.RelayAr
return r.Service.NewLLOProvider(ctx, rargs, pargs)
}

func (r *RelayerService) LatestHead(ctx context.Context) (types.Head, error) {
if err := r.WaitCtx(ctx); err != nil {
return types.Head{}, err
}
return r.Service.LatestHead(ctx)
}

func (r *RelayerService) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
if err := r.WaitCtx(ctx); err != nil {
return types.ChainStatus{}, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type NodeStatus struct {
type ChainService interface {
Service

// LatestHead returns the latest head for the underlying chain.
LatestHead(ctx context.Context) (Head, error)
// GetChainStatus returns the ChainStatus for this Relayer.
GetChainStatus(ctx context.Context) (ChainStatus, error)
// ListNodeStatuses returns the status of RPC nodes.
Expand Down
Loading