Skip to content

Commit

Permalink
Rename NewChainReader to NewContractReader
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed May 22, 2024
1 parent 93d8216 commit ab5ed86
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 378 deletions.
4 changes: 2 additions & 2 deletions pkg/loop/adapters/relay/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type RelayerAdapter struct {
RelayerExt
}

func (r *RelayerAdapter) NewChainReader(_ context.Context, chainReaderConfig []byte) (types.ChainReader, error) {
return r.Relayer.NewChainReader(chainReaderConfig)
func (r *RelayerAdapter) NewContractReader(_ context.Context, contractReaderConfig []byte) (types.ChainReader, error) {
return r.Relayer.NewContractReader(contractReaderConfig)
}

func (r *RelayerAdapter) NewConfigProvider(ctx context.Context, rargs types.RelayArgs) (types.ConfigProvider, error) {
Expand Down
651 changes: 326 additions & 325 deletions pkg/loop/internal/pb/relayer.pb.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pkg/loop/internal/pb/relayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ message SignReply {
}

service Relayer {
rpc NewChainReader (NewChainReaderRequest) returns (NewChainReaderReply) {}
rpc NewContractReader (NewContractReaderRequest) returns (NewContractReaderReply) {}
rpc NewConfigProvider (NewConfigProviderRequest) returns (NewConfigProviderReply) {}
rpc NewPluginProvider (NewPluginProviderRequest) returns (NewPluginProviderReply) {}

Expand All @@ -65,14 +65,14 @@ message PluginArgs {
bytes pluginConfig = 2;
}

// NewChainReaderRequest has arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewChainReader].
message NewChainReaderRequest{
bytes chainReaderConfig = 1;
// NewContractReaderRequest has arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewContractReader].
message NewContractReaderRequest{
bytes contractReaderConfig = 1;
}

// NewChainReaderReply has return arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewChainReader].
message NewChainReaderReply{
uint32 chainReaderID = 1;
// NewContractReaderReply has return arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewContractReader].
message NewContractReaderReply{
uint32 contractReaderID = 1;
}

// NewPluginProviderRequest has arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewPluginProvider].
Expand Down
30 changes: 15 additions & 15 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.

Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,6 @@ func convertSequencesFromProto(pbSequences []*pb.Sequence, sequenceDataType any)
return sequences, nil
}

func RegisterChainReaderService(s *grpc.Server, chainReader types.ChainReader) {
pb.RegisterServiceServer(s, &goplugin.ServiceServer{Srv: chainReader})
func RegisterContractReaderService(s *grpc.Server, contractReader types.ChainReader) {
pb.RegisterServiceServer(s, &goplugin.ServiceServer{Srv: contractReader})
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
}
)

// staticChainReader is a static implementation of ChainReaderEvaluator
// staticChainReader is a static implementation of ChainReaderTester
type staticChainReader struct {
contractName string
contractMethod string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type staticMedianProviderConfig struct {
reportCodec staticReportCodec
medianContract staticMedianContract
onchainConfigCodec staticOnchainConfigCodec
chainReader testtypes.ChainReaderEvaluator
chainReader testtypes.ChainReaderTester
codec testtypes.CodecEvaluator
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type staticPluginProvider struct {
offchainConfigDigester staticOffchainConfigDigester
contractConfigTracker staticContractConfigTracker
contractTransmitter testtypes.ContractTransmitterEvaluator
chainReader testtypes.ChainReaderEvaluator
chainReader testtypes.ChainReaderTester
codec testtypes.CodecEvaluator
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/loop/internal/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ func newRelayerClient(b *net.BrokerExt, conn grpc.ClientConnInterface) *relayerC
return &relayerClient{b, goplugin.NewServiceClient(b, conn), pb.NewRelayerClient(conn)}
}

func (r *relayerClient) NewChainReader(_ context.Context, chainReaderConfig []byte) (types.ChainReader, error) {
cc := r.NewClientConn("ChainReader", func(ctx context.Context) (uint32, net.Resources, error) {
reply, err := r.relayer.NewChainReader(ctx, &pb.NewChainReaderRequest{ChainReaderConfig: chainReaderConfig})
func (r *relayerClient) NewContractReader(_ context.Context, contractReaderConfig []byte) (types.ChainReader, error) {
cc := r.NewClientConn("ContractReader", func(ctx context.Context) (uint32, net.Resources, error) {
reply, err := r.relayer.NewContractReader(ctx, &pb.NewContractReaderRequest{ContractReaderConfig: contractReaderConfig})
if err != nil {
return 0, nil, err
}
return reply.ChainReaderID, nil, nil
return reply.ContractReaderID, nil, nil
})

return chainreader.NewClient(r.WithName("ChainReaderClient"), cc), nil
Expand Down Expand Up @@ -331,8 +331,8 @@ func newChainRelayerServer(impl looptypes.Relayer, b *net.BrokerExt) *relayerSer
return &relayerServer{impl: impl, BrokerExt: b.WithName("ChainRelayerServer")}
}

func (r *relayerServer) NewChainReader(ctx context.Context, request *pb.NewChainReaderRequest) (*pb.NewChainReaderReply, error) {
cr, err := r.impl.NewChainReader(ctx, request.GetChainReaderConfig())
func (r *relayerServer) NewContractReader(ctx context.Context, request *pb.NewContractReaderRequest) (*pb.NewContractReaderReply, error) {
cr, err := r.impl.NewContractReader(ctx, request.GetContractReaderConfig())
if err != nil {
return nil, err
}
Expand All @@ -341,15 +341,15 @@ func (r *relayerServer) NewChainReader(ctx context.Context, request *pb.NewChain
return nil, err
}

const name = "ChainReader"
const name = "ContractReader"
id, _, err := r.ServeNew(name, func(s *grpc.Server) {
chainreader.RegisterChainReaderService(s, cr)
chainreader.RegisterContractReaderService(s, cr)
}, net.Resource{Closer: cr, Name: name})
if err != nil {
return nil, err
}

return &pb.NewChainReaderReply{ChainReaderID: id}, nil
return &pb.NewContractReaderReply{ContractReaderID: id}, nil
}

func (r *relayerServer) NewConfigProvider(ctx context.Context, request *pb.NewConfigProviderRequest) (*pb.NewConfigProviderReply, error) {
Expand Down
18 changes: 9 additions & 9 deletions pkg/loop/internal/relayer/test/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ type nodeResponse struct {
}
type staticPluginRelayerConfig struct {
StaticChecks bool
chainReaderConfig []byte
relayArgs types.RelayArgs
pluginArgs types.PluginArgs
contractReaderConfig []byte
medianProvider testtypes.MedianProviderTester
agnosticProvider testtypes.PluginProviderTester
mercuryProvider mercurytest.MercuryProviderTester
executionProvider cciptest.ExecProviderTester
commitProvider cciptest.CommitProviderTester
chainReader testtypes.ChainReaderEvaluator
configProvider ocr2test.ConfigProviderTester
ocr3CapabilityProvider testtypes.OCR3CapabilityProviderTester
contractReaderProvider testtypes.ChainReaderTester
// Note: add other Provider testers here when we implement them
// eg Functions, Automation, etc
nodeRequest nodeRequest
Expand All @@ -78,14 +78,14 @@ func NewRelayerTester(staticChecks bool) testtypes.RelayerTester {
StaticChecks: staticChecks,
relayArgs: RelayArgs,
pluginArgs: PluginArgs,
contractReaderConfig: []byte("test"),
medianProvider: mediantest.MedianProvider,
mercuryProvider: mercurytest.MercuryProvider,
executionProvider: cciptest.ExecutionProvider,
agnosticProvider: ocr2test.AgnosticProvider,
chainReaderConfig: []byte("test"),
chainReader: chainreadertest.ChainReader,
configProvider: ocr2test.ConfigProvider,
ocr3CapabilityProvider: ocr3capabilitytest.OCR3CapabilityProvider,
contractReaderProvider: chainreadertest.ChainReader,
nodeRequest: nodeRequest{
pageSize: 137,
pageToken: "",
Expand Down Expand Up @@ -135,11 +135,11 @@ func (s staticPluginRelayer) Name() string { panic("unimplemented") }

func (s staticPluginRelayer) HealthReport() map[string]error { panic("unimplemented") }

func (s staticPluginRelayer) NewChainReader(_ context.Context, chainReaderConfig []byte) (types.ChainReader, error) {
if s.StaticChecks && !(bytes.Equal(s.chainReaderConfig, chainReaderConfig)) {
return nil, fmt.Errorf("expected chainReaderConfig:\n\t%v\nbut got:\n\t%v", string(s.chainReaderConfig), string(chainReaderConfig))
func (s staticPluginRelayer) NewContractReader(_ context.Context, contractReaderConfig []byte) (types.ChainReader, error) {
if s.StaticChecks && !(bytes.Equal(s.contractReaderConfig, contractReaderConfig)) {
return nil, fmt.Errorf("expected contractReaderConfig:\n\t%v\nbut got:\n\t%v", string(s.contractReaderConfig), string(contractReaderConfig))
}
return s.chainReader, nil
return s.contractReaderProvider, nil
}

func (s staticPluginRelayer) NewConfigProvider(ctx context.Context, r types.RelayArgs) (types.ConfigProvider, error) {
Expand Down Expand Up @@ -266,7 +266,7 @@ func (s staticPluginRelayer) AssertEqual(_ context.Context, t *testing.T, relaye
t.Run("ChainReader", func(t *testing.T) {
t.Parallel()
ctx := tests.Context(t)
chainReader, err := relayer.NewChainReader(ctx, []byte("test"))
chainReader, err := relayer.NewContractReader(ctx, []byte("test"))
require.NoError(t, err)
require.NoError(t, chainReader.Start(ctx))

Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/internal/test/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type AssertEqualer[T any] interface {
AssertEqual(ctx context.Context, t *testing.T, other T)
}

// ChainReaderEvaluator is a helper interface for testing ChainReaders
type ChainReaderEvaluator interface {
// ChainReaderTester is a helper interface for testing ChainReaders
type ChainReaderTester interface {
types.ChainReader
Evaluator[types.ChainReader]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/loop/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type OCR3CapabilityProvider interface {
// Relayer is like types.Relayer, but with a dynamic NewPluginProvider method.
type Relayer interface {
types.ChainService
NewChainReader(ctx context.Context, chainReaderConfig []byte) (types.ChainReader, error)
NewContractReader(ctx context.Context, contractReaderConfig []byte) (types.ChainReader, error)
NewConfigProvider(context.Context, types.RelayArgs) (types.ConfigProvider, error)
NewPluginProvider(context.Context, types.RelayArgs, types.PluginArgs) (types.PluginProvider, error)
NewLLOProvider(context.Context, types.RelayArgs, types.PluginArgs) (types.LLOProvider, error)
Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/relayer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func NewRelayerService(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec.C
return &rs
}

func (r *RelayerService) NewChainReader(ctx context.Context, chainReaderConfig []byte) (types.ChainReader, error) {
func (r *RelayerService) NewContractReader(ctx context.Context, contractReaderConfig []byte) (types.ChainReader, error) {
if err := r.WaitCtx(ctx); err != nil {
return nil, err
}
return r.Service.NewChainReader(ctx, chainReaderConfig)
return r.Service.NewContractReader(ctx, contractReaderConfig)
}

func (r *RelayerService) NewConfigProvider(ctx context.Context, args types.RelayArgs) (types.ConfigProvider, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type ChainService interface {
// Deprecated: use loop.Relayer, which includes context.Context.
type Relayer interface {
Service
NewChainReader(chainReaderCfg []byte) (ChainReader, error)
NewContractReader(contractReaderConfig []byte) (ChainReader, error)
NewConfigProvider(rargs RelayArgs) (ConfigProvider, error)
NewMedianProvider(rargs RelayArgs, pargs PluginArgs) (MedianProvider, error)
NewMercuryProvider(rargs RelayArgs, pargs PluginArgs) (MercuryProvider, error)
Expand Down

0 comments on commit ab5ed86

Please sign in to comment.