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

Properly create the module account for auction #8178

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions app/upgrades/v25/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"errors"
"sort"

"github.com/osmosis-labs/osmosis/osmoutils"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -67,6 +70,11 @@ func CreateUpgradeHandler(
return nil, errors.New("unsupported chain ID")
}

// Ensure the auction module account is properly created to avoid sniping
err = osmoutils.CreateModuleAccountByName(ctx, keepers.AccountKeeper, auctiontypes.ModuleName)
if err != nil {
return nil, err
}
// update block-sdk params
if err := keepers.AuctionKeeper.SetParams(ctx, AuctionParams); err != nil {
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades/v25/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v25_test

import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
"testing"
"time"

Expand Down Expand Up @@ -48,6 +50,12 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.App.BeginBlocker(s.Ctx, abci.RequestBeginBlock{})
})

// check auction module account
acc := s.App.AccountKeeper.GetModuleAccount(s.Ctx, auctiontypes.ModuleName)
s.Require().NotNil(acc)
s.Require().Equal(auctiontypes.ModuleName, acc.GetName())
s.Require().Equal(authtypes.NewModuleAddress(auctiontypes.ModuleName), acc.GetAddress())

// check auction params
params, err := s.App.AuctionKeeper.GetParams(s.Ctx)
s.Require().NoError(err)
Expand Down
19 changes: 19 additions & 0 deletions osmoutils/module_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,22 @@ func CreateModuleAccount(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress)
ak.SetAccount(ctx, acc)
return nil
}

// CreateModuleAccountByName creates a module account at the provided name
func CreateModuleAccountByName(ctx sdk.Context, ak AccountKeeper, name string) error {
addr := authtypes.NewModuleAddress(name)
err := CanCreateModuleAccountAtAddr(ctx, ak, addr)
if err != nil {
return err
}

acc := ak.NewAccount(
ctx,
authtypes.NewModuleAccount(
authtypes.NewBaseAccountWithAddress(addr),
name,
),
)
ak.SetAccount(ctx, acc)
return nil
}