From f65659505b6cbdd1ecca04c82f363643b652fb75 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 17 Dec 2024 19:41:57 +0100 Subject: [PATCH 1/2] refactor: use header info for interchain accounts address generation --- .../controller/keeper/genesis_test.go | 2 +- .../27-interchain-accounts/host/ibc_module_test.go | 2 +- .../27-interchain-accounts/host/keeper/account.go | 2 +- .../host/keeper/genesis_test.go | 4 ++-- .../host/keeper/handshake_test.go | 2 +- modules/apps/27-interchain-accounts/types/account.go | 12 +++++------- .../27-interchain-accounts/types/account_test.go | 2 +- testing/chain.go | 6 ++++++ 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go index 70ec159d0b0..974e12f852c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go @@ -21,7 +21,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { }, } - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext().HeaderInfo(), ibctesting.FirstConnectionID, TestPortID) genesisState := genesistypes.ControllerGenesisState{ ActiveChannels: []genesistypes.ActiveChannel{ { diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index f636098f710..900dd6c383c 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -149,7 +149,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { }, { "account address generation is block dependent", func() { - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext().HeaderInfo(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) interchainAcc := icatypes.NewInterchainAccount(authtypes.NewBaseAccountWithAddress(interchainAccAddr), path.EndpointA.ChannelConfig.PortID) suite.chainB.GetSimApp().AuthKeeper.NewAccount(suite.chainB.GetContext(), interchainAcc) suite.chainB.GetSimApp().AuthKeeper.SetAccount(suite.chainB.GetContext(), interchainAcc) diff --git a/modules/apps/27-interchain-accounts/host/keeper/account.go b/modules/apps/27-interchain-accounts/host/keeper/account.go index 2a5499e3632..42509530e89 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account.go @@ -15,7 +15,7 @@ import ( // and block dependent information. An error is returned if an account already exists for the generated account. // An interchain account type is set in the account keeper and the interchain account address mapping is updated. func (k Keeper) createInterchainAccount(ctx context.Context, connectionID, controllerPortID string) (sdk.AccAddress, error) { - accAddress := icatypes.GenerateAddress(ctx, connectionID, controllerPortID) + accAddress := icatypes.GenerateAddress(k.HeaderService.HeaderInfo(ctx), connectionID, controllerPortID) if acc := k.authKeeper.GetAccount(ctx, accAddress); acc != nil { return nil, errorsmod.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 079e2aa7903..fe0a2cbb368 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -10,7 +10,7 @@ import ( ) func (suite *KeeperTestSuite) TestInitGenesis() { - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext().HeaderInfo(), ibctesting.FirstConnectionID, TestPortID) genesisState := genesistypes.HostGenesisState{ ActiveChannels: []genesistypes.ActiveChannel{ { @@ -65,7 +65,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() { suite.Run(tc.name, func() { suite.SetupTest() // reset - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext().HeaderInfo(), ibctesting.FirstConnectionID, TestPortID) genesisState := genesistypes.HostGenesisState{ ActiveChannels: []genesistypes.ActiveChannel{ { diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index f69752acbae..db00f4decde 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { { "account already exists", func() { - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext().HeaderInfo(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) interchainAcc := icatypes.NewInterchainAccount(authtypes.NewBaseAccountWithAddress(interchainAccAddr), path.EndpointA.ChannelConfig.PortID) suite.chainB.GetSimApp().AuthKeeper.NewAccount(suite.chainB.GetContext(), interchainAcc) suite.chainB.GetSimApp().AuthKeeper.SetAccount(suite.chainB.GetContext(), interchainAcc) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index d1542f52ace..44cb5142d21 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -1,13 +1,13 @@ package types import ( - "context" "encoding/json" "regexp" "strings" yaml "gopkg.in/yaml.v2" + "cosmossdk.io/core/header" errorsmod "cosmossdk.io/errors" crypto "github.com/cosmos/cosmos-sdk/crypto/types" @@ -43,15 +43,13 @@ type interchainAccountPretty struct { } // GenerateAddress returns an sdk.AccAddress derived using a host module account address, host connection ID, the controller portID, -// the current block app hash, and the current block data hash. The sdk.AccAddress returned is a sub-address of the host module account. -func GenerateAddress(ctx context.Context, connectionID, portID string) sdk.AccAddress { +// the current block app hash, and the current block hash (merkle root of block). The sdk.AccAddress returned is a sub-address of the host module account. +func GenerateAddress(headerInfo header.Info, connectionID, portID string) sdk.AccAddress { hostModuleAcc := sdkaddress.Module(ModuleName, []byte(hostAccountsKey)) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - header := sdkCtx.BlockHeader() buf := []byte(connectionID + portID) - buf = append(buf, header.AppHash...) - buf = append(buf, header.DataHash...) + buf = append(buf, headerInfo.AppHash...) + buf = append(buf, headerInfo.Hash...) return sdkaddress.Derive(hostModuleAcc, buf) } diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index 8eaf04be974..996d5b85e21 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -44,7 +44,7 @@ func TestTypesTestSuite(t *testing.T) { } func (suite *TypesTestSuite) TestGenerateAddress() { - addr := types.GenerateAddress(suite.chainA.GetContext(), "test-connection-id", "test-port-id") + addr := types.GenerateAddress(suite.chainA.GetContext().HeaderInfo(), "test-connection-id", "test-port-id") accAddr, err := sdk.AccAddressFromBech32(addr.String()) suite.Require().NoError(err, "TestGenerateAddress failed") diff --git a/testing/chain.go b/testing/chain.go index f57a7c47d35..afa881846c2 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -201,8 +201,13 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain { func (chain *TestChain) GetContext() sdk.Context { ctx := chain.App.GetBaseApp().NewUncachedContext(false, chain.ProposedHeader) + cmtHeader, err := cmttypes.HeaderFromProto(&chain.ProposedHeader) + require.NoError(chain.TB, err) + // since:cosmos-sdk/v0.52 when fetching time from context, it now returns from HeaderInfo headerInfo := header.Info{ + AppHash: chain.ProposedHeader.AppHash, + Hash: cmtHeader.Hash(), Time: chain.ProposedHeader.Time, ChainID: chain.ProposedHeader.ChainID, } @@ -337,6 +342,7 @@ func (chain *TestChain) commitBlock(res *abci.FinalizeBlockResponse) { // increment the current header chain.ProposedHeader = cmtproto.Header{ + Version: cmtprotoversion.Consensus{Block: cmtversion.BlockProtocol, App: 1}, ChainID: chain.ChainID, Height: chain.App.LastBlockHeight() + 1, AppHash: chain.App.LastCommitID().Hash, From 2bcf0941b8b6bfc603efe7fd0ecf78af2360e7b2 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 18 Dec 2024 09:23:14 +0100 Subject: [PATCH 2/2] chore: update changelog --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f9200953d2..48438165af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,16 +36,14 @@ 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 -* [\#7540](https://github.com/cosmos/ibc-go/pull/7540) Bump CometBFT to v0.38.15. +* [\#7261](https://github.com/cosmos/ibc-go/pull/7261) Bump CometBFT to v1.0.0. +* [\#7261](https://github.com/cosmos/ibc-go/pull/7261) Bump Cosmos SDK to v0.52.0. ### API Breaking +* (apps/27-interchain-accounts) [\#7713](https://github.com/cosmos/ibc-go/pull/7713) Update interchain accounts `GenerateAddress` func to now accept `header.Info` in favour of `sdk.Context`. This function now uses `AppHash` and `Hash` (merkle root of block) instead of `AppHash` and `DataHash` as pre-image data for address generation. * (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7213) Remove capabilities from `SendPacket`. * (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7225) Remove capabilities from `WriteAcknowledgement`. * (core, apps) [\#7232](https://github.com/cosmos/ibc-go/pull/7232) Remove capabilities from channel handshake methods. TODO list all changes @@ -63,6 +61,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (testing)[\#7430](https://github.com/cosmos/ibc-go/pull/7430) Update the block proposer in test chains for each block. + ### Features ### Bug Fixes