Skip to content

Commit ea004c7

Browse files
committed
Add more comments and move adapters around + rename
1 parent a754fb9 commit ea004c7

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

pkg/loop/internal/reportingplugin/securemint/pb_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
1515
)
1616

17-
var _ core.PluginSecureMint = (*PluginSecureMintClient)(nil)
18-
1917
// PluginSecureMintClient is a client that runs on the core node to connect to the SecureMint LOOP server.
2018
type PluginSecureMintClient struct {
2119
// hashicorp plugin client
@@ -26,6 +24,8 @@ type PluginSecureMintClient struct {
2624
reportingPluginService pb.ReportingPluginServiceClient
2725
}
2826

27+
var _ core.PluginSecureMint = (*PluginSecureMintClient)(nil)
28+
2929
func NewPluginSecureMintClient(brokerCfg net.BrokerConfig) *PluginSecureMintClient {
3030
brokerCfg.Logger = logger.Named(brokerCfg.Logger, "PluginSecureMintClient")
3131
pc := goplugin.NewPluginClient(brokerCfg)
@@ -72,7 +72,7 @@ func (c *PluginSecureMintClient) NewSecureMintFactory(
7272
return reply.ID, deps, nil
7373
})
7474

75-
return &ocr3ReportingPluginFactoryAdapter{
75+
return &ocr3ReportingPluginFactoryBytesToChainSelectorAdapter{
7676
ocr3.NewReportingPluginFactoryClient(c.BrokerExt, cc), // protobuf client
7777
}, nil
7878
}

pkg/loop/internal/reportingplugin/securemint/pb_server.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ import (
1111
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
1212
ocr3pb "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb/ocr3"
1313
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
14-
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
1514
)
1615

17-
var _ pb.ReportingPluginServiceServer = (*pluginSecureMintServer)(nil)
18-
16+
// pluginSecureMintServer is the protobuf server that runs on the loopp plugin side to handle requests from the core node.
1917
type pluginSecureMintServer struct {
2018
pb.UnimplementedReportingPluginServiceServer
2119

2220
*net.BrokerExt
2321
impl core.PluginSecureMint
2422
}
2523

24+
var _ pb.ReportingPluginServiceServer = (*pluginSecureMintServer)(nil)
25+
26+
// NewValidationService is not implemented for the secure mint plugin.
2627
func (m *pluginSecureMintServer) NewValidationService(ctx context.Context, request *pb.ValidationServiceRequest) (*pb.ValidationServiceResponse, error) {
2728
m.Logger.Infof("NewValidationService called, not implemented")
2829
return &pb.ValidationServiceResponse{}, nil
2930
}
3031

32+
// NewReportingPluginFactory is called by the core node to create a new reporting plugin factory.
33+
// It delegates to the NewSecureMintFactory function in the plugin implementation.
3134
func (m *pluginSecureMintServer) NewReportingPluginFactory(ctx context.Context, request *pb.NewReportingPluginFactoryRequest) (*pb.NewReportingPluginFactoryReply, error) {
3235
m.Logger.Infof("NewReportingPluginFactory called, delegating to impl.NewSecureMintFactory")
3336

@@ -55,6 +58,7 @@ func (m *pluginSecureMintServer) NewReportingPluginFactory(ctx context.Context,
5558
return &pb.NewReportingPluginFactoryReply{ID: id}, nil
5659
}
5760

61+
// RegisterPluginSecureMintServer registers the plugin server with the given broker and broker config so that it can be called by the protobuf client.
5862
func RegisterPluginSecureMintServer(server *grpc.Server, broker net.Broker, brokerCfg net.BrokerConfig, impl core.PluginSecureMint) error {
5963
pb.RegisterServiceServer(server, &goplugin.ServiceServer{Srv: impl})
6064
pb.RegisterReportingPluginServiceServer(server, newPluginSecureMintServer(&net.BrokerExt{Broker: broker, BrokerConfig: brokerCfg}, impl))
@@ -64,18 +68,3 @@ func RegisterPluginSecureMintServer(server *grpc.Server, broker net.Broker, brok
6468
func newPluginSecureMintServer(b *net.BrokerExt, gp core.PluginSecureMint) *pluginSecureMintServer {
6569
return &pluginSecureMintServer{BrokerExt: b.WithName("PluginSecureMintServer"), impl: gp}
6670
}
67-
68-
var _ ocr3types.ReportingPluginFactory[[]byte] = (*reportingPluginFactoryChainSelectorToBytesAdapter)(nil)
69-
70-
// reportingPluginFactoryChainSelectorToBytesAdapter is a wrapper around the ReportingPluginFactory to implement ocr3types.ReportingPluginFactory[[]byte]
71-
type reportingPluginFactoryChainSelectorToBytesAdapter struct {
72-
ocr3types.ReportingPluginFactory[core.ChainSelector]
73-
}
74-
75-
func (r *reportingPluginFactoryChainSelectorToBytesAdapter) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[[]byte], ocr3types.ReportingPluginInfo, error) {
76-
plugin, info, err := r.ReportingPluginFactory.NewReportingPlugin(ctx, config)
77-
if err != nil {
78-
return nil, ocr3types.ReportingPluginInfo{}, err
79-
}
80-
return &reportingPluginChainSelectorToBytesAdapter{plugin: plugin}, info, nil
81-
}

pkg/loop/internal/reportingplugin/securemint/reportingplugin_adapter.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
1111
)
1212

13-
// ocr3ReportingPluginFactoryAdapter wraps a core.OCR3ReportingPluginFactory to implement ReportingPluginFactory[core.ChainSelector]
14-
type ocr3ReportingPluginFactoryAdapter struct {
13+
// ocr3ReportingPluginFactoryBytesToChainSelectorAdapter wraps a core.OCR3ReportingPluginFactory to implement ReportingPluginFactory[core.ChainSelector]
14+
type ocr3ReportingPluginFactoryBytesToChainSelectorAdapter struct {
1515
core.OCR3ReportingPluginFactory
1616
}
1717

18-
func (a *ocr3ReportingPluginFactoryAdapter) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[core.ChainSelector], ocr3types.ReportingPluginInfo, error) {
19-
// The core.OCR3ReportingPluginFactory works with []byte, but we need to return core.ChainSelector
20-
// We'll need to convert between the types here
18+
var _ ocr3types.ReportingPluginFactory[core.ChainSelector] = (*ocr3ReportingPluginFactoryBytesToChainSelectorAdapter)(nil)
19+
20+
func (a *ocr3ReportingPluginFactoryBytesToChainSelectorAdapter) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[core.ChainSelector], ocr3types.ReportingPluginInfo, error) {
2121
plugin, info, err := a.OCR3ReportingPluginFactory.NewReportingPlugin(ctx, config)
2222
if err != nil {
2323
return nil, ocr3types.ReportingPluginInfo{}, err
@@ -33,6 +33,8 @@ type reportingPluginBytesToChainSelectorAdapter struct {
3333
plugin ocr3types.ReportingPlugin[[]byte]
3434
}
3535

36+
var _ ocr3types.ReportingPlugin[core.ChainSelector] = (*reportingPluginBytesToChainSelectorAdapter)(nil)
37+
3638
func (r *reportingPluginBytesToChainSelectorAdapter) Query(ctx context.Context, outctx ocr3types.OutcomeContext) (types.Query, error) {
3739
return r.plugin.Query(ctx, outctx)
3840
}
@@ -113,11 +115,28 @@ func (r *reportingPluginBytesToChainSelectorAdapter) Close() error {
113115
return r.plugin.Close()
114116
}
115117

118+
// reportingPluginFactoryChainSelectorToBytesAdapter wraps a ReportingPluginFactory[core.ChainSelector] to implement ocr3types.ReportingPluginFactory[[]byte]
119+
type reportingPluginFactoryChainSelectorToBytesAdapter struct {
120+
ocr3types.ReportingPluginFactory[core.ChainSelector]
121+
}
122+
123+
var _ ocr3types.ReportingPluginFactory[[]byte] = (*reportingPluginFactoryChainSelectorToBytesAdapter)(nil)
124+
125+
func (r *reportingPluginFactoryChainSelectorToBytesAdapter) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[[]byte], ocr3types.ReportingPluginInfo, error) {
126+
plugin, info, err := r.ReportingPluginFactory.NewReportingPlugin(ctx, config)
127+
if err != nil {
128+
return nil, ocr3types.ReportingPluginInfo{}, err
129+
}
130+
return &reportingPluginChainSelectorToBytesAdapter{plugin: plugin}, info, nil
131+
}
132+
116133
// reportingPluginChainSelectorToBytesAdapter wraps a ReportingPlugin[core.ChainSelector] to implement ReportingPlugin[[]byte]
117134
type reportingPluginChainSelectorToBytesAdapter struct {
118135
plugin ocr3types.ReportingPlugin[core.ChainSelector]
119136
}
120137

138+
var _ ocr3types.ReportingPlugin[[]byte] = (*reportingPluginChainSelectorToBytesAdapter)(nil)
139+
121140
func (r *reportingPluginChainSelectorToBytesAdapter) Query(ctx context.Context, outctx ocr3types.OutcomeContext) (types.Query, error) {
122141
return r.plugin.Query(ctx, outctx)
123142
}

pkg/loop/internal/reportingplugin/securemint/reportingplugin_adapter_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
1515
)
1616

17-
// TODO(gg): add other unit tests where possible
18-
1917
func TestReportingPluginBytesToChainSelectorAdapter_Reports(t *testing.T) {
2018
tests := []struct {
2119
name string

0 commit comments

Comments
 (0)