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

fix(x/protocolpool): withdraw rewards before export genesis (backport #23467) #23471

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,28 @@ var (
},
// When ExportGenesis is not specified, the export genesis module order
// is equal to the init genesis order
// ExportGenesis: []string{},
ExportGenesis: []string{
consensustypes.ModuleName,
accounts.ModuleName,
authtypes.ModuleName,
pooltypes.ModuleName, // Must be exported before bank
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
nft.ModuleName,
group.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
circuittypes.ModuleName,
epochstypes.ModuleName,
},
// Uncomment if you want to set a custom migration order here.
// OrderMigrations: []string{},
// SkipStoreKeys is an optional list of store keys to skip when constructing the
Expand Down
15 changes: 15 additions & 0 deletions x/protocolpool/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) error
}

func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) {
// refresh all funds
if err := k.IterateAndUpdateFundsDistribution(ctx); err != nil {
return nil, err
}

// withdraw all rewards before exporting genesis
if err := k.RecipientFundDistribution.Walk(ctx, nil, func(key sdk.AccAddress, value types.DistributionAmount) (stop bool, err error) {
if _, err := k.withdrawRecipientFunds(ctx, key.Bytes()); err != nil {
return true, err
}
return false, nil
}); err != nil {
return nil, err
}

var cf []*types.ContinuousFund
err := k.ContinuousFund.Walk(ctx, nil, func(key sdk.AccAddress, value types.ContinuousFund) (stop bool, err error) {
recipient, err := k.authKeeper.AddressCodec().BytesToString(key)
Expand Down
9 changes: 7 additions & 2 deletions x/protocolpool/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package keeper_test
import (
"time"

"github.com/golang/mock/gomock"

"cosmossdk.io/math"
"cosmossdk.io/x/protocolpool/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (suite *KeeperTestSuite) TestInitGenesis() {
func (suite *KeeperTestSuite) TestInitExportGenesis() {
suite.bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), types.ProtocolPoolDistrAccount, gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
suite.bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.StreamAccount, gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

hour := time.Hour
gs := types.NewGenesisState(
[]*types.ContinuousFund{
Expand Down Expand Up @@ -49,5 +54,5 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
suite.Require().NoError(err)
suite.Require().Equal(gs.ContinuousFund, exportedGenState.ContinuousFund)
suite.Require().Equal(gs.Budget, exportedGenState.Budget)
suite.Require().Equal(math.NewInt(101), exportedGenState.LastBalance.Amount.AmountOf("stake"))
suite.Require().Equal(math.ZeroInt(), exportedGenState.LastBalance.Amount.AmountOf("stake"))
}
Loading