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

chore: add upgrade handler v2 + reenable ante for MsgCreateValidator #255

Merged
merged 2 commits into from
Aug 6, 2024
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
27 changes: 27 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ func New(
panic(err)
}

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.ModuleManager` and `app.configurator` are set.
app.RegisterUpgradeHandlers()

autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))
reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
Expand Down Expand Up @@ -956,6 +960,29 @@ func (app *App) setAnteHandler(txConfig client.TxConfig) {
app.SetAnteHandler(anteHandler)
}

func (app *App) RegisterUpgradeHandlers() {
const UpgradeName = "v0.2.0"

app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.ModuleManager().RunMigrations(ctx, app.Configurator(), fromVM)
},
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }

Expand Down
4 changes: 2 additions & 2 deletions x/reporter/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (t TrackStakeChangesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
var msgAmount math.Int
for _, msg := range tx.GetMsgs() {
switch msg := msg.(type) {
// case *stakingtypes.MsgCreateValidator:
// msgAmount = msg.Value.Amount
case *stakingtypes.MsgCreateValidator:
msgAmount = msg.Value.Amount
case *stakingtypes.MsgDelegate:
msgAmount = msg.Amount.Amount
case *stakingtypes.MsgBeginRedelegate:
Expand Down
28 changes: 14 additions & 14 deletions x/reporter/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ func TestNewTrackStakeChangesDecorator(t *testing.T) {
msg sdk.Msg
err error
}{
// {
// name: "CreateValidator",
// msg: &stakingtypes.MsgCreateValidator{
// Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(1)},
// },
// err: nil,
// },
// {
// name: "CreateValidator",
// msg: &stakingtypes.MsgCreateValidator{
// Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(100)},
// },
// err: errors.New("amount increases total stake by more than the allowed 5% in a twelve hour period"),
// },
{
name: "CreateValidator",
msg: &stakingtypes.MsgCreateValidator{
Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(1)},
},
err: nil,
},
{
name: "CreateValidator",
msg: &stakingtypes.MsgCreateValidator{
Value: sdk.Coin{Denom: "loya", Amount: math.NewInt(100)},
},
err: errors.New("amount increases total stake by more than the allowed 5% in a twelve hour period"),
},
{
name: "Delegate",
msg: &stakingtypes.MsgDelegate{
Expand Down
Loading