diff --git a/go.mod b/go.mod index 6d947cc58..ae1c2409a 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 8320bd283..e21db41d1 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 65d256c01..2b7805e4d 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -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 @@ -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 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 93118e1ff..96e1c56aa 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -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= @@ -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= diff --git a/pkg/cosmos/adapters/cosmwasm/config_digester.go b/pkg/cosmos/adapters/cosmwasm/config_digester.go index 88e2f9721..faafbc368 100644 --- a/pkg/cosmos/adapters/cosmwasm/config_digester.go +++ b/pkg/cosmos/adapters/cosmwasm/config_digester.go @@ -2,6 +2,7 @@ package cosmwasm import ( "bytes" + "context" "encoding/binary" "errors" "fmt" @@ -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{}) @@ -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 } @@ -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 } diff --git a/pkg/cosmos/adapters/cosmwasm/config_digester_test.go b/pkg/cosmos/adapters/cosmwasm/config_digester_test.go index e9f69fb69..9d314af52 100644 --- a/pkg/cosmos/adapters/cosmwasm/config_digester_test.go +++ b/pkg/cosmos/adapters/cosmwasm/config_digester_test.go @@ -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{ @@ -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()) } @@ -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) } diff --git a/pkg/cosmos/adapters/cosmwasm/contract_transmitter.go b/pkg/cosmos/adapters/cosmwasm/contract_transmitter.go index 66bcdbf10..bc580c7ef 100644 --- a/pkg/cosmos/adapters/cosmwasm/contract_transmitter.go +++ b/pkg/cosmos/adapters/cosmwasm/contract_transmitter.go @@ -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 } diff --git a/pkg/cosmos/adapters/cosmwasm/report.go b/pkg/cosmos/adapters/cosmwasm/report.go index d31724a86..669345308 100644 --- a/pkg/cosmos/adapters/cosmwasm/report.go +++ b/pkg/cosmos/adapters/cosmwasm/report.go @@ -1,6 +1,7 @@ package cosmwasm import ( + "context" "encoding/binary" "fmt" "math/big" @@ -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") @@ -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 { diff --git a/pkg/cosmos/adapters/cosmwasm/report_fuzz_test.go b/pkg/cosmos/adapters/cosmwasm/report_fuzz_test.go index 3651ed348..ad296b12f 100644 --- a/pkg/cosmos/adapters/cosmwasm/report_fuzz_test.go +++ b/pkg/cosmos/adapters/cosmwasm/report_fuzz_test.go @@ -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)}}) @@ -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) } }) diff --git a/pkg/cosmos/adapters/cosmwasm/report_test.go b/pkg/cosmos/adapters/cosmwasm/report_test.go index 9ae75d442..a674e5f96 100644 --- a/pkg/cosmos/adapters/cosmwasm/report_test.go +++ b/pkg/cosmos/adapters/cosmwasm/report_test.go @@ -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) { @@ -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 @@ -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()) } @@ -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{ { @@ -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{ @@ -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()) }) diff --git a/pkg/cosmos/adapters/injective/median_report/report.go b/pkg/cosmos/adapters/injective/median_report/report.go index 52b5e08f9..c15093308 100644 --- a/pkg/cosmos/adapters/injective/median_report/report.go +++ b/pkg/cosmos/adapters/injective/median_report/report.go @@ -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" @@ -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 @@ -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 diff --git a/pkg/cosmos/adapters/injective/offchain_config_digester.go b/pkg/cosmos/adapters/injective/offchain_config_digester.go index ea5eb5201..45090e4c3 100644 --- a/pkg/cosmos/adapters/injective/offchain_config_digester.go +++ b/pkg/cosmos/adapters/injective/offchain_config_digester.go @@ -1,6 +1,8 @@ package injective import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -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()) @@ -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 } diff --git a/pkg/cosmos/adapters/injective/transmitter.go b/pkg/cosmos/adapters/injective/transmitter.go index e3bc8fe9b..d4f284411 100644 --- a/pkg/cosmos/adapters/injective/transmitter.go +++ b/pkg/cosmos/adapters/injective/transmitter.go @@ -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 } diff --git a/pkg/cosmos/client/gas_price_estimator.go b/pkg/cosmos/client/gas_price_estimator.go index 3ef007948..f46f731e0 100644 --- a/pkg/cosmos/client/gas_price_estimator.go +++ b/pkg/cosmos/client/gas_price_estimator.go @@ -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 { diff --git a/pkg/cosmos/relay.go b/pkg/cosmos/relay.go index dbe1e48a0..76e2c9462 100644 --- a/pkg/cosmos/relay.go +++ b/pkg/cosmos/relay.go @@ -3,8 +3,10 @@ package cosmos import ( "context" "errors" + "math/big" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/adapters" @@ -25,16 +27,12 @@ type ErrMsgUnsupported = txm.ErrMsgUnsupported var _ types.Relayer = &Relayer{} //nolint:staticcheck type Relayer struct { - lggr logger.Logger - chain adapters.Chain - ctx context.Context - cancel func() + lggr logger.Logger + chain adapters.Chain } // Note: constructed in core func NewRelayer(lggr logger.Logger, chain adapters.Chain) *Relayer { - ctx, cancel := context.WithCancel(context.Background()) - bech32Prefix := chain.Config().Bech32Prefix() gasToken := chain.Config().GasToken() params.InitCosmosSdk( @@ -43,58 +41,69 @@ func NewRelayer(lggr logger.Logger, chain adapters.Chain) *Relayer { ) return &Relayer{ - lggr: lggr, - chain: chain, - ctx: ctx, - cancel: cancel, + lggr: logger.Named(lggr, "Relayer"), + chain: chain, } } +func (r *Relayer) Chain() adapters.Chain { return r.chain } + func (r *Relayer) Name() string { return r.lggr.Name() } // Start starts the relayer respecting the given context. -func (r *Relayer) Start(context.Context) error { +func (r *Relayer) Start(ctx context.Context) error { if r.chain == nil { return errors.New("Cosmos unavailable") } - return nil + return r.chain.Start(ctx) } -func (r *Relayer) Close() error { - r.cancel() - return nil -} +func (r *Relayer) Close() error { return r.chain.Close() } func (r *Relayer) Ready() error { return r.chain.Ready() } func (r *Relayer) HealthReport() map[string]error { + hp := map[string]error{r.Name(): nil} + services.CopyHealth(hp, r.chain.HealthReport()) return r.chain.HealthReport() } -func (r *Relayer) NewMercuryProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.MercuryProvider, error) { +func (r *Relayer) GetChainStatus(ctx context.Context) (types.ChainStatus, error) { + return r.chain.GetChainStatus(ctx) +} + +func (r *Relayer) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (stats []types.NodeStatus, nextPageToken string, total int, err error) { + return r.chain.ListNodeStatuses(ctx, pageSize, pageToken) +} + +func (r *Relayer) Transact(ctx context.Context, from, to string, amount *big.Int, balanceCheck bool) error { + return r.chain.Transact(ctx, from, to, amount, balanceCheck) +} + +func (r *Relayer) NewMercuryProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.MercuryProvider, error) { return nil, errors.New("mercury is not supported for cosmos") } -func (r *Relayer) NewLLOProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.LLOProvider, error) { +func (r *Relayer) NewLLOProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.LLOProvider, error) { return nil, errors.New("data streams is not supported for cosmos") } -func (r *Relayer) NewFunctionsProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.FunctionsProvider, error) { +func (r *Relayer) NewFunctionsProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.FunctionsProvider, error) { return nil, errors.New("functions are not supported for cosmos") } -func (r *Relayer) NewConfigProvider(args types.RelayArgs) (types.ConfigProvider, error) { +func (r *Relayer) NewConfigProvider(ctx context.Context, args types.RelayArgs) (types.ConfigProvider, error) { var configProvider types.ConfigProvider var err error if r.chain.Config().Bech32Prefix() == InjectivePrefix { - configProvider, err = injective.NewConfigProvider(r.ctx, r.lggr, r.chain, args) + configProvider, err = injective.NewConfigProvider(ctx, r.lggr, r.chain, args) } else { // Default to cosmwasm adapter - configProvider, err = cosmwasm.NewConfigProvider(r.ctx, r.lggr, r.chain, args) + configProvider, err = cosmwasm.NewConfigProvider(ctx, r.lggr, r.chain, args) } if err != nil { return nil, err @@ -103,18 +112,18 @@ func (r *Relayer) NewConfigProvider(args types.RelayArgs) (types.ConfigProvider, return configProvider, err } -func (r *Relayer) NewMedianProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.MedianProvider, error) { - configProvider, err := cosmwasm.NewMedianProvider(r.ctx, r.lggr, r.chain, rargs, pargs) +func (r *Relayer) NewMedianProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.MedianProvider, error) { + configProvider, err := cosmwasm.NewMedianProvider(ctx, r.lggr, r.chain, rargs, pargs) if err != nil { return nil, err } return configProvider, err } -func (r *Relayer) NewAutomationProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.AutomationProvider, error) { +func (r *Relayer) NewAutomationProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.AutomationProvider, error) { return nil, errors.New("automation is not supported for cosmos") } -func (r *Relayer) NewPluginProvider(rargs types.RelayArgs, pargs types.PluginArgs) (types.PluginProvider, error) { +func (r *Relayer) NewPluginProvider(ctx context.Context, rargs types.RelayArgs, pargs types.PluginArgs) (types.PluginProvider, error) { return nil, errors.New("plugin provider is not supported for cosmos") } diff --git a/pkg/monitoring/mocks/ChainReader.go b/pkg/monitoring/mocks/ChainReader.go index 2ffa60731..a2e0fd28f 100644 --- a/pkg/monitoring/mocks/ChainReader.go +++ b/pkg/monitoring/mocks/ChainReader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.0. DO NOT EDIT. +// Code generated by mockery v2.38.0. DO NOT EDIT. package mocks @@ -9,8 +9,6 @@ import ( query "github.com/cosmos/cosmos-sdk/types/query" - testing "testing" - tx "github.com/cosmos/cosmos-sdk/types/tx" types "github.com/cosmos/cosmos-sdk/types" @@ -25,7 +23,15 @@ type ChainReader struct { func (_m *ChainReader) ContractState(ctx context.Context, contractAddress types.AccAddress, queryMsg []byte) ([]byte, error) { ret := _m.Called(ctx, contractAddress, queryMsg) + if len(ret) == 0 { + panic("no return value specified for ContractState") + } + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, []byte) ([]byte, error)); ok { + return rf(ctx, contractAddress, queryMsg) + } if rf, ok := ret.Get(0).(func(context.Context, types.AccAddress, []byte) []byte); ok { r0 = rf(ctx, contractAddress, queryMsg) } else { @@ -34,7 +40,6 @@ func (_m *ChainReader) ContractState(ctx context.Context, contractAddress types. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, types.AccAddress, []byte) error); ok { r1 = rf(ctx, contractAddress, queryMsg) } else { @@ -48,7 +53,15 @@ func (_m *ChainReader) ContractState(ctx context.Context, contractAddress types. func (_m *ChainReader) TxsEvents(ctx context.Context, events []string, paginationParams *query.PageRequest) (*tx.GetTxsEventResponse, error) { ret := _m.Called(ctx, events, paginationParams) + if len(ret) == 0 { + panic("no return value specified for TxsEvents") + } + var r0 *tx.GetTxsEventResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string, *query.PageRequest) (*tx.GetTxsEventResponse, error)); ok { + return rf(ctx, events, paginationParams) + } if rf, ok := ret.Get(0).(func(context.Context, []string, *query.PageRequest) *tx.GetTxsEventResponse); ok { r0 = rf(ctx, events, paginationParams) } else { @@ -57,7 +70,6 @@ func (_m *ChainReader) TxsEvents(ctx context.Context, events []string, paginatio } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, []string, *query.PageRequest) error); ok { r1 = rf(ctx, events, paginationParams) } else { @@ -67,8 +79,12 @@ func (_m *ChainReader) TxsEvents(ctx context.Context, events []string, paginatio return r0, r1 } -// NewChainReader creates a new instance of ChainReader. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewChainReader(t testing.TB) *ChainReader { +// NewChainReader creates a new instance of ChainReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewChainReader(t interface { + mock.TestingT + Cleanup(func()) +}) *ChainReader { mock := &ChainReader{} mock.Mock.Test(t) diff --git a/pkg/monitoring/mocks/Metrics.go b/pkg/monitoring/mocks/Metrics.go index cfc0e5330..4b206efd1 100644 --- a/pkg/monitoring/mocks/Metrics.go +++ b/pkg/monitoring/mocks/Metrics.go @@ -1,12 +1,8 @@ -// Code generated by mockery v2.12.0. DO NOT EDIT. +// Code generated by mockery v2.38.0. DO NOT EDIT. package mocks -import ( - mock "github.com/stretchr/testify/mock" - - testing "testing" -) +import mock "github.com/stretchr/testify/mock" // Metrics is an autogenerated mock type for the Metrics type type Metrics struct { @@ -28,8 +24,12 @@ func (_m *Metrics) SetProxyAnswersRaw(answer float64, proxyContractAddress strin _m.Called(answer, proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName) } -// NewMetrics creates a new instance of Metrics. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewMetrics(t testing.TB) *Metrics { +// NewMetrics creates a new instance of Metrics. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMetrics(t interface { + mock.TestingT + Cleanup(func()) +}) *Metrics { mock := &Metrics{} mock.Mock.Test(t)