Skip to content

Commit

Permalink
Merge pull request #138 from stader-labs/1.4.2-hotfix
Browse files Browse the repository at this point in the history
Remove cycle 5 and download it
  • Loading branch information
batphonghan authored Nov 2, 2023
2 parents 86d9aa9 + 0785e15 commit afba869
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shared/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package shared

const BinaryBucket string = "/stader-node-build/permissionless"
const DockerAccount string = "staderlabs"
const StaderVersion string = "1.4.1"
const StaderVersion string = "1.4.2"

const Logo string = `
_____ _ _ _ _ 𝅺
Expand Down
48 changes: 48 additions & 0 deletions stader-cli/service/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package service
import (
_ "embed"
"fmt"
"os"

"github.com/hashicorp/go-version"
"github.com/mitchellh/go-homedir"
"github.com/stader-labs/stader-node/shared/services/stader"
"github.com/urfave/cli"
)

const RefreshingCycle = 5

type ConfigUpgrader struct {
version *version.Version
upgradeFunc func(c *cli.Context) error
Expand All @@ -30,6 +34,11 @@ func migrate(c *cli.Context) ([]ConfigUpgrader, error) {
return nil, err
}

v142, err := parseVersion("1.4.2")
if err != nil {
return nil, err
}

// Create the collection of upgraders
upgraders := []ConfigUpgrader{
{
Expand All @@ -40,6 +49,10 @@ func migrate(c *cli.Context) ([]ConfigUpgrader, error) {
version: v140,
upgradeFunc: upgradeFuncV140,
},
{
version: v142,
upgradeFunc: upgradeFuncV142,
},
}

cfg, err := loadConfig(c)
Expand Down Expand Up @@ -103,3 +116,38 @@ func upgradeFuncV140(c *cli.Context) error {

return nil
}

func upgradeFuncV142(c *cli.Context) error {
staderClient, err := stader.NewClientFromCtx(c)
if err != nil {
return fmt.Errorf("error NewClientFromCtx: %w", err)
}

cfg, _, err := staderClient.LoadConfig()
if err != nil {
return fmt.Errorf("error loading user settings: %w", err)
}

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)
if err == nil {
if err = os.Remove(expandedCycleMerkleRewardFile); 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
}

0 comments on commit afba869

Please sign in to comment.