From aa0908650128039136521923bac528a0de8b5b7b Mon Sep 17 00:00:00 2001 From: jmank88 Date: Thu, 25 May 2023 10:14:27 -0500 Subject: [PATCH] pkg/loop/internal: bump libocr and update affected areas --- go.mod | 2 +- go.sum | 4 ++-- pkg/loop/internal/config.go | 11 +++++++---- pkg/loop/internal/median.go | 12 ++++++++---- pkg/loop/internal/provider.go | 12 ++++++++---- pkg/loop/internal/test/config.go | 8 ++++---- pkg/loop/internal/test/median.go | 21 +++++++++++++++------ pkg/loop/internal/test/relayer.go | 12 ++++++++---- 8 files changed, 53 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 1a4f341dc..e5b501b7a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 38503e810..1a7260dd4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/loop/internal/config.go b/pkg/loop/internal/config.go index ce970ded1..1b2da02ca 100644 --- a/pkg/loop/internal/config.go +++ b/pkg/loop/internal/config.go @@ -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) @@ -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 } diff --git a/pkg/loop/internal/median.go b/pkg/loop/internal/median.go index 761473e8f..d820ec9d6 100644 --- a/pkg/loop/internal/median.go +++ b/pkg/loop/internal/median.go @@ -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) @@ -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) diff --git a/pkg/loop/internal/provider.go b/pkg/loop/internal/provider.go index d6214aa07..3183b0d34 100644 --- a/pkg/loop/internal/provider.go +++ b/pkg/loop/internal/provider.go @@ -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) @@ -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 } diff --git a/pkg/loop/internal/test/config.go b/pkg/loop/internal/test/config.go index 85d7cbc6a..ba53f368a 100644 --- a/pkg/loop/internal/test/config.go +++ b/pkg/loop/internal/test/config.go @@ -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{} @@ -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 } diff --git a/pkg/loop/internal/test/median.go b/pkg/loop/internal/test/median.go index 170e91f74..6cca70303 100644 --- a/pkg/loop/internal/test/median.go +++ b/pkg/loop/internal/test/median.go @@ -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) } @@ -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) } @@ -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) } @@ -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{} diff --git a/pkg/loop/internal/test/relayer.go b/pkg/loop/internal/test/relayer.go index 66b696071..3453de148 100644 --- a/pkg/loop/internal/test/relayer.go +++ b/pkg/loop/internal/test/relayer.go @@ -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) @@ -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) @@ -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) @@ -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) {