Skip to content

Commit

Permalink
chore: improvements to v4-ics branch (#883)
Browse files Browse the repository at this point in the history
(cherry picked from commit cfbca40)

# Conflicts:
#	relayer/hermes/hermes_config.go
#	relayer/hermes/hermes_relayer.go
  • Loading branch information
johnletey authored and mergify[bot] committed Nov 30, 2023
1 parent d6b47e1 commit bcea912
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 16 deletions.
75 changes: 66 additions & 9 deletions relayer/hermes/hermes_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewConfig(chainConfigs ...ChainConfig) Config {
}

chains = append(chains, Chain{
<<<<<<< HEAD

Check failure on line 22 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected <<, expected expression

Check failure on line 22 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected <<, expected expression

Check failure on line 22 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected <<, expected expression

Check failure on line 22 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected <<, expected expression

Check failure on line 22 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '<<' (typecheck)
ID: chainCfg.ChainID,
RPCAddr: hermesCfg.rpcAddr,
GrpcAddr: fmt.Sprintf("http://%s", hermesCfg.grpcAddr),

Check failure on line 25 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 25 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 25 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 25 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected ) in composite literal; possibly missing comma or }
Expand All @@ -28,6 +29,20 @@ func NewConfig(chainConfigs ...ChainConfig) Config {
BatchDelay: "500ms"},

Check failure on line 29 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected comma at end of statement

Check failure on line 29 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected comma at end of statement

Check failure on line 29 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected comma at end of statement

Check failure on line 29 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected comma at end of statement
RPCTimeout: "10s",
TrustedNode: true,
=======
ID: chainCfg.ChainID,
Type: "CosmosSdk",
CCVConsumerChain: false,
RPCAddr: hermesCfg.rpcAddr,
GrpcAddr: fmt.Sprintf("http://%s", hermesCfg.grpcAddr),
EventSource: EventSource{
Mode: "push",
URL: strings.ReplaceAll(fmt.Sprintf("%s/websocket", hermesCfg.rpcAddr), "http", "ws"),
BatchDelay: "500ms",
},

Check failure on line 42 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected comma after top level declaration

Check failure on line 42 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected comma after top level declaration

Check failure on line 42 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected comma after top level declaration

Check failure on line 42 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected comma after top level declaration
RPCTimeout: "10s",
TrustedNode: false,
>>>>>>> cfbca40 (chore: improvements to `v4-ics` branch (#883))

Check failure on line 45 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

invalid character U+0023 '#'

Check failure on line 45 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

invalid character U+0023 '#'

Check failure on line 45 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

invalid character U+0023 '#'

Check failure on line 45 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

invalid character U+0023 '#'

Check failure on line 45 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)
AccountPrefix: chainCfg.Bech32Prefix,
KeyName: hermesCfg.keyName,
AddressType: AddressType{
Expand Down Expand Up @@ -84,16 +99,20 @@ func NewConfig(chainConfigs ...ChainConfig) Config {
Telemetry: Telemetry{
Enabled: false,
},
TracingServer: TracingServer{
Enabled: false,
},
Chains: chains,
}
}

type Config struct {
Global Global `toml:"global"`
Mode Mode `toml:"mode"`
Rest Rest `toml:"rest"`
Telemetry Telemetry `toml:"telemetry"`
Chains []Chain `toml:"chains"`
Global Global `toml:"global"`
Mode Mode `toml:"mode"`
Rest Rest `toml:"rest"`
Telemetry Telemetry `toml:"telemetry"`
TracingServer TracingServer `toml:"tracing_server"`
Chains []Chain `toml:"chains"`
}

type Global struct {
Expand All @@ -115,10 +134,11 @@ type Channels struct {
}

type Packets struct {
Enabled bool `toml:"enabled"`
ClearInterval int `toml:"clear_interval"`
ClearOnStart bool `toml:"clear_on_start"`
TxConfirmation bool `toml:"tx_confirmation"`
Enabled bool `toml:"enabled"`
ClearInterval int `toml:"clear_interval"`
ClearOnStart bool `toml:"clear_on_start"`
TxConfirmation bool `toml:"tx_confirmation"`
AutoRegisterCounterpartyPayee bool `toml:"auto_register_counterparty_payee"`
}

type Mode struct {
Expand All @@ -140,6 +160,17 @@ type Telemetry struct {
Port int `toml:"port"`
}

type TracingServer struct {
Enabled bool `toml:"enabled"`
Port int `toml:"port"`
}

type EventSource struct {
Mode string `toml:"mode"`
URL string `toml:"url"`
BatchDelay string `toml:"batch_delay"`
}

type AddressType struct {
Derivation string `toml:"derivation"`
}
Expand All @@ -161,6 +192,7 @@ type TrustThreshold struct {
}

type Chain struct {
<<<<<<< HEAD

Check failure on line 195 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 195 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 195 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 195 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected <<, expected field name or embedded type
ID string `toml:"id"`
RPCAddr string `toml:"rpc_addr"`
GrpcAddr string `toml:"grpc_addr"`
Expand All @@ -182,4 +214,29 @@ type Chain struct {
TrustingPeriod string `toml:"trusting_period"`
TrustThreshold TrustThreshold `toml:"trust_threshold"`
MemoPrefix string `toml:"memo_prefix,omitempty"`
=======

Check failure on line 217 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 217 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 217 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 217 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected ==, expected field name or embedded type
ID string `toml:"id"`
Type string `toml:"type"`
CCVConsumerChain bool `toml:"ccv_consumer_chain"`
RPCAddr string `toml:"rpc_addr"`
GrpcAddr string `toml:"grpc_addr"`
EventSource EventSource `toml:"event_source"`
RPCTimeout string `toml:"rpc_timeout"`
TrustedNode bool `toml:"trusted_node"`
AccountPrefix string `toml:"account_prefix"`
KeyName string `toml:"key_name"`
AddressType AddressType `toml:"address_type"`
StorePrefix string `toml:"store_prefix"`
DefaultGas int `toml:"default_gas"`
MaxGas int `toml:"max_gas"`
GasPrice GasPrice `toml:"gas_price"`
GasMultiplier float64 `toml:"gas_multiplier"`
MaxMsgNum int `toml:"max_msg_num"`
MaxTxSize int `toml:"max_tx_size"`
ClockDrift string `toml:"clock_drift"`
MaxBlockTime string `toml:"max_block_time"`
TrustingPeriod string `toml:"trusting_period"`
TrustThreshold TrustThreshold `toml:"trust_threshold"`
MemoPrefix string `toml:"memo_prefix,omitempty"`
>>>>>>> cfbca40 (chore: improvements to `v4-ics` branch (#883))

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

invalid character U+0023 '#'

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

invalid character U+0023 '#'

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / test-conformance

invalid character U+0023 '#'

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 241 in relayer/hermes/hermes_config.go

View workflow job for this annotation

GitHub Actions / unit-tests

invalid character U+0023 '#'
}
55 changes: 48 additions & 7 deletions relayer/hermes/hermes_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import (
const (
hermes = "hermes"
defaultContainerImage = "ghcr.io/informalsystems/hermes"
<<<<<<< HEAD

Check failure on line 21 in relayer/hermes/hermes_relayer.go

View workflow job for this annotation

GitHub Actions / lint

expected 'IDENT', found '<<' (typecheck)
DefaultContainerVersion = "1.6.0"
=======
DefaultContainerVersion = "v1.7.1"
>>>>>>> cfbca40 (chore: improvements to `v4-ics` branch (#883))

Check failure on line 25 in relayer/hermes/hermes_relayer.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)
hermesDefaultUidGid = "1001:1001"
hermesHome = "/home/hermes"
Expand Down Expand Up @@ -90,6 +94,34 @@ func (r *Relayer) AddChainConfiguration(ctx context.Context, rep ibc.RelayerExec
return r.validateConfig(ctx, rep)
}

func (r *Relayer) MarkChainAsConsumer(ctx context.Context, chainID string) error {
bz, err := r.ReadFileFromHomeDir(ctx, hermesConfigPath)
if err != nil {
return err
}

var cfg Config
err = toml.Unmarshal(bz, &cfg)
if err != nil {
return err
}

for i, chain := range cfg.Chains {
if chain.ID == chainID {
chain.CCVConsumerChain = true
cfg.Chains[i] = chain
break
}
}

bz, err = toml.Marshal(cfg)
if err != nil {
return err
}

return r.WriteFileToHomeDir(ctx, hermesConfigPath, bz)
}

// LinkPath performs the operations that happen when a path is linked. This includes creating clients, creating connections
// and establishing a channel. This happens across multiple operations rather than a single link path cli command.
func (r *Relayer) LinkPath(ctx context.Context, rep ibc.RelayerExecReporter, pathName string, channelOpts ibc.CreateChannelOptions, clientOpts ibc.CreateClientOptions) error {
Expand Down Expand Up @@ -137,7 +169,7 @@ func (r *Relayer) CreateConnections(ctx context.Context, rep ibc.RelayerExecRepo
return res.Err
}

chainAConnectionID, chainBConnectionID, err := getConnectionIDsFromStdout(res.Stdout)
chainAConnectionID, chainBConnectionID, err := GetConnectionIDsFromStdout(res.Stdout)
if err != nil {
return err
}
Expand Down Expand Up @@ -174,7 +206,7 @@ func (r *Relayer) CreateClients(ctx context.Context, rep ibc.RelayerExecReporter
return res.Err
}

chainAClientId, err := getClientIdFromStdout(res.Stdout)
chainAClientId, err := GetClientIdFromStdout(res.Stdout)
if err != nil {
return err
}
Expand All @@ -189,7 +221,7 @@ func (r *Relayer) CreateClients(ctx context.Context, rep ibc.RelayerExecReporter
return res.Err
}

chainBClientId, err := getClientIdFromStdout(res.Stdout)
chainBClientId, err := GetClientIdFromStdout(res.Stdout)
if err != nil {
return err
}
Expand Down Expand Up @@ -289,24 +321,33 @@ func extractJsonResult(stdout []byte) []byte {
return []byte(jsonOutput)
}

// getClientIdFromStdout extracts the client ID from stdout.
func getClientIdFromStdout(stdout []byte) (string, error) {
// GetClientIdFromStdout extracts the client ID from stdout.
func GetClientIdFromStdout(stdout []byte) (string, error) {
var clientCreationResult ClientCreationResponse
if err := json.Unmarshal(extractJsonResult(stdout), &clientCreationResult); err != nil {
return "", err
}
return clientCreationResult.Result.CreateClient.ClientID, nil
}

// getConnectionIDsFromStdout extracts the connectionIDs on both ends from the stdout.
func getConnectionIDsFromStdout(stdout []byte) (string, string, error) {
// GetConnectionIDsFromStdout extracts the connectionIDs on both ends from the stdout.
func GetConnectionIDsFromStdout(stdout []byte) (string, string, error) {
var connectionResponse ConnectionResponse
if err := json.Unmarshal(extractJsonResult(stdout), &connectionResponse); err != nil {
return "", "", err
}
return connectionResponse.Result.ASide.ConnectionID, connectionResponse.Result.BSide.ConnectionID, nil
}

// GetChannelIDsFromStdout extracts the channelIDs on both ends from stdout.
func GetChannelIDsFromStdout(stdout []byte) (string, string, error) {
var channelResponse ChannelCreationResponse
if err := json.Unmarshal(extractJsonResult(stdout), &channelResponse); err != nil {
return "", "", err
}
return channelResponse.Result.ASide.ChannelID, channelResponse.Result.BSide.ChannelID, nil
}

// parseRestoreKeyOutput extracts the address from the hermes output.
func parseRestoreKeyOutput(stdout string) string {
fullMatchIdx, addressGroupIdx := 0, 1
Expand Down
14 changes: 14 additions & 0 deletions relayer/hermes/hermes_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ type ConnectionSide struct {
ConnectionID string `json:"connection_id"`
}

// ChannelCreationResponse contains the minimum required values to extract the channel ids from a hermes response.
type ChannelCreationResponse struct {
Result CreateChannelResult `json:"result"`
}

type CreateChannelResult struct {
ASide ChannelSide `json:"a_side"`
BSide ChannelSide `json:"b_side"`
}

type ChannelSide struct {
ChannelID string `json:"channel_id"`
}

// ChannelOutputResult contains the minimum required channel values.
type ChannelOutputResult struct {
Result []ChannelResult `json:"result"`
Expand Down

0 comments on commit bcea912

Please sign in to comment.