Skip to content

Commit

Permalink
Merge pull request #80 from neutron-org/feat/upd-sdk47
Browse files Browse the repository at this point in the history
feat: upd cosmos-sdk v0.47
  • Loading branch information
pr0n00gler authored Dec 7, 2023
2 parents 92f99a1 + f6ae375 commit cd76120
Show file tree
Hide file tree
Showing 23 changed files with 708 additions and 2,190 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ jobs:
name: Test
runs-on: ubuntu-latest

env:
GOPRIVATE: github.com/neutron-org/neutron

steps:
- name: Set up Go 1.18
uses: actions/setup-go@v2
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: '1.20'
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.18
golang 1.20
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18-buster as builder
FROM golang:1.20-buster as builder

ARG LDFLAGS
RUN mkdir /app
Expand All @@ -10,7 +10,7 @@ RUN go build -ldflags "${LDFLAGS}" -a -o build/neutron_query_relayer ./cmd/neutr

FROM debian:buster
RUN apt update && apt install ca-certificates curl -y && apt-get clean
ADD ["https://github.com/CosmWasm/wasmvm/raw/v1.0.0/api/libwasmvm.x86_64.so", "https://github.com/CosmWasm/wasmvm/raw/v1.0.0/api/libwasmvm.aarch64.so", "/lib/"]
ADD ["https://github.com/CosmWasm/wasmvm/releases/download/v1.5.0/libwasmvm.x86_64.so","https://github.com/CosmWasm/wasmvm/releases/download/v1.5.0/libwasmvm.aarch64.so","/lib/"]
ADD run.sh .
COPY --from=builder /app/build/neutron_query_relayer /bin/
EXPOSE 9999
Expand Down
238 changes: 147 additions & 91 deletions go.mod

Large diffs are not rendered by default.

2,521 changes: 489 additions & 2,032 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"time"

rpcclienthttp "github.com/tendermint/tendermint/rpc/client/http"
rpcclienthttp "github.com/cometbft/cometbft/rpc/client/http"
"go.uber.org/zap"

nlogger "github.com/neutron-org/neutron-logger"
Expand Down Expand Up @@ -142,6 +142,7 @@ func NewDefaultStorage(cfg config.NeutronQueryRelayerConfig, logger *zap.Logger)
}

