Skip to content

Commit

Permalink
feat: v2.6 migrations and custom ante hanlder
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 9, 2023
1 parent 64783d3 commit d6f6f96
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
auctionDecorator,
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewCommunityPoolDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
Expand Down
40 changes: 40 additions & 0 deletions app/ante/custom_ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ante

import (
"fmt"
"time"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

type CommunityPoolDecorator struct {
futureBlockTime time.Time
msgCommunityPoolSpend string
}

func NewCommunityPoolDecorator() CommunityPoolDecorator {
return CommunityPoolDecorator{
futureBlockTime: time.Date(2025, 1, 1, 0, 0, 0, 0, time.Local),
msgCommunityPoolSpend: sdk.MsgTypeURL(&types.MsgCommunityPoolSpend{}),
}
}

func (d CommunityPoolDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// Compare block time to be before 2025
if ctx.BlockTime().Before(d.futureBlockTime) {
// Iterate the tx messages
for _, msg := range tx.GetMsgs() {
// check if the msg is a MsgFundCommunityPool
msgType := sdk.MsgTypeURL(msg)

if msgType == d.msgCommunityPoolSpend {
message := fmt.Sprintf("%s is blocked until the future blocktime %s", d.msgCommunityPoolSpend, d.futureBlockTime)
return ctx, sdkerrors.Register(types.ModuleName, 999, message)
}
}
}

return next(newCtx, tx, simulate)
}
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ import (
v2_3_0 "github.com/terra-money/core/v2/app/upgrades/v2.3.0"
v2_4 "github.com/terra-money/core/v2/app/upgrades/v2.4"
v2_5 "github.com/terra-money/core/v2/app/upgrades/v2.5"
v2_6 "github.com/terra-money/core/v2/app/upgrades/v2.6"

// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
Expand Down Expand Up @@ -1165,6 +1166,14 @@ func (app *TerraApp) RegisterUpgradeHandlers(cfg module.Configurator) {
app.AccountKeeper,
),
)
app.UpgradeKeeper.SetUpgradeHandler(
terraappconfig.Upgrade2_6,
v2_6.CreateUpgradeHandler(app.mm,
app.configurator,
app.appCodec,
app.IBCKeeper.ClientKeeper,
),
)
}

// RegisterSwaggerAPI registers swagger route with API Server
Expand Down
1 change: 1 addition & 0 deletions app/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ const (
Upgrade2_4_rc = "2.4.0-rc4" // This is pisco only since an incorrect plan name was used for the upgrade
Upgrade2_4 = "v2.4"
Upgrade2_5 = "v2.5"
Upgrade2_6 = "v2.6"
)
67 changes: 67 additions & 0 deletions app/upgrades/v2.6/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package v2_6

import (
"time"

sdkerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
cdc codec.Codec,
clientKeeper clientkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
err := increaseUnbondingPeriod(ctx, cdc, clientKeeper)
if err != nil {
return nil, err
}
return mm.RunMigrations(ctx, cfg, fromVM)
}
}

// Iterate all IBC clients and increase unbonding period for all atlantic-2 clients
func increaseUnbondingPeriod(ctx sdk.Context, cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) error {
var clientIDs []string
clientKeeper.IterateClientStates(ctx, []byte(ibcexported.Tendermint), func(clientID string, _ ibcexported.ClientState) bool {
clientIDs = append(clientIDs, clientID)
return false
})

var totalUpdated int

for _, clientID := range clientIDs {
clientState, ok := clientKeeper.GetClientState(ctx, clientID)
if !ok {
return sdkerrors.Wrapf(ibcclienttypes.ErrClientNotFound, "clientID %s", clientID)
}

tmClientState, ok := clientState.(*ibctm.ClientState)
if !ok {
return sdkerrors.Wrap(ibcclienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint")
}

// ATLANTIC 2 blockchain changed the unbonding period on their side,
// we take advantage of having to upgrade the chain to also increase
// the unbonding priod on our side.
if tmClientState.GetChainID() == "atlantic-2" {
tmClientState.UnbondingPeriod = time.Hour * 24 * 21

clientKeeper.SetClientState(ctx, clientID, tmClientState)
}
}

clientLogger := clientKeeper.Logger(ctx)
clientLogger.Info("total ibc clients updated: ", totalUpdated)

return nil
}
2 changes: 1 addition & 1 deletion client/docs/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
"description": "Source code for <a target='_blank' href='https://github.com/terra-money/core'>Terra Core v2.5</a><br/>UI to interact with the blockchain <a target='_blank' href='https://station.terra.money/'>Station</a><br/>Create a DAO on Terra using <a target='_blank' href='https://enterprise.money/'>Enterprise</a><br/>Run on-chain automted jobs <a target='_blank' href='https://warp.money/'>Wrap</a><br/>Explore the network using <a target='_blank' href='https://terrasco.pe/'>TerraScope</a><br/>Anything you need to know about shared security on <a target='_blank' href='https://alliance.terra.money/'>Alliance Docs</a><br/>More info about the protocol on <a target='_blank' href='https://docs.terra.money/'>Terra Docs</a>",
"description": "Source code for <a target='_blank' href='https://github.com/terra-money/core'>Terra Core v2.6</a><br/>UI to interact with the blockchain <a target='_blank' href='https://station.terra.money/'>Station</a><br/>Create a DAO on Terra using <a target='_blank' href='https://enterprise.money/'>Enterprise</a><br/>Run on-chain automted jobs <a target='_blank' href='https://warp.money/'>Wrap</a><br/>Explore the network using <a target='_blank' href='https://terrasco.pe/'>TerraScope</a><br/>Anything you need to know about shared security on <a target='_blank' href='https://alliance.terra.money/'>Alliance Docs</a><br/>More info about the protocol on <a target='_blank' href='https://docs.terra.money/'>Terra Docs</a>",
"version": "2.5"
},
"apis": [
Expand Down
2 changes: 1 addition & 1 deletion client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swagger: '2.0'
info:
description: >-
Source code for <a target='_blank'
href='https://github.com/terra-money/core'>Terra Core v2.5</a><br/>UI to
href='https://github.com/terra-money/core'>Terra Core v2.6</a><br/>UI to
interact with the blockchain <a target='_blank'
href='https://station.terra.money/'>Station</a><br/>Create a DAO on Terra
using <a target='_blank'
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/chain-upgrade/chain-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

OLD_VERSION=release/v2.4
OLD_VERSION=release/v2.5
UPGRADE_HEIGHT=30
CHAIN_ID=pisco-1
ROOT=$(pwd)
CHAIN_HOME=$ROOT/_build/.testnet
DENOM=uluna
SOFTWARE_UPGRADE_NAME="v2.5"
SOFTWARE_UPGRADE_NAME="v2.6"
GOV_PERIOD="10s"

VAL_MNEMONIC_1="clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion"
Expand Down

0 comments on commit d6f6f96

Please sign in to comment.