Skip to content

Commit

Permalink
fix(upgrade): init new params post-upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Sep 20, 2024
1 parent f09b02e commit c1db4b2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 76 deletions.
32 changes: 1 addition & 31 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
package app

import (
// "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
// auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
// auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
)

// BlockSDKAnteHandlerParams are the parameters necessary to configure the block-sdk antehandlers
// type BlockSDKAnteHandlerParams struct {
// mevLane auctionante.MEVLane
// auctionKeeper auctionkeeper.Keeper
// txConfig client.TxConfig
// }

// HandlerOptions extends the SDK's AnteHandler options
type HandlerOptions struct {
ante.HandlerOptions
CDC codec.BinaryCodec
// AStakingKeeper astakingkeeper.IKeeper
CDC codec.BinaryCodec
GovKeeper *govkeeper.Keeper
// AGovKeeper agovkeeper.IKeeper
// BlockSDK BlockSDKAnteHandlerParams
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -48,26 +35,16 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, sdkerrors.ErrLogic.Wrap("sig gas consumer handler is required for ante builder")
}

// if options.AStakingKeeper == nil {
// return nil, sdkerrors.ErrLogic.Wrap("custom akash staking keeper is required for ante builder")
// }

if options.GovKeeper == nil {
return nil, sdkerrors.ErrLogic.Wrap("akash governance keeper is required for ante builder")
}

// if options.AGovKeeper == nil {
// return nil, sdkerrors.ErrLogic.Wrap("custom akash governance keeper is required for ante builder")
// }

if options.FeegrantKeeper == nil {
return nil, sdkerrors.ErrLogic.Wrap("akash feegrant keeper is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
// ante.NewRejectExtensionOptionsDecorator(),
// ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
Expand All @@ -78,13 +55,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
// decorators.NewMinCommissionDecorator(options.CDC, options.AStakingKeeper),
// auction module antehandler
// auctionante.NewAuctionDecorator(
// options.BlockSDK.auctionKeeper,
// options.BlockSDK.txConfig.TxEncoder(),
// options.BlockSDK.mevLane,
// ),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
55 changes: 43 additions & 12 deletions tests/upgrade/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
sdkclient "github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
"pkg.akt.dev/go/cli"
"pkg.akt.dev/go/cli/flags"
cltypes "pkg.akt.dev/go/node/client/types"
"pkg.akt.dev/go/node/client/v1beta3"

"pkg.akt.dev/node/app"
uttypes "pkg.akt.dev/node/tests/upgrade/types"
Expand All @@ -23,7 +25,9 @@ func init() {
uttypes.RegisterPostUpgradeWorker("v1.0.0", &postUpgrade{})
}

type postUpgrade struct{}
type postUpgrade struct {
cl v1beta3.Client
}

var _ uttypes.TestWorker = (*postUpgrade)(nil)

Expand Down Expand Up @@ -63,41 +67,68 @@ func (pu *postUpgrade) Run(ctx context.Context, t *testing.T, params uttypes.Tes
cltypes.WithGasAdjustment(2),
}

mcl, err := cli.DiscoverClient(ctx, cctx, opts...)
pu.cl, err = cli.DiscoverClient(ctx, cctx, opts...)
require.NoError(t, err)
require.NotNil(t, mcl)
require.NotNil(t, pu.cl)

pu.testGov(ctx, t)

pu.testStaking(ctx, t)
}

func (pu *postUpgrade) testGov(ctx context.Context, t *testing.T) {
t.Logf("testing gov module")
cctx := pu.cl.ClientContext()

paramsResp, err := mcl.Query().Staking().Params(ctx, &stakingtypes.QueryParamsRequest{})
paramsResp, err := pu.cl.Query().Gov().Params(ctx, &govtypes.QueryParamsRequest{ParamsType: "deposit"})
require.NoError(t, err)
require.NotNil(t, paramsResp)

require.True(t, paramsResp.Params.MinCommissionRate.GTE(sdk.NewDecWithPrec(5, 2)), "per upgrade v1.0.0 MinCommissionRate should be 5%")
// paramsResp.Params.ExpeditedMinDeposit.
require.Equal(t, sdk.Coins{sdk.NewCoin("uakt", sdk.NewInt(2000000000))}.String(), sdk.Coins(paramsResp.Params.ExpeditedMinDeposit).String(), "ExpeditedMinDeposit must have 2000AKT")
require.Equal(t, paramsResp.Params.MinInitialDepositRatio, sdk.NewDecWithPrec(40, 2).String(), "MinInitialDepositRatio must be 40%")

opAddr := sdk.ValAddress(cctx.FromAddress)

comVal := sdk.NewDecWithPrec(4, 2)

valResp, err := mcl.Query().Staking().Validator(ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: opAddr.String()})
valResp, err := pu.cl.Query().Staking().Validator(ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: opAddr.String()})
require.NoError(t, err)

tx := stakingtypes.NewMsgEditValidator(opAddr, valResp.Validator.Description, &comVal)
broadcastResp, err := mcl.Tx().BroadcastMsgs(ctx, []sdk.Msg{tx})
broadcastResp, err := pu.cl.Tx().BroadcastMsgs(ctx, []sdk.Msg{tx})
require.Error(t, err)
require.NotNil(t, broadcastResp)

require.IsType(t, &sdk.TxResponse{}, broadcastResp)
txResp := broadcastResp.(*sdk.TxResponse)
require.NotEqual(t, uint32(0), txResp.Code, "update validator commission should fail if new value is < 5%")
}

comVal = sdk.NewDecWithPrec(6, 2)
func (pu *postUpgrade) testStaking(ctx context.Context, t *testing.T) {
t.Logf("testing staking module")

tx = stakingtypes.NewMsgEditValidator(opAddr, valResp.Validator.Description, &comVal)
cctx := pu.cl.ClientContext()

broadcastResp, err = mcl.Tx().BroadcastMsgs(ctx, []sdk.Msg{tx})
paramsResp, err := pu.cl.Query().Staking().Params(ctx, &stakingtypes.QueryParamsRequest{})
require.NoError(t, err)
require.NotNil(t, paramsResp)

require.True(t, paramsResp.Params.MinCommissionRate.GTE(sdk.NewDecWithPrec(5, 2)), "per upgrade v1.0.0 MinCommissionRate should be 5%")

opAddr := sdk.ValAddress(cctx.FromAddress)

comVal := sdk.NewDecWithPrec(4, 2)

valResp, err := pu.cl.Query().Staking().Validator(ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: opAddr.String()})
require.NoError(t, err)

tx := stakingtypes.NewMsgEditValidator(opAddr, valResp.Validator.Description, &comVal)
broadcastResp, err := pu.cl.Tx().BroadcastMsgs(ctx, []sdk.Msg{tx})
require.Error(t, err)
require.NotNil(t, broadcastResp)

require.IsType(t, &sdk.TxResponse{}, broadcastResp)
txResp = broadcastResp.(*sdk.TxResponse)
require.Equal(t, uint32(0), txResp.Code, "update validator commission should pass if new value is >= 5%")
txResp := broadcastResp.(*sdk.TxResponse)
require.NotEqual(t, uint32(0), txResp.Code, "update validator commission should fail if new value is < 5%")
}
49 changes: 16 additions & 33 deletions upgrades/software/v1.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,6 @@ func CanCreateModuleAccountAtAddr(ctx sdk.Context, ak AccountKeeper, addr sdk.Ac
"due to an account at that address already existing & not being an overridable type")
}

// const (
// // Noble USDC is used as the auction denom
// AuctionUSDCDenom = "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4"
// )
//
// // AuctionParams expected initial params for the block-sdk
// var AuctionParams = auctiontypes.Params{
// MaxBundleSize: 5,
// ReserveFee: sdk.NewCoin(AuctionUSDCDenom, sdk.NewInt(1000000)),
// MinBidIncrement: sdk.NewCoin(AuctionUSDCDenom, sdk.NewInt(1000000)),
// EscrowAccountAddress: auctiontypes.DefaultEscrowAccountAddress,
// FrontRunningProtection: true,
// ProposerFee: math.LegacyMustNewDecFromStr("0.05"),
// }

// CreateModuleAccountByName creates a module account at the provided name
func CreateModuleAccountByName(ctx sdk.Context, ak AccountKeeper, name string) error {
addr := authtypes.NewModuleAddress(name)
Expand Down Expand Up @@ -219,32 +204,30 @@ func (up *upgrade) UpgradeHandler() upgradetypes.UpgradeHandler {
dparams := agovtypes.DepositParams{}
sspace.Get(ctx, agovtypes.KeyDepositParams, &dparams)

// Migrate governance min deposit parameter to builtin gov params
gparams := up.Keepers.Cosmos.Gov.GetParams(ctx)
gparams.MinInitialDepositRatio = dparams.MinInitialDepositRate.String()
err = up.Keepers.Cosmos.Gov.SetParams(ctx, gparams)
toVM, err := up.MM.RunMigrations(ctx, up.Configurator, fromVM)
if err != nil {
return nil, err
}

// // Ensure the auction module account is properly created to avoid sniping
// err = CreateModuleAccountByName(ctx, up.Keepers.Cosmos.Acct, auctiontypes.ModuleName)
// if err != nil {
// return nil, err
// }
//
// // update block-sdk params
// if err := up.Keepers.External.Auction.SetParams(ctx, AuctionParams); err != nil {
// return nil, err
// }

toVM, err := up.MM.RunMigrations(ctx, up.Configurator, fromVM)
// patch deposit authorizations after authz store upgrade
err = up.patchDepositAuthorizations(ctx)
if err != nil {
return nil, err
}

// patch deposit authorizations after authz store upgrade
err = up.patchDepositAuthorizations(ctx)
// Migrate governance min deposit parameter to builtin gov params
gparams := up.Keepers.Cosmos.Gov.GetParams(ctx)
gparams.MinInitialDepositRatio = dparams.MinInitialDepositRate.String()

// min deposit for expedited proposal is set to 2000AKT
gparams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewCoin("uakt", sdk.NewInt(2000000000)))
gparams.ExpeditedThreshold = sdk.NewDecWithPrec(667, 3).String()

eVotePeriod := time.Hour * 24
gparams.ExpeditedVotingPeriod = &eVotePeriod

// gparams.ExpeditedMinDeposit
err = up.Keepers.Cosmos.Gov.SetParams(ctx, gparams)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c1db4b2

Please sign in to comment.