func loadChains(
ctx context.Context,
cfg config.NeutronQueryRelayerConfig,
logRegistry *nlogger.Registry,
connParams *connectionParams,
Expand All @@ -155,7 +156,7 @@ func loadChains(
return nil, nil, fmt.Errorf("failed to AddPath to source chain: %w", err)
}

if err := targetChain.ChainProvider.Init(); err != nil {
if err := targetChain.ChainProvider.Init(ctx); err != nil {
return nil, nil, fmt.Errorf("failed to Init source chain provider: %w", err)
}

Expand All @@ -168,7 +169,7 @@ func loadChains(
return nil, nil, fmt.Errorf("failed to AddPath to destination chain: %w", err)
}

if err := neutronChain.ChainProvider.Init(); err != nil {
if err := neutronChain.ChainProvider.Init(ctx); err != nil {
return nil, nil, fmt.Errorf("failed to Init source chain provider: %w", err)
}

Expand Down
9 changes: 5 additions & 4 deletions internal/app/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"

cosmosrelayer "github.com/cosmos/relayer/v2/relayer"

Expand Down Expand Up @@ -54,15 +55,15 @@ func NewDefaultDependencyContainer(ctx context.Context,
return nil, fmt.Errorf("cannot connect to target chain: %w", err)
}

codec := raw.MakeCodecDefault()
keybase, err := submit.TestKeybase(connParams.neutronChainID, cfg.NeutronChain.HomeDir)
cdc := raw.MakeCodecDefault()
keybase, err := submit.TestKeybase(connParams.neutronChainID, cfg.NeutronChain.HomeDir, codec.NewProtoCodec(cdc.InterfaceRegistry))
if err != nil {
return nil, fmt.Errorf("cannot initialize keybase: %w", err)
}

txSender, err := submit.NewTxSender(ctx,
neutronClient,
codec.Marshaller,
cdc.Marshaller,
keybase,
*cfg.NeutronChain,
logRegistry.Get(TxSenderContext),
Expand All @@ -71,7 +72,7 @@ func NewDefaultDependencyContainer(ctx context.Context,
return nil, fmt.Errorf("cannot create tx sender: %w", err)
}

neutronChain, targetChain, err := loadChains(cfg, logRegistry, connParams)
neutronChain, targetChain, err := loadChains(ctx, cfg, logRegistry, connParams)
if err != nil {
return nil, fmt.Errorf("failed to loadChains: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/kvprocessor/kvprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/avast/retry-go/v4"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"time"

neutronmetrics "github.com/neutron-org/neutron-query-relayer/internal/metrics"

"github.com/avast/retry-go/v4"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported"
"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"github.com/cosmos/relayer/v2/relayer/provider"
Expand Down Expand Up @@ -149,9 +149,9 @@ func (p *KVProcessor) submitKVWithProof(
return nil
}

func (p *KVProcessor) getSrcChainHeader(ctx context.Context, height int64) (ibcexported.Header, error) {
func (p *KVProcessor) getSrcChainHeader(ctx context.Context, height int64) (*tmclient.Header, error) {
start := time.Now()
var srcHeader ibcexported.Header
var srcHeader *tmclient.Header
if err := retry.Do(func() error {
var err error
srcHeader, err = p.trustedHeaderFetcher.Fetch(ctx, uint64(height))
Expand All @@ -167,7 +167,7 @@ func (p *KVProcessor) getSrcChainHeader(ctx context.Context, height int64) (ibce
return srcHeader, nil
}

func (p *KVProcessor) getUpdateClientMsg(ctx context.Context, srcHeader ibcexported.Header) (sdk.Msg, error) {
func (p *KVProcessor) getUpdateClientMsg(ctx context.Context, srcHeader *tmclient.Header) (sdk.Msg, error) {
start := time.Now()
// Construct UpdateClient msg
var updateMsgRelayer provider.RelayerMessage
Expand Down
4 changes: 2 additions & 2 deletions internal/raw/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

rpcclienthttp "github.com/tendermint/tendermint/rpc/client/http"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
rpcclienthttp "github.com/cometbft/cometbft/rpc/client/http"
jsonrpcclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
)

const socketEndpoint = "/websocket"
Expand Down
3 changes: 1 addition & 2 deletions internal/relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func getChain(logger *zap.Logger, cfg cosmos.CosmosProviderConfig, homepath stri
if !ok {
return nil, fmt.Errorf("failed to patch CosmosProvider config (type cast failed)")
}
provConcrete.Config.KeyDirectory = homepath

provConcrete.PCfg.KeyDirectory = homepath
return relayer.NewChain(logger, prov, debug), nil
}
2 changes: 1 addition & 1 deletion internal/relay/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

tmtypes "github.com/tendermint/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"

neutronmetrics "github.com/neutron-org/neutron-query-relayer/internal/metrics"

Expand Down
5 changes: 2 additions & 3 deletions internal/relay/trusted_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package relay

import (
"context"

"github.com/cosmos/ibc-go/v4/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

// TrustedHeaderFetcher able to get trusted headers for a given height
type TrustedHeaderFetcher interface {
// Fetch returns only one trusted Header for specified height
Fetch(ctx context.Context, height uint64) (exported.Header, error)
Fetch(ctx context.Context, height uint64) (*tmclient.Header, error)
}
2 changes: 1 addition & 1 deletion internal/relay/txprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package relay
import (
"context"

ctypes "github.com/tendermint/tendermint/rpc/core/types"
ctypes "github.com/cometbft/cometbft/rpc/core/types"

neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
)
Expand Down
16 changes: 10 additions & 6 deletions internal/submit/tx_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"strings"
"sync"

tmtypes "github.com/tendermint/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"go.uber.org/zap"

"github.com/cosmos/cosmos-sdk/api/tendermint/abci"
"cosmossdk.io/api/tendermint/abci"
rpcclient "github.com/cometbft/cometbft/rpc/client"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtxtypes "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
rpcclient "github.com/tendermint/tendermint/rpc/client"

"github.com/neutron-org/neutron-query-relayer/internal/config"
)
Expand All @@ -47,8 +47,8 @@ type TxSender struct {
logger *zap.Logger
}

func TestKeybase(chainID string, keyringRootDir string) (keyring.Keyring, error) {
keybase, err := keyring.New(chainID, "test", keyringRootDir, nil)
func TestKeybase(chainID string, keyringRootDir string, cdc codec.Codec) (keyring.Keyring, error) {
keybase, err := keyring.New(chainID, "test", keyringRootDir, nil, cdc)
if err != nil {
return keybase, fmt.Errorf("error creating keybase for chainId=%s and keyringRootDir=%s: %w", chainID, keyringRootDir, err)
}
Expand Down Expand Up @@ -171,7 +171,11 @@ func (txs *TxSender) SenderAddr() (string, error) {
return "", fmt.Errorf("could not fetch sender info from keychain with signKeyName=%s: %w", txs.signKeyName, err)
}

return info.GetAddress().String(), nil
addr, err := info.GetAddress()
if err != nil {
return "", fmt.Errorf("failed to get addr from pubkey: %w", err)
}
return addr.String(), nil
}

// queryAccount returns BaseAccount for given account address
Expand Down
2 changes: 1 addition & 1 deletion internal/subscriber/querier/client/query/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strconv"

ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/subscriber/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

instrumenters "github.com/neutron-org/neutron-query-relayer/internal/metrics"

"github.com/tendermint/tendermint/rpc/client/http"
tmtypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/cometbft/cometbft/rpc/client/http"
tmtypes "github.com/cometbft/cometbft/rpc/core/types"
"go.uber.org/zap"

rg "github.com/neutron-org/neutron-query-relayer/internal/registry"
Expand Down
8 changes: 4 additions & 4 deletions internal/subscriber/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"net/url"
"time"

tmhttp "github.com/cometbft/cometbft/rpc/client/http"
tmtypes "github.com/cometbft/cometbft/rpc/core/types"
jsonrpcclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
"github.com/cometbft/cometbft/types"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
tmhttp "github.com/tendermint/tendermint/rpc/client/http"
tmtypes "github.com/tendermint/tendermint/rpc/core/types"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
"go.uber.org/zap"

restclient "github.com/neutron-org/neutron-query-relayer/internal/subscriber/querier/client"
Expand Down
6 changes: 3 additions & 3 deletions internal/tmquerier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

abci "github.com/cometbft/cometbft/abci/types"
rpcclient "github.com/cometbft/cometbft/rpc/client"
rpcclienthttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/codec"
abci "github.com/tendermint/tendermint/abci/types"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpcclienthttp "github.com/tendermint/tendermint/rpc/client/http"

neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
)
Expand Down
24 changes: 14 additions & 10 deletions internal/trusted_headers/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package trusted_headers
import (
"context"
"fmt"
"github.com/avast/retry-go/v4"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/relayer/v2/relayer/provider"
"time"

"github.com/cosmos/relayer/v2/relayer/chains/cosmos"

neutronmetrics "github.com/neutron-org/neutron-query-relayer/internal/metrics"

"github.com/avast/retry-go/v4"
"github.com/cosmos/cosmos-sdk/types/query"
clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v4/modules/light-clients/07-tendermint/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/relayer/v2/relayer"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ func NewTrustedHeaderFetcher(neutronChain *relayer.Chain, targetChain *relayer.C
// FetchTrustedHeaderForHeight returns the best suitable TrustedHeader for given height
// Arguments:
// `height` - remote chain block height X = transaction with such block height
func (thf *TrustedHeaderFetcher) Fetch(ctx context.Context, height uint64) (header ibcexported.Header, err error) {
func (thf *TrustedHeaderFetcher) Fetch(ctx context.Context, height uint64) (header *tmclient.Header, err error) {
start := time.Now()

// tries to find height of the closest consensus state height that is less or equal than provided height
Expand Down Expand Up @@ -91,7 +92,7 @@ func (thf *TrustedHeaderFetcher) Fetch(ctx context.Context, height uint64) (head
// Arguments:
// `trustedHeight` - height of any consensus state that's height < supplied height
// `height` - remote chain height for a header
func (thf *TrustedHeaderFetcher) trustedHeaderAtHeight(ctx context.Context, trustedHeight *clienttypes.Height, height uint64) (ibcexported.Header, error) {
func (thf *TrustedHeaderFetcher) trustedHeaderAtHeight(ctx context.Context, trustedHeight *clienttypes.Height, height uint64) (*tmclient.Header, error) {
header, err := thf.retryGetLightSignedHeaderAtHeight(ctx, height)
if err != nil {
return nil, fmt.Errorf("could not get light header: %w", err)
Expand Down Expand Up @@ -182,17 +183,20 @@ func (thf *TrustedHeaderFetcher) retryGetLightSignedHeaderAtHeight(ctx context.C
var tmHeader *tmclient.Header

if err := retry.Do(func() error {
header, err := thf.targetChain.ChainProvider.GetLightSignedHeaderAtHeight(ctx, int64(height))
header, err := thf.targetChain.ChainProvider.QueryIBCHeader(ctx, int64(height))
if err != nil {
return err
}

tmp, ok := header.(*tmclient.Header)
tmp, ok := header.(provider.TendermintIBCHeader)
if !ok {
return fmt.Errorf("expected header of type *tmclient.Header, got %T", header)
return fmt.Errorf("expected header of type provider.TendermintIBCHeader, got %T", header)
}

tmHeader = tmp
tmHeader, err = tmp.TMHeader()
if err != nil {
return fmt.Errorf("failed to convert provider.TendermintIBCHeader to tmclient.Header: %w", err)
}
return nil
}, retry.Context(ctx), RtyAtt, RtyDel, RtyErr); err != nil {
return nil, fmt.Errorf(
Expand Down
6 changes: 3 additions & 3 deletions internal/txprocessor/txprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

neutronmetrics "github.com/neutron-org/neutron-query-relayer/internal/metrics"

tmtypes "github.com/cometbft/cometbft/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
tmtypes "github.com/tendermint/tendermint/types"
"go.uber.org/zap"

clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"

"github.com/neutron-org/neutron-query-relayer/internal/relay"
neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r TXProcessor) getTrustedHeader(ctx context.Context, height uint64) (
return nil, fmt.Errorf("failed to get header with trusted height: %w", err)
}

packedHeader, err = clienttypes.PackHeader(header)
packedHeader, err = clienttypes.PackClientMessage(header)
if err != nil {
return nil, fmt.Errorf("failed to pack header: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/txquerier/txquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/proto/tendermint/crypto"
"github.com/tendermint/tendermint/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/merkle"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/cometbft/cometbft/types"

"github.com/neutron-org/neutron-query-relayer/internal/relay"
neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
Expand Down
Loading

0 comments on commit cd76120

Please sign in to comment.