Skip to content

Commit

Permalink
[chore] Move core types to types/core; add RelayerSet type
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Apr 18, 2024
1 parent ec6d48a commit 157d875
Show file tree
Hide file tree
Showing 48 changed files with 356 additions and 249 deletions.
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 @@ -71,7 +72,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 @@ -85,7 +86,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
20 changes: 10 additions & 10 deletions pkg/loop/internal/core/services/pipeline/test/pipeline_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

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"
"github.com/smartcontractkit/chainlink-common/pkg/utils/jsonserializable"
)

Expand All @@ -19,15 +19,15 @@ answer;
var PipelineRunner = staticPipelineRunnerService{
staticPipelineRunnerConfig: staticPipelineRunnerConfig{
spec: pipleineSpec,
vars: types.Vars{
vars: core.Vars{
Vars: map[string]interface{}{"foo": "baz"},
},
options: types.Options{
options: core.Options{
MaxTaskDuration: 10 * time.Second,
},
taskResults: types.TaskResults([]types.TaskResult{
taskResults: core.TaskResults([]core.TaskResult{
{
TaskValue: types.TaskValue{
TaskValue: core.TaskValue{
Value: jsonserializable.JSONSerializable{
Val: "hello",
Valid: true,
Expand All @@ -43,16 +43,16 @@ var _ testtypes.PipelineEvaluator = (*staticPipelineRunnerService)(nil)

type staticPipelineRunnerConfig struct {
spec string
vars types.Vars
options types.Options
taskResults types.TaskResults
vars core.Vars
options core.Options
taskResults core.TaskResults
}

type staticPipelineRunnerService struct {
staticPipelineRunnerConfig
}

func (pr staticPipelineRunnerService) ExecuteRun(ctx context.Context, s string, v types.Vars, o types.Options) (types.TaskResults, error) {
func (pr staticPipelineRunnerService) ExecuteRun(ctx context.Context, s string, v core.Vars, o core.Options) (core.TaskResults, error) {
if s != pr.spec {
return nil, fmt.Errorf("expected %s but got %s", pr.spec, s)
}
Expand All @@ -65,7 +65,7 @@ func (pr staticPipelineRunnerService) ExecuteRun(ctx context.Context, s string,
return pr.taskResults, nil
}

func (pr staticPipelineRunnerService) Evaluate(ctx context.Context, other types.PipelineRunnerService) error {
func (pr staticPipelineRunnerService) Evaluate(ctx context.Context, other core.PipelineRunnerService) error {
tr, err := pr.ExecuteRun(ctx, pr.spec, pr.vars, pr.options)
if err != nil {
return fmt.Errorf("failed to execute pipeline: %w", err)
Expand Down
30 changes: 30 additions & 0 deletions pkg/loop/internal/core/services/relayerset/relayerset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package relayerset

import (
"context"

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

type RelayerSet interface {
Get(ctx context.Context, relayID types.RelayID) (Relayer, error)
GetAll(ctx context.Context) ([]Relayer, error)
}

type PluginArgs struct {
TransmitterID string
PluginConfig []byte
}

type RelayArgs struct {
ContractID string
RelayConfig []byte
ProviderType string
MercuryCredentials *types.MercuryCredentials
}

type Relayer interface {
services.Service
NewPluginProvider(rargs RelayArgs, pargs PluginArgs) (types.PluginProvider, error)
}
Loading

0 comments on commit 157d875

Please sign in to comment.