From f40291a50915fa2ae688c73d3d05a1714b69e2e0 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 20 Aug 2024 17:59:16 -0500 Subject: [PATCH] support cosmos as LOOP Plugin --- .github/workflows/ci-core.yml | 3 + .goreleaser.develop.yaml | 2 + .goreleaser.devspace.yaml | 1 + GNUmakefile | 2 +- core/cmd/cosmos_transaction_commands_test.go | 60 ++++++++++++++----- core/cmd/solana_transaction_commands_test.go | 10 ++-- core/config/env/env.go | 1 + core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- .../mocks/relayer_chain_interoperators.go | 4 -- .../chainlink/relayer_chain_interoperators.go | 58 +----------------- .../relayer_chain_interoperators_test.go | 14 ----- core/services/chainlink/relayer_factory.go | 52 ++++++++++++---- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- plugins/chainlink.Dockerfile | 6 ++ plugins/loop_registry_test.go | 8 +-- tools/bin/goreleaser_utils | 1 + 22 files changed, 122 insertions(+), 124 deletions(-) diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index 9a1a707c194..c22b2ed7df3 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -168,6 +168,9 @@ jobs: pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-data-streams) go install ./mercury/cmd/chainlink-mercury popd + pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-cosmos) + go install ./pkg/cosmos/cmd/chainlink-cosmos + popd pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-solana) go install ./pkg/solana/cmd/chainlink-solana popd diff --git a/.goreleaser.develop.yaml b/.goreleaser.develop.yaml index f8757676f83..e4cc7e43988 100644 --- a/.goreleaser.develop.yaml +++ b/.goreleaser.develop.yaml @@ -124,6 +124,7 @@ dockers: - "--build-arg=COMMIT_SHA={{ .FullCommit }}" - "--build-arg=CL_MEDIAN_CMD=chainlink-feeds" - "--build-arg=CL_MERCURY_CMD=chainlink-mercury" + - "--build-arg=CL_COSMOS_CMD=chainlink-cosmos" - "--build-arg=CL_SOLANA_CMD=chainlink-solana" - "--build-arg=CL_STARKNET_CMD=chainlink-starknet" - "--label=org.opencontainers.image.created={{ .Date }}" @@ -154,6 +155,7 @@ dockers: - "--build-arg=COMMIT_SHA={{ .FullCommit }}" - "--build-arg=CL_MEDIAN_CMD=chainlink-feeds" - "--build-arg=CL_MERCURY_CMD=chainlink-mercury" + - "--build-arg=CL_COSMOS_CMD=chainlink-cosmos" - "--build-arg=CL_SOLANA_CMD=chainlink-solana" - "--build-arg=CL_STARKNET_CMD=chainlink-starknet" - "--label=org.opencontainers.image.created={{ .Date }}" diff --git a/.goreleaser.devspace.yaml b/.goreleaser.devspace.yaml index d0167b34cda..a2db570ed68 100644 --- a/.goreleaser.devspace.yaml +++ b/.goreleaser.devspace.yaml @@ -53,6 +53,7 @@ dockers: - "--build-arg=COMMIT_SHA={{ .FullCommit }}" - "--build-arg=CL_MEDIAN_CMD=chainlink-feeds" - "--build-arg=CL_MERCURY_CMD=chainlink-mercury" + - "--build-arg=CL_COSMOS_CMD=chainlink-cosmos" - "--build-arg=CL_SOLANA_CMD=chainlink-solana" - "--build-arg=CL_STARKNET_CMD=chainlink-starknet" - "--label=org.opencontainers.image.created={{ .Date }}" diff --git a/GNUmakefile b/GNUmakefile index de5511ce6df..23082a1f5ae 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -178,7 +178,7 @@ modgraph: .PHONY: test-short test-short: ## Run 'go test -short' and suppress uninteresting output - go test -short ./... | grep -v "[no test files]" | grep -v "\(cached\)" + go test -short ./... | grep -v "no test files" | grep -v "\(cached\)" help: @echo "" diff --git a/core/cmd/cosmos_transaction_commands_test.go b/core/cmd/cosmos_transaction_commands_test.go index c3e6a048103..32de045a353 100644 --- a/core/cmd/cosmos_transaction_commands_test.go +++ b/core/cmd/cosmos_transaction_commands_test.go @@ -3,8 +3,13 @@ package cmd_test import ( + "encoding/json" + "errors" "flag" + "fmt" + "math/big" "os" + "os/exec" "testing" "time" @@ -16,7 +21,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/config" cosmosclient "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client" coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config" - cosmosdb "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db" "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/denom" "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/params" @@ -45,7 +49,7 @@ func TestShell_SendCosmosCoins(t *testing.T) { chainID := cosmostest.RandomChainID() cosmosChain := coscfg.Chain{} cosmosChain.SetDefaults() - accounts, _, url := cosmosclient.SetupLocalCosmosNode(t, chainID, *cosmosChain.GasToken) + accounts, testDir, url := cosmosclient.SetupLocalCosmosNode(t, chainID, *cosmosChain.GasToken) require.Greater(t, len(accounts), 1) nodes := coscfg.Nodes{ &coscfg.Node{ @@ -59,18 +63,14 @@ func TestShell_SendCosmosCoins(t *testing.T) { from := accounts[0] to := accounts[1] require.NoError(t, app.GetKeyStore().Cosmos().Add(ctx, cosmoskey.Raw(from.PrivateKey.Bytes()).Key())) - chain, err := app.GetRelayers().LegacyCosmosChains().Get(chainID) - require.NoError(t, err) - - reader, err := chain.Reader("") - require.NoError(t, err) require.Eventually(t, func() bool { - coin, err := reader.Balance(from.Address, *cosmosChain.GasToken) + coin, err := cosmosBalance(testDir, url, from.Address.String(), *cosmosChain.GasToken) if !assert.NoError(t, err) { + t.Logf("failed to get balance for %s: %v", from.Address.String(), err) return false } - return coin.IsPositive() + return coin.Sign() > 0 }, time.Minute, 5*time.Second) client, r := app.NewShellAndRenderer() @@ -89,7 +89,7 @@ func TestShell_SendCosmosCoins(t *testing.T) { } { tt := tt t.Run(tt.amount, func(t *testing.T) { - startBal, err := reader.Balance(from.Address, *cosmosChain.GasToken) + startBal, err := cosmosBalance(testDir, url, from.Address.String(), *cosmosChain.GasToken) require.NoError(t, err) set := flag.NewFlagSet("sendcosmoscoins", 0) @@ -113,20 +113,52 @@ func TestShell_SendCosmosCoins(t *testing.T) { renderer := r.Renders[len(r.Renders)-1] renderedMsg := renderer.(*cmd.CosmosMsgPresenter) require.NotEmpty(t, renderedMsg.ID) - assert.Equal(t, string(cosmosdb.Unstarted), renderedMsg.State) + assert.Equal(t, "unstarted", renderedMsg.State) assert.Nil(t, renderedMsg.TxHash) // Check balance sent, err := denom.ConvertDecCoinToDenom(sdk.NewDecCoinFromDec(nativeToken, sdk.MustNewDecFromStr(tt.amount)), *cosmosChain.GasToken) require.NoError(t, err) - expBal := startBal.Sub(sent) + expBal := startBal.Sub(startBal, sent.Amount.BigInt()) testutils.AssertEventually(t, func() bool { - endBal, err := reader.Balance(from.Address, *cosmosChain.GasToken) + endBal, err := cosmosBalance(testDir, url, from.Address.String(), *cosmosChain.GasToken) require.NoError(t, err) t.Logf("%s <= %s", endBal, expBal) - return endBal.IsLTE(expBal) + return endBal.Cmp(expBal) <= 0 }) }) } } + +func cosmosBalance(homeDir string, tendermintURL string, addr string, denom string) (bal *big.Int, err error) { + var output []byte + output, err = exec.Command("wasmd", "--home", homeDir, "query", "bank", "balances", "--denom", denom, addr, "--node", tendermintURL, "--output", "json").Output() + if err != nil { + var ee *exec.ExitError + if errors.As(err, &ee) { + err = fmt.Errorf("%v\n%s", err, string(ee.Stderr)) + } + return + } + var raw = struct { + Amount string `json:"amount"` + Denom string `json:"demon"` + }{} + err = json.Unmarshal(output, &raw) + if err != nil { + err = fmt.Errorf("failed to unmarshal output: %w", err) + return + } + if raw.Denom == denom { + err = fmt.Errorf("requested denom %s but got %s", denom, raw.Denom) + return + } + if raw.Amount == "" { + err = errors.New("amount missing") + return + } + bal = new(big.Int) + bal.SetString(raw.Amount, 10) + return +} diff --git a/core/cmd/solana_transaction_commands_test.go b/core/cmd/solana_transaction_commands_test.go index 79a5513f190..641e7bdfa8a 100644 --- a/core/cmd/solana_transaction_commands_test.go +++ b/core/cmd/solana_transaction_commands_test.go @@ -44,7 +44,7 @@ func TestShell_SolanaSendSol(t *testing.T) { solanaClient.FundTestAccounts(t, []solanago.PublicKey{from.PublicKey()}, url) require.Eventually(t, func() bool { - coin, err := balance(from.PublicKey(), url) + coin, err := solBalance(from.PublicKey(), url) if err != nil { return false } @@ -65,7 +65,7 @@ func TestShell_SolanaSendSol(t *testing.T) { } { tt := tt t.Run(tt.amount, func(t *testing.T) { - startBal, err := balance(from.PublicKey(), url) + startBal, err := solBalance(from.PublicKey(), url) require.NoError(t, err) set := flag.NewFlagSet("sendsolcoins", 0) @@ -102,7 +102,7 @@ func TestShell_SolanaSendSol(t *testing.T) { time.Sleep(time.Second) // wait for tx execution // Check balance - endBal, err = balance(from.PublicKey(), url) + endBal, err = solBalance(from.PublicKey(), url) require.NoError(t, err) require.NoError(t, err) @@ -117,7 +117,7 @@ func TestShell_SolanaSendSol(t *testing.T) { // Check balance if assert.NotEqual(t, 0, startBal) && assert.NotEqual(t, 0, endBal) { diff := startBal - endBal - receiveBal, err := balance(to.PublicKey(), url) + receiveBal, err := solBalance(to.PublicKey(), url) require.NoError(t, err) assert.Equal(t, tt.amount, strconv.FormatUint(receiveBal, 10)) assert.Greater(t, diff, receiveBal) @@ -126,7 +126,7 @@ func TestShell_SolanaSendSol(t *testing.T) { } } -func balance(key solanago.PublicKey, url string) (uint64, error) { +func solBalance(key solanago.PublicKey, url string) (uint64, error) { b, err := exec.Command("solana", "balance", "--lamports", key.String(), "--url", url).Output() if err != nil { return 0, err diff --git a/core/config/env/env.go b/core/config/env/env.go index c34cd7f4f5e..5e1c666c5a6 100644 --- a/core/config/env/env.go +++ b/core/config/env/env.go @@ -27,6 +27,7 @@ var ( var ( MedianPlugin = NewPlugin("median") MercuryPlugin = NewPlugin("mercury") + CosmosPlugin = NewPlugin("cosmos") SolanaPlugin = NewPlugin("solana") StarknetPlugin = NewPlugin("starknet") // PrometheusDiscoveryHostName is the externally accessible hostname diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 4a3e8656769..5440b8c0ec7 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -272,7 +272,7 @@ require ( github.com/shirou/gopsutil/v3 v3.24.3 // indirect github.com/smartcontractkit/chain-selectors v1.0.23 // indirect github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 // indirect - github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect + github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index c10a1348c2f..1e71c666e61 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1085,8 +1085,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 h1 github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978/go.mod h1:X1f4CKlR1RilSgzArQv5HNvMrVSt+Zloihm3REwxhdQ= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb h1:rlboIQq8npAurzZewRIclFO8ov8VQT84ATS/Mz5uXbs= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb/go.mod h1:Dbz39AQtVSA+bACnqhrU1pHBNhyT2b10MUQj0Yff3Xo= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7/go.mod h1:BMYE1vC/pGmdFSsOJdPrAA0/4gZ0Xo0SxTMdGspBtRo= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c h1:mKE5WppfG+UxIHAY2EaFG22WYzR4fF7EdvujjPTd75I= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c/go.mod h1:A7XZG9Z+VUQjwpHQJbKlcaknqlnn4uTnfpzir76hcGM= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc h1:tRmTlaoAt+7FakMXXgeCuRPmzzBo5jsGpeCVvcU6KMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc/go.mod h1:PwPcmQNAzVmU8r8JWKrDRgvXesDwxnqbMD6DvYt/Z7M= github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f h1:p4p3jBT91EQyLuAMvHD+zNJsuAYI/QjJbzuGUJ7wIgg= diff --git a/core/services/chainlink/mocks/relayer_chain_interoperators.go b/core/services/chainlink/mocks/relayer_chain_interoperators.go index 5b0815b6569..2677d1bcb0a 100644 --- a/core/services/chainlink/mocks/relayer_chain_interoperators.go +++ b/core/services/chainlink/mocks/relayer_chain_interoperators.go @@ -51,10 +51,6 @@ func (f *FakeRelayerChainInteroperators) Slice() []loop.Relayer { return f.Relayers } -func (f *FakeRelayerChainInteroperators) LegacyCosmosChains() chainlink.LegacyCosmosContainer { - panic("unimplemented") -} - func (f *FakeRelayerChainInteroperators) ChainStatus(ctx context.Context, id types.RelayID) (types.ChainStatus, error) { panic("unimplemented") } diff --git a/core/services/chainlink/relayer_chain_interoperators.go b/core/services/chainlink/relayer_chain_interoperators.go index 582dd61677c..bcec64f4c25 100644 --- a/core/services/chainlink/relayer_chain_interoperators.go +++ b/core/services/chainlink/relayer_chain_interoperators.go @@ -8,11 +8,7 @@ import ( "sync" "github.com/smartcontractkit/chainlink-common/pkg/loop" - "github.com/smartcontractkit/chainlink-common/pkg/loop/adapters/relay" "github.com/smartcontractkit/chainlink-common/pkg/types" - "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos" - "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/adapters" - "github.com/smartcontractkit/chainlink/v2/core/chains" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" "github.com/smartcontractkit/chainlink/v2/core/services" @@ -47,7 +43,6 @@ type LoopRelayerStorer interface { // on the relayer interface. type LegacyChainer interface { LegacyEVMChains() legacyevm.LegacyChainContainer - LegacyCosmosChains() LegacyCosmosContainer } type ChainStatuser interface { @@ -139,14 +134,11 @@ func InitCosmos(ctx context.Context, factory RelayerFactory, config CosmosFactor if err2 != nil { return fmt.Errorf("failed to setup Cosmos relayer: %w", err2) } - legacyMap := make(map[string]cosmos.Chain) for id, a := range adapters { op.srvs = append(op.srvs, a) op.loopRelayers[id] = a - legacyMap[id.ChainID] = a.Chain() } - op.legacyChains.CosmosChains = NewLegacyCosmos(legacyMap) return nil } @@ -243,14 +235,6 @@ func (rs *CoreRelayerChainInteroperators) LegacyEVMChains() legacyevm.LegacyChai return rs.legacyChains.EVMChains } -// LegacyCosmosChains returns a container with all the cosmos chains -// TODO BCF-2511 -func (rs *CoreRelayerChainInteroperators) LegacyCosmosChains() LegacyCosmosContainer { - rs.mu.Lock() - defer rs.mu.Unlock() - return rs.legacyChains.CosmosChains -} - // ChainStatus gets [types.ChainStatus] func (rs *CoreRelayerChainInteroperators) ChainStatus(ctx context.Context, id types.RelayID) (types.ChainStatus, error) { lr, err := rs.Get(id) @@ -400,45 +384,5 @@ func (rs *CoreRelayerChainInteroperators) Services() (s []services.ServiceCtx) { // legacyChains encapsulates the chain-specific dependencies. Will be // deprecated when chain-specific logic is removed from products. type legacyChains struct { - EVMChains legacyevm.LegacyChainContainer - CosmosChains LegacyCosmosContainer -} - -// LegacyCosmosContainer is container interface for Cosmos chains -type LegacyCosmosContainer interface { - Get(id string) (adapters.Chain, error) - Len() int - List(ids ...string) ([]adapters.Chain, error) - Slice() []adapters.Chain -} - -type LegacyCosmos = chains.ChainsKV[adapters.Chain] - -var _ LegacyCosmosContainer = &LegacyCosmos{} - -func NewLegacyCosmos(m map[string]adapters.Chain) *LegacyCosmos { - return chains.NewChainsKV[adapters.Chain](m) -} - -type CosmosLoopRelayerChainer interface { - loop.Relayer - Chain() adapters.Chain -} - -type CosmosLoopRelayerChain struct { - loop.Relayer - chain adapters.Chain + EVMChains legacyevm.LegacyChainContainer } - -func NewCosmosLoopRelayerChain(r *cosmos.Relayer, s adapters.Chain) *CosmosLoopRelayerChain { - ra := relay.NewServerAdapter(r, s) - return &CosmosLoopRelayerChain{ - Relayer: ra, - chain: s, - } -} -func (r *CosmosLoopRelayerChain) Chain() adapters.Chain { - return r.chain -} - -var _ CosmosLoopRelayerChainer = &CosmosLoopRelayerChain{} diff --git a/core/services/chainlink/relayer_chain_interoperators_test.go b/core/services/chainlink/relayer_chain_interoperators_test.go index 8ae97adc4a8..0e456d93c1f 100644 --- a/core/services/chainlink/relayer_chain_interoperators_test.go +++ b/core/services/chainlink/relayer_chain_interoperators_test.go @@ -398,14 +398,6 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { assert.Nil(t, cr.LegacyEVMChains()) } } - if relayNetwork == relay.NetworkCosmos { - _, wantCosmos := tt.expectedRelayerNetworks[relay.NetworkCosmos] - if wantCosmos { - assert.Len(t, cr.LegacyCosmosChains().Slice(), expectedChainCnt) - } else { - assert.Nil(t, cr.LegacyCosmosChains()) - } - } nodesStats, cnt, err := interops.NodeStatuses(testctx, 0, 0) assert.NoError(t, err) @@ -436,12 +428,6 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { assert.NotNil(t, c) assert.Equal(t, wantId.ChainID, c.ID().String()) } - if wantId.Network == relay.NetworkCosmos { - c, err := cr.LegacyCosmosChains().Get(wantId.ChainID) - assert.NoError(t, err) - assert.NotNil(t, c) - assert.Equal(t, wantId.ChainID, c.ID()) - } } } diff --git a/core/services/chainlink/relayer_factory.go b/core/services/chainlink/relayer_factory.go index 11e477a54f6..f810c1adffe 100644 --- a/core/services/chainlink/relayer_factory.go +++ b/core/services/chainlink/relayer_factory.go @@ -137,14 +137,15 @@ func (r *RelayerFactory) NewSolana(ks keystore.Solana, chainCfgs solcfg.TOMLConf cfgTOML, err := toml.Marshal(struct { Solana solcfg.TOMLConfig }{Solana: *chainCfg}) - if err != nil { return nil, fmt.Errorf("failed to marshal Solana configs: %w", err) } + envVars, err := plugins.ParseEnvFile(env.SolanaPlugin.Env.Get()) if err != nil { return nil, fmt.Errorf("failed to parse Solana env file: %w", err) } + solCmdFn, err := plugins.NewCmdFactory(r.Register, plugins.CmdConfig{ ID: relayID.Name(), Cmd: cmdName, @@ -271,12 +272,12 @@ func (c CosmosFactoryConfig) Validate() error { return err } -func (r *RelayerFactory) NewCosmos(config CosmosFactoryConfig) (map[types.RelayID]CosmosLoopRelayerChainer, error) { +func (r *RelayerFactory) NewCosmos(config CosmosFactoryConfig) (map[types.RelayID]loop.Relayer, error) { err := config.Validate() if err != nil { return nil, fmt.Errorf("cannot create Cosmos relayer: %w", err) } - relayers := make(map[types.RelayID]CosmosLoopRelayerChainer) + relayers := make(map[types.RelayID]loop.Relayer) var ( cosmosLggr = r.Logger.Named("Cosmos") @@ -289,18 +290,43 @@ func (r *RelayerFactory) NewCosmos(config CosmosFactoryConfig) (map[types.RelayI lggr := cosmosLggr.Named(relayID.ChainID) - opts := cosmos.ChainOpts{ - Logger: lggr, - DS: config.DS, - KeyStore: loopKs, - } + if cmdName := env.CosmosPlugin.Cmd.Get(); cmdName != "" { + cfgTOML, err := toml.Marshal(struct { + Cosmos coscfg.TOMLConfig + }{Cosmos: *chainCfg}) + if err != nil { + return nil, fmt.Errorf("failed to marshal Cosmos configs: %w", err) + } - chain, err := cosmos.NewChain(chainCfg, opts) - if err != nil { - return nil, fmt.Errorf("failed to load Cosmos chain %q: %w", relayID, err) - } + envVars, err := plugins.ParseEnvFile(env.CosmosPlugin.Env.Get()) + if err != nil { + return nil, fmt.Errorf("failed to parse Cosmos env file: %w", err) + } + + cosCmdFn, err := plugins.NewCmdFactory(r.Register, plugins.CmdConfig{ + ID: relayID.Name(), + Cmd: cmdName, + Env: envVars, + }) + if err != nil { + return nil, fmt.Errorf("failed to create Cosmos LOOP command: %w", err) + } + + relayers[relayID] = loop.NewRelayerService(lggr, r.GRPCOpts, cosCmdFn, string(cfgTOML), loopKs, r.CapabilitiesRegistry) + } else { + opts := cosmos.ChainOpts{ + Logger: lggr, + DS: config.DS, + KeyStore: loopKs, + } - relayers[relayID] = NewCosmosLoopRelayerChain(cosmos.NewRelayer(lggr, chain), chain) + chain, err := cosmos.NewChain(chainCfg, opts) + if err != nil { + return nil, fmt.Errorf("failed to load Cosmos chain %q: %w", relayID, err) + } + + relayers[relayID] = relay.NewServerAdapter(cosmos.NewRelayer(lggr, chain), chain) + } } return relayers, nil } diff --git a/go.mod b/go.mod index 9aed84310bf..444af86ec3d 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,7 @@ require ( github.com/smartcontractkit/chainlink-automation v1.0.4 github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb - github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 + github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 diff --git a/go.sum b/go.sum index e2b0c5f8a83..547510d7e16 100644 --- a/go.sum +++ b/go.sum @@ -1046,8 +1046,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 h1 github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978/go.mod h1:X1f4CKlR1RilSgzArQv5HNvMrVSt+Zloihm3REwxhdQ= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb h1:rlboIQq8npAurzZewRIclFO8ov8VQT84ATS/Mz5uXbs= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb/go.mod h1:Dbz39AQtVSA+bACnqhrU1pHBNhyT2b10MUQj0Yff3Xo= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7/go.mod h1:BMYE1vC/pGmdFSsOJdPrAA0/4gZ0Xo0SxTMdGspBtRo= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c h1:mKE5WppfG+UxIHAY2EaFG22WYzR4fF7EdvujjPTd75I= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c/go.mod h1:A7XZG9Z+VUQjwpHQJbKlcaknqlnn4uTnfpzir76hcGM= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc h1:tRmTlaoAt+7FakMXXgeCuRPmzzBo5jsGpeCVvcU6KMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc/go.mod h1:PwPcmQNAzVmU8r8JWKrDRgvXesDwxnqbMD6DvYt/Z7M= github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f h1:p4p3jBT91EQyLuAMvHD+zNJsuAYI/QjJbzuGUJ7wIgg= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 20dee2e6528..a465b704094 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -403,7 +403,7 @@ require ( github.com/shirou/gopsutil/v3 v3.24.3 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect + github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index bf6473a69c6..9ed064d1459 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1427,8 +1427,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 h1 github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978/go.mod h1:X1f4CKlR1RilSgzArQv5HNvMrVSt+Zloihm3REwxhdQ= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb h1:rlboIQq8npAurzZewRIclFO8ov8VQT84ATS/Mz5uXbs= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb/go.mod h1:Dbz39AQtVSA+bACnqhrU1pHBNhyT2b10MUQj0Yff3Xo= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7/go.mod h1:BMYE1vC/pGmdFSsOJdPrAA0/4gZ0Xo0SxTMdGspBtRo= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c h1:mKE5WppfG+UxIHAY2EaFG22WYzR4fF7EdvujjPTd75I= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c/go.mod h1:A7XZG9Z+VUQjwpHQJbKlcaknqlnn4uTnfpzir76hcGM= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc h1:tRmTlaoAt+7FakMXXgeCuRPmzzBo5jsGpeCVvcU6KMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc/go.mod h1:PwPcmQNAzVmU8r8JWKrDRgvXesDwxnqbMD6DvYt/Z7M= github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f h1:p4p3jBT91EQyLuAMvHD+zNJsuAYI/QjJbzuGUJ7wIgg= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 34f62c140af..15922c420b3 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -394,7 +394,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/chain-selectors v1.0.23 // indirect github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 // indirect - github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect + github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 84504acf90a..76ec8608802 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1401,8 +1401,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 h1 github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978/go.mod h1:X1f4CKlR1RilSgzArQv5HNvMrVSt+Zloihm3REwxhdQ= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb h1:rlboIQq8npAurzZewRIclFO8ov8VQT84ATS/Mz5uXbs= github.com/smartcontractkit/chainlink-common v0.2.2-0.20240913194736-b21460c94acb/go.mod h1:Dbz39AQtVSA+bACnqhrU1pHBNhyT2b10MUQj0Yff3Xo= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7/go.mod h1:BMYE1vC/pGmdFSsOJdPrAA0/4gZ0Xo0SxTMdGspBtRo= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c h1:mKE5WppfG+UxIHAY2EaFG22WYzR4fF7EdvujjPTd75I= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240913200612-7c79a6f6251c/go.mod h1:A7XZG9Z+VUQjwpHQJbKlcaknqlnn4uTnfpzir76hcGM= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc h1:tRmTlaoAt+7FakMXXgeCuRPmzzBo5jsGpeCVvcU6KMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc/go.mod h1:PwPcmQNAzVmU8r8JWKrDRgvXesDwxnqbMD6DvYt/Z7M= github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f h1:p4p3jBT91EQyLuAMvHD+zNJsuAYI/QjJbzuGUJ7wIgg= diff --git a/plugins/chainlink.Dockerfile b/plugins/chainlink.Dockerfile index 6d42567c745..11fd6dbcca4 100644 --- a/plugins/chainlink.Dockerfile +++ b/plugins/chainlink.Dockerfile @@ -44,6 +44,10 @@ WORKDIR /chainlink-data-streams COPY --from=buildgo /chainlink-data-streams . RUN go install ./mercury/cmd/chainlink-mercury +WORKDIR /chainlink-cosmos +COPY --from=buildgo /chainlink-cosmos . +RUN go install ./pkg/cosmos/cmd/chainlink-cosmos + WORKDIR /chainlink-solana COPY --from=buildgo /chainlink-solana . RUN go install ./pkg/solana/cmd/chainlink-solana @@ -73,6 +77,8 @@ COPY --from=buildplugins /go/bin/chainlink-feeds /usr/local/bin/ ENV CL_MEDIAN_CMD chainlink-feeds COPY --from=buildplugins /go/bin/chainlink-mercury /usr/local/bin/ ENV CL_MERCURY_CMD chainlink-mercury +COPY --from=buildplugins /go/bin/chainlink-cosmos /usr/local/bin/ +ENV CL_COSMOS_CMD chainlink-cosmos COPY --from=buildplugins /go/bin/chainlink-solana /usr/local/bin/ ENV CL_SOLANA_CMD chainlink-solana COPY --from=buildplugins /go/bin/chainlink-starknet /usr/local/bin/ diff --git a/plugins/loop_registry_test.go b/plugins/loop_registry_test.go index 7503a54d7e4..0781196a616 100644 --- a/plugins/loop_registry_test.go +++ b/plugins/loop_registry_test.go @@ -78,9 +78,9 @@ func (m MockCfgDatabase) Dialect() dialects.DialectName { panic("unimplemented") func (m MockCfgDatabase) LogSQL() bool { return true } -func (m MockCfgDatabase) MaxIdleConns() int { return 99 } +func (m MockCfgDatabase) MaxIdleConns() int { return 42 } -func (m MockCfgDatabase) MaxOpenConns() int { return 42 } +func (m MockCfgDatabase) MaxOpenConns() int { return 99 } func (m MockCfgDatabase) MigrateDatabase() bool { panic("unimplemented") } @@ -115,8 +115,8 @@ func TestLoopRegistry_Register(t *testing.T) { require.Equal(t, time.Minute, envCfg.DatabaseLockTimeout) require.Equal(t, time.Second, envCfg.DatabaseQueryTimeout) require.Equal(t, true, envCfg.DatabaseLogSQL) - require.Equal(t, 42, envCfg.DatabaseMaxOpenConns) - require.Equal(t, 99, envCfg.DatabaseMaxIdleConns) + require.Equal(t, 99, envCfg.DatabaseMaxOpenConns) + require.Equal(t, 42, envCfg.DatabaseMaxIdleConns) require.True(t, envCfg.TracingEnabled) require.Equal(t, "http://localhost:9000", envCfg.TracingCollectorTarget) diff --git a/tools/bin/goreleaser_utils b/tools/bin/goreleaser_utils index fa9553274c5..eba2349a66c 100755 --- a/tools/bin/goreleaser_utils +++ b/tools/bin/goreleaser_utils @@ -89,6 +89,7 @@ install_local_plugins() { get_remote_plugin_paths() { plugins=( + "github.com/smartcontractkit/chainlink-cosmos|/pkg/solana/cmd/chainlink-cosmos" "github.com/smartcontractkit/chainlink-solana|/pkg/solana/cmd/chainlink-solana" "github.com/smartcontractkit/chainlink-starknet/relayer|/pkg/chainlink/cmd/chainlink-starknet" "github.com/smartcontractkit/chainlink-feeds|/cmd/chainlink-feeds"