Skip to content

Commit

Permalink
Creates a codec interface for encoding and decoding data to a chain. …
Browse files Browse the repository at this point in the history
…Implements the relay chain reader to use it and creates interface tests for the chain reader to be run by all implementations (#209)
  • Loading branch information
nolag authored Nov 2, 2023
1 parent 49ff074 commit 4dcbee3
Show file tree
Hide file tree
Showing 12 changed files with 1,307 additions and 152 deletions.
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ go 1.21

require (
github.com/confluentinc/confluent-kafka-go v1.9.2
github.com/fxamacker/cbor/v2 v2.5.0
github.com/google/uuid v1.3.1
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-plugin v1.5.2
github.com/jpillora/backoff v1.0.0
github.com/linkedin/goavro/v2 v2.12.0
github.com/mitchellh/mapstructure v1.5.0
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
Expand Down Expand Up @@ -40,6 +42,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
Expand All @@ -55,14 +58,15 @@ require (
github.com/prometheus/procfs v0.11.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.1.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
Expand All @@ -73,6 +77,9 @@ replace (
// until merged upstream: https://github.com/hashicorp/go-plugin/pull/257
github.com/hashicorp/go-plugin => github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306

// until merged upstream: https://github.com/mitchellh/mapstructure/pull/343
github.com/mitchellh/mapstructure v1.5.0 => github.com/nolag/mapstructure v1.5.1

// until merged upstream: https://github.com/mwitkow/grpc-proxy/pull/69
github.com/mwitkow/grpc-proxy => github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f
)
22 changes: 14 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHs
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE=
github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -143,8 +145,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -231,6 +233,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/nolag/mapstructure v1.5.1 h1:jEMB2AM8NXEosSMTPXlbycOpBsqttEBh5owT0gJs9/I=
github.com/nolag/mapstructure v1.5.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nrwiersma/avro-benchmarks v0.0.0-20210913175520-21aec48c8f76/go.mod h1:iKyFMidsk/sVYONJRE372sJuX/QTRPacU7imPqqsu7g=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down Expand Up @@ -284,6 +288,8 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -321,8 +327,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -388,8 +394,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -450,8 +456,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
168 changes: 152 additions & 16 deletions pkg/loop/internal/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"

"github.com/fxamacker/cbor/v2"
libocr "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"google.golang.org/grpc/status"

"github.com/smartcontractkit/chainlink-relay/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-relay/pkg/types"
Expand All @@ -19,44 +24,76 @@ type chainReaderClient struct {
// enum of all known encoding formats for versioned data
const (
SimpleJsonEncodingVersion = iota
CborEncodingVersion
)

// Version to be used for encoding ( version used for decoding is determined by data received )
// These are separate constants in case we want to upgrade their data formats independently
const ParamsCurrentEncodingVersion = SimpleJsonEncodingVersion
const RetvalCurrentEncodingVersion = SimpleJsonEncodingVersion
const ParamsCurrentEncodingVersion = CborEncodingVersion
const RetvalCurrentEncodingVersion = CborEncodingVersion

func encodeVersionedBytes(data any, version int32) (*pb.VersionedBytes, error) {
var jsonData []byte
var bytes []byte
var err error

switch version {
case SimpleJsonEncodingVersion:
jsonData, err = json.Marshal(data)
bytes, err = json.Marshal(data)
case CborEncodingVersion:
enco := cbor.CoreDetEncOptions()
enco.Time = cbor.TimeRFC3339Nano
var enc cbor.EncMode
enc, err = enco.EncMode()
if err != nil {
return nil, err
}
bytes, err = enc.Marshal(data)
default:
return nil, fmt.Errorf("unsupported encoding version %d for data %v", version, data)
}

return &pb.VersionedBytes{Version: SimpleJsonEncodingVersion, Data: jsonData}, nil
if err != nil {
return nil, types.InvalidTypeError{}
}
return &pb.VersionedBytes{Version: uint32(version), Data: bytes}, nil
}

func decodeVersionedBytes(res any, vData *pb.VersionedBytes) error {
var err error
switch vData.Version {
case SimpleJsonEncodingVersion:
err := json.Unmarshal(vData.Data, res)
if err != nil {
return err
}
err = json.Unmarshal(vData.Data, res)
case CborEncodingVersion:
err = cbor.Unmarshal(vData.Data, res)
default:
return fmt.Errorf("unsupported encoding version %d for versionedData %v", vData.Version, vData.Data)
}

if err != nil {
return types.InvalidTypeError{}
}
return nil
}

func isArray(vData *pb.VersionedBytes) (bool, error) {
data := vData.Data
if len(data) > 0 {
switch vData.Version {
case SimpleJsonEncodingVersion:
return data[0] == '[', nil
case CborEncodingVersion:

// Major type for array in CBOR is 4 which is 100 in binary.
// So, we are checking if the first 3 bits are 100.
return data[0]>>5 == 4, nil
default:
return false, fmt.Errorf("Unsupported encoding version %d for versionedData %v", vData.Version, vData.Data)
}
}

return false, nil
}

func (c *chainReaderClient) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, retVal any) error {
versionedParams, err := encodeVersionedBytes(params, ParamsCurrentEncodingVersion)
if err != nil {
Expand All @@ -67,12 +104,45 @@ func (c *chainReaderClient) GetLatestValue(ctx context.Context, bc types.BoundCo

reply, err := c.grpc.GetLatestValue(ctx, &pb.GetLatestValueRequest{Bc: &boundContract, Method: method, Params: versionedParams})
if err != nil {
return err
return unwrapClientError(err)
}

return decodeVersionedBytes(retVal, reply.RetVal)
}

func (c *chainReaderClient) Encode(ctx context.Context, item any, itemType string) (libocr.Report, error) {
versionedParams, err := encodeVersionedBytes(item, ParamsCurrentEncodingVersion)
if err != nil {
return nil, err
}

reply, err := c.grpc.GetEncoding(ctx, &pb.GetEncodingRequest{
Params: versionedParams,
ItemType: itemType,
})

if err != nil {
return nil, unwrapClientError(err)
}

return reply.RetVal, nil
}

func (c *chainReaderClient) Decode(ctx context.Context, raw []byte, into any, itemType string) error {
k := reflect.ValueOf(into).Kind()
request := &pb.GetDecodingRequest{
Encoded: raw,
ItemType: itemType,
ForceSplit: k == reflect.Array || k == reflect.Slice,
}
resp, err := c.grpc.GetDecoding(ctx, request)
if err != nil {
return unwrapClientError(err)
}

return decodeVersionedBytes(into, resp.RetVal)
}

var _ pb.ChainReaderServer = (*chainReaderServer)(nil)

type chainReaderServer struct {
Expand All @@ -86,24 +156,64 @@ func (c *chainReaderServer) GetLatestValue(ctx context.Context, request *pb.GetL
bc.Address = request.Bc.Address[:]
bc.Pending = request.Bc.Pending

var paramsMap map[string]any
err := decodeVersionedBytes(&paramsMap, request.Params)
params, err := c.getEncodedType(request.Method, false, true)
if err != nil {
return nil, err
}

var retVal map[string]any
err = c.impl.GetLatestValue(ctx, bc, request.Method, paramsMap, &retVal)
if err = decodeVersionedBytes(params, request.Params); err != nil {
return nil, err
}

retVal, err := c.getEncodedType(request.Method, false, false)
if err != nil {
return nil, err
}
err = c.impl.GetLatestValue(ctx, bc, request.Method, params, retVal)
if err != nil {
return nil, err
}

jsonRetVal, err := encodeVersionedBytes(&retVal, RetvalCurrentEncodingVersion)
encodedRetVal, err := encodeVersionedBytes(retVal, RetvalCurrentEncodingVersion)
if err != nil {
return nil, err
}

return &pb.GetLatestValueReply{RetVal: jsonRetVal}, nil
return &pb.GetLatestValueReply{RetVal: encodedRetVal}, nil
}

func (c *chainReaderServer) GetEncoding(ctx context.Context, req *pb.GetEncodingRequest) (*pb.GetEncodingResponse, error) {
forceArray, err := isArray(req.Params)
if err != nil {
return nil, err
}

encodedType, err := c.getEncodedType(req.ItemType, forceArray, true)
if err != nil {
return nil, err
}

if err = decodeVersionedBytes(encodedType, req.Params); err != nil {
return nil, err
}

encoded, err := c.impl.Encode(ctx, encodedType, req.ItemType)
return &pb.GetEncodingResponse{RetVal: encoded}, err
}

func (c *chainReaderServer) GetDecoding(ctx context.Context, req *pb.GetDecodingRequest) (*pb.GetDecodingResponse, error) {
encodedType, err := c.getEncodedType(req.ItemType, req.ForceSplit, false)
if err != nil {
return nil, err
}

err = c.impl.Decode(ctx, req.Encoded, encodedType, req.ItemType)
if err != nil {
return nil, err
}

versionBytes, err := encodeVersionedBytes(encodedType, RetvalCurrentEncodingVersion)
return &pb.GetDecodingResponse{RetVal: versionBytes}, err
}

func (c *chainReaderServer) RegisterEventFilter(ctx context.Context, in *pb.RegisterEventFilterRequest) (*pb.RegisterEventFilterReply, error) {
Expand All @@ -115,3 +225,29 @@ func (c *chainReaderServer) UnregisterEventFilter(ctx context.Context, in *pb.Un
func (c *chainReaderServer) QueryEvents(ctx context.Context, in *pb.QueryEventsRequest) (*pb.QueryEventsReply, error) {
return nil, nil
}

func (c *chainReaderServer) getEncodedType(itemType string, forceArray bool, forEncoding bool) (any, error) {
if rc, ok := c.impl.(types.RemoteCodec); ok {
return rc.CreateType(itemType, forceArray, forEncoding)
}

return &map[string]any{}, nil
}

func unwrapClientError(err error) error {
if s, ok := status.FromError(err); ok {
switch s.Message() {
case types.InvalidEncodingError{}.Error():
return types.InvalidEncodingError{}
case types.InvalidTypeError{}.Error():
return types.InvalidTypeError{}
case types.FieldNotFoundError{}.Error():
return types.FieldNotFoundError{}
case types.WrongNumberOfElements{}.Error():
return types.WrongNumberOfElements{}
case types.NotASliceError{}.Error():
return types.NotASliceError{}
}
}
return err
}
Loading

0 comments on commit 4dcbee3

Please sign in to comment.