Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/loop/internal: bump libocr and update affected areas #115

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.0
github.com/riferrei/srclient v0.5.4
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc
github.com/smartcontractkit/libocr v0.0.0-20230525150148-a75f6e244bb3
github.com/stretchr/testify v1.8.2
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
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/santhosh-tekuri/jsonschema/v5 v5.1.1/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H
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-20230413082317-9561d14087cc h1:aSCDAai0Dmbhp/KHTtJnC/EJcaEz4CAO80SKRzRZiQA=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc/go.mod h1:5JnCHuYgmIP9ZyXzgAfI5Iwu0WxBtBKp+ApeT5o1Cjw=
github.com/smartcontractkit/libocr v0.0.0-20230525150148-a75f6e244bb3 h1:/Gel/U5eIZ/BGGr25OrHaXiVDTAJ5DYX5+UlXp3q7Gg=
github.com/smartcontractkit/libocr v0.0.0-20230525150148-a75f6e244bb3/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/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
11 changes: 7 additions & 4 deletions pkg/loop/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func (o *offchainConfigDigesterClient) ConfigDigest(config libocr.ContractConfig
return
}

func (o *offchainConfigDigesterClient) ConfigDigestPrefix() libocr.ConfigDigestPrefix {
func (o *offchainConfigDigesterClient) ConfigDigestPrefix() (libocr.ConfigDigestPrefix, error) {
ctx, cancel := o.ctx()
defer cancel()

reply, err := o.grpc.ConfigDigestPrefix(ctx, &pb.ConfigDigestPrefixRequest{})
if err != nil {
panic(err) //TODO only during shutdown https://smartcontract-it.atlassian.net/browse/BCF-2234
return 0, err
}
return libocr.ConfigDigestPrefix(reply.ConfigDigestPrefix)
return libocr.ConfigDigestPrefix(reply.ConfigDigestPrefix), nil
}

var _ pb.OffchainConfigDigesterServer = (*offchainConfigDigesterServer)(nil)
Expand Down Expand Up @@ -105,7 +105,10 @@ func (o *offchainConfigDigesterServer) ConfigDigest(ctx context.Context, request
}

func (o *offchainConfigDigesterServer) ConfigDigestPrefix(ctx context.Context, request *pb.ConfigDigestPrefixRequest) (*pb.ConfigDigestPrefixReply, error) {
p := o.impl.ConfigDigestPrefix()
p, err := o.impl.ConfigDigestPrefix()
if err != nil {
return nil, err
}
return &pb.ConfigDigestPrefixReply{ConfigDigestPrefix: uint32(p)}, nil
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/loop/internal/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ func (r *reportCodecClient) MedianFromReport(report libocr.Report) (*big.Int, er
return reply.Median.Int(), nil
}

func (r *reportCodecClient) MaxReportLength(n int) int {
func (r *reportCodecClient) MaxReportLength(n int) (int, error) {
ctx, cancel := r.ctx()
defer cancel()

reply, err := r.grpc.MaxReportLength(ctx, &pb.MaxReportLengthRequest{N: int64(n)})
if err != nil {
panic(err) //TODO only during shutdown https://smartcontract-it.atlassian.net/browse/BCF-2234
return -1, err
}
return int(reply.Max)
return int(reply.Max), nil
}

var _ pb.ReportCodecServer = (*reportCodecServer)(nil)
Expand Down Expand Up @@ -285,7 +285,11 @@ func (r *reportCodecServer) MedianFromReport(ctx context.Context, request *pb.Me
}

func (r *reportCodecServer) MaxReportLength(ctx context.Context, request *pb.MaxReportLengthRequest) (*pb.MaxReportLengthReply, error) {
return &pb.MaxReportLengthReply{Max: int64(r.impl.MaxReportLength(int(request.N)))}, nil
l, err := r.impl.MaxReportLength(int(request.N))
if err != nil {
return nil, err
}
return &pb.MaxReportLengthReply{Max: int64(l)}, nil
}

var _ median.MedianContract = (*medianContractClient)(nil)
Expand Down
12 changes: 8 additions & 4 deletions pkg/loop/internal/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func (c *contractTransmitterClient) LatestConfigDigestAndEpoch(ctx context.Conte
return
}

func (c *contractTransmitterClient) FromAccount() libocr.Account {
func (c *contractTransmitterClient) FromAccount() (libocr.Account, error) {
ctx, cancel := c.ctx()
defer cancel()

reply, err := c.grpc.FromAccount(ctx, &pb.FromAccountRequest{})
if err != nil {
panic(err) //TODO only during shutdown https://smartcontract-it.atlassian.net/browse/BCF-2234
return "", err
}
return libocr.Account(reply.Account)
return libocr.Account(reply.Account), nil
}

var _ pb.ContractTransmitterServer = (*contractTransmitterServer)(nil)
Expand Down Expand Up @@ -114,5 +114,9 @@ func (c *contractTransmitterServer) LatestConfigDigestAndEpoch(ctx context.Conte
}

func (c *contractTransmitterServer) FromAccount(ctx context.Context, request *pb.FromAccountRequest) (*pb.FromAccountReply, error) {
return &pb.FromAccountReply{Account: string(c.impl.FromAccount())}, nil
a, err := c.impl.FromAccount()
if err != nil {
return nil, err
}
return &pb.FromAccountReply{Account: string(a)}, nil
}
8 changes: 4 additions & 4 deletions pkg/loop/internal/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (s staticOffchainConfigDigester) ConfigDigest(config libocr.ContractConfig)
return configDigest, nil
}

func (s staticOffchainConfigDigester) ConfigDigestPrefix() libocr.ConfigDigestPrefix {
return configDigestPrefix
func (s staticOffchainConfigDigester) ConfigDigestPrefix() (libocr.ConfigDigestPrefix, error) {
return configDigestPrefix, nil
}

type staticContractConfigTracker struct{}
Expand Down Expand Up @@ -82,6 +82,6 @@ func (s staticContractTransmitter) LatestConfigDigestAndEpoch(ctx context.Contex
return configDigest, epoch, nil
}

func (s staticContractTransmitter) FromAccount() libocr.Account {
return account
func (s staticContractTransmitter) FromAccount() (libocr.Account, error) {
return account, nil
}
21 changes: 15 additions & 6 deletions pkg/loop/internal/test/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ type StaticPluginMedian struct{}

func (s StaticPluginMedian) NewMedianFactory(ctx context.Context, provider types.MedianProvider, dataSource, juelsPerFeeCoinDataSource median.DataSource, errorLog internal.ErrorLog) (internal.ReportingPluginFactory, error) {
ocd := provider.OffchainConfigDigester()
gotDigestPrefix := ocd.ConfigDigestPrefix()
gotDigestPrefix, err := ocd.ConfigDigestPrefix()
if err != nil {
return nil, fmt.Errorf("failed to get ConfigDigestPrefix: %w", err)
}
if gotDigestPrefix != configDigestPrefix {
return nil, fmt.Errorf("expected ConfigDigestPrefix %x but got %x", configDigestPrefix, gotDigestPrefix)
}
Expand Down Expand Up @@ -101,7 +104,10 @@ func (s StaticPluginMedian) NewMedianFactory(ctx context.Context, provider types
return nil, fmt.Errorf("expected ContractConfig %v but got %v", contractConfig, gotContractConfig)
}
ct := provider.ContractTransmitter()
gotAccount := ct.FromAccount()
gotAccount, err := ct.FromAccount()
if err != nil {
return nil, fmt.Errorf("failed to get FromAccount: %w", err)
}
if gotAccount != account {
return nil, fmt.Errorf("expectd FromAccount %s but got %s", account, gotAccount)
}
Expand Down Expand Up @@ -134,7 +140,10 @@ func (s StaticPluginMedian) NewMedianFactory(ctx context.Context, provider types
if medianValue.Cmp(gotMedianValue) != 0 {
return nil, fmt.Errorf("expected MedianValue %s but got %s", medianValue, gotMedianValue)
}
gotMax := rc.MaxReportLength(n)
gotMax, err := rc.MaxReportLength(n)
if err != nil {
return nil, fmt.Errorf("failed to get MaxReportLength: %w", err)
}
if gotMax != max {
return nil, fmt.Errorf("expected MaxReportLength %d but got %d", max, gotMax)
}
Expand Down Expand Up @@ -306,11 +315,11 @@ func (s staticReportCodec) MedianFromReport(r libocr.Report) (*big.Int, error) {
return medianValue, nil
}

func (s staticReportCodec) MaxReportLength(n2 int) int {
func (s staticReportCodec) MaxReportLength(n2 int) (int, error) {
if n != n2 {
panic(fmt.Errorf("expected n %d but got %d", n, n2))
return -1, fmt.Errorf("expected n %d but got %d", n, n2)
}
return max
return max, nil
}

type staticMedianContract struct{}
Expand Down
12 changes: 8 additions & 4 deletions pkg/loop/internal/test/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func TestRelayer(t *testing.T, relayer internal.Relayer) {
t.Run("OffchainConfigDigester", func(t *testing.T) {
t.Parallel()
ocd := configProvider.OffchainConfigDigester()
gotConfigDigestPrefix := ocd.ConfigDigestPrefix()
gotConfigDigestPrefix, err := ocd.ConfigDigestPrefix()
require.NoError(t, err)
assert.Equal(t, configDigestPrefix, gotConfigDigestPrefix)
gotConfigDigest, err := ocd.ConfigDigest(contractConfig)
require.NoError(t, err)
Expand Down Expand Up @@ -207,7 +208,8 @@ func TestRelayer(t *testing.T, relayer internal.Relayer) {
t.Run("OffchainConfigDigester", func(t *testing.T) {
t.Parallel()
ocd := provider.OffchainConfigDigester()
gotConfigDigestPrefix := ocd.ConfigDigestPrefix()
gotConfigDigestPrefix, err := ocd.ConfigDigestPrefix()
require.NoError(t, err)
assert.Equal(t, configDigestPrefix, gotConfigDigestPrefix)
gotConfigDigest, err := ocd.ConfigDigest(contractConfig)
require.NoError(t, err)
Expand All @@ -230,7 +232,8 @@ func TestRelayer(t *testing.T, relayer internal.Relayer) {
t.Run("ContractTransmitter", func(t *testing.T) {
t.Parallel()
ct := provider.ContractTransmitter()
gotAccount := ct.FromAccount()
gotAccount, err := ct.FromAccount()
require.NoError(t, err)
assert.Equal(t, account, gotAccount)
gotConfigDigest, gotEpoch, err := ct.LatestConfigDigestAndEpoch(ctx)
require.NoError(t, err)
Expand All @@ -248,7 +251,8 @@ func TestRelayer(t *testing.T, relayer internal.Relayer) {
gotMedianValue, err := rc.MedianFromReport(report)
require.NoError(t, err)
assert.Equal(t, medianValue, gotMedianValue)
gotMax := rc.MaxReportLength(n)
gotMax, err := rc.MaxReportLength(n)
require.NoError(t, err)
assert.Equal(t, max, gotMax)
})
t.Run("MedianContract", func(t *testing.T) {
Expand Down