Skip to content

Commit

Permalink
feat: upgrade handler for IBC client
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Sep 5, 2023
1 parent e4cb3e4 commit 8dc3ea0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coverage:
status:
project:
default:
threshold: 5% # allow this much decrease on project
threshold: 10% # allow this much decrease on project
changes: false

comment:
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ coverage.txt
profile.out
sim_log_file

_build
.testnet

# Vagrant
.vagrant/
*.box
Expand Down
49 changes: 47 additions & 2 deletions app/upgrades/v2.5/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v2_5

import (
"time"

sdkerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,8 +15,9 @@ import (
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/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"
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

func CreateUpgradeHandler(
Expand All @@ -32,7 +36,11 @@ func CreateUpgradeHandler(
baseapp.MigrateParams(ctx, baseAppLegacySS, &consensusParamsKeeper)

// READ: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md#chains
_, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper)
// _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper)
// if err != nil {
// return nil, err
// }
err := increaseUnbondingPeriod(ctx, cdc, clientKeeper)
if err != nil {
return nil, err
}
Expand All @@ -48,3 +56,40 @@ func CreateUpgradeHandler(
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 * 5

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

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

return nil
}
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.0.1
cosmossdk.io/math v1.1.2
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.41.0
github.com/CosmWasm/wasmvm v1.3.0
Expand All @@ -17,7 +17,6 @@ require (
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand All @@ -28,7 +27,6 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230523193151-73dea436e53f
github.com/stretchr/testify v1.8.4
github.com/terra-money/alliance v0.2.3
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529
Expand All @@ -44,7 +42,7 @@ require (
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.2.0 // indirect
cosmossdk.io/log v1.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -94,6 +92,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand Down Expand Up @@ -187,7 +186,7 @@ require (
replace (
// This is a temporary fix since the latest version updated some function signatures. To remove when updating to cosmos 47
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.1
github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.2
github.com/cosmos/ledger-cosmos-go => github.com/terra-money/ledger-terra-go v0.11.2
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98ok
cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU=
cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04=
cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0=
cosmossdk.io/log v1.2.0 h1:BbykkDsutXPSy8RojFB3KZEWyvMsToLy0ykb/ZhsLqQ=
cosmossdk.io/log v1.2.0/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg=
cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM=
cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down Expand Up @@ -1106,8 +1106,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc=
github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230523193151-73dea436e53f h1:NJdZ+YJ9Vf2t286L20IjFK0SxGpobF1xIp5ZQlxWetk=
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230523193151-73dea436e53f/go.mod h1:DJNSVK8NCYHM+aZHCFkcAqPwjzwHYAjhjSMlhAGtJ3c=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down Expand Up @@ -1137,8 +1135,8 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/terra-money/alliance v0.2.3 h1:Ibxjgm1HFE2JBUD28FR4Y0VExhcVReIfToBTxif3XJ0=
github.com/terra-money/alliance v0.2.3/go.mod h1:zo6pmH0n6PjJRYBVfH33ov9l8KBt0756ZH4JEOrUemg=
github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.1 h1:4URIYtFOmoNbJCF8KybNVuSYmpq/iiH6mUk/6Wbcq8c=
github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.1/go.mod h1:T9rq+KgUyG8iWcOa3IWH20Y1zBUBVichjBXseDIMkp8=
github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.2 h1:6pELLnY2ML3eCNfxR/SOr+hEa3vdT5P43usFxv/rSCw=
github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.2/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/terra-money/ledger-terra-go v0.11.2 h1:BVXZl+OhJOri6vFNjjVaTabRLApw9MuG7mxWL4V718c=
github.com/terra-money/ledger-terra-go v0.11.2/go.mod h1:ClJ2XMj1ptcnONzKH+GhVPi7Y8pXIT+UzJ0TNt0tfZE=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
Expand Down

0 comments on commit 8dc3ea0

Please sign in to comment.