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

edit rpc endpoints using command #1292

Merged
merged 7 commits into from
Oct 12, 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
2 changes: 1 addition & 1 deletion .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
id: set-matrix
run: |
# Run the command and convert its output to a JSON array
TESTS=$(cd interchaintest && go test -list ^TestScenario | grep -v "^ok " | jq -R -s -c 'split("\n")[:-1]')
TESTS=$(cd interchaintest && go test -list ^TestScenario ./... | grep -v "^ok " | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${TESTS}" >> $GITHUB_OUTPUT

# Note : This job will not start until prepare-scenario-matrix completes sucessfully
Expand Down
13 changes: 13 additions & 0 deletions cmd/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,16 @@ func (a *appState) useKey(chainName, key string) error {
return nil
})
}

func (a *appState) useRpcAddr(chainName string, rpcAddr string) error {

_, exists := a.config.Chains[chainName]
if !exists {
return fmt.Errorf("chain %s not found in config", chainName)
}

return a.performConfigLockingOperation(context.Background(), func() error {
a.config.Chains[chainName].ChainProvider.SetRpcAddr(rpcAddr)
return nil
})
}
29 changes: 29 additions & 0 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,35 @@ func chainsCmd(a *appState) *cobra.Command {
chainsAddrCmd(a),
chainsAddDirCmd(a),
cmdChainsConfigure(a),
cmdChainsUseRpcAddr(a),
)

return cmd
}

func cmdChainsUseRpcAddr(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "set-rpc-addr chain_name valid_rpc_url",
Aliases: []string{"rpc"},
Short: "Sets chain's rpc address",
Args: withUsage(cobra.ExactArgs(2)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s chains set-rpc-addr ibc-0 https://abc.xyz.com:443
$ %s ch set-rpc-addr ibc-0 https://abc.xyz.com:443`, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
chainName := args[0]
rpc_address := args[1]
if !isValidURL(rpc_address) {
return invalidRpcAddr(rpc_address)
}

return a.useRpcAddr(chainName, rpc_address)
},
}

return cmd
}

func chainsAddrCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "address chain_name",
Expand Down Expand Up @@ -513,3 +537,8 @@ func addChainsFromRegistry(ctx context.Context, a *appState, forceAdd, testnet b
)
return nil
}

func isValidURL(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != ""
}
4 changes: 4 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func errChainNotFound(chainName string) error {
return fmt.Errorf("chain with name \"%s\" not found in config. consider running `rly chains add %s`", chainName, chainName)
}

func invalidRpcAddr(rpcAddr string) error {
return fmt.Errorf("rpc-addr %s is not valid", rpcAddr)
}

var (
errMultipleAddFlags = errors.New("expected either --file/-f OR --url/u, found multiple")
errInvalidTestnetFlag = errors.New("cannot use --testnet with --file/-f OR --url/u, must be used alone")
Expand Down
7 changes: 7 additions & 0 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ func (cc *CosmosProvider) Sprint(toPrint proto.Message) (string, error) {
return string(out), nil
}

// SetPCAddr 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 {
cc.PCfg.RPCAddr = rpcAddr
return nil
}

// Init initializes the keystore, RPC client, amd light client provider.
// Once initialization is complete an attempt to query the underlying node's tendermint version is performed.
// NOTE: Init must be called after creating a new instance of CosmosProvider.
Expand Down
7 changes: 7 additions & 0 deletions relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func (cc *PenumbraProvider) Sprint(toPrint proto.Message) (string, error) {
return string(out), nil
}

// SetPCAddr sets the rpc-addr for the chain.
// It will fail if the rpcAddr is invalid(not a url).
func (cc *PenumbraProvider) SetRpcAddr(rpcAddr string) error {
cc.PCfg.RPCAddr = rpcAddr
return nil
}

// Init initializes the keystore, RPC client, amd light client provider.
// Once initialization is complete an attempt to query the underlying node's tendermint version is performed.
// NOTE: Init must be called after creating a new instance of CosmosProvider.
Expand Down
2 changes: 2 additions & 0 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ type ChainProvider interface {
TrustingPeriod(ctx context.Context) (time.Duration, error)
WaitForNBlocks(ctx context.Context, n int64) error
Sprint(toPrint proto.Message) (string, error)

SetRpcAddr(rpcAddr string) error
}

// Do we need intermediate types? i.e. can we use the SDK types for both substrate and cosmos?
Expand Down
Loading