Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cosmos/ibc-go into colin/7231-rm-wa…
Browse files Browse the repository at this point in the history
…sm-callbacks-bin-logic
  • Loading branch information
colin-axner committed Oct 17, 2024
2 parents af4fe10 + f59dbcc commit 1cd2408
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 99 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Testing

* [\#7430](https://github.com/cosmos/ibc-go/pull/7430) Update the block proposer in test chains for each block.

### Dependencies

* [\#7247](https://github.com/cosmos/ibc-go/pull/7247) Bump CometBFT to v0.38.12.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module github.com/cosmos/ibc-go/v9

require (
cosmossdk.io/api v0.7.6
cosmossdk.io/client/v2 v2.0.0-beta.5
cosmossdk.io/core v0.11.1
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.4.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY=
cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
cosmossdk.io/client/v2 v2.0.0-beta.5 h1:0LVv3nEByn//hFDIrYLs2WvsEU3HodOelh4SDHnA/1I=
cosmossdk.io/client/v2 v2.0.0-beta.5/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as=
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
cosmossdk.io/core v0.11.1 h1:h9WfBey7NAiFfIcUhDVNS503I2P2HdZLebJlUIs8LPA=
Expand Down
79 changes: 4 additions & 75 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,10 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
"github.com/cosmos/ibc-go/v9/testing/mock"
)

const appName = "SimApp"

// IBC application testing ports
const (
MockFeePort string = mock.ModuleName + ibcfeetypes.ModuleName
)

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand All @@ -155,7 +149,6 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
mock.ModuleName: nil,
}
)

Expand All @@ -174,9 +167,8 @@ type SimApp struct {
interfaceRegistry types.InterfaceRegistry

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
memKeys map[string]*storetypes.MemoryStoreKey
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
Expand All @@ -202,12 +194,6 @@ type SimApp struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
CircuitKeeper circuitkeeper.Keeper

// make IBC modules public for test purposes
// these modules are never directly routed to by the IBC Router
IBCMockModule mock.IBCModule
ICAAuthModule mock.IBCModule
FeeMockModule mock.IBCModule

// the module manager
ModuleManager *module.Manager
BasicModuleManager module.BasicManager
Expand Down Expand Up @@ -301,7 +287,6 @@ func NewSimApp(
}

tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(mock.MemStoreKey)

app := &SimApp{
BaseApp: bApp,
Expand All @@ -311,7 +296,6 @@ func NewSimApp(
interfaceRegistry: interfaceRegistry,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
}

app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand Down Expand Up @@ -472,25 +456,6 @@ func NewSimApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Mock Module Stack

// Mock Module setup for testing IBC and also acts as the interchain accounts authentication module
// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
// not replicate if you do not need to test core IBC or light clients.
mockModule := mock.NewAppModule()

// The mock module is used for testing IBC
mockIBCModule := mock.NewIBCModule(&mockModule, mock.NewIBCApp(mock.ModuleName))
app.IBCMockModule = mockIBCModule
ibcRouter.AddRoute(mock.ModuleName, mockIBCModule)

// Mock IBC app wrapped with a middleware which does not implement the UpgradeableModule interface.
// NOTE: this is used to test integration with apps which do not yet fulfill the UpgradeableModule interface and error when
// an upgrade is tried on the channel.
mockBlockUpgradeIBCModule := mock.NewIBCModule(&mockModule, mock.NewIBCApp(mock.MockBlockUpgrade))
mockBlockUpgradeMw := mock.NewBlockUpgradeMiddleware(&mockModule, mockBlockUpgradeIBCModule.IBCApp)
ibcRouter.AddRoute(mock.MockBlockUpgrade, mockBlockUpgradeMw)

// Create Transfer Stack
// SendPacket, since it is originating from the application to core IBC:
// transferKeeper.SendPacket -> fee.SendPacket -> channel.SendPacket
Expand All @@ -513,15 +478,7 @@ func NewSimApp(
// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaControllerKeeper.SendTx -> fee.SendPacket -> channel.SendPacket

// initialize ICA module with mock module as the authentication module on the controller side
var icaControllerStack porttypes.IBCModule
icaControllerStack = mock.NewIBCModule(&mockModule, mock.NewIBCApp(""))
var ok bool
app.ICAAuthModule, ok = icaControllerStack.(mock.IBCModule)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", icaControllerStack, app.ICAAuthModule))
}
icaControllerStack = icacontroller.NewIBCMiddleware(app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)

Expand All @@ -535,23 +492,7 @@ func NewSimApp(
// Add host, controller & ica auth modules to IBC router
ibcRouter.
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(mock.ModuleName+icacontrollertypes.SubModuleName, icaControllerStack) // ica with mock auth module stack route to ica (top level of middleware stack)

// Create Mock IBC Fee module stack for testing
// SendPacket, mock module cannot send packets

// OnRecvPacket, message that originates from core IBC and goes down to app, the flow is the otherway
// channel.RecvPacket -> fee.OnRecvPacket -> mockModule.OnRecvPacket

// OnAcknowledgementPacket as this is where fee's are paid out
// mockModule.OnAcknowledgementPacket -> fee.OnAcknowledgementPacket -> channel.OnAcknowledgementPacket

// create fee wrapped mock module
feeMockModule := mock.NewIBCModule(&mockModule, mock.NewIBCApp(MockFeePort))
app.FeeMockModule = feeMockModule
feeWithMockModule := ibcfee.NewIBCMiddleware(feeMockModule, app.IBCFeeKeeper)
ibcRouter.AddRoute(MockFeePort, feeWithMockModule)
AddRoute(icahosttypes.SubModuleName, icaHostStack)

// Seal the IBC Router
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -611,7 +552,6 @@ func NewSimApp(
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
mockModule,

// IBC light clients
wasm.NewAppModule(app.WasmClientKeeper), // TODO(damian): see if we want to pass the lightclient module here, keeper is used in AppModule.RegisterServices etc
Expand Down Expand Up @@ -658,7 +598,6 @@ func NewSimApp(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
mock.ModuleName,
)
app.ModuleManager.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -671,7 +610,6 @@ func NewSimApp(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
mock.ModuleName,
group.ModuleName,
)

Expand All @@ -683,7 +621,7 @@ func NewSimApp(
banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
ibcexported.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName,
icatypes.ModuleName, ibcfeetypes.ModuleName, mock.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
icatypes.ModuleName, ibcfeetypes.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName, group.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName, wasmtypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -728,7 +666,6 @@ func NewSimApp(
// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
Expand Down Expand Up @@ -1015,7 +952,6 @@ func BlockedAddresses() map[string]bool {

// allow the following addresses to receive funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(mock.ModuleName).String())

return modAccAddrs
}
Expand All @@ -1034,10 +970,3 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

// GetMemKey returns the MemStoreKey for the provided mem key.
//
// NOTE: This is solely used for testing purposes.
func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
return app.memKeys[storeKey]
}
5 changes: 4 additions & 1 deletion testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
chain.Vals = chain.NextVals
chain.NextVals = ApplyValSetChanges(chain, chain.Vals, res.ValidatorUpdates)

// increment the proposer priority of validators
chain.Vals.IncrementProposerPriority(1)

// increment the current header
chain.ProposedHeader = cmtproto.Header{
ChainID: chain.ChainID,
Expand All @@ -333,7 +336,7 @@ func (chain *TestChain) commitBlock(res *abci.ResponseFinalizeBlock) {
Time: chain.ProposedHeader.Time,
ValidatorsHash: chain.Vals.Hash(),
NextValidatorsHash: chain.NextVals.Hash(),
ProposerAddress: chain.ProposedHeader.ProposerAddress,
ProposerAddress: chain.Vals.Proposer.Address,
}
}

Expand Down
34 changes: 34 additions & 0 deletions testing/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"

ibctesting "github.com/cosmos/ibc-go/v9/testing"
Expand Down Expand Up @@ -41,3 +42,36 @@ func TestChangeValSet(t *testing.T) {
err = path.EndpointB.UpdateClient()
require.NoError(t, err)
}

func TestJailProposerValidator(t *testing.T) {
coord := ibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(ibctesting.GetChainID(1))
chainB := coord.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(chainA, chainB)
coord.Setup(path)

// save valset length before jailing
valsetLen := len(chainA.Vals.Validators)

// jail the proposer validator in chain A
propAddr := sdk.ConsAddress(chainA.Vals.Proposer.Address)

err := chainA.GetSimApp().StakingKeeper.Jail(
chainA.GetContext(), propAddr)
require.NoError(t, err)

coord.CommitBlock(chainA)

// verify that update clients works even after validator update goes into effect
err = path.EndpointB.UpdateClient()
require.NoError(t, err)
err = path.EndpointB.UpdateClient()
require.NoError(t, err)

// check that the jailing has taken effect in chain A
require.Equal(t, valsetLen-1, len(chainA.Vals.Validators))

// check that the valset in chain A has a new proposer
require.False(t, propAddr.Equals(sdk.ConsAddress(chainA.Vals.Proposer.Address)))
}
20 changes: 0 additions & 20 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/tx/signing"
Expand Down Expand Up @@ -770,24 +768,6 @@ func (app *SimApp) TxConfig() client.TxConfig {
return app.txConfig
}

// AutoCliOpts returns the autocli options for the app.
func (app *SimApp) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range app.ModuleManager.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}
}
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
}
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *SimApp) DefaultGenesis() map[string]json.RawMessage {
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
Expand Down

0 comments on commit 1cd2408

Please sign in to comment.