From bafd99f7d04612c11ef04f8651a85c3c92eeef87 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 17:21:16 +0700 Subject: [PATCH 1/7] fix band client --- relayer/app.go | 4 ++-- relayer/band/client.go | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/relayer/app.go b/relayer/app.go index 5f78b5e..70adf03 100644 --- a/relayer/app.go +++ b/relayer/app.go @@ -80,10 +80,10 @@ func (a *App) Init(ctx context.Context) error { return err } - // initialize band client + // initialize band client; if error due to init band client, log and continue if a.Config != nil { if err := a.initBandClient(); err != nil { - return err + a.Log.Debug("Cannot initialize band client", zap.Error(err)) } } diff --git a/relayer/band/client.go b/relayer/band/client.go index bfe5400..c06e1fe 100644 --- a/relayer/band/client.go +++ b/relayer/band/client.go @@ -70,6 +70,11 @@ func NewClient(ctx cosmosclient.Context, queryClient *QueryClient, log *zap.Logg // Connect connects to the Band chain using the provided RPC endpoints. func (c *client) Connect(timeout uint) error { + // Return if there are no RPC endpoints + if len(c.RpcEndpoints) == 0 { + return nil + } + for _, rpcEndpoint := range c.RpcEndpoints { // Create a new HTTP client for the specified node URI client, err := httpclient.NewWithTimeout(rpcEndpoint, "/websocket", timeout) @@ -78,12 +83,6 @@ func (c *client) Connect(timeout uint) error { continue // Try the next endpoint if there's an error } - // Start the client to establish a connection - if err = client.Start(); err != nil { - c.Log.Error("Failed to start client", zap.String("rpcEndpoint", rpcEndpoint), zap.Error(err)) - continue // Try the next endpoint if starting the client fails - } - // Create a new client context and configure it with necessary parameters encodingConfig := MakeEncodingConfig() ctx := cosmosclient.Context{}. @@ -99,7 +98,7 @@ func (c *client) Connect(timeout uint) error { return nil } - return nil + return fmt.Errorf("failed to connect to Band Chain") } // GetTunnel gets tunnel info from band client @@ -246,7 +245,7 @@ func (c *client) GetTunnels(ctx context.Context) ([]types.Tunnel, error) { return tunnels, nil } -// unpackAny unpacks the provided *codectypes.Any into the specified interface. +// UnpackAny unpacks the provided *codectypes.Any into the specified interface. func (c *client) UnpackAny(any *codectypes.Any, target interface{}) error { err := c.Context.InterfaceRegistry.UnpackAny(any, target) if err != nil { From 681c8789b92eb2bc0e1830ec1cec268d60616a80 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 22:07:28 +0700 Subject: [PATCH 2/7] fix init and config --- relayer/app.go | 103 ++++++++++++++++++++++++++-------------------- relayer/config.go | 4 +- 2 files changed, 60 insertions(+), 47 deletions(-) diff --git a/relayer/app.go b/relayer/app.go index 70adf03..b607ea1 100644 --- a/relayer/app.go +++ b/relayer/app.go @@ -75,40 +75,56 @@ func (a *App) Init(ctx context.Context) error { } } - // initialize target chains + // load passphrase from .env file or system environment variables + a.EnvPassphrase = a.loadEnvPassphrase() + + // if config is not initialized, return + if a.Config == nil { + return nil + } + + // initialize target chain clients. if err := a.initTargetChains(); err != nil { return err } - // initialize band client; if error due to init band client, log and continue - if a.Config != nil { - if err := a.initBandClient(); err != nil { - a.Log.Debug("Cannot initialize band client", zap.Error(err)) - } + // initialize band chain client + if err := a.initBandClient(); err != nil { + return err } - a.EnvPassphrase = a.loadEnvPassphrase() - return nil } // initBandClient establishes connection to rpc endpoints. func (a *App) initBandClient() error { - c := band.NewClient(cosmosclient.Context{}, nil, a.Log, a.Config.BandChain.RpcEndpoints) - if err := c.Connect(uint(a.Config.BandChain.Timeout)); err != nil { + a.BandClient = band.NewClient(cosmosclient.Context{}, nil, a.Log, a.Config.BandChain.RpcEndpoints) + + // connect to band chain, if error occurs, log the error as debug and continue + if err := a.BandClient.Connect(uint(a.Config.BandChain.Timeout)); err != nil { + a.Log.Error("Cannot connect to BandChain", zap.Error(err)) return err } - a.BandClient = c + return nil } // InitLogger initializes the logger with the given log level. func (a *App) initLogger(configLogLevel string) error { - logLevel := a.Viper.GetString("log-level") + // Assign log level based on the following priority: + // 1. debug flag + // 2. log-level flag from viper + // 3. log-level from configuration object. + // 4. given log level from the input. + logLevel := configLogLevel + logLevelViper := a.Viper.GetString("log-level") + if a.Viper.GetBool("debug") { logLevel = "debug" - } else if logLevel == "" { - logLevel = configLogLevel + } else if logLevelViper != "" { + logLevel = logLevelViper + } else if a.Config != nil { + logLevel = a.Config.Global.LogLevel } // initialize logger only if user run command "start" or log level is "debug" @@ -128,10 +144,6 @@ func (a *App) initLogger(configLogLevel string) error { // InitTargetChains initializes the target chains. func (a *App) initTargetChains() error { a.targetChains = make(chains.ChainProviders) - if a.Config == nil || a.Config.TargetChains == nil { - a.Log.Error("Target chains not found in config") - return nil - } for chainName, chainConfig := range a.Config.TargetChains { cp, err := chainConfig.NewChainProvider(chainName, a.Log, a.HomePath, a.Debug) @@ -145,15 +157,19 @@ func (a *App) initTargetChains() error { a.targetChains[chainName] = cp } + return nil } // LoadConfigFile reads config file into a.Config if file is present. func (a *App) LoadConfigFile() error { cfgPath := path.Join(a.HomePath, configFolderName, configFileName) - if _, err := os.Stat(cfgPath); err != nil { - // don't return error if file doesn't exist + + // check if file doesn't exist, exit the function as the config may not be initialized. + if _, err := os.Stat(cfgPath); os.IsNotExist(err) { return nil + } else if err != nil { + return err } // read the config from config path @@ -162,12 +178,6 @@ func (a *App) LoadConfigFile() error { return err } - if a.Log == nil { - if err := a.initLogger(cfg.Global.LogLevel); err != nil { - return err - } - } - // save configuration a.Config = cfg @@ -211,6 +221,8 @@ func (a *App) InitConfigFile(homePath string, customFilePath string) error { if err = os.Mkdir(homePath, os.ModePerm); err != nil { return err } + } else if err != nil { + return err } // Create the config folder if doesn't exist @@ -218,6 +230,8 @@ func (a *App) InitConfigFile(homePath string, customFilePath string) error { if err = os.Mkdir(cfgDir, os.ModePerm); err != nil { return err } + } else if err != nil { + return err } // Create the file and write the default config to the given location. @@ -264,8 +278,7 @@ func (a *App) QueryTunnelInfo(ctx context.Context, tunnelID uint64) (*types.Tunn return nil, fmt.Errorf("config is not initialized") } - c := a.BandClient - tunnel, err := c.GetTunnel(ctx, tunnelID) + tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID) if err != nil { return nil, err } @@ -278,17 +291,15 @@ func (a *App) QueryTunnelInfo(ctx context.Context, tunnelID uint64) (*types.Tunn tunnel.IsActive, ) - targetChain := tunnel.TargetChainID - targetAddr := tunnel.TargetAddress + cp, exists := a.targetChains[bandChainInfo.TargetChainID] + if !exists { + a.Log.Debug("Target chain provider not found", zap.String("chain_id", bandChainInfo.TargetChainID)) + return types.NewTunnel(bandChainInfo, nil), nil + } - var tunnelChainInfo *chainstypes.Tunnel - cp, ok := a.targetChains[targetChain] - if ok { - var err error - tunnelChainInfo, err = cp.QueryTunnelInfo(ctx, tunnelID, targetAddr) - if err != nil { - return nil, err - } + tunnelChainInfo, err := cp.QueryTunnelInfo(ctx, tunnelID, bandChainInfo.TargetAddress) + if err != nil { + return nil, err } return types.NewTunnel( @@ -303,16 +314,16 @@ func (a *App) QueryTunnelPacketInfo(ctx context.Context, tunnelID uint64, sequen return nil, fmt.Errorf("config is not initialized") } - c := a.BandClient - return c.GetTunnelPacket(ctx, tunnelID, sequence) + return a.BandClient.GetTunnelPacket(ctx, tunnelID, sequence) } +// AddChainConfig adds a new chain configuration to the config file. func (a *App) AddChainConfig(chainName string, filePath string) error { if a.Config == nil { return fmt.Errorf("config does not exist: %s", a.HomePath) } - if _, exist := a.Config.TargetChains[chainName]; exist { + if _, exists := a.Config.TargetChains[chainName]; exists { return fmt.Errorf("existing chain name : %s", chainName) } @@ -335,6 +346,7 @@ func (a *App) AddChainConfig(chainName string, filePath string) error { return os.WriteFile(cfgPath, b, 0o600) } +// DeleteChainConfig deletes the chain configuration from the config file. func (a *App) DeleteChainConfig(chainName string) error { if a.Config == nil { return fmt.Errorf("config does not exist: %s", a.HomePath) @@ -358,6 +370,7 @@ func (a *App) DeleteChainConfig(chainName string) error { return os.WriteFile(cfgPath, b, 0o600) } +// GetChainConfig retrieves the chain configuration by given chain name. func (a *App) GetChainConfig(chainName string) (chains.ChainProviderConfig, error) { if a.Config == nil { return nil, fmt.Errorf("config does not exist: %s", a.HomePath) @@ -602,8 +615,8 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error { } for _, tunnel := range tunnels { - chainProvider, ok := a.targetChains[tunnel.TargetChainID] - if !ok { + chainProvider, exists := a.targetChains[tunnel.TargetChainID] + if !exists { return fmt.Errorf("target chain provider not found: %s", tunnel.TargetChainID) } @@ -646,8 +659,8 @@ func (a *App) Relay(ctx context.Context, tunnelID uint64) error { return err } - chainProvider, ok := a.targetChains[tunnel.TargetChainID] - if !ok { + chainProvider, exists := a.targetChains[tunnel.TargetChainID] + if !exists { return fmt.Errorf("target chain provider not found: %s", tunnel.TargetChainID) } diff --git a/relayer/config.go b/relayer/config.go index 484028c..9d5e409 100644 --- a/relayer/config.go +++ b/relayer/config.go @@ -42,8 +42,8 @@ type ConfigInputWrapper struct { // ParseChainProviderConfig converts a TOMLWrapper object to a ChainProviderConfig object. func ParseChainProviderConfig(w ChainProviderConfigWrapper) (chains.ChainProviderConfig, error) { - typeName, ok := w["chain_type"].(string) - if !ok { + typeName, exists := w["chain_type"].(string) + if !exists { return nil, fmt.Errorf("chain_type is required") } chainType := chains.ToChainType(typeName) From df8d00c94c015f2e0ba7a8048cf34cef7c6e1bb8 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 22:49:56 +0700 Subject: [PATCH 3/7] fix tunnel relayer --- relayer/app.go | 68 +++++++++++++++++++++------------------ relayer/config.go | 4 +-- relayer/scheduler.go | 8 +++-- relayer/tunnel_relayer.go | 15 +++++---- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/relayer/app.go b/relayer/app.go index b607ea1..2f1b206 100644 --- a/relayer/app.go +++ b/relayer/app.go @@ -291,8 +291,8 @@ func (a *App) QueryTunnelInfo(ctx context.Context, tunnelID uint64) (*types.Tunn tunnel.IsActive, ) - cp, exists := a.targetChains[bandChainInfo.TargetChainID] - if !exists { + cp, ok := a.targetChains[bandChainInfo.TargetChainID] + if !ok { a.Log.Debug("Target chain provider not found", zap.String("chain_id", bandChainInfo.TargetChainID)) return types.NewTunnel(bandChainInfo, nil), nil } @@ -323,7 +323,7 @@ func (a *App) AddChainConfig(chainName string, filePath string) error { return fmt.Errorf("config does not exist: %s", a.HomePath) } - if _, exists := a.Config.TargetChains[chainName]; exists { + if _, ok := a.Config.TargetChains[chainName]; ok { return fmt.Errorf("existing chain name : %s", chainName) } @@ -352,7 +352,7 @@ func (a *App) DeleteChainConfig(chainName string) error { return fmt.Errorf("config does not exist: %s", a.HomePath) } - if _, exist := a.Config.TargetChains[chainName]; !exist { + if _, ok := a.Config.TargetChains[chainName]; !ok { return fmt.Errorf("not existing chain name : %s", chainName) } @@ -378,7 +378,7 @@ func (a *App) GetChainConfig(chainName string) (chains.ChainProviderConfig, erro chainProviders := a.Config.TargetChains - if _, exist := chainProviders[chainName]; !exist { + if _, ok := chainProviders[chainName]; !ok { return nil, fmt.Errorf("not existing chain name : %s", chainName) } @@ -562,26 +562,10 @@ func (a *App) validatePassphrase(envPassphrase string) error { func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error { a.Log.Info("Starting tunnel relayer") - isSyncTunnelsAllowed := false - // query tunnels - var tunnels []bandtypes.Tunnel - if len(tunnelIDs) == 0 { - var err error - tunnels, err = a.BandClient.GetTunnels(ctx) - isSyncTunnelsAllowed = true - if err != nil { - return err - } - } else { - tunnels = make([]bandtypes.Tunnel, 0, len(tunnelIDs)) - for _, tunnelID := range tunnelIDs { - tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID) - if err != nil { - return err - } - tunnels = append(tunnels, *tunnel) - } + tunnels, err := a.getTunnels(ctx, tunnelIDs) + if err != nil { + a.Log.Error("Cannot get tunnels", zap.Error(err)) } if len(tunnels) == 0 { @@ -589,13 +573,12 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error { return fmt.Errorf("no tunnel ID provided") } - // initialize the tunnel relayer - tunnelRelayers := []*TunnelRelayer{} - + // validate passphrase if err := a.validatePassphrase(a.EnvPassphrase); err != nil { return err } + // initialize target chain providers for chainName, chainProvider := range a.targetChains { if err := chainProvider.LoadFreeSenders(a.HomePath, a.EnvPassphrase); err != nil { a.Log.Error("Cannot load keys in target chain", @@ -614,9 +597,11 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error { } } + // initialize the tunnel relayer + tunnelRelayers := []*TunnelRelayer{} for _, tunnel := range tunnels { - chainProvider, exists := a.targetChains[tunnel.TargetChainID] - if !exists { + chainProvider, ok := a.targetChains[tunnel.TargetChainID] + if !ok { return fmt.Errorf("target chain provider not found: %s", tunnel.TargetChainID) } @@ -632,6 +617,7 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error { } // start the tunnel relayers + isSyncTunnelsAllowed := (len(tunnelIDs) == 0) scheduler := NewScheduler( a.Log, tunnelRelayers, @@ -659,8 +645,8 @@ func (a *App) Relay(ctx context.Context, tunnelID uint64) error { return err } - chainProvider, exists := a.targetChains[tunnel.TargetChainID] - if !exists { + chainProvider, ok := a.targetChains[tunnel.TargetChainID] + if !ok { return fmt.Errorf("target chain provider not found: %s", tunnel.TargetChainID) } @@ -683,3 +669,23 @@ func (a *App) Relay(ctx context.Context, tunnelID uint64) error { return tr.CheckAndRelay(ctx) } + +// GetTunnels retrieves the list of tunnels by given tunnel IDs. If no tunnel ID is provided, +// get all tunnels +func (a *App) getTunnels(ctx context.Context, tunnelIDs []uint64) ([]bandtypes.Tunnel, error) { + if len(tunnelIDs) == 0 { + return a.BandClient.GetTunnels(ctx) + } + + tunnels := make([]bandtypes.Tunnel, 0, len(tunnelIDs)) + for _, tunnelID := range tunnelIDs { + tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID) + if err != nil { + return nil, err + } + + tunnels = append(tunnels, *tunnel) + } + + return tunnels, nil +} diff --git a/relayer/config.go b/relayer/config.go index 9d5e409..484028c 100644 --- a/relayer/config.go +++ b/relayer/config.go @@ -42,8 +42,8 @@ type ConfigInputWrapper struct { // ParseChainProviderConfig converts a TOMLWrapper object to a ChainProviderConfig object. func ParseChainProviderConfig(w ChainProviderConfigWrapper) (chains.ChainProviderConfig, error) { - typeName, exists := w["chain_type"].(string) - if !exists { + typeName, ok := w["chain_type"].(string) + if !ok { return nil, fmt.Errorf("chain_type is required") } chainType := chains.ToChainType(typeName) diff --git a/relayer/scheduler.go b/relayer/scheduler.go index 92f93cb..1b9ac4e 100644 --- a/relayer/scheduler.go +++ b/relayer/scheduler.go @@ -59,12 +59,13 @@ func NewScheduler( // Start starts all tunnel relayers func (s *Scheduler) Start(ctx context.Context) error { ticker := time.NewTicker(s.CheckingPacketInterval) + defer ticker.Stop() + syncTunnelTicker := time.NewTicker(s.SyncTunnelsInterval) + defer syncTunnelTicker.Stop() // execute once we start the scheduler. s.Execute(ctx) - defer ticker.Stop() - defer syncTunnelTicker.Stop() for { select { @@ -156,7 +157,7 @@ func (s *Scheduler) SyncTunnels(ctx context.Context) { return } - s.Log.Info("Starting sync tunnels") + s.Log.Info("Start syncing new tunnels") tunnels, err := s.BandClient.GetTunnels(ctx) if err != nil { s.Log.Error("Failed to fetch tunnels from Band Chain", zap.Error(err)) @@ -179,6 +180,7 @@ func (s *Scheduler) SyncTunnels(ctx context.Context) { ) continue } + tr := NewTunnelRelayer( s.Log, tunnels[i].ID, diff --git a/relayer/tunnel_relayer.go b/relayer/tunnel_relayer.go index 4d6fc88..fc30fc2 100644 --- a/relayer/tunnel_relayer.go +++ b/relayer/tunnel_relayer.go @@ -100,18 +100,19 @@ func (t *TunnelRelayer) CheckAndRelay(ctx context.Context) (err error) { signing = packet.IncomingGroupSigning } - switch tsstypes.SigningStatus(tsstypes.SigningStatus_value[signing.Status]) { - case tsstypes.SIGNING_STATUS_FALLEN: - err := fmt.Errorf("signing status is fallen") - t.Log.Error("Failed to relay packet", zap.Error(err), zap.Uint64("sequence", seq)) - return err - - case tsstypes.SIGNING_STATUS_WAITING: + // Check signing status; if it is waiting, wait for the completion of the EVM signature. + // If it is not success (Failed or Undefined), return error. + signingStatus := tsstypes.SigningStatus(tsstypes.SigningStatus_value[signing.Status]) + if signingStatus == tsstypes.SIGNING_STATUS_WAITING { t.Log.Info( "The current packet must wait for the completion of the EVM signature", zap.Uint64("sequence", seq), ) return nil + } else if signingStatus != tsstypes.SIGNING_STATUS_SUCCESS { + err := fmt.Errorf("signing status is not success") + t.Log.Error("Failed to relay packet", zap.Error(err), zap.Uint64("sequence", seq)) + return err } if err := t.TargetChainProvider.RelayPacket(ctx, packet); err != nil { From 97f5d7a9e712e383a257005b162817887ad10499 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 22:56:49 +0700 Subject: [PATCH 4/7] fix comment --- relayer/app.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/relayer/app.go b/relayer/app.go index 2f1b206..a8106e8 100644 --- a/relayer/app.go +++ b/relayer/app.go @@ -385,6 +385,7 @@ func (a *App) GetChainConfig(chainName string) (chains.ChainProviderConfig, erro return chainProviders[chainName], nil } +// AddKey adds a new key to the chain provider. func (a *App) AddKey( chainName string, keyName string, @@ -420,6 +421,7 @@ func (a *App) AddKey( return keyOutput, nil } +// DeleteKey deletes the key from the chain provider. func (a *App) DeleteKey(chainName string, keyName string) error { if a.Config == nil { return fmt.Errorf("config does not exist: %s", a.HomePath) @@ -442,6 +444,7 @@ func (a *App) DeleteKey(chainName string, keyName string) error { return cp.DeleteKey(a.HomePath, keyName, a.EnvPassphrase) } +// ExportKey exports the private key from the chain provider. func (a *App) ExportKey(chainName string, keyName string) (string, error) { if a.Config == nil { return "", fmt.Errorf("config does not exist: %s", a.HomePath) @@ -469,6 +472,7 @@ func (a *App) ExportKey(chainName string, keyName string) (string, error) { return privateKey, nil } +// ListKeys retrieves the list of keys from the chain provider. func (a *App) ListKeys(chainName string) ([]*chainstypes.Key, error) { if a.Config == nil { return make([]*chainstypes.Key, 0), fmt.Errorf("config does not exist: %s", a.HomePath) @@ -483,6 +487,7 @@ func (a *App) ListKeys(chainName string) ([]*chainstypes.Key, error) { return cp.Listkeys(), nil } +// ShowKey retrieves the key information from the chain provider. func (a *App) ShowKey(chainName string, keyName string) (string, error) { if a.Config == nil { return "", fmt.Errorf("config does not exist: %s", a.HomePath) @@ -500,6 +505,7 @@ func (a *App) ShowKey(chainName string, keyName string) (string, error) { return cp.ShowKey(keyName), nil } +// QueryBalance retrieves the balance of the key from the chain provider. func (a *App) QueryBalance(ctx context.Context, chainName string, keyName string) (*big.Int, error) { if a.Config == nil { return nil, fmt.Errorf("config does not exist: %s", a.HomePath) From a261ee42e905e044fed2752dfa637ee7a1d3c182 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 23:20:37 +0700 Subject: [PATCH 5/7] fix ListKeys --- internal/relayertest/mocks/chain_provider.go | 24 ++++++++++---------- relayer/app.go | 2 +- relayer/chains/evm/keys.go | 4 ++-- relayer/chains/provider.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/relayertest/mocks/chain_provider.go b/internal/relayertest/mocks/chain_provider.go index 4ff9364..621b8f2 100644 --- a/internal/relayertest/mocks/chain_provider.go +++ b/internal/relayertest/mocks/chain_provider.go @@ -115,18 +115,18 @@ func (mr *MockChainProviderMockRecorder) IsKeyNameExist(keyName any) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsKeyNameExist", reflect.TypeOf((*MockChainProvider)(nil).IsKeyNameExist), keyName) } -// Listkeys mocks base method. -func (m *MockChainProvider) Listkeys() []*types0.Key { +// ListKeys mocks base method. +func (m *MockChainProvider) ListKeys() []*types0.Key { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Listkeys") + ret := m.ctrl.Call(m, "ListKeys") ret0, _ := ret[0].([]*types0.Key) return ret0 } -// Listkeys indicates an expected call of Listkeys. -func (mr *MockChainProviderMockRecorder) Listkeys() *gomock.Call { +// ListKeys indicates an expected call of ListKeys. +func (mr *MockChainProviderMockRecorder) ListKeys() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Listkeys", reflect.TypeOf((*MockChainProvider)(nil).Listkeys)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListKeys", reflect.TypeOf((*MockChainProvider)(nil).ListKeys)) } // LoadFreeSenders mocks base method. @@ -283,18 +283,18 @@ func (mr *MockKeyProviderMockRecorder) IsKeyNameExist(keyName any) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsKeyNameExist", reflect.TypeOf((*MockKeyProvider)(nil).IsKeyNameExist), keyName) } -// Listkeys mocks base method. -func (m *MockKeyProvider) Listkeys() []*types0.Key { +// ListKeys mocks base method. +func (m *MockKeyProvider) ListKeys() []*types0.Key { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Listkeys") + ret := m.ctrl.Call(m, "ListKeys") ret0, _ := ret[0].([]*types0.Key) return ret0 } -// Listkeys indicates an expected call of Listkeys. -func (mr *MockKeyProviderMockRecorder) Listkeys() *gomock.Call { +// ListKeys indicates an expected call of ListKeys. +func (mr *MockKeyProviderMockRecorder) ListKeys() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Listkeys", reflect.TypeOf((*MockKeyProvider)(nil).Listkeys)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListKeys", reflect.TypeOf((*MockKeyProvider)(nil).ListKeys)) } // LoadFreeSenders mocks base method. diff --git a/relayer/app.go b/relayer/app.go index a8106e8..411e5c6 100644 --- a/relayer/app.go +++ b/relayer/app.go @@ -484,7 +484,7 @@ func (a *App) ListKeys(chainName string) ([]*chainstypes.Key, error) { return make([]*chainstypes.Key, 0), fmt.Errorf("chain name does not exist: %s", chainName) } - return cp.Listkeys(), nil + return cp.ListKeys(), nil } // ShowKey retrieves the key information from the chain provider. diff --git a/relayer/chains/evm/keys.go b/relayer/chains/evm/keys.go index 7beae48..2dd2c7e 100644 --- a/relayer/chains/evm/keys.go +++ b/relayer/chains/evm/keys.go @@ -154,8 +154,8 @@ func (cp *EVMChainProvider) ExportPrivateKey(keyName, passphrase string) (string return hex.EncodeToString(crypto.FromECDSA(key.PrivateKey)), nil } -// Listkeys lists all keys. -func (cp *EVMChainProvider) Listkeys() []*chainstypes.Key { +// ListKeys lists all keys. +func (cp *EVMChainProvider) ListKeys() []*chainstypes.Key { res := make([]*chainstypes.Key, 0, len(cp.KeyInfo)) for keyName, address := range cp.KeyInfo { key := chainstypes.NewKey("", address, keyName) diff --git a/relayer/chains/provider.go b/relayer/chains/provider.go index dfb3c85..ad49740 100644 --- a/relayer/chains/provider.go +++ b/relayer/chains/provider.go @@ -54,7 +54,7 @@ type KeyProvider interface { DeleteKey(homePath, keyName, passphrase string) error // ListKeys lists all keys - Listkeys() []*chainstypes.Key + ListKeys() []*chainstypes.Key // ShowKey shows the address of the given key ShowKey(keyName string) string From 5241b8cd74bf266aea54477c710f7c82efd3aec9 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 23:23:45 +0700 Subject: [PATCH 6/7] remove private key from config --- internal/relayertest/testdata/chain_config.toml | 1 - internal/relayertest/testdata/custom_config.toml | 1 - internal/relayertest/testdata/custom_config_with_time_str.toml | 1 - internal/relayertest/testdata/default_with_chain_config.toml | 1 - relayer/chains/evm/config.go | 1 - 5 files changed, 5 deletions(-) diff --git a/internal/relayertest/testdata/chain_config.toml b/internal/relayertest/testdata/chain_config.toml index 19ae6f3..00ae1ef 100644 --- a/internal/relayertest/testdata/chain_config.toml +++ b/internal/relayertest/testdata/chain_config.toml @@ -4,7 +4,6 @@ max_retry = 3 query_timeout = 3000000000 chain_id = 31337 tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' -private_key = '' block_confirmation = 5 waiting_tx_duration = 3000000000 checking_tx_interval = 1000000000 diff --git a/internal/relayertest/testdata/custom_config.toml b/internal/relayertest/testdata/custom_config.toml index 87e4f0e..c146c42 100644 --- a/internal/relayertest/testdata/custom_config.toml +++ b/internal/relayertest/testdata/custom_config.toml @@ -18,7 +18,6 @@ query_timeout = 3000000000 execute_timeout = 3000000000 chain_id = 31337 tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' -private_key = '' block_confirmation = 5 waiting_tx_duration = 3000000000 liveliness_checking_interval = 900000000000 diff --git a/internal/relayertest/testdata/custom_config_with_time_str.toml b/internal/relayertest/testdata/custom_config_with_time_str.toml index efb3cff..87bb723 100644 --- a/internal/relayertest/testdata/custom_config_with_time_str.toml +++ b/internal/relayertest/testdata/custom_config_with_time_str.toml @@ -18,7 +18,6 @@ query_timeout = '3s' execute_timeout = '3s' chain_id = 31337 tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' -private_key = '' block_confirmation = 5 waiting_tx_duration = 3000000000 liveliness_checking_interval = '15m' diff --git a/internal/relayertest/testdata/default_with_chain_config.toml b/internal/relayertest/testdata/default_with_chain_config.toml index 7de744a..cd78c22 100644 --- a/internal/relayertest/testdata/default_with_chain_config.toml +++ b/internal/relayertest/testdata/default_with_chain_config.toml @@ -18,7 +18,6 @@ query_timeout = 3000000000 execute_timeout = 3000000000 chain_id = 31337 tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' -private_key = '' block_confirmation = 5 waiting_tx_duration = 3000000000 liveliness_checking_interval = 900000000000 diff --git a/relayer/chains/evm/config.go b/relayer/chains/evm/config.go index a47f8a5..9bf5c0f 100644 --- a/relayer/chains/evm/config.go +++ b/relayer/chains/evm/config.go @@ -14,7 +14,6 @@ var _ chains.ChainProviderConfig = &EVMChainProviderConfig{} type EVMChainProviderConfig struct { chains.BaseChainProviderConfig `mapstructure:",squash"` - PrivateKey string `mapstructure:"private_key" toml:"private_key"` BlockConfirmation uint64 `mapstructure:"block_confirmation" toml:"block_confirmation"` WaitingTxDuration time.Duration `mapstructure:"waiting_tx_duration" toml:"waiting_tx_duration"` LivelinessCheckingInterval time.Duration `mapstructure:"liveliness_checking_interval" toml:"liveliness_checking_interval"` From ebac0ba96de41ef7b4eabd4d84548d832d16fed0 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 16 Dec 2024 23:40:50 +0700 Subject: [PATCH 7/7] fix command --- cmd/chains.go | 2 +- cmd/config.go | 2 +- cmd/query.go | 2 +- cmd/root.go | 12 ++++++------ cmd/start.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/chains.go b/cmd/chains.go index 6bad572..83d2ac5 100644 --- a/cmd/chains.go +++ b/cmd/chains.go @@ -110,7 +110,7 @@ func chainsShowCmd(app *relayer.App) *cobra.Command { cmd := &cobra.Command{ Use: "show [chain_name]", Aliases: []string{"s"}, - Short: "Return a chain's configuration data", + Short: "Return chain's configuration data", Args: withUsage(cobra.ExactArgs(1)), Example: strings.TrimSpace(fmt.Sprintf(` $ %s ch s eth diff --git a/cmd/config.go b/cmd/config.go index 7df5763..787ccb2 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -57,7 +57,7 @@ func configInitCmd(app *relayer.App) *cobra.Command { cmd := &cobra.Command{ Use: "init", Aliases: []string{"i"}, - Short: "Create a default configuration at home directory path defined by --home", + Short: "Create a default configuration at home directory path", Args: withUsage(cobra.NoArgs), Example: strings.TrimSpace(fmt.Sprintf(` $ %s config init --home %s diff --git a/cmd/query.go b/cmd/query.go index 72e78f1..3c1d517 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -16,7 +16,7 @@ func queryCmd(app *relayer.App) *cobra.Command { cmd := &cobra.Command{ Use: "query", Aliases: []string{"q"}, - Short: "Query commands on source and destination chains.", + Short: "Query commands on source and destination chains", } cmd.AddCommand( diff --git a/cmd/root.go b/cmd/root.go index 0233a8e..7a803e4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,12 +33,12 @@ func NewRootCmd(log *zap.Logger) *cobra.Command { // RootCmd represents the base command when called without any subcommands rootCmd := &cobra.Command{ Use: appName, - Short: "This application relays tunnel messages to the target chains/contracts.", - Long: strings.TrimSpace(`falcon has: - 1. Configuration management for destination chains - 2. Key management for managing multiple keys for multiple chains - 3. transaction Execution functionality on destination chains. - 4. Query functionality on source and destination chains. + Short: "Falcon relays tss tunnel messages from BandChain to destination chains/smart contracts", + Long: strings.TrimSpace(`This application has: + 1. Configuration Management: Handles the configuration of the program. + 2. Key Management: Supports managing multiple keys across multiple chains. + 3. Transaction Execution: Enables executing transactions on destination chains. + 4. Query Functionality: Facilitates querying data from both source and destination chains. NOTE: Most of the commands have aliases that make typing them much quicker (i.e. 'falcon tx', 'falcon q', etc...)`), diff --git a/cmd/start.go b/cmd/start.go index 97557d2..519bc69 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -15,7 +15,7 @@ func startCmd(app *relayer.App) *cobra.Command { cmd := &cobra.Command{ Use: "start [tunnel_id...]", Aliases: []string{"st"}, - Short: "Start the falcon tunnel relayer system.", + Short: "Start the falcon tunnel relayer program", Args: withUsage(cobra.MinimumNArgs(0)), Example: strings.TrimSpace(fmt.Sprintf(` $ %s start # start relaying data from every tunnel being registered on source chain.