From 923c886dc5b90f0855c956f85a31ee7609201655 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:24:13 +0700 Subject: [PATCH 1/7] Remove expanded --- stader-cli/service/migration.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 3b50572d7..147a25e54 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -6,7 +6,6 @@ import ( "os" "github.com/hashicorp/go-version" - "github.com/mitchellh/go-homedir" "github.com/stader-labs/stader-node/shared/services/stader" "github.com/urfave/cli" ) @@ -130,24 +129,13 @@ func upgradeFuncV142(c *cli.Context) error { cycleMerkleRewardFile := cfg.StaderNode.GetSpRewardCyclePath(RefreshingCycle, true) - expandedCycleMerkleRewardFile, err := homedir.Expand(cycleMerkleRewardFile) - if err != nil { - return fmt.Errorf("error expand cycleMerkleRewardFile: %w", err) - } - // Remove old cycle 5 proof - _, err = os.Stat(expandedCycleMerkleRewardFile) + _, err = os.Stat(cycleMerkleRewardFile) if err == nil { - if err = os.Remove(expandedCycleMerkleRewardFile); err != nil { + if err = os.Remove(cycleMerkleRewardFile); err != nil { return fmt.Errorf("error Remove old cycle 5: %w", err) } } - // Download new one - _, err = staderClient.DownloadSpMerkleProofs() - if err != nil { - return fmt.Errorf("error DownloadSpMerkleProofs: %w", err) - } - return nil } From 0f22fa6dec68133bc08cc755c491bbd0a4538d86 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:39:28 +0700 Subject: [PATCH 2/7] Put some log --- stader-cli/service/migration.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 147a25e54..1641026b4 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -131,10 +131,12 @@ func upgradeFuncV142(c *cli.Context) error { // Remove old cycle 5 proof _, err = os.Stat(cycleMerkleRewardFile) + fmt.Printf("Stat err: %+v \n", err) if err == nil { if err = os.Remove(cycleMerkleRewardFile); err != nil { return fmt.Errorf("error Remove old cycle 5: %w", err) } + fmt.Printf("Success remove %+v \n", cycleMerkleRewardFile) } return nil From a91113d90c255efd25a42be6c4163356511e3c42 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:42:41 +0700 Subject: [PATCH 3/7] Set non daemon --- stader-cli/service/migration.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 1641026b4..865daf341 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -6,6 +6,7 @@ import ( "os" "github.com/hashicorp/go-version" + "github.com/mitchellh/go-homedir" "github.com/stader-labs/stader-node/shared/services/stader" "github.com/urfave/cli" ) @@ -127,17 +128,28 @@ func upgradeFuncV142(c *cli.Context) error { return fmt.Errorf("error loading user settings: %w", err) } - cycleMerkleRewardFile := cfg.StaderNode.GetSpRewardCyclePath(RefreshingCycle, true) + cycleMerkleRewardFile := cfg.StaderNode.GetSpRewardCyclePath(RefreshingCycle, false) + + expandedCycleMerkleRewardFile, err := homedir.Expand(cycleMerkleRewardFile) + if err != nil { + return fmt.Errorf("error expand cycleMerkleRewardFile: %w", err) + } // Remove old cycle 5 proof - _, err = os.Stat(cycleMerkleRewardFile) + _, err = os.Stat(expandedCycleMerkleRewardFile) fmt.Printf("Stat err: %+v \n", err) if err == nil { - if err = os.Remove(cycleMerkleRewardFile); err != nil { + if err = os.Remove(expandedCycleMerkleRewardFile); err != nil { return fmt.Errorf("error Remove old cycle 5: %w", err) } fmt.Printf("Success remove %+v \n", cycleMerkleRewardFile) } + // Download new one + _, err = staderClient.DownloadSpMerkleProofs() + if err != nil { + return fmt.Errorf("error DownloadSpMerkleProofs: %w", err) + } + return nil } From 1bc8c1cb27d032a322f234451365e325cf4ba20b Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:46:36 +0700 Subject: [PATCH 4/7] Remove log --- stader-cli/service/migration.go | 1 - 1 file changed, 1 deletion(-) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 865daf341..9967f03d1 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -137,7 +137,6 @@ func upgradeFuncV142(c *cli.Context) error { // Remove old cycle 5 proof _, err = os.Stat(expandedCycleMerkleRewardFile) - fmt.Printf("Stat err: %+v \n", err) if err == nil { if err = os.Remove(expandedCycleMerkleRewardFile); err != nil { return fmt.Errorf("error Remove old cycle 5: %w", err) From 745ddaba873384e45f2c3d2cacd27866be2ec0a1 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:49:47 +0700 Subject: [PATCH 5/7] Fix can not found config --- stader-cli/service/migration.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 9967f03d1..83ce39ebb 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -55,13 +55,15 @@ func migrate(c *cli.Context) ([]ConfigUpgrader, error) { }, } - cfg, err := loadConfig(c) + staderClient, err := stader.NewClientFromCtx(c) + cfg, _, err := staderClient.LoadConfig() if err != nil { return nil, fmt.Errorf("error loading user settings: %w", err) } // cfg nill or version empty in case fresh install if cfg == nil || len(cfg.Version) == 0 { + fmt.Printf("Can not found config %+v\n", cfg) return nil, nil } From cab765afa7c8a1cc17af5bdc08dd77c1395898e2 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 19:56:24 +0700 Subject: [PATCH 6/7] Fix liting --- stader-cli/service/migration.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 83ce39ebb..7049c007c 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -56,6 +56,10 @@ func migrate(c *cli.Context) ([]ConfigUpgrader, error) { } staderClient, err := stader.NewClientFromCtx(c) + if err != nil { + return nil, fmt.Errorf("error NewClientFromCtx: %w", err) + } + cfg, _, err := staderClient.LoadConfig() if err != nil { return nil, fmt.Errorf("error loading user settings: %w", err) @@ -110,8 +114,8 @@ func upgradeFuncV140(c *cli.Context) error { if err != nil { return fmt.Errorf("error NewClientFromCtx: %w", err) } - err = staderClient.UpdateGuardianConfiguration(guardian) + err = staderClient.UpdateGuardianConfiguration(guardian) if err != nil { return fmt.Errorf("error NewClientFromCtx: %w", err) } From 26d65e43925240cc2399b96e526366697fe00ebd Mon Sep 17 00:00:00 2001 From: batphonghan Date: Thu, 2 Nov 2023 20:03:44 +0700 Subject: [PATCH 7/7] Refactor --- stader-cli/service/migration.go | 1 + 1 file changed, 1 insertion(+) diff --git a/stader-cli/service/migration.go b/stader-cli/service/migration.go index 7049c007c..5ff32ac6f 100644 --- a/stader-cli/service/migration.go +++ b/stader-cli/service/migration.go @@ -147,6 +147,7 @@ func upgradeFuncV142(c *cli.Context) error { if err = os.Remove(expandedCycleMerkleRewardFile); err != nil { return fmt.Errorf("error Remove old cycle 5: %w", err) } + fmt.Printf("Success remove %+v \n", cycleMerkleRewardFile) }