-
Notifications
You must be signed in to change notification settings - Fork 367
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
Kava gRPC Client #1784
Kava gRPC Client #1784
Conversation
158c67e
to
d083188
Compare
} | ||
|
||
// NewClient creates a new KavaGrpcClient via a grpc url | ||
func NewClient(grpcUrl string) (*KavaGrpcClient, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend adding url as a field to the config struct above and taking that as the only input to this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
majority of the time the config won't be needed and is optional, so I think some benefit in splitting it as that allows the client to be created with less code. Thoughts?
Query *query.QueryClient | ||
|
||
// Utils for common queries (ie fetch an unpacked BaseAccount) | ||
*util.Util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest "sdk" as a more intention revealing name here as we're builidng a higher level interface for making common dApp workflows simpler without having to make n number of calls to multiple api's to stitch together the end result that a dApp developer or kava engineer writing tests would care about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so like client.sdk.BaseAccount
instead of client.BaseAccount
?
|
||
// NewUtil creates a new Util instance | ||
func NewUtil(query *query.QueryClient) *Util { | ||
return &Util{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm now I'm curious as to if we even need this util package and type - could be simpler to have the top level client use the query clients already associated with versus constructing this other client to make calls to the same api (e.g. the query client from
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
type KavaGrpcClient struct {
config KavaGrpcClientConfig
// Query clients for cosmos and kava modules
Query *query.QueryClient
already has access to the account client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the top level client has everything needed by util already so we can just write all utils (ie BaseAccount
) on the GrpcClient. I do think splitting the util stuff out into its own package is a good separation though, but I'm open to changing this behavior.
- Utilize utility functions for common queries (e.g., `client.BaseAccount(str)`). | ||
|
||
## Usage | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DracoLi found out that trying to use this client from another package (kava's ethermint forked) failed with error during go dependency resolution,
⋊> ~/f/k/e/scratch on patch-ethermint-gas-tracking ⨯ go get github.com/kava-labs/kava/
client/grpc@260d43291e4321e1b6ddb18abc2381436c8f7bc5
go: downloading github.com/tendermint/tendermint v0.34.27
go: downloading github.com/gogo/protobuf v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/gogo/protobuf/gogoproto: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/gogo/protobuf/grpc: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/gogo/protobuf/proto: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/gogo/protobuf/types: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/tendermint/tendermint/abci/types: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/tendermint/tendermint/proto/tendermint/p2p: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/tendermint/tendermint/proto/tendermint/types: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/tendermint/tendermint/proto/tendermint/version: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/tendermint/tendermint/rpc/core/types: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/auth/types imports
github.com/tendermint/tendermint/crypto: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/evidence/types imports
github.com/tendermint/tendermint/crypto/tmhash: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/evidence/types imports
github.com/tendermint/tendermint/libs/bytes: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/staking/types imports
github.com/gogo/protobuf/protoc-gen-gogo/descriptor: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/staking/types imports
github.com/tendermint/tendermint/proto/tendermint/crypto: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/ibc-go/v6/modules/apps/transfer/types imports
github.com/gogo/protobuf/jsonpb: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/ibc-go/v6/modules/apps/transfer/types imports
github.com/tendermint/tendermint/types: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/kava-labs/kava/x/bep3/types imports
github.com/tendermint/tendermint/types/time: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/tendermint/tendermint/libs/json: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/tendermint/tendermint/libs/log: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/client imports
github.com/tendermint/tendermint/libs/cli: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/client imports
github.com/tendermint/tendermint/mempool: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/client imports
github.com/tendermint/tendermint/rpc/client: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/client imports
github.com/tendermint/tendermint/rpc/client/http: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/client/rpc imports
github.com/tendermint/tendermint/p2p: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/auth/types imports
github.com/cosmos/cosmos-sdk/crypto/codec imports
github.com/tendermint/tendermint/crypto/encoding: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/auth/types imports
github.com/cosmos/cosmos-sdk/crypto/codec imports
github.com/tendermint/tendermint/crypto/sr25519: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/upgrade/types imports
github.com/cosmos/cosmos-sdk/store/types imports
github.com/tendermint/tendermint/crypto/merkle: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/cosmos-sdk/server/api imports
github.com/tendermint/tendermint/rpc/jsonrpc/server: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/cosmos-sdk/x/genutil imports
github.com/tendermint/tendermint/config: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/cosmos-sdk/x/genutil imports
github.com/tendermint/tendermint/crypto/ed25519: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/cosmos-sdk/x/genutil imports
github.com/tendermint/tendermint/libs/os: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/cosmos-sdk/x/genutil imports
github.com/tendermint/tendermint/privval: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/evmos/ethermint/server/config imports
github.com/tendermint/tendermint/libs/strings: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/client/grpc/tmservice imports
github.com/cosmos/cosmos-sdk/baseapp imports
github.com/cosmos/cosmos-sdk/snapshots imports
github.com/gogo/protobuf/io: reading github.com/gogo/protobuf/go.mod at revision v1.3.3: unknown revision v1.3.3
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/query imports
github.com/cosmos/cosmos-sdk/x/upgrade/types imports
github.com/cosmos/cosmos-sdk/store/types imports
github.com/cosmos/cosmos-sdk/store/internal/proofs imports
github.com/tendermint/tendermint/libs/rand: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/ibc-go/v6/modules/core imports
github.com/cosmos/ibc-go/v6/modules/core/02-client/keeper imports
github.com/tendermint/tendermint/light: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/cosmos/ibc-go/v6/modules/core/02-client imports
github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint/types imports
github.com/tendermint/tendermint/libs/math: reading github.com/tendermint/tendermint/go.mod at revision v0.34.27: unknown revision v0.34.27
go: github.com/kava-labs/kava/client/grpc imports
github.com/kava-labs/kava/client/grpc/util imports
github.com/kava-labs/kava/app imports
github.com/kava-labs/kava/x/evmutil imports
github.com/kava-labs/kava/x/evmutil/client/cli imports
github.com/evmos/ethermint/crypto/hd imports
github.com/btcsuite/btcutil/hdkeychain imports
github.com/btcsuite/btcd/btcec: cannot find module providing package github.com/btcsuite/btcd/btcec
only fix was to update the go.mod with the same replaces as we have in kava's go.mod
replace (
// Use the cosmos keyring code
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Use rocksdb 7.9.2
github.com/cometbft/cometbft-db => github.com/kava-labs/cometbft-db v0.7.0-rocksdb-v7.9.2-kava.1
// Use cosmos-sdk fork with backported fix for unsafe-reset-all, staking transfer events, and custom tally handler support
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.46.11-kava.1
// See https://github.com/cosmos/cosmos-sdk/pull/13093
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.21.1-0.20231127220940-f5eaf3a08c1a
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
// Use the cosmos modified protobufs
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
// Use cometbft fork of tendermint
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27
// Indirect dependencies still use tendermint/tm-db
github.com/tendermint/tm-db => github.com/kava-labs/tm-db v0.6.7-kava.3
)
probably worth calling out in the readme to save someone else time in resolving it (ideally this is why I would like to see this client in a seperate package, by keeping it in the kava monorepo we aren't really dogfooding the client and feeling / fixing pain points that a third party developer would go through cc @karzak @Behdad-Kava )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it not being a separate package is leading to import cycles trying to use this in ethermint as the client for talking to the cosmos sdk...ending up falling back to copy pasting all the code in this package for setting up the grpc connection, defeating the very purpose of this client in terms of being the one true / last implementation of a go client for talking to the kava grpc endpoints
this is the code I would be able to write if this was a standalone package, now it's gonna be a lot more lines / copy pasting / duplication of effort
// handle edge cases in differences between traced tx status
// and actual tx status when it was executed as part of a block
if jsonResult["failed"] != transaction.Failed {
jsonResult["failed"] = transaction.Failed
_, exists := jsonResult["error"]
if !exists {
// fallback to tendermint tx indexer
query := fmt.Sprintf("%s.%s='%s'", evmtypes.TypeMsgEthereumTx, evmtypes.AttributeKeyEthereumTxHash, hash.Hex())
resTxs, err := b.clientCtx.Client.TxSearch(b.ctx, query, false, nil, nil, "")
if err != nil {
panic(err)
}
txMe := resTxs.Txs[0]
cosmosHash := txMe.Hash
grpcUrl := "http://localhost:9090"
kava, err := kavaCosmosClient.NewClient(grpcUrl)
if err != nil {
panic(err)
}
res, err := kava.Query.Tx.GetTx(context.Background(), &txtypes.GetTxRequest{Hash: cosmosHash.String()})
if err != nil {
panic(err)
}
jsonResult["error"] = res.TxResponse.RawLog
jsonResult["gas_used"] = res.TxResponse.GasUsed
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts:
- Regarding the replace rules - I encountered this as well when looking to set up auction bot to use the updated kava module. I think we can definitely add some docs for adding kava module to a new project.
- For using the kava module in the modules it depends on (ie ethermint) - I think we will still get this import cycle issue even if the client is standalone? Since ethermint will now depend on the grpc client module, which is dependent on kava module, which depends on ethermint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my two cents 😄
attempting to use the grpc client in ethermint is not the same as including it in a service that interacts with the chain. i don't think a dependency of kava should attempt to import this grpc client. it's intended end user is a service interacting with the chain, not the chain interacting with itself
regarding the replaces, it's been my experience that you always need to replaces to match kava's. not sure if there's a more ergonomic way around it..
Description
See grpc client readme
Checklist