Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring in key management, tx broadcasting, and configuration logic from lens #1097

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ $ %s k a cosmoshub testkey`, appName, appName, appName)),

if coinType < 0 {
if ccp, ok := chain.ChainProvider.(*cosmos.CosmosProvider); ok {
coinType = int32(ccp.Config.Slip44)
coinType = int32(ccp.PCfg.Slip44)
} else {
coinType = int32(defaultCoinType)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ $ %s k r cosmoshub faucet-key "[mnemonic-words]"`, appName, appName)),

if coinType < 0 {
if ccp, ok := chain.ChainProvider.(*cosmos.CosmosProvider); ok {
coinType = int32(ccp.Config.Slip44)
coinType = int32(ccp.PCfg.Slip44)
} else {
coinType = int32(defaultCoinType)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module github.com/cosmos/relayer/v2
go 1.19

require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.4
github.com/avast/retry-go/v4 v4.3.2
github.com/btcsuite/btcd v0.22.2
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cosmos/cosmos-proto v1.0.0-beta.1
github.com/cosmos/cosmos-sdk v0.47.0-rc1
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.3
github.com/cosmos/ibc-go/v7 v7.0.0-beta2
github.com/ethereum/go-ethereum v1.10.26
github.com/gofrs/flock v0.8.1
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.5.9
Expand All @@ -20,11 +26,15 @@ require (
github.com/strangelove-ventures/lens v0.5.2-0.20230202043138-4141145349c8
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.37.0-rc2
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.24.0
golang.org/x/mod v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/term v0.4.0
golang.org/x/text v0.5.0
google.golang.org/grpc v1.52.3
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -37,8 +47,6 @@ require (
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/core v0.3.2 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-beta.4 // indirect
cosmossdk.io/tools/rosetta v0.2.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand All @@ -50,17 +58,14 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.22.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
Expand All @@ -77,7 +82,6 @@ require (
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/ethereum/go-ethereum v1.10.26 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
Expand Down Expand Up @@ -157,7 +161,6 @@ require (
github.com/tendermint/tm-db v0.6.7 // indirect
github.com/tidwall/btree v1.5.2 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
Expand All @@ -169,15 +172,12 @@ require (
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.107.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/grpc v1.52.3 // indirect
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
20 changes: 8 additions & 12 deletions interchaintest/relay_many_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
relayerinterchaintest "github.com/cosmos/relayer/v2/interchaintest"
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/testreporter"
Expand Down Expand Up @@ -97,15 +97,6 @@ func TestRelayerMultiplePathsSingleProcess(t *testing.T) {
_ = ic.Close()
})

// Fund user accounts, so we can query balances and make assertions.
const userFunds = int64(10_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, gaia, osmosis, juno)
gaiaUser, osmosisUser, junoUser := users[0].(*cosmos.CosmosWallet), users[1].(*cosmos.CosmosWallet), users[2].(*cosmos.CosmosWallet)

// Wait a few blocks for user accounts to be created on chain.
err = testutil.WaitForBlocks(ctx, 2, gaia, osmosis, juno)
require.NoError(t, err)

// Start the relayers
err = r.StartRelayer(ctx, eRep, pathGaiaOsmosis, pathGaiaJuno)
require.NoError(t, err)
Expand All @@ -119,8 +110,13 @@ func TestRelayerMultiplePathsSingleProcess(t *testing.T) {
},
)

// Wait a few blocks for the relayer to start.
err = testutil.WaitForBlocks(ctx, 2, gaia, osmosis, juno)
// Fund user accounts, so we can query balances and make assertions.
const userFunds = int64(10_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, gaia, osmosis, juno)
gaiaUser, osmosisUser, junoUser := users[0].(*cosmos.CosmosWallet), users[1].(*cosmos.CosmosWallet), users[2].(*cosmos.CosmosWallet)

// Wait a few blocks for user accounts to be created on chain.
err = testutil.WaitForBlocks(ctx, 5, gaia, osmosis, juno)
require.NoError(t, err)

gaiaAddress := gaiaUser.FormattedAddress()
Expand Down
26 changes: 26 additions & 0 deletions proto/ethermint/crypto/v1/ethsecp256k1/keys.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";

// buf:lint:ignore PACKAGE_VERSION_SUFFIX
package ethermint.crypto.v1.ethsecp256k1;

import "gogoproto/gogo.proto";

// Originally github.com/evmos/ethermint/crypto/ethsecp256k1
option go_package = "github.com/cosmos/relayer/v2/relayer/codecs/ethermint";

// PubKey defines a type alias for an ecdsa.PublicKey that implements
// Tendermint's PubKey interface. It represents the 33-byte compressed public
// key format.
message PubKey {
option (gogoproto.goproto_stringer) = false;

// key is the public key in byte form
bytes key = 1;
}

// PrivKey defines a type alias for an ecdsa.PrivateKey that implements
// Tendermint's PrivateKey interface.
message PrivKey {
// key is the private key in byte form
bytes key = 1;
}
29 changes: 29 additions & 0 deletions proto/ethermint/types/v1/account.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package ethermint.types.v1;

import "cosmos/auth/v1beta1/auth.proto";
// import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

// Originally github.com/evmos/ethermint/types
option go_package = "github.com/cosmos/relayer/v2/relayer/codecs/ethermint";

// EthAccount implements the authtypes.AccountI interface and embeds an
// authtypes.BaseAccount type. It is compatible with the auth AccountKeeper.
message EthAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.equal) = false;

// option (cosmos_proto.implements_interface) =
// "github.com/cosmos/cosmos-sdk/x/auth/types.AccountI";

// base_account is an authtypes.BaseAccount
cosmos.auth.v1beta1.BaseAccount base_account = 1 [
(gogoproto.embed) = true,
(gogoproto.moretags) = "yaml:\"base_account\""
];

// code_hash is the hash calculated from the code contents
string code_hash = 2 [ (gogoproto.moretags) = "yaml:\"code_hash\"" ];
}
18 changes: 18 additions & 0 deletions proto/ethermint/types/v1/dynamic_fee.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package ethermint.types.v1;

import "gogoproto/gogo.proto";

// Originally github.com/evmos/ethermint/types
option go_package = "github.com/cosmos/relayer/v2/relayer/ethermint";

// ExtensionOptionDynamicFeeTx is an extension option that specifies the
// maxPrioPrice for cosmos tx
message ExtensionOptionDynamicFeeTx {
// max_priority_price is the same as `max_priority_fee_per_gas` in eip-1559
// spec
string max_priority_price = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
23 changes: 23 additions & 0 deletions proto/injective/crypto/v1beta1/ethsecp256k1/keys.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

// buf:lint:ignore PACKAGE_VERSION_SUFFIX
package injective.crypto.v1beta1.ethsecp256k1;

import "gogoproto/gogo.proto";

// Originally
// github.com/InjectiveLabs/injective-core/injective-chain/crypto/ethsecp256k1
option go_package = "github.com/cosmos/relayer/v2/relayer/codecs/injective";

// PubKey defines a type alias for an ecdsa.PublicKey that implements
// Tendermint's PubKey interface. It represents the 33-byte compressed public
// key format.
message PubKey {
option (gogoproto.goproto_stringer) = false;

bytes key = 1;
}

// PrivKey defines a type alias for an ecdsa.PrivateKey that implements
// Tendermint's PrivateKey interface.
message PrivKey { bytes key = 1; }
26 changes: 26 additions & 0 deletions proto/injective/types/v1beta1/account.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package injective.types.v1beta1;

import "cosmos/auth/v1beta1/auth.proto";
// import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

// Originally github.com/InjectiveLabs/injective-core/injective-chain/types
option go_package = "github.com/cosmos/relayer/v2/relayer/codecs/injective";

// EthAccount implements the authtypes.AccountI interface and embeds an
// authtypes.BaseAccount type. It is compatible with the auth AccountKeeper.
message EthAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.equal) = false;

// option (cosmos_proto.implements_interface) =
// "github.com/cosmos/cosmos-sdk/x/auth/types.AccountI";

cosmos.auth.v1beta1.BaseAccount base_account = 1 [
(gogoproto.embed) = true,
(gogoproto.moretags) = "yaml:\"base_account\""
];
bytes code_hash = 2 [ (gogoproto.moretags) = "yaml:\"code_hash\"" ];
}
75 changes: 75 additions & 0 deletions relayer/chains/cosmos/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cosmos

import (
"context"
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

var _ client.AccountRetriever = &CosmosProvider{}

// GetAccount queries for an account given an address and a block height. An
// error is returned if the query or decoding fails.
func (cc *CosmosProvider) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error) {
account, _, err := cc.GetAccountWithHeight(clientCtx, addr)
return account, err
}

// GetAccountWithHeight queries for an account given an address. Returns the
// height of the query with the account. An error is returned if the query
// or decoding fails.
func (cc *CosmosProvider) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error) {
var header metadata.MD
address, err := cc.EncodeBech32AccAddr(addr)
if err != nil {
return nil, 0, err
}

queryClient := authtypes.NewQueryClient(cc)
res, err := queryClient.Account(context.Background(), &authtypes.QueryAccountRequest{Address: address}, grpc.Header(&header))
if err != nil {
return nil, 0, err
}

blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
if l := len(blockHeight); l != 1 {
return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected: %d", grpctypes.GRPCBlockHeightHeader, l, 1)
}

nBlockHeight, err := strconv.Atoi(blockHeight[0])
if err != nil {
return nil, 0, fmt.Errorf("failed to parse block height: %w", err)
}

var acc authtypes.AccountI
if err := cc.Codec.InterfaceRegistry.UnpackAny(res.Account, &acc); err != nil {
return nil, 0, err
}

return acc, int64(nBlockHeight), nil
}

// EnsureExists returns an error if no account exists for the given address else nil.
func (cc *CosmosProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error {
if _, err := cc.GetAccount(clientCtx, addr); err != nil {
return err
}
return nil
}

// GetAccountNumberSequence returns sequence and account number for the given address.
// It returns an error if the account couldn't be retrieved from the state.
func (cc *CosmosProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
acc, err := cc.GetAccount(clientCtx, addr)
if err != nil {
return 0, 0, err
}
return acc.GetAccountNumber(), acc.GetSequence(), nil
}
23 changes: 23 additions & 0 deletions relayer/chains/cosmos/bech32_hack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cosmos

import (
"sync"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// This file is cursed and this mutex is too
// you don't want none of this dewey cox.
var sdkConfigMutex sync.Mutex

// SetSDKContext sets the SDK config to the proper bech32 prefixes.
// Don't use this unless you know what you're doing.
// TODO: :dagger: :knife: :chainsaw: remove this function
func (cc *CosmosProvider) SetSDKContext() func() {
sdkConfigMutex.Lock()
sdkConf := sdk.GetConfig()
sdkConf.SetBech32PrefixForAccount(cc.PCfg.AccountPrefix, cc.PCfg.AccountPrefix+"pub")
sdkConf.SetBech32PrefixForValidator(cc.PCfg.AccountPrefix+"valoper", cc.PCfg.AccountPrefix+"valoperpub")
sdkConf.SetBech32PrefixForConsensusNode(cc.PCfg.AccountPrefix+"valcons", cc.PCfg.AccountPrefix+"valconspub")
return sdkConfigMutex.Unlock
}
Loading