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

[chore] Move core service types to types/core to mirror package structure; Add RelayerSet #475

Merged
merged 1 commit into from
Apr 19, 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
5 changes: 3 additions & 2 deletions pkg/capabilities/consensus/ocr3/ocr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/values"
)

Expand Down Expand Up @@ -78,7 +79,7 @@ func NewOCR3(config Config) *Capability {
return cp
}

func (o *Capability) NewReportingPluginFactory(ctx context.Context, cfg commontypes.ReportingPluginServiceConfig, provider commontypes.PluginProvider, pipelineRunner commontypes.PipelineRunnerService, telemetry commontypes.TelemetryClient, errorLog commontypes.ErrorLog, capabilityRegistry commontypes.CapabilitiesRegistry, keyValueStore commontypes.KeyValueStore) (commontypes.OCR3ReportingPluginFactory, error) {
func (o *Capability) NewReportingPluginFactory(ctx context.Context, cfg core.ReportingPluginServiceConfig, provider commontypes.PluginProvider, pipelineRunner core.PipelineRunnerService, telemetry core.TelemetryClient, errorLog core.ErrorLog, capabilityRegistry core.CapabilitiesRegistry, keyValueStore core.KeyValueStore) (core.OCR3ReportingPluginFactory, error) {
factory, err := newFactory(o.config.store, o.config.capability, o.config.BatchSize, o.config.Logger)
if err != nil {
return nil, err
Expand All @@ -92,7 +93,7 @@ func (o *Capability) NewReportingPluginFactory(ctx context.Context, cfg commonty
return factory, err
}

func (o *Capability) NewValidationService(ctx context.Context) (commontypes.ValidationService, error) {
func (o *Capability) NewValidationService(ctx context.Context) (core.ValidationService, error) {
s := &validationService{lggr: o.Logger}
o.SubService(s)
return s, nil
Expand Down
21 changes: 11 additions & 10 deletions pkg/capabilities/consensus/ocr3/ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/types/mocks"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)
Expand All @@ -24,14 +25,14 @@ func TestOCR3_ReportingFactoryAddsCapability(t *testing.T) {
require.NoError(t, o.Start(ctx))

var p types.PluginProvider
var pr types.PipelineRunnerService
var tc types.TelemetryClient
var el types.ErrorLog
var kv types.KeyValueStore
var pr core.PipelineRunnerService
var tc core.TelemetryClient
var el core.ErrorLog
var kv core.KeyValueStore
r := mocks.NewCapabilitiesRegistry(t)
r.On("Add", mock.Anything, o.config.capability).Return(nil)

_, err := o.NewReportingPluginFactory(ctx, types.ReportingPluginServiceConfig{}, p, pr, tc, el, r, kv)
_, err := o.NewReportingPluginFactory(ctx, core.ReportingPluginServiceConfig{}, p, pr, tc, el, r, kv)
require.NoError(t, err)
}

Expand All @@ -46,14 +47,14 @@ func TestOCR3_ReportingFactoryIsAService(t *testing.T) {
require.NoError(t, o.Start(ctx))

var p types.PluginProvider
var pr types.PipelineRunnerService
var tc types.TelemetryClient
var el types.ErrorLog
var kv types.KeyValueStore
var pr core.PipelineRunnerService
var tc core.TelemetryClient
var el core.ErrorLog
var kv core.KeyValueStore
r := mocks.NewCapabilitiesRegistry(t)
r.On("Add", mock.Anything, o.config.capability).Return(nil)

factory, err := o.NewReportingPluginFactory(ctx, types.ReportingPluginServiceConfig{}, p, pr, tc, el, r, kv)
factory, err := o.NewReportingPluginFactory(ctx, core.ReportingPluginServiceConfig{}, p, pr, tc, el, r, kv)
require.NoError(t, err)

require.NoError(t, factory.Start(ctx))
Expand Down
4 changes: 2 additions & 2 deletions pkg/capabilities/consensus/ocr3/validation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var _ commontypes.ValidationService = (*validationService)(nil)
var _ core.ValidationService = (*validationService)(nil)

type validationService struct {
lggr logger.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
capabilitiespb "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/net"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var _ types.CapabilitiesRegistry = (*capabilitiesRegistryClient)(nil)
var _ core.CapabilitiesRegistry = (*capabilitiesRegistryClient)(nil)

type capabilitiesRegistryClient struct {
*net.BrokerExt
Expand Down Expand Up @@ -169,7 +169,7 @@ var _ pb.CapabilitiesRegistryServer = (*capabilitiesRegistryServer)(nil)
type capabilitiesRegistryServer struct {
pb.UnimplementedCapabilitiesRegistryServer
*net.BrokerExt
impl types.CapabilitiesRegistry
impl core.CapabilitiesRegistry
}

func (c *capabilitiesRegistryServer) Get(ctx context.Context, request *pb.GetRequest) (*pb.GetReply, error) {
Expand Down Expand Up @@ -358,7 +358,7 @@ func (c *capabilitiesRegistryServer) Add(ctx context.Context, request *pb.AddReq
return &emptypb.Empty{}, nil
}

func NewCapabilitiesRegistryServer(b *net.BrokerExt, i types.CapabilitiesRegistry) *capabilitiesRegistryServer {
func NewCapabilitiesRegistryServer(b *net.BrokerExt, i core.CapabilitiesRegistry) *capabilitiesRegistryServer {
return &capabilitiesRegistryServer{
BrokerExt: b.WithName("CapabilitiesRegistryServer"),
impl: i,
Expand Down
8 changes: 4 additions & 4 deletions pkg/loop/internal/core/services/errorlog/error_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var _ types.ErrorLog = (*errorLogClient)(nil)
var _ core.ErrorLog = (*errorLogClient)(nil)

type errorLogClient struct {
grpc pb.ErrorLogClient
Expand All @@ -30,10 +30,10 @@ var _ pb.ErrorLogServer = (*Server)(nil)
type Server struct {
pb.UnimplementedErrorLogServer

impl types.ErrorLog
impl core.ErrorLog
}

func NewServer(impl types.ErrorLog) *Server {
func NewServer(impl core.ErrorLog) *Server {
return &Server{impl: impl}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/internal/core/services/errorlog/test/error_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

testtypes "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/test/types"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var ErrorLog = StaticErrorLog{errMsg: "an error"}
Expand All @@ -23,6 +23,6 @@ func (s StaticErrorLog) SaveError(ctx context.Context, msg string) error {
return nil
}

func (s StaticErrorLog) Evaluate(ctx context.Context, other types.ErrorLog) error {
func (s StaticErrorLog) Evaluate(ctx context.Context, other core.ErrorLog) error {
return s.SaveError(ctx, s.errMsg)
}
8 changes: 4 additions & 4 deletions pkg/loop/internal/core/services/keystore/test/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
libocr "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

testtypes "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/test/types"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var Keystore = staticKeystore{
Expand All @@ -19,8 +19,8 @@ var Keystore = staticKeystore{
},
}

var _ types.Keystore = (*staticKeystore)(nil)
var _ testtypes.Evaluator[types.Keystore] = (*staticKeystore)(nil)
var _ core.Keystore = (*staticKeystore)(nil)
var _ testtypes.Evaluator[core.Keystore] = (*staticKeystore)(nil)

type staticKeystoreConfig struct {
Account libocr.Account
Expand All @@ -46,7 +46,7 @@ func (s staticKeystore) Sign(ctx context.Context, id string, data []byte) ([]byt
return s.signed, nil
}

func (s staticKeystore) Evaluate(ctx context.Context, other types.Keystore) error {
func (s staticKeystore) Evaluate(ctx context.Context, other core.Keystore) error {
accounts, err := s.Accounts(ctx)
if err != nil {
return fmt.Errorf("failed to get accounts: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/loop/internal/core/services/keyvalue/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

var _ types.KeyValueStore = (*Client)(nil)
var _ core.KeyValueStore = (*Client)(nil)

type Client struct {
grpc pb.KeyValueStoreClient
Expand Down Expand Up @@ -43,10 +43,10 @@ var _ pb.KeyValueStoreServer = (*Server)(nil)

type Server struct {
pb.UnimplementedKeyValueStoreServer
impl types.KeyValueStore
impl core.KeyValueStore
}

func NewServer(impl types.KeyValueStore) *Server {
func NewServer(impl core.KeyValueStore) *Server {
return &Server{impl: impl}
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/loop/internal/core/services/pipeline/pipeline_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/net"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/utils/jsonserializable"
)

var _ types.PipelineRunnerService = (*pipelineRunnerServiceClient)(nil)
var _ core.PipelineRunnerService = (*pipelineRunnerServiceClient)(nil)

type pipelineRunnerServiceClient struct {
*net.BrokerExt
Expand All @@ -25,7 +25,7 @@ func NewRunnerClient(cc grpc.ClientConnInterface) *pipelineRunnerServiceClient {
return &pipelineRunnerServiceClient{grpc: pb.NewPipelineRunnerServiceClient(cc)}
}

func (p pipelineRunnerServiceClient) ExecuteRun(ctx context.Context, spec string, vars types.Vars, options types.Options) (types.TaskResults, error) {
func (p pipelineRunnerServiceClient) ExecuteRun(ctx context.Context, spec string, vars core.Vars, options core.Options) (core.TaskResults, error) {
varsStruct, err := structpb.NewStruct(vars.Vars)
if err != nil {
return nil, err
Expand All @@ -44,7 +44,7 @@ func (p pipelineRunnerServiceClient) ExecuteRun(ctx context.Context, spec string
return nil, err
}

trs := make([]types.TaskResult, len(executeRunResult.Results))
trs := make([]core.TaskResult, len(executeRunResult.Results))
for i, trr := range executeRunResult.Results {
var err error
if trr.HasError {
Expand All @@ -56,10 +56,10 @@ func (p pipelineRunnerServiceClient) ExecuteRun(ctx context.Context, spec string
if err2 != nil {
return nil, err2
}
trs[i] = types.TaskResult{
trs[i] = core.TaskResult{
ID: trr.Id,
Type: trr.Type,
TaskValue: types.TaskValue{
TaskValue: core.TaskValue{
Value: js,
Error: err,
IsTerminal: trr.IsTerminal,
Expand All @@ -77,18 +77,18 @@ type RunnerServer struct {
pb.UnimplementedPipelineRunnerServiceServer
*net.BrokerExt

impl types.PipelineRunnerService
impl core.PipelineRunnerService
}

func NewRunnerServer(impl types.PipelineRunnerService) *RunnerServer {
func NewRunnerServer(impl core.PipelineRunnerService) *RunnerServer {
return &RunnerServer{impl: impl}
}

func (p *RunnerServer) ExecuteRun(ctx context.Context, rr *pb.RunRequest) (*pb.RunResponse, error) {
vars := types.Vars{
vars := core.Vars{
Vars: rr.Vars.AsMap(),
}
options := types.Options{
options := core.Options{
MaxTaskDuration: rr.Options.MaxTaskDuration.AsDuration(),
}
trs, err := p.impl.ExecuteRun(ctx, rr.Spec, vars, options)
Expand Down
24 changes: 12 additions & 12 deletions pkg/loop/internal/core/services/pipeline/pipeline_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"google.golang.org/grpc"

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/utils/jsonserializable"
)

type mockPipelineRunner struct {
taskResults []types.TaskResult
taskResults []core.TaskResult
err error
spec string
vars types.Vars
options types.Options
vars core.Vars
options core.Options
}

func (m *mockPipelineRunner) ExecuteRun(ctx context.Context, spec string, vars types.Vars, options types.Options) (types.TaskResults, error) {
func (m *mockPipelineRunner) ExecuteRun(ctx context.Context, spec string, vars core.Vars, options core.Options) (core.TaskResults, error) {
m.spec, m.vars, m.options = spec, vars, options
return m.taskResults, m.err
}
Expand All @@ -37,10 +37,10 @@ func (c *clientAdapter) ExecuteRun(ctx context.Context, in *pb.RunRequest, opts
}

func TestPipelineRunnerService(t *testing.T) {
originalResults := []types.TaskResult{
originalResults := []core.TaskResult{
{
ID: "1",
TaskValue: types.TaskValue{
TaskValue: core.TaskValue{
Value: jsonserializable.JSONSerializable{
Val: 123.123,
Valid: true,
Expand All @@ -51,7 +51,7 @@ func TestPipelineRunnerService(t *testing.T) {
{
ID: "2",

TaskValue: types.TaskValue{
TaskValue: core.TaskValue{
Value: jsonserializable.JSONSerializable{},
Error: errors.New("Error task"),
},
Expand All @@ -66,8 +66,8 @@ func TestPipelineRunnerService(t *testing.T) {
trs, err := client.ExecuteRun(
context.Background(),
"my-spec",
types.Vars{Vars: map[string]interface{}{"my-vars": true}},
types.Options{MaxTaskDuration: 10 * time.Second},
core.Vars{Vars: map[string]interface{}{"my-vars": true}},
core.Options{MaxTaskDuration: 10 * time.Second},
)
require.NoError(t, err)
assert.ElementsMatch(t, originalResults, trs)
Expand All @@ -79,10 +79,10 @@ func TestPipelineRunnerService_CallArgs(t *testing.T) {
client := &pipelineRunnerServiceClient{grpc: &clientAdapter{srv: srv}}

spec := "my-spec"
vars := types.Vars{
vars := core.Vars{
Vars: map[string]interface{}{"my-vars": true},
}
options := types.Options{
options := core.Options{
MaxTaskDuration: 10 * time.Second,
}
_, err := client.ExecuteRun(context.Background(), spec, vars, options)
Expand Down
Loading
Loading