From 32dc0260985a10dd90ce72ff346df9267d56b27e Mon Sep 17 00:00:00 2001 From: simlecode Date: Thu, 17 Feb 2022 17:56:14 +0800 Subject: [PATCH 1/3] migrate maxfee --- pkg/migration/migrate.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/migration/migrate.go b/pkg/migration/migrate.go index ee25a4a8b5..639dd038f5 100644 --- a/pkg/migration/migrate.go +++ b/pkg/migration/migrate.go @@ -1,14 +1,19 @@ package migration import ( + "encoding/json" + "fmt" + "io/ioutil" + "math" + "path/filepath" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/fixtures/networks" "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/repo" + "github.com/filecoin-project/venus/venus-shared/types" logging "github.com/ipfs/go-log/v2" - - "math" ) var migrateLog = logging.Logger("data_migrate") @@ -220,6 +225,28 @@ func Version7Upgrade(repoPath string) (err error) { return fsrRepo.Close() } + // In order to migrate maxfee + // from 10000000000000000000 to 10 FIL + type MpoolCfg struct { + MaxFee float64 `json:"maxFee"` + } + type tempCfg struct { + Mpool *MpoolCfg `json:"mpool"` + } + data, err := ioutil.ReadFile(filepath.Join(repoPath, "config.json")) + if err != nil { + migrateLog.Errorf("open config file failed: %v", err) + } else { + tmpCfg := tempCfg{} + if err := json.Unmarshal(data, &tmpCfg); err != nil { + migrateLog.Warn(err) + } else { + maxFee := types.MustParseFIL(fmt.Sprintf("%fattofil", tmpCfg.Mpool.MaxFee)) + migrateLog.Info("current max fee: ", maxFee.String()) + cfg.Mpool.MaxFee = maxFee + } + } + if err = fsrRepo.ReplaceConfig(cfg); err != nil { return } From 10f5ab174bbcc4bf03b3e7de916a22d310b72ee2 Mon Sep 17 00:00:00 2001 From: simlecode Date: Fri, 18 Feb 2022 10:11:52 +0800 Subject: [PATCH 2/3] add comment --- pkg/migration/migrate.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/migration/migrate.go b/pkg/migration/migrate.go index 639dd038f5..05007cc501 100644 --- a/pkg/migration/migrate.go +++ b/pkg/migration/migrate.go @@ -226,7 +226,6 @@ func Version7Upgrade(repoPath string) (err error) { } // In order to migrate maxfee - // from 10000000000000000000 to 10 FIL type MpoolCfg struct { MaxFee float64 `json:"maxFee"` } @@ -237,13 +236,15 @@ func Version7Upgrade(repoPath string) (err error) { if err != nil { migrateLog.Errorf("open config file failed: %v", err) } else { + // If maxFee value is String(10 FIL), unmarshal failure is expected + // If maxFee value is Number(10000000000000000000), need convert to FIL(10 FIL) tmpCfg := tempCfg{} if err := json.Unmarshal(data, &tmpCfg); err != nil { migrateLog.Warn(err) } else { maxFee := types.MustParseFIL(fmt.Sprintf("%fattofil", tmpCfg.Mpool.MaxFee)) - migrateLog.Info("current max fee: ", maxFee.String()) cfg.Mpool.MaxFee = maxFee + migrateLog.Info("convert mpool.maxFee from %v to %s", tmpCfg.Mpool.MaxFee, maxFee.String()) } } From b76f1761d303597aaf91ef818a7e177da252d65f Mon Sep 17 00:00:00 2001 From: simlecode Date: Fri, 18 Feb 2022 10:35:58 +0800 Subject: [PATCH 3/3] To simplify the logic --- pkg/migration/migrate.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/migration/migrate.go b/pkg/migration/migrate.go index 05007cc501..e9ce96b898 100644 --- a/pkg/migration/migrate.go +++ b/pkg/migration/migrate.go @@ -239,9 +239,7 @@ func Version7Upgrade(repoPath string) (err error) { // If maxFee value is String(10 FIL), unmarshal failure is expected // If maxFee value is Number(10000000000000000000), need convert to FIL(10 FIL) tmpCfg := tempCfg{} - if err := json.Unmarshal(data, &tmpCfg); err != nil { - migrateLog.Warn(err) - } else { + if err := json.Unmarshal(data, &tmpCfg); err == nil { maxFee := types.MustParseFIL(fmt.Sprintf("%fattofil", tmpCfg.Mpool.MaxFee)) cfg.Mpool.MaxFee = maxFee migrateLog.Info("convert mpool.maxFee from %v to %s", tmpCfg.Mpool.MaxFee, maxFee.String())