diff --git a/app/upgrades/v6/upgrade.go b/app/upgrades/v6/upgrade.go index ba9799e7c..944ecdcbb 100644 --- a/app/upgrades/v6/upgrade.go +++ b/app/upgrades/v6/upgrade.go @@ -7,13 +7,16 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/ethereum/go-ethereum/common" "github.com/functionx/fx-core/v6/app/keepers" crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper" - govtypes "github.com/functionx/fx-core/v6/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v6/x/gov/types" layer2types "github.com/functionx/fx-core/v6/x/layer2/types" migratekeeper "github.com/functionx/fx-core/v6/x/migrate/keeper" fxstakingkeeper "github.com/functionx/fx-core/v6/x/staking/keeper" @@ -33,6 +36,7 @@ func CreateUpgradeHandler( MigrateMetadata(cacheCtx, app.BankKeeper) MigrateLayer2Module(cacheCtx, app.Layer2Keeper) + ExportCommunityPool(cacheCtx, app.DistrKeeper, app.BankKeeper) ctx.Logger().Info("start to run v6 migrations...", "module", "upgrade") toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM) @@ -77,7 +81,7 @@ func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error { govTallyParams.VetoThreshold = sdk.OneDec().String() // 100% app.GovKeeper.SetTallyParams(cacheCtx, govTallyParams) - app.GovKeeper.IterateParams(cacheCtx, func(param *govtypes.Params) (stop bool) { + app.GovKeeper.IterateParams(cacheCtx, func(param *fxgovtypes.Params) (stop bool) { param.Quorum = sdk.OneDec().String() // 100% param.Threshold = sdk.OneDec().String() // 100% param.VetoThreshold = sdk.OneDec().String() // 100% @@ -92,6 +96,22 @@ func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error { return nil } +func ExportCommunityPool(ctx sdk.Context, distrKeeper distrkeeper.Keeper, bankKeeper bankkeeper.Keeper) sdk.Coins { + feePool := distrKeeper.GetFeePool(ctx) + truncatedCoins, changeCoins := feePool.CommunityPool.TruncateDecimal() + feePool.CommunityPool = changeCoins + distrKeeper.SetFeePool(ctx, feePool) + + if err := bankKeeper.SendCoinsFromModuleToModule(ctx, distrtypes.ModuleName, govtypes.ModuleName, truncatedCoins); err != nil { + panic(err) + } + if err := bankKeeper.BurnCoins(ctx, govtypes.ModuleName, truncatedCoins); err != nil { + panic(err) + } + ctx.Logger().Info("export community pool", "coins", truncatedCoins.String()) + return truncatedCoins +} + func MigrateMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) { bankKeeper.IterateAllDenomMetaData(ctx, func(metadata banktypes.Metadata) bool { address, ok := Layer2GenesisTokenAddress[metadata.Symbol] diff --git a/app/upgrades/v6/upgrade_test.go b/app/upgrades/v6/upgrade_test.go index 3e4eefc77..4b75fe361 100644 --- a/app/upgrades/v6/upgrade_test.go +++ b/app/upgrades/v6/upgrade_test.go @@ -57,6 +57,12 @@ func (s *UpgradeTestSuite) TestUpdateParams() { s.CommitBlock(10) } +func (s *UpgradeTestSuite) TestExportCommunityPool() { + s.CommitBlock(10) + communityPool := v6.ExportCommunityPool(s.ctx, s.app.DistrKeeper, s.app.BankKeeper) + s.True(communityPool.IsAllPositive()) +} + func (s *UpgradeTestSuite) TestMigrateMetadata() { for symbol := range v6.Layer2GenesisTokenAddress { hasDenomMetaData := s.app.BankKeeper.HasDenomMetaData(s.ctx, strings.ToLower(symbol))