Skip to content

Commit

Permalink
migrate v7 version config (#4761)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode authored Feb 11, 2022
1 parent 3417842 commit 94e15a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions pkg/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var versionMap = []versionInfo{
{version: 4, upgrade: Version4Upgrade},
{version: 5, upgrade: Version5Upgrade},
{version: 6, upgrade: Version6Upgrade},
{version: 7, upgrade: Version7Upgrade},
}

// TryToMigrate used to migrate data(db,config,file,etc) in local repo
Expand Down Expand Up @@ -188,3 +189,44 @@ func Version6Upgrade(repoPath string) (err error) {

return repo.WriteVersion(repoPath, 6)
}

//Version7Upgrade
func Version7Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 6); err != nil {
return
}
cfg := fsrRepo.Config()
switch cfg.NetworkParams.NetworkType {
case constants.NetworkMainnet:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = 999999999999
case constants.Network2k:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = -18
case constants.NetworkCalibnet:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = 682006
case constants.NetworkButterfly:
cfg.NetworkParams.GenesisNetworkVersion = network.Version14
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = 240
case constants.NetworkForce:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = -18
case constants.NetworkInterop:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight = -18
default:
return fsrRepo.Close()
}

if err = fsrRepo.ReplaceConfig(cfg); err != nil {
return
}

if err = fsrRepo.Close(); err != nil {
return
}

return repo.WriteVersion(repoPath, 7)
}
2 changes: 1 addition & 1 deletion pkg/repo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// Version is the version of repo schema that this code understands.
const LatestVersion uint = 6
const LatestVersion uint = 7

const (
// apiFile is the filename containing the filecoin node's api address.
Expand Down

0 comments on commit 94e15a3

Please sign in to comment.