From bcea912646e4da2a60a610221895f9582b7a7d23 Mon Sep 17 00:00:00 2001 From: John Letey Date: Thu, 30 Nov 2023 19:03:00 +0100 Subject: [PATCH] chore: improvements to `v4-ics` branch (#883) (cherry picked from commit cfbca40ab8ce067eec691a6f5a82084eaa1078bb) # Conflicts: # relayer/hermes/hermes_config.go # relayer/hermes/hermes_relayer.go --- relayer/hermes/hermes_config.go | 75 ++++++++++++++++++++++++++++---- relayer/hermes/hermes_relayer.go | 55 ++++++++++++++++++++--- relayer/hermes/hermes_types.go | 14 ++++++ 3 files changed, 128 insertions(+), 16 deletions(-) diff --git a/relayer/hermes/hermes_config.go b/relayer/hermes/hermes_config.go index 5f6d0b4e4..ad5c23bfe 100644 --- a/relayer/hermes/hermes_config.go +++ b/relayer/hermes/hermes_config.go @@ -19,6 +19,7 @@ func NewConfig(chainConfigs ...ChainConfig) Config { } chains = append(chains, Chain{ +<<<<<<< HEAD ID: chainCfg.ChainID, RPCAddr: hermesCfg.rpcAddr, GrpcAddr: fmt.Sprintf("http://%s", hermesCfg.grpcAddr), @@ -28,6 +29,20 @@ func NewConfig(chainConfigs ...ChainConfig) Config { BatchDelay: "500ms"}, 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", + }, + RPCTimeout: "10s", + TrustedNode: false, +>>>>>>> cfbca40 (chore: improvements to `v4-ics` branch (#883)) AccountPrefix: chainCfg.Bech32Prefix, KeyName: hermesCfg.keyName, AddressType: AddressType{ @@ -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 { @@ -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 { @@ -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"` } @@ -161,6 +192,7 @@ type TrustThreshold struct { } type Chain struct { +<<<<<<< HEAD ID string `toml:"id"` RPCAddr string `toml:"rpc_addr"` GrpcAddr string `toml:"grpc_addr"` @@ -182,4 +214,29 @@ type Chain struct { TrustingPeriod string `toml:"trusting_period"` TrustThreshold TrustThreshold `toml:"trust_threshold"` MemoPrefix string `toml:"memo_prefix,omitempty"` +======= + 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)) } diff --git a/relayer/hermes/hermes_relayer.go b/relayer/hermes/hermes_relayer.go index fc133db82..de70b085d 100644 --- a/relayer/hermes/hermes_relayer.go +++ b/relayer/hermes/hermes_relayer.go @@ -18,7 +18,11 @@ import ( const ( hermes = "hermes" defaultContainerImage = "ghcr.io/informalsystems/hermes" +<<<<<<< HEAD DefaultContainerVersion = "1.6.0" +======= + DefaultContainerVersion = "v1.7.1" +>>>>>>> cfbca40 (chore: improvements to `v4-ics` branch (#883)) hermesDefaultUidGid = "1001:1001" hermesHome = "/home/hermes" @@ -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 { @@ -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 } @@ -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 } @@ -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 } @@ -289,8 +321,8 @@ 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 @@ -298,8 +330,8 @@ func getClientIdFromStdout(stdout []byte) (string, error) { 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 @@ -307,6 +339,15 @@ func getConnectionIDsFromStdout(stdout []byte) (string, string, error) { 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 diff --git a/relayer/hermes/hermes_types.go b/relayer/hermes/hermes_types.go index 0a13c286c..2648625ea 100644 --- a/relayer/hermes/hermes_types.go +++ b/relayer/hermes/hermes_types.go @@ -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"`