Skip to content

Commit

Permalink
Fix signatures of GetLatestValue methods to match CLIP, re-run go gen…
Browse files Browse the repository at this point in the history
…erate
  • Loading branch information
reductionista committed Oct 24, 2023
1 parent 1561c36 commit 0e354da
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 209 deletions.
19 changes: 8 additions & 11 deletions pkg/loop/internal/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ type chainReaderClient struct {
grpc pb.ChainReaderClient
}

func (c *chainReaderClient) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, retValues any) ([]byte, error) {
func (c *chainReaderClient) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, retVal any) error {
boundContract := pb.BoundContract{Name: bc.Name, Address: bc.Address, Pending: bc.Pending}
jsonParams, err := json.Marshal(params)
if err != nil {
return nil, err
}
jsonRetValues, err := json.Marshal(retValues)
if err != nil {
return nil, err
return err
}

reply, err := c.grpc.GetLatestValue(ctx, &pb.GetLatestValueRequest{Bc: &boundContract, Method: method, Params: jsonParams, ReturnValues: jsonRetValues})
reply, err := c.grpc.GetLatestValue(ctx, &pb.GetLatestValueRequest{Bc: &boundContract, Method: method, Params: jsonParams})
if err != nil {
return nil, err
return err
}
return reply.RetValues, nil
return json.Unmarshal(reply.RetVal, &retVal)
}

var _ pb.ChainReaderServer = (*chainReaderServer)(nil)
Expand All @@ -45,11 +41,12 @@ func (c *chainReaderServer) GetLatestValue(ctx context.Context, request *pb.GetL
bc.Name = request.Bc.Name[:]
bc.Address = request.Bc.Address[:]
bc.Pending = request.Bc.Pending
retValues, err := c.impl.GetLatestValue(ctx, bc, request.Method, request.Params, request.ReturnValues)
var retVal []byte
err := c.impl.GetLatestValue(ctx, bc, request.Method, request.Params, &retVal)
if err != nil {
return nil, err
}
return &pb.GetLatestValueReply{RetValues: retValues}, nil
return &pb.GetLatestValueReply{RetVal: retVal}, nil
}

func (c *chainReaderServer) RegisterEventFilter(ctx context.Context, in *pb.RegisterEventFilterRequest) (*pb.RegisterEventFilterReply, error) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/loop/internal/pb/median.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/loop/internal/pb/median_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

331 changes: 165 additions & 166 deletions pkg/loop/internal/pb/relayer.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/loop/internal/pb/relayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ message GetLatestValueRequest {

// GetLatestValueReply has return arguments for [github.com/smartcontractkit/chainlink-relay/pkg/types.ChainReader.GetLatestValue].
message GetLatestValueReply {
bytes retValues = 1;
bytes retVal = 1;
}

// BoundContract represents a [github.com/smartcontractkit/chainlink-relay/pkg/types.BoundContract].
Expand Down
1 change: 0 additions & 1 deletion pkg/loop/internal/pb/relayer_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pkg/loop/internal/pb/reporting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/loop/internal/pb/reporting_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions pkg/loop/internal/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -93,26 +92,23 @@ func (s staticContractTransmitter) FromAccount() (libocr.Account, error) {

type staticChainReader struct{}

func (c staticChainReader) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, returnVal any) ([]byte, error) {
func (c staticChainReader) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, returnVal any) error {
if !assert.ObjectsAreEqual(bc, boundContract) {
return nil, fmt.Errorf("expected report context %v but got %v", boundContract, bc)
return fmt.Errorf("expected report context %v but got %v", boundContract, bc)
}
if method != medianContractGenericMethod {
return nil, fmt.Errorf("expected generic contract method %v but got %v", medianContractGenericMethod, method)
return fmt.Errorf("expected generic contract method %v but got %v", medianContractGenericMethod, method)
}
if !assert.ObjectsAreEqual(params, getLatestValueParams) {
return nil, fmt.Errorf("expected params %v but got %v", params, getLatestValueParams)
return fmt.Errorf("expected params %v but got %v", params, getLatestValueParams)
}

retStruct := struct {
returnVal = struct {
Epoch uint32
Round uint8
LatestAnswer *big.Int
LatestTimestamp time.Time
}{epoch, round, latestAnswer, latestTimestamp}
ret, err := json.Marshal(retStruct)
if err != nil {
return nil, fmt.Errorf("Failed constructing static return data from GetLatestValue")
}
return ret, nil

return nil
}
10 changes: 10 additions & 0 deletions pkg/loop/internal/test/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func TestReportingPluginFactory(t *testing.T, factory types.ReportingPluginFacto
type StaticPluginMedian struct{}

func (s StaticPluginMedian) NewMedianFactory(ctx context.Context, provider types.MedianProvider, dataSource, juelsPerFeeCoinDataSource median.DataSource, errorLog types.ErrorLog) (types.ReportingPluginFactory, error) {
cr := provider.ChainReader()
var gotTransmissionDetails LatestTransmissionDetails
err := cr.GetLatestValue(ctx, boundContract, "LatestTransmissionDetails", nil, gotTransmissionDetails)
if err != nil {
return nil, fmt.Errorf("failed to call GetLatestValue() on median provider: %w", err)
}
if gotTransmissionDetails != latestTransmissionDetails {
return nil, fmt.Errorf("expected LatestTransmissionDetails %v but got %v", gotTransmissionDetails, latestTransmissionDetails)
}

ocd := provider.OffchainConfigDigester()
gotDigestPrefix, err := ocd.ConfigDigestPrefix()
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions pkg/loop/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const ConfigTOML = `[Foo]
Bar = "Baz"
`

type LatestTransmissionDetails struct {
ConfigDigest libocr.ConfigDigest
Epoch uint32
Round uint8
Timestamp time.Time
}

const (
account = libocr.Account("testaccount")
balanceCheck = true
Expand All @@ -41,10 +48,11 @@ var (
ID: chainID,
Config: ConfigTOML,
}
chainID = "chain-id"
configDigest = libocr.ConfigDigest([32]byte{2: 10, 12: 16})
configDigestPrefix = libocr.ConfigDigestPrefix(99)
contractConfig = libocr.ContractConfig{
chainID = "chain-id"
configDigest = libocr.ConfigDigest([32]byte{2: 10, 12: 16})
configDigestPrefix = libocr.ConfigDigestPrefix(99)
latestTransmissionDetails = LatestTransmissionDetails{ConfigDigest: configDigest, Epoch: epoch, Round: round, Timestamp: time.Now()}
contractConfig = libocr.ContractConfig{
ConfigDigest: configDigest,
ConfigCount: 42,
Signers: []libocr.OnchainPublicKey{[]byte{15: 1}},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ChainReader interface {
// json.Marshal(). Typically would be either an anonymous map such as `map[string]any{"baz": 42, "test": true}}` or something which implements the `MarshalJSON()` method (satisfying `Marshaller` interface).
//
// returnVal should satisfy Marshaller interface.
GetLatestValue(ctx context.Context, bc BoundContract, method string, params, returnVal any) ([]byte, error)
GetLatestValue(ctx context.Context, bc BoundContract, method string, params, returnVal any) error
}

type BoundContract struct {
Expand Down

0 comments on commit 0e354da

Please sign in to comment.