Skip to content

Commit

Permalink
add context
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Mar 10, 2024
1 parent 01a2395 commit 4a392ac
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 84 deletions.
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.21

toolchain go1.21.1

replace github.com/smartcontractkit/libocr => github.com/jmank88/libocr v0.0.0-20240310194736-d3f510b9f9e2

require (
cosmossdk.io/errors v1.0.0
github.com/CosmWasm/wasmd v0.40.1
Expand All @@ -18,7 +20,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.16.0
Expand Down Expand Up @@ -107,11 +109,11 @@ require (
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o
github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU=
github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
Expand All @@ -493,6 +493,8 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/jmank88/libocr v0.0.0-20240310194736-d3f510b9f9e2 h1:WqwrEnVkaDWldq2ljN6ytKbQtdEmoO4gdoqspyZxXlo=
github.com/jmank88/libocr v0.0.0-20240310194736-d3f510b9f9e2/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
Expand Down Expand Up @@ -687,14 +689,12 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4 h1:Yk0RK9WV59ISOZZMsdtxZBAKaBfdgb05oXyca/qSqcw=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4/go.mod h1:pRlQrvcizMmuHAUV4N96oO2e3XbA99JCQELLc6ES160=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f h1:1et8C/1Ze/w02VJs7zHpY4XIJ9DD4ihsQFmPyVQMjMc=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f/go.mod h1:ftihcSXX2W0CPHEb0p70BRbZbIjgI0D25bkInYFgcEA=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 h1:3y9WsXkZ5lxFrmfH7DQHs/q308lylKId5l/3VC0QAdM=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/uuid v1.4.0
github.com/lib/pq v1.10.9
github.com/rs/zerolog v1.30.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231222201016-da3f0a763f71
github.com/smartcontractkit/chainlink-cosmos/ops v0.0.0-20231206164210-03f8b219402e
github.com/smartcontractkit/chainlink-testing-framework v1.22.6
Expand Down Expand Up @@ -166,10 +166,10 @@ require (
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU=
github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo=
github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw=
Expand Down Expand Up @@ -1174,8 +1174,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 h1:xkejUBZhcBpBrTSfxc91Iwzadrb6SXw8ks69bHIQ9Ww=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429/go.mod h1:wJmVvDf4XSjsahWtfUq3wvIAYEAuhr7oxmxYnEL/LGQ=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4 h1:Yk0RK9WV59ISOZZMsdtxZBAKaBfdgb05oXyca/qSqcw=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240213113935-001c2f4befd4/go.mod h1:pRlQrvcizMmuHAUV4N96oO2e3XbA99JCQELLc6ES160=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f h1:1et8C/1Ze/w02VJs7zHpY4XIJ9DD4ihsQFmPyVQMjMc=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240310203442-c2f41d4f438f/go.mod h1:ftihcSXX2W0CPHEb0p70BRbZbIjgI0D25bkInYFgcEA=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1/go.mod h1:GuPvyXryvbiUZIHmPeLBz4L+yJKeyGUjrDfd1KNne+o=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240119021347-3c541a78cdb8 h1:1BcjXuviSAKttOX7BZoVHRZZGfxqoA2+AL8tykmkdoc=
Expand Down
7 changes: 4 additions & 3 deletions pkg/cosmos/adapters/cosmwasm/config_digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cosmwasm

import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -29,7 +30,7 @@ func NewOffchainConfigDigester(chainID string, contract cosmosSDK.AccAddress) Of
}
}

func (cd OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.ConfigDigest, error) {
func (cd OffchainConfigDigester) ConfigDigest(ctx context.Context, cfg types.ContractConfig) (types.ConfigDigest, error) {
digest := types.ConfigDigest{}
buf := bytes.NewBuffer([]byte{})

Expand Down Expand Up @@ -103,7 +104,7 @@ func (cd OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.C
return digest, fmt.Errorf("incorrect hash size %d, expected %d", n, len(digest))
}

pre, err := cd.ConfigDigestPrefix()
pre, err := cd.ConfigDigestPrefix(ctx)
if err != nil {
return digest, err
}
Expand All @@ -115,6 +116,6 @@ func (cd OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.C
}

// This should return the same constant value on every invocation
func (OffchainConfigDigester) ConfigDigestPrefix() (types.ConfigDigestPrefix, error) {
func (OffchainConfigDigester) ConfigDigestPrefix(ctx context.Context) (types.ConfigDigestPrefix, error) {
return ConfigDigestPrefixCosmos, nil
}
6 changes: 4 additions & 2 deletions pkg/cosmos/adapters/cosmwasm/config_digester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

var testConfig = types.ContractConfig{
Expand Down Expand Up @@ -36,7 +38,7 @@ func TestConfigDigester(t *testing.T) {
sdk.MustAccAddressFromBech32("wasm1cd65xyq076dm9cw3xxqtdh4d6ypzug0edd9958"),
)

digest, err := d.ConfigDigest(testConfig)
digest, err := d.ConfigDigest(tests.Context(t), testConfig)
assert.NoError(t, err)
assert.Equal(t, "000289b55121341b1ff99cc8e15659fb8de14fca52a695b2b269a7fb94059b9f", digest.Hex())
}
Expand All @@ -47,6 +49,6 @@ func TestConfigDigester_InvalidChainID(t *testing.T) {
sdk.MustAccAddressFromBech32("wasm1cd65xyq076dm9cw3xxqtdh4d6ypzug0edd9958"),
)

_, err := d.ConfigDigest(testConfig)
_, err := d.ConfigDigest(tests.Context(t), testConfig)
assert.Error(t, err)
}
2 changes: 1 addition & 1 deletion pkg/cosmos/adapters/cosmwasm/contract_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ func (ct *ContractTransmitter) Transmit(
return err
}

func (ct *ContractTransmitter) FromAccount() (types.Account, error) {
func (ct *ContractTransmitter) FromAccount(ctx context.Context) (types.Account, error) {
return types.Account(ct.sender.String()), nil
}
7 changes: 4 additions & 3 deletions pkg/cosmos/adapters/cosmwasm/report.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cosmwasm

import (
"context"
"encoding/binary"
"fmt"
"math/big"
Expand Down Expand Up @@ -34,7 +35,7 @@ var _ median.ReportCodec = (*ReportCodec)(nil)

type ReportCodec struct{}

func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types.Report, error) {
func (c ReportCodec) BuildReport(ctx context.Context, oo []median.ParsedAttributedObservation) (types.Report, error) {
n := len(oo)
if n == 0 {
return nil, fmt.Errorf("cannot build report from empty attributed observations")
Expand Down Expand Up @@ -95,11 +96,11 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types
return report, nil
}

func (c ReportCodec) MaxReportLength(n int) (int, error) {
func (c ReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) {
return prefixSizeBytes + (n * observationSizeBytes) + juelsPerFeeCoinSizeBytes, nil
}

func (c ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) {
func (c ReportCodec) MedianFromReport(ctx context.Context, report types.Report) (*big.Int, error) {
// report should at least be able to contain timestamp, observers, observations length
rLen := len(report)
if rLen < prefixSizeBytes {
Expand Down
9 changes: 6 additions & 3 deletions pkg/cosmos/adapters/cosmwasm/report_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"github.com/stretchr/testify/require"

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

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

// go test -tags=go1.18 -fuzz ./...
func FuzzReportCodecMedianFromReport(f *testing.F) {
cdc := ReportCodec{}
report, err := cdc.BuildReport([]median.ParsedAttributedObservation{
report, err := cdc.BuildReport(tests.Context(f), []median.ParsedAttributedObservation{
{Timestamp: uint32(time.Now().Unix()), Value: big.NewInt(10), JuelsPerFeeCoin: big.NewInt(100000)},
{Timestamp: uint32(time.Now().Unix()), Value: big.NewInt(10), JuelsPerFeeCoin: big.NewInt(200000)},
{Timestamp: uint32(time.Now().Unix()), Value: big.NewInt(11), JuelsPerFeeCoin: big.NewInt(300000)}})
Expand All @@ -25,10 +27,11 @@ func FuzzReportCodecMedianFromReport(f *testing.F) {
// Seed with valid report
f.Add([]byte(report))
f.Fuzz(func(t *testing.T, report []byte) {
med, err := cdc.MedianFromReport(report)
ctx := tests.Context(t)
med, err := cdc.MedianFromReport(ctx, report)
if err == nil {
// Should always be able to build a report from the medians extracted
_, err = cdc.BuildReport([]median.ParsedAttributedObservation{{Timestamp: uint32(time.Now().Unix()), Value: med, JuelsPerFeeCoin: med}})
_, err = cdc.BuildReport(ctx, []median.ParsedAttributedObservation{{Timestamp: uint32(time.Now().Unix()), Value: med, JuelsPerFeeCoin: med}})
require.NoError(t, err)
}
})
Expand Down
15 changes: 9 additions & 6 deletions pkg/cosmos/adapters/cosmwasm/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

func TestBuildReport(t *testing.T) {
Expand All @@ -36,7 +38,7 @@ func TestBuildReport(t *testing.T) {
observers[i] = uint8(i)
}

report, err := c.BuildReport(oo)
report, err := c.BuildReport(tests.Context(t), oo)
assert.NoError(t, err)

// validate length
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestMedianFromOnChainReport(t *testing.T) {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 150, 2, 210, // observation 2
0, 0, 0, 0, 0, 0, 0, 0, 13, 224, 182, 179, 167, 100, 0, 0, // juels per atom (1 with 18 decimal places)
}
res, err := c.MedianFromReport(report)
res, err := c.MedianFromReport(tests.Context(t), report)
assert.NoError(t, err)
assert.Equal(t, "1234567890", res.String())
}
Expand All @@ -88,7 +90,7 @@ type medianTest struct {
func TestMedianFromReport(t *testing.T) {
cdc := ReportCodec{}
// Requires at least one obs
_, err := cdc.BuildReport(nil)
_, err := cdc.BuildReport(tests.Context(t), nil)
require.Error(t, err)
var tt = []medianTest{
{
Expand Down Expand Up @@ -142,6 +144,7 @@ func TestMedianFromReport(t *testing.T) {
for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
ctx := tests.Context(t)
var pos []median.ParsedAttributedObservation
for i, obs := range tc.obs {
pos = append(pos, median.ParsedAttributedObservation{
Expand All @@ -150,12 +153,12 @@ func TestMedianFromReport(t *testing.T) {
Observer: commontypes.OracleID(uint8(i))},
)
}
report, err := cdc.BuildReport(pos)
report, err := cdc.BuildReport(ctx, pos)
require.NoError(t, err)
max, err := cdc.MaxReportLength(len(tc.obs))
max, err := cdc.MaxReportLength(ctx, len(tc.obs))
require.NoError(t, err)
assert.Equal(t, len(report), max)
med, err := cdc.MedianFromReport(report)
med, err := cdc.MedianFromReport(ctx, report)
require.NoError(t, err)
assert.Equal(t, tc.expectedMedian.String(), med.String())
})
Expand Down
11 changes: 6 additions & 5 deletions pkg/cosmos/adapters/injective/median_report/report.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package median_report

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

sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/proto"

"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
Expand All @@ -19,7 +20,7 @@ var _ median.ReportCodec = ReportCodec{}

type ReportCodec struct{}

func (ReportCodec) BuildReport(observations []median.ParsedAttributedObservation) (types.Report, error) {
func (ReportCodec) BuildReport(ctx context.Context, observations []median.ParsedAttributedObservation) (types.Report, error) {
if len(observations) == 0 {
err := errors.New("cannot build report from empty attributed observations")
return nil, err
Expand Down Expand Up @@ -60,13 +61,13 @@ func (ReportCodec) BuildReport(observations []median.ParsedAttributedObservation
return types.Report(reportBytes), err
}

func (ReportCodec) MaxReportLength(n int) (int, error) {
func (ReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) {
// TODO:
return 0, nil
// return prefixSizeBytes + (n * observationSizeBytes) + juelsPerFeeCoinSizeBytes
}

func (ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) {
func (ReportCodec) MedianFromReport(ctx context.Context, report types.Report) (*big.Int, error) {
reportRaw, err := ParseReport([]byte(report))
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions pkg/cosmos/adapters/injective/offchain_config_digester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package injective

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

Expand All @@ -23,7 +25,7 @@ func NewCosmosOffchainConfigDigester(chainID string, feedID string) *CosmosOffch
}
}

func (d CosmosOffchainConfigDigester) ConfigDigest(cc types.ContractConfig) (types.ConfigDigest, error) {
func (d CosmosOffchainConfigDigester) ConfigDigest(ctx context.Context, cc types.ContractConfig) (types.ConfigDigest, error) {
signers := make([]string, 0, len(cc.Signers))
for _, acc := range cc.Signers {
signers = append(signers, sdk.AccAddress(acc).String())
Expand Down Expand Up @@ -54,7 +56,7 @@ func (d CosmosOffchainConfigDigester) ConfigDigest(cc types.ContractConfig) (typ
return configDigest, nil
}

func (d CosmosOffchainConfigDigester) ConfigDigestPrefix() (types.ConfigDigestPrefix, error) {
func (d CosmosOffchainConfigDigester) ConfigDigestPrefix(ctx context.Context) (types.ConfigDigestPrefix, error) {
return ConfigDigestPrefixCosmos, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cosmos/adapters/injective/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewCosmosModuleTransmitter(
}
}

func (c *CosmosModuleTransmitter) FromAccount() (types.Account, error) {
func (c *CosmosModuleTransmitter) FromAccount(ctx context.Context) (types.Account, error) {
return types.Account(c.sender.String()), nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cosmos/client/gas_price_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type ComposedGasPriceEstimator struct {
}

func NewMustGasPriceEstimator(estimators []GasPricesEstimator, lggr logger.Logger) *ComposedGasPriceEstimator {
return &ComposedGasPriceEstimator{estimators: estimators, lggr: lggr}
return &ComposedGasPriceEstimator{estimators: estimators, lggr: logger.Named(lggr, "ComposedGasPriceEstimator")}
}

func (gpe *ComposedGasPriceEstimator) GasPrices() map[string]sdk.DecCoin {
Expand Down
Loading

0 comments on commit 4a392ac

Please sign in to comment.