Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

feat: vanilla implementation #1

Merged
merged 3 commits into from
Nov 15, 2022
Merged

feat: vanilla implementation #1

merged 3 commits into from
Nov 15, 2022

Conversation

gitferry
Copy link
Contributor

@gitferry gitferry commented Nov 14, 2022

This PR creates a vanilla implementation of Babylon rpc client with most of the code copied from https://github.com/babylonchain/vigilante/blob/965384cd3a659e63662c7fa417c5ed51c0580a5b/babylonclient/client.go

Copy link
Member

@SebastianElvis SebastianElvis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! No blocker from my side. One minor thing is that could we copy the CI thing here as well?

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! The main comments are around the dependency of this repository to the vigilante one, which I think should not happen.

Also, do you think it would be better if we rename instances of client to rpcclient? I think it would make the point of this repository much clearer.

A README with some details about how this can be built and used would also be appreciated but it can happen on another PR.

.gitconfig Outdated
@@ -0,0 +1,2 @@
[url "ssh://[email protected]/"]
insteadOf = https://github.com/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this does not have a place in this repository. If someone wants to use this replacement rule, we can add instructions on how this can happen on the repository README.

MOCKGEN_REPO=github.com/golang/mock/mockgen
MOCKGEN_VERSION=v1.6.0
MOCKGEN_CMD=go run ${MOCKGEN_REPO}@${MOCKGEN_VERSION}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rules for building would also be useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, is there a usecase in which someone uses this client directly from this repository without anything else? Currently, I do not think we have such a usecase so a build rule might not be needed.

In the future, I can envision this client also providing a CLI interface in which someone can interact with a remote Babylon node (although the same can be accomplished through babylond commands so this would be a wrapper).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We should implement it as a command line tool just like lens did.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! An issue for that would be appreciated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

MOCKGEN_VERSION=v1.6.0
MOCKGEN_CMD=go run ${MOCKGEN_REPO}@${MOCKGEN_VERSION}

test:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this depend on the mocks getting generated by mock-gen? Not entirely familiar with the mockgen package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying we should re-generate mock files every time before we run tests? Not sure about that. It seems we can manually generate mock files once and upload them in the repo so that others do not need to generate them again, just like the protobuf files.

client/client.go Outdated
return nil, err
}
log.Debugf("Babylon key directory: %v", cfg.KeyDirectory)
log.Debugf("All Babylon addresses: %v", addrs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we retrieve the Babylon addresses? Is this some kind of sanity check? As they are not used anywhere else in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a sanity check. Any thoughts @SebastianElvis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reporter uses this address to submit txs to Babylon. The logs and thus retrieving addresses can be omitted though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure: Do we need to execute cc.ListAddresses() here? I don't see the addrs being used elsewhere other than logging here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, the accounts are retrieved just for logging.

client/client.go Outdated
"fmt"
"time"

"github.com/babylonchain/vigilante/config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the vigilante depends on the babylon client and the client depends on the vigilante, this might introduce a cyclic dependency.


// adapted from https://github.com/strangelove-ventures/lens/blob/v0.5.1/client/chain_client.go#L48-L63
// The notable difference is parsing the key directory
// TODO: key directory support for different types of keyring backend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a Github issue for that for easier tracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebastianElvis Not sure about this description. Could you please revisit this TODO and create an issue for tracking if it is needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, created #2

client/query.go Outdated
@@ -0,0 +1,173 @@
package client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the client aims to be able to perform all queries related to our modules, maybe we can have different query files for each one of the modules we implement.

@@ -0,0 +1,3 @@
package client_test

// TODO: mocks on queries for testing reporter/*.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reporter/.*go does not exist here.

@@ -0,0 +1,3 @@
package client_test

// TODO: mocks on txs for testing reporter/*.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

go.mod Outdated

require (
github.com/babylonchain/babylon v0.1.0
github.com/babylonchain/vigilante v0.1.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency should not exist imo.

@gitferry
Copy link
Contributor Author

gitferry commented Nov 14, 2022

Thanks, @SebastianElvis and @vitsalis for your comments. Please see the latest changes:

  1. added CI configs
  2. removed dependencies over vigilante -- copied Babylon config from the vigilante
  3. separate queries into different query files according to different Babylon modules.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the updates! Also, please enable CircleCI for the repository (looks like only the admin can do this -- which is probably you since you created the repo 😄 )

MOCKGEN_REPO=github.com/golang/mock/mockgen
MOCKGEN_VERSION=v1.6.0
MOCKGEN_CMD=go run ${MOCKGEN_REPO}@${MOCKGEN_VERSION}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! An issue for that would be appreciated


// QueryStakingParams queries staking module's parameters via ChainClient
// code is adapted from https://github.com/strangelove-ventures/lens/blob/v0.5.1/cmd/staking.go#L128-L149
func (c *Client) QueryStakingParams() (*stakingtypes.Params, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used here

@gitferry gitferry merged commit 871da1d into dev Nov 15, 2022
@gitferry gitferry deleted the vanilla-client branch November 15, 2022 01:27
@gitferry
Copy link
Contributor Author

@vitsalis I enabled CI but it failed due to a lack of build rules. Maybe it will work after we add CLI and add build rules in Makefile? I added issue #4 for this.

SebastianElvis pushed a commit that referenced this pull request Jan 21, 2024
* add new queries

* add rpc

* add more rpc

* more methods

* add comments

* remove space

* add comments

* add another arg
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants