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

chore: remove cosmos/relayer dependency #429

Merged
merged 22 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup more
Lazar955 committed Jan 21, 2025
commit 28b7931a922c61e71c3f7cfb04f510b5c4a56e27
46 changes: 0 additions & 46 deletions client/relayer/app_module.go

This file was deleted.

3 changes: 1 addition & 2 deletions client/relayer/codec.go
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ var ModuleBasics = []module.AppModuleBasic{
upgrade.AppModuleBasic{},
transfer.AppModuleBasic{},
ibc.AppModuleBasic{},
AppModuleBasic{},
stride.AppModuleBasic{},
ibcfee.AppModuleBasic{},
}
@@ -64,7 +63,7 @@ type Codec struct {
Amino *codec.LegacyAmino
}

func MakeCodec(moduleBasics []module.AppModuleBasic, extraCodecs []string, accBech32Prefix, valBech32Prefix string) Codec {
func MakeCodec(moduleBasics []module.AppModuleBasic, accBech32Prefix, valBech32Prefix string) Codec {
modBasic := module.NewBasicManager(moduleBasics...)
encodingConfig := MakeCodecConfig(accBech32Prefix, valBech32Prefix)
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
49 changes: 5 additions & 44 deletions client/relayer/provider.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
"github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
"github.com/strangelove-ventures/cometbft-client/client"
"go.uber.org/zap"
@@ -68,28 +67,15 @@ type CosmosProvider struct {
Keybase keyring.Keyring
KeyringOptions []keyring.Option
RPCClient RPCClient
//LightProvider provtypes.Provider
Input io.Reader
Output io.Writer
Cdc Codec

//nextAccountSeq uint64
feegrantMu sync.Mutex
Input io.Reader
Output io.Writer
Cdc Codec
feegrantMu sync.Mutex

// the map key is the TX signer, which can either be 'default' (provider key) or a feegrantee
// the purpose of the map is to lock on the signer from TX creation through submission,
// thus making TX sequencing errors less likely.
walletStateMap map[string]*WalletState

// metrics to monitor the provider
TotalFees sdk.Coins
totalFeesMu sync.Mutex

// for comet < v0.37, decode tm events as base64 todo remove this
cometLegacyEncoding bool

// for comet < v0.38, use legacy RPC client for ResultsBlockResults todo remove this
cometLegacyBlockResults bool
}

func (pc CosmosProviderConfig) BroadcastMode() BroadcastMode {
@@ -125,7 +111,7 @@ func (pc CosmosProviderConfig) NewProvider(log *zap.Logger, homepath string, cha
walletStateMap: map[string]*WalletState{},

// TODO: this is a bit of a hack, we should probably have a better way to inject modules
Cdc: MakeCodec(pc.Modules, pc.ExtraCodecs, pc.AccountPrefix, pc.AccountPrefix+"valoper"),
Cdc: MakeCodec(pc.Modules, pc.AccountPrefix, pc.AccountPrefix+"valoper"),
}

return cp, nil
@@ -167,11 +153,6 @@ func (cc *CosmosProvider) Timeout() string {
return cc.PCfg.Timeout
}

// CommitmentPrefix returns the commitment prefix for Cosmos
func (cc *CosmosProvider) CommitmentPrefix() commitmenttypes.MerklePrefix {
return defaultChainPrefix
}

// Address returns the chains configured address as a string
func (cc *CosmosProvider) Address() (string, error) {
info, err := cc.Keybase.Key(cc.PCfg.Key)
@@ -200,20 +181,6 @@ func (cc *CosmosProvider) MustEncodeAccAddr(addr sdk.AccAddress) string {
return enc
}

// AccountFromKeyOrAddress returns an account from either a key or an address.
// If 'keyOrAddress' is the empty string, this returns the default key's address.
func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk.AccAddress, err error) {
switch {
case keyOrAddress == "":
out, err = cc.GetKeyAddress(cc.PCfg.Key)
case cc.KeyExists(keyOrAddress):
out, err = cc.GetKeyAddress(keyOrAddress)
default:
out, err = sdk.GetFromBech32(keyOrAddress, cc.PCfg.AccountPrefix)
}
return
}

// SetRpcAddr sets the rpc-addr for the chain.
// It will fail if the rpcAddr is invalid(not a url).
func (cc *CosmosProvider) SetRpcAddr(rpcAddr string) error {
@@ -248,15 +215,9 @@ func (cc *CosmosProvider) Init(ctx context.Context) error {
return err
}

//lightprovider, err := prov.New(cc.PCfg.ChainID, cc.PCfg.RPCAddr) todo check if needed
//if err != nil {
// return err
//}

rpcClient := NewRPCClient(c)

cc.RPCClient = rpcClient
//cc.LightProvider = lightprovider
cc.Keybase = keybase

return nil
21 changes: 0 additions & 21 deletions client/relayer/query.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import (
"context"
"fmt"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"strconv"
@@ -43,7 +42,7 @@
return consumerUnbondingPeriod, nil
}

//Attempt Staking query.

Check failure on line 45 in client/relayer/query.go

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
unbondingPeriod, stakingParamsErr := cc.queryParamsSubspaceTime(ctx, "staking", "UnbondingTime")
if stakingParamsErr == nil {
return unbondingPeriod, nil
@@ -61,23 +60,3 @@
return 0,
fmt.Errorf("failed to query unbonding period from ccvconsumer, staking & fallback : %w: %s : %s", consumerErr, stakingParamsErr.Error(), err.Error())
}

// parseEventsFromResponseDeliverTx parses the events from a ResponseDeliverTx and builds a slice
// of provider.RelayerEvent's.
func parseEventsFromResponseDeliverTx(events []abci.Event) []RelayerEvent {
var rlyEvents []RelayerEvent

for _, event := range events {
attributes := make(map[string]string)
for _, attribute := range event.Attributes {
attributes[attribute.Key] = attribute.Value
}

rlyEvents = append(rlyEvents, RelayerEvent{
EventType: event.Type,
Attributes: attributes,
})
}

return rlyEvents
}
8 changes: 0 additions & 8 deletions client/relayer/tx.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@
"time"

"github.com/avast/retry-go/v4"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
)

// Variables used for retries
@@ -43,15 +42,8 @@
errUnknown = "unknown"
)

// Default IBC settings
var (
defaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
)

// Strings for parsing events
var (
spTag = "send_packet"
waTag = "write_acknowledgement"
srcChanTag = "packet_src_channel"
dstChanTag = "packet_dst_channel"
)
@@ -196,7 +188,7 @@

if len(callbacks) > 0 {
for _, cb := range callbacks {
//Call each callback in order since waitForTx is already invoked asyncronously

Check failure on line 191 in client/relayer/tx.go

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
cb(rlyResp, nil)
}
}

Unchanged files with check annotations Beta

// MarshalLogArray satisfies the zapcore.ArrayMarshaler interface.
func (es loggableEvents) MarshalLogArray(enc zapcore.ArrayEncoder) error {
for _, e := range es {
enc.AppendObject(e)

Check failure on line 57 in client/relayer/chain_provider.go

GitHub Actions / lint_test / lint

Error return value of `enc.AppendObject` is not checked (errcheck)
}
return nil
}
enc.AddString("codespace", r.Codespace)
enc.AddUint32("code", r.Code)
enc.AddString("data", r.Data)
enc.AddArray("events", loggableEvents(r.Events))

Check failure on line 69 in client/relayer/chain_provider.go

GitHub Actions / lint_test / lint

Error return value of `enc.AddArray` is not checked (errcheck)
return nil
}
if lastGranteeIdx >= 0 && lastGranteeIdx <= len(cc.PCfg.FeeGrants.ManagedGrantees)-1 {
txSignerKey = cc.PCfg.FeeGrants.ManagedGrantees[lastGranteeIdx]
cc.PCfg.FeeGrants.GranteeLastSignerIndex = cc.PCfg.FeeGrants.GranteeLastSignerIndex + 1

Check failure on line 28 in client/relayer/feegrant.go

GitHub Actions / lint_test / lint

assignOp: replace `cc.PCfg.FeeGrants.GranteeLastSignerIndex = cc.PCfg.FeeGrants.GranteeLastSignerIndex + 1` with `cc.PCfg.FeeGrants.GranteeLastSignerIndex++` (gocritic)
// Restart the round-robin at 0 if we reached the end of the list of grantees
if cc.PCfg.FeeGrants.GranteeLastSignerIndex == len(cc.PCfg.FeeGrants.ManagedGrantees) {
}
// Make a copy since we may continue to the warning
errorFields := append(fields, zap.Error(err))

Check failure on line 65 in client/relayer/log.go

GitHub Actions / lint_test / lint

appendAssign: append result not assigned to the same slice (gocritic)
cc.log.Error(
"Failed sending cosmos transaction",
errorFields...,
type CosmosMessage struct {
Msg sdk.Msg
SetSigner func(string) //callback to update the Msg Signer field

Check failure on line 14 in client/relayer/msg.go

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
FeegrantDisabled bool //marks whether this message type should ALWAYS disable feegranting (use the default signer)

Check failure on line 15 in client/relayer/msg.go

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
}
func NewCosmosMessage(msg sdk.Msg, optionalSetSigner func(string)) RelayerMessage {
"client.Context.Invoke: height (%d) from %q must be >= 0", height, grpctypes.GRPCBlockHeightHeader)
}
}

Check failure on line 115 in client/relayer/grpc_query.go

GitHub Actions / lint_test / lint

unnecessary trailing newline (whitespace)
height, err := GetHeightFromMetadata(md)
if err != nil {
return k.Name == name
}

Check failure on line 16 in client/relayer/keys.go

GitHub Actions / lint_test / lint

unnecessary trailing newline (whitespace)
// GetKeyAddress returns the account address representation for the currently configured key.
func (cc *CosmosProvider) GetKeyAddress(key string) (sdk.AccAddress, error) {