-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: v2.6 migrations and custom ante hanlder
- Loading branch information
Showing
8 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters