Skip to content

Commit aed5895

Browse files
committed
WIP: libocr uses any for ReportingPluginFactory's type.
Since we want to use protobuf in between (because of loopps) and protobuf doesn't support generic types, let's use a type constraint so that it can be marshalled to and from []byte.
1 parent 7713941 commit aed5895

File tree

1 file changed

+40
-13
lines changed
  • pkg/loop/internal/core/services/reportingplugin/ocr3

1 file changed

+40
-13
lines changed

pkg/loop/internal/core/services/reportingplugin/ocr3/reporting.go

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package ocr3
22

33
import (
44
"context"
5+
"encoding"
6+
"fmt"
57
"math"
68
"time"
79

@@ -12,10 +14,10 @@ import (
1214
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
1315
libocr "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
1416

15-
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/goplugin"
16-
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/net"
17-
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
18-
ocr3 "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb/ocr3"
17+
"github.com/smartcontractkit/tmp-sm-plugin-loopp/v2/internal/goplugin"
18+
"github.com/smartcontractkit/tmp-sm-plugin-loopp/v2/internal/net"
19+
"github.com/smartcontractkit/tmp-sm-plugin-loopp/v2/internal/pb"
20+
ocr3 "github.com/smartcontractkit/tmp-sm-plugin-loopp/v2/internal/pb/ocr3"
1921
)
2022

2123
type reportingPluginFactoryClient struct {
@@ -65,15 +67,23 @@ func (r *reportingPluginFactoryClient) NewReportingPlugin(ctx context.Context, c
6567

6668
var _ ocr3.ReportingPluginFactoryServer = (*reportingPluginFactoryServer)(nil)
6769

70+
// var _ encoding.BinaryMarshaler = (BinaryRI)(nil)
71+
// var _ encoding.BinaryUnmarshaler = (BinaryRI)(nil)
72+
73+
type BinaryRI interface {
74+
encoding.BinaryMarshaler
75+
encoding.BinaryUnmarshaler
76+
}
77+
6878
type reportingPluginFactoryServer struct {
6979
ocr3.UnimplementedReportingPluginFactoryServer
7080

7181
*net.BrokerExt
7282

73-
impl ocr3types.ReportingPluginFactory[[]byte]
83+
impl ocr3types.ReportingPluginFactory[BinaryRI]
7484
}
7585

76-
func NewReportingPluginFactoryServer(impl ocr3types.ReportingPluginFactory[[]byte], b *net.BrokerExt) *reportingPluginFactoryServer {
86+
func NewReportingPluginFactoryServer(impl ocr3types.ReportingPluginFactory[BinaryRI], b *net.BrokerExt) *reportingPluginFactoryServer {
7787
return &reportingPluginFactoryServer{impl: impl, BrokerExt: b.WithName("OCR3ReportingPluginFactoryServer")}
7888
}
7989

@@ -233,7 +243,7 @@ var _ ocr3.ReportingPluginServer = (*reportingPluginServer)(nil)
233243
type reportingPluginServer struct {
234244
ocr3.UnimplementedReportingPluginServer
235245

236-
impl ocr3types.ReportingPlugin[[]byte]
246+
impl ocr3types.ReportingPlugin[BinaryRI]
237247
}
238248

239249
func (o *reportingPluginServer) Query(ctx context.Context, request *ocr3.QueryRequest) (*ocr3.QueryReply, error) {
@@ -299,9 +309,15 @@ func (o *reportingPluginServer) Reports(ctx context.Context, request *ocr3.Repor
299309
}
300310

301311
func (o *reportingPluginServer) ShouldAcceptAttestedReport(ctx context.Context, request *ocr3.ShouldAcceptAttestedReportRequest) (*ocr3.ShouldAcceptAttestedReportReply, error) {
302-
sa, err := o.impl.ShouldAcceptAttestedReport(ctx, request.SegNr, ocr3types.ReportWithInfo[[]byte]{
312+
var b BinaryRI
313+
err := b.UnmarshalBinary(request.Ri.Info)
314+
if err != nil {
315+
return nil, err
316+
}
317+
318+
sa, err := o.impl.ShouldAcceptAttestedReport(ctx, request.SegNr, ocr3types.ReportWithInfo[BinaryRI]{
303319
Report: request.Ri.Report,
304-
Info: request.Ri.Info,
320+
Info: b,
305321
})
306322
if err != nil {
307323
return nil, err
@@ -312,13 +328,20 @@ func (o *reportingPluginServer) ShouldAcceptAttestedReport(ctx context.Context,
312328
}
313329

314330
func (o *reportingPluginServer) ShouldTransmitAcceptedReport(ctx context.Context, request *ocr3.ShouldTransmitAcceptedReportRequest) (*ocr3.ShouldTransmitAcceptedReportReply, error) {
315-
st, err := o.impl.ShouldTransmitAcceptedReport(ctx, request.SegNr, ocr3types.ReportWithInfo[[]byte]{
331+
var b BinaryRI
332+
err := b.UnmarshalBinary(request.Ri.Info)
333+
if err != nil {
334+
return nil, err
335+
}
336+
337+
st, err := o.impl.ShouldTransmitAcceptedReport(ctx, request.SegNr, ocr3types.ReportWithInfo[BinaryRI]{
316338
Report: request.Ri.Report,
317-
Info: request.Ri.Info,
339+
Info: b,
318340
})
319341
if err != nil {
320342
return nil, err
321343
}
344+
322345
return &ocr3.ShouldTransmitAcceptedReportReply{
323346
ShouldTransmit: st,
324347
}, nil
@@ -344,12 +367,16 @@ func pbAttributedObservation(ao libocr.AttributedObservation) *ocr3.AttributedOb
344367
}
345368
}
346369

347-
func pbReportsPlus(rwi []ocr3types.ReportPlus[[]byte]) (ri []*ocr3.ReportPlus) {
370+
func pbReportsPlus(rwi []ocr3types.ReportPlus[BinaryRI]) (ri []*ocr3.ReportPlus) {
348371
for _, r := range rwi {
372+
info, err := r.ReportWithInfo.Info.MarshalBinary()
373+
if err != nil {
374+
panic(fmt.Sprintf("can't marshal %v to bytes: %v", r.ReportWithInfo.Info, err))
375+
}
349376
ri = append(ri, &ocr3.ReportPlus{
350377
ReportWithInfo: &ocr3.ReportWithInfo{
351378
Report: r.ReportWithInfo.Report,
352-
Info: r.ReportWithInfo.Info,
379+
Info: info,
353380
},
354381
TransmissionScheduleOverride: pbTransmissionSchedule(r.TransmissionScheduleOverride),
355382
})

0 commit comments

Comments
 (0)