Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: config: migrate maxfee #4783

Merged
merged 3 commits into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions pkg/migration/migrate.go
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -220,6 +225,27 @@ func Version7Upgrade(repoPath string) (err error) {
return fsrRepo.Close()
}

// In order to migrate maxfee
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 {
// 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 {
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())
}
}

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