From 1ee79e56a5490539d220f8629c021d33d1e627c3 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 27 Apr 2023 03:27:11 +0800 Subject: [PATCH] fix: nil receiver initiate for path (#1177) * fix nil receiver initiate for path ensure path get written to config * add change doc --- CHANGELOG.md | 1 + cmd/appstate.go | 4 ++-- cmd/config.go | 8 ++++++-- cmd/paths.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 315deb42d..5752bf0fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * [\#466](https://github.com/cosmos/relayer/pull/466) Docs cleanup. * [\#506](https://github.com/cosmos/relayer/pull/506) Fix Timeout Handling on Relayer restart * [\#940](https://github.com/cosmos/relayer/pull/940) Add min-gas-amount parameter for chain configs, to workaround gas estimation failure. +* [\#1177](https://github.com/cosmos/relayer/pull/1177) Avoid panic due to nil map when add new path and ensure path get written to config. ## v0.9.3 diff --git a/cmd/appstate.go b/cmd/appstate.go index 4e0e057e8..d6378bb8a 100644 --- a/cmd/appstate.go +++ b/cmd/appstate.go @@ -94,7 +94,7 @@ func (a *appState) addPathFromFile(ctx context.Context, stderr io.Writer, file, return err } - return a.config.Paths.Add(name, p) + return a.config.AddPath(name, p) } // addPathFromUserInput manually prompts the user to specify all the path details. @@ -169,7 +169,7 @@ func (a *appState) addPathFromUserInput( return err } - return a.config.Paths.Add(name, path) + return a.config.AddPath(name, path) } func (a *appState) performConfigLockingOperation(ctx context.Context, operation func() error) error { diff --git a/cmd/config.go b/cmd/config.go index aca1061bc..5266a4685 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -28,7 +28,7 @@ import ( "reflect" "strings" "time" - + "github.com/cosmos/relayer/v2/relayer" "github.com/cosmos/relayer/v2/relayer/chains/cosmos" "github.com/cosmos/relayer/v2/relayer/chains/penumbra" @@ -545,6 +545,10 @@ func checkPathEndConflict(pathID, direction string, oldPe, newPe *relayer.PathEn // AddPath adds an additional path to the config func (c *Config) AddPath(name string, path *relayer.Path) (err error) { + // Ensure path is initialized. + if c.Paths == nil { + c.Paths = make(relayer.Paths) + } // Check if the path does not yet exist. oldPath, err := c.Paths.Get(name) if err != nil { @@ -668,4 +672,4 @@ func (c *Config) ValidateConnection(ctx context.Context, chain *relayer.Chain, h } return nil -} \ No newline at end of file +} diff --git a/cmd/paths.go b/cmd/paths.go index 0c99c8233..640414fa5 100644 --- a/cmd/paths.go +++ b/cmd/paths.go @@ -255,7 +255,7 @@ $ %s pth n ibc-0 ibc-1 demo-path`, appName, appName)), } name := args[2] - if err = a.config.Paths.Add(name, p); err != nil { + if err = a.config.AddPath(name, p); err != nil { return err } return nil