Skip to content

Commit

Permalink
feat: Add a function for migration configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Sep 28, 2022
1 parent f93ba73 commit 01b8dc4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 38 deletions.
3 changes: 2 additions & 1 deletion fixtures/networks/integrationtestnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func IntegrationNet() *NetworkConf {
UpgradeHyperdriveHeight: 892800,
UpgradeChocolateHeight: 1231620,
UpgradeOhSnapHeight: 1594680,
UpgradeSkyrHeight: 99999999999999,
UpgradeSkyrHeight: 1960320,
UpgradeV17Height: 99999999999999,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 5, 51000: 1},
AddressNetwork: address.Testnet,
Expand Down
37 changes: 18 additions & 19 deletions fixtures/networks/net_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,25 @@ func Net2k() *NetworkConf {
MinVerifiedDealSize: 256,
PreCommitChallengeDelay: abi.ChainEpoch(10),
ForkUpgradeParam: &config.ForkUpgradeConfig{
UpgradeBreezeHeight: -1,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeTapeHeight: -5,
UpgradeAssemblyHeight: -6,
UpgradeLiftoffHeight: -7,
UpgradeKumquatHeight: -8,
UpgradeCalicoHeight: -9,
UpgradePersianHeight: -10,
UpgradeOrangeHeight: -11,
UpgradeTrustHeight: -13,
UpgradeNorwegianHeight: -14,
UpgradeTurboHeight: -15,
UpgradeHyperdriveHeight: -16,
UpgradeChocolateHeight: -17,
UpgradeOhSnapHeight: -18,

BreezeGasTampingDuration: 0,
UpgradeClausHeight: -11,
UpgradeBreezeHeight: -1,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeTapeHeight: -5,
UpgradeAssemblyHeight: -6,
UpgradeLiftoffHeight: -7,
UpgradeKumquatHeight: -8,
UpgradeCalicoHeight: -9,
UpgradePersianHeight: -10,
UpgradeOrangeHeight: -11,
UpgradeClausHeight: -12,
UpgradeTrustHeight: -13,
UpgradeNorwegianHeight: -14,
UpgradeTurboHeight: -15,
UpgradeHyperdriveHeight: -16,
UpgradeChocolateHeight: -17,
UpgradeOhSnapHeight: -18,
UpgradeSkyrHeight: -19,
UpgradeV17Height: 99999999999999,
},
Expand Down
54 changes: 48 additions & 6 deletions pkg/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var versionMap = []versionInfo{
{version: 6, upgrade: Version6Upgrade},
{version: 7, upgrade: Version7Upgrade},
{version: 8, upgrade: Version8Upgrade},
{version: 9, upgrade: Version9Upgrade},
}

// TryToMigrate used to migrate data(db,config,file,etc) in local repo
Expand Down Expand Up @@ -121,7 +122,7 @@ func Version4Upgrade(repoPath string) (err error) {
return repo.WriteVersion(repoPath, 4)
}

//Version5Upgrade
// Version5Upgrade
func Version5Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 4); err != nil {
Expand Down Expand Up @@ -159,7 +160,7 @@ func Version5Upgrade(repoPath string) (err error) {
return repo.WriteVersion(repoPath, 5)
}

//Version6Upgrade
// Version6Upgrade
func Version6Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 5); err != nil {
Expand Down Expand Up @@ -197,7 +198,7 @@ func Version6Upgrade(repoPath string) (err error) {
return repo.WriteVersion(repoPath, 6)
}

//Version7Upgrade
// Version7Upgrade
func Version7Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 6); err != nil {
Expand Down Expand Up @@ -259,7 +260,7 @@ func Version7Upgrade(repoPath string) (err error) {
return repo.WriteVersion(repoPath, 7)
}

//Version8Upgrade
// Version8Upgrade
func Version8Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 7); err != nil {
Expand All @@ -281,10 +282,10 @@ func Version8Upgrade(repoPath string) (err error) {
cfg.NetworkParams.ForkUpgradeParam.UpgradeSkyrHeight = -19
case types.NetworkInterop:
cfg.NetworkParams.GenesisNetworkVersion = network.Version15
cfg.NetworkParams.ForkUpgradeParam.UpgradeSkyrHeight = 100
cfg.NetworkParams.ForkUpgradeParam.UpgradeSkyrHeight = -19
case types.NetworkButterfly:
cfg.NetworkParams.GenesisNetworkVersion = network.Version15
cfg.NetworkParams.ForkUpgradeParam.UpgradeSkyrHeight = 50
cfg.NetworkParams.ForkUpgradeParam.UpgradeSkyrHeight = -19
default:
return fsrRepo.Close()
}
Expand All @@ -299,3 +300,44 @@ func Version8Upgrade(repoPath string) (err error) {

return repo.WriteVersion(repoPath, 8)
}

// Version9Upgrade
func Version9Upgrade(repoPath string) (err error) {
var fsrRepo repo.Repo
if fsrRepo, err = repo.OpenFSRepo(repoPath, 8); err != nil {
return
}
cfg := fsrRepo.Config()
switch cfg.NetworkParams.NetworkType {
case types.NetworkMainnet:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
case types.Network2k:
cfg.NetworkParams.GenesisNetworkVersion = network.Version16
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
case types.NetworkCalibnet:
cfg.NetworkParams.GenesisNetworkVersion = network.Version0
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
case types.NetworkForce:
cfg.NetworkParams.GenesisNetworkVersion = network.Version16
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
case types.NetworkInterop:
cfg.NetworkParams.GenesisNetworkVersion = network.Version16
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
case types.NetworkButterfly:
cfg.NetworkParams.GenesisNetworkVersion = network.Version16
cfg.NetworkParams.ForkUpgradeParam.UpgradeV17Height = 99999999999999
default:
return fsrRepo.Close()
}

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

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

return repo.WriteVersion(repoPath, 9)
}
1 change: 1 addition & 0 deletions pkg/migration/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestMigration(t *testing.T) {
types.NetworkButterfly: &networks.ButterflySnapNet().Network,
types.NetworkCalibnet: &networks.Calibration().Network,
types.NetworkMainnet: &networks.Mainnet().Network,
types.Integrationnet: &networks.IntegrationNet().Network,
}

for nt, paramsCfg := range cfgs {
Expand Down
13 changes: 1 addition & 12 deletions 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 = 8
const LatestVersion uint = 9

const (
// apiFile is the filename containing the filecoin node's api address.
Expand Down Expand Up @@ -247,9 +247,6 @@ func (r *FSRepo) loadFromDisk() error {
return errors.Wrap(err, "failed to open paych datastore")
}

/*if err := r.openMarketDataStore(); err != nil {
return errors.Wrap(err, "failed to open market datastore")
}*/
return nil
}

Expand Down Expand Up @@ -474,14 +471,6 @@ func (r *FSRepo) openPaychDataStore() error {
return nil
}

/*func (r *FSRepo) openMarketDataStore() error {
var err error
r.marketDs, err = badgerds.NewDatastore(filepath.Join(r.path, marketDatastoreProfix), badgerOptions())
if err != nil {
return err
}
return nil
}*/
func (r *FSRepo) openWalletDatastore() error {
// TODO: read wallet datastore info from config, use that to open it up
ds, err := badgerds.NewDatastore(filepath.Join(r.path, walletDatastorePrefix), badgerOptions())
Expand Down

0 comments on commit 01b8dc4

Please sign in to comment.