Skip to content

Commit

Permalink
bump libocr; update loop DataSource.Observe usages (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Apr 22, 2023
1 parent c66fa54 commit 5fee8d7
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 440 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/prometheus/client_golang v1.12.0
github.com/riferrei/srclient v0.5.4
github.com/satori/go.uuid v1.2.0
github.com/smartcontractkit/libocr v0.0.0-20220812191430-db92a9fdaa52
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc
github.com/stretchr/testify v1.7.5
go.uber.org/atomic v1.7.0
go.uber.org/goleak v1.1.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartcontractkit/libocr v0.0.0-20220812191430-db92a9fdaa52 h1:Nac1UCKJwt0AY15bAaorscflOcBs/FnmO7NoCh8Tons=
github.com/smartcontractkit/libocr v0.0.0-20220812191430-db92a9fdaa52/go.mod h1:5JnCHuYgmIP9ZyXzgAfI5Iwu0WxBtBKp+ApeT5o1Cjw=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc h1:aSCDAai0Dmbhp/KHTtJnC/EJcaEz4CAO80SKRzRZiQA=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc/go.mod h1:5JnCHuYgmIP9ZyXzgAfI5Iwu0WxBtBKp+ApeT5o1Cjw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
Expand Down
14 changes: 9 additions & 5 deletions pkg/loop/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"math/big"

"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

pb "github.com/smartcontractkit/chainlink-relay/pkg/loop/internal/pb"
)
Expand All @@ -22,8 +22,8 @@ func newDataSourceClient(cc *grpc.ClientConn) *dataSourceClient {
return &dataSourceClient{grpc: pb.NewDataSourceClient(cc)}
}

func (d *dataSourceClient) Observe(ctx context.Context) (*big.Int, error) {
reply, err := d.grpc.Observe(ctx, &emptypb.Empty{})
func (d *dataSourceClient) Observe(ctx context.Context, timestamp types.ReportTimestamp) (*big.Int, error) {
reply, err := d.grpc.Observe(ctx, &pb.ObserveRequest{ReportTimestamp: pbReportTimestamp(timestamp)})
if err != nil {
return nil, err
}
Expand All @@ -38,8 +38,12 @@ type dataSourceServer struct {
impl median.DataSource
}

func (d *dataSourceServer) Observe(ctx context.Context, _ *emptypb.Empty) (*pb.ObserveReply, error) {
val, err := d.impl.Observe(ctx)
func (d *dataSourceServer) Observe(ctx context.Context, request *pb.ObserveRequest) (*pb.ObserveReply, error) {
timestamp, err := reportTimestamp(request.ReportTimestamp)
if err != nil {
return nil, err
}
val, err := d.impl.Observe(ctx, timestamp)
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/loop/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package loop_test

import (
"context"
"fmt"
"math/big"

"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
)

var _ median.DataSource = (*staticDataSource)(nil)
Expand All @@ -13,6 +15,9 @@ type staticDataSource struct {
value *big.Int
}

func (s *staticDataSource) Observe(ctx context.Context) (*big.Int, error) {
func (s *staticDataSource) Observe(ctx context.Context, timestamp types.ReportTimestamp) (*big.Int, error) {
if timestamp != reportContext.ReportTimestamp {
return nil, fmt.Errorf("expected %v but got %v", reportContext.ReportTimestamp, timestamp)
}
return s.value, nil
}
Loading

0 comments on commit 5fee8d7

Please sign in to comment.