From c11a3337f7899c479ed431de6fdc9d774ebcf4a1 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 7 Feb 2024 11:31:51 +0100 Subject: [PATCH 1/3] 02-client routing: fix linter warnings --- e2e/testsuite/testsuite.go | 1 + modules/core/02-client/types/store.go | 1 + modules/core/exported/client.go | 4 +- .../06-solomachine/light_client_module.go | 86 +++++++------- .../08-wasm/light_client_module.go | 74 ++++++------ .../09-localhost/light_client_module.go | 12 +- .../09-localhost/light_client_module_test.go | 109 +++++++++--------- modules/light-clients/09-localhost/store.go | 2 + 8 files changed, 147 insertions(+), 142 deletions(-) diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 3d3e9410438..138632982ba 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -18,6 +18,7 @@ import ( sdkmath "cosmossdk.io/math" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/ibc-go/e2e/relayer" "github.com/cosmos/ibc-go/e2e/testsuite/diagnostics" feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" diff --git a/modules/core/02-client/types/store.go b/modules/core/02-client/types/store.go index d527a12d548..10c7be7f7ac 100644 --- a/modules/core/02-client/types/store.go +++ b/modules/core/02-client/types/store.go @@ -7,6 +7,7 @@ import ( storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index db02c654544..b1bc51f1eab 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -112,7 +112,7 @@ type LightClientModule interface { // CheckSubstituteAndUpdateState must verify that the provided substitute may be used to update the subject client. // The light client must set the updated client and consensus states within the clientStore for the subject client. - // DEPRECATED: will be removed as performs internal functionality + // Deprecated: will be removed as performs internal functionality RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error // Upgrade functions @@ -122,7 +122,7 @@ type LightClientModule interface { // This is to ensure that no premature upgrades occur, since upgrade plans committed to by the counterparty // may be cancelled or modified before the last planned height. // If the upgrade is verified, the upgraded client and consensus states must be set in the client store. - // DEPRECATED: will be removed as performs internal functionality + // Deprecated: will be removed as performs internal functionality VerifyUpgradeAndUpdateState( ctx sdk.Context, clientID string, diff --git a/modules/light-clients/06-solomachine/light_client_module.go b/modules/light-clients/06-solomachine/light_client_module.go index cb785b41ce3..68941c1e478 100644 --- a/modules/light-clients/06-solomachine/light_client_module.go +++ b/modules/light-clients/06-solomachine/light_client_module.go @@ -25,19 +25,19 @@ func NewLightClientModule(cdc codec.BinaryCodec) LightClientModule { } } -func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) { - l.storeProvider = storeProvider +func (lcm *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) { + lcm.storeProvider = storeProvider } // Initialize is called upon client creation, it allows the client to perform validation on the initial consensus state and set the // client state, consensus state and any client-specific metadata necessary for correct light client operation in the provided client store. -func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { +func (lcm LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { if err := validateClientID(clientID); err != nil { return err } var clientState ClientState - if err := l.cdc.Unmarshal(clientStateBz, &clientState); err != nil { + if err := lcm.cdc.Unmarshal(clientStateBz, &clientState); err != nil { return err } @@ -46,7 +46,7 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt } var consensusState ConsensusState - if err := l.cdc.Unmarshal(consensusStateBz, &consensusState); err != nil { + if err := lcm.cdc.Unmarshal(consensusStateBz, &consensusState); err != nil { return err } @@ -54,78 +54,78 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - return clientState.Initialize(ctx, l.cdc, clientStore, &consensusState) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + return clientState.Initialize(ctx, lcm.cdc, clientStore, &consensusState) } // VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. // It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour // will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned // if the ClientMessage fails to verify. -func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { +func (lcm LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { if err := validateClientID(clientID); err != nil { return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.VerifyClientMessage(ctx, l.cdc, clientStore, clientMsg) + return clientState.VerifyClientMessage(ctx, lcm.cdc, clientStore, clientMsg) } // Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage // has already been verified. -func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { +func (lcm LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { panic(errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID)) } - return clientState.CheckForMisbehaviour(ctx, l.cdc, clientStore, clientMsg) + return clientState.CheckForMisbehaviour(ctx, lcm.cdc, clientStore, clientMsg) } // UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified -func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { +func (lcm LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { panic(errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID)) } - clientState.UpdateStateOnMisbehaviour(ctx, l.cdc, clientStore, clientMsg) + clientState.UpdateStateOnMisbehaviour(ctx, lcm.cdc, clientStore, clientMsg) } // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. -func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { +func (lcm LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { panic(errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID)) } - return clientState.UpdateState(ctx, l.cdc, clientStore, clientMsg) + return clientState.UpdateState(ctx, lcm.cdc, clientStore, clientMsg) } // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -func (l LightClientModule) VerifyMembership( +func (lcm LightClientModule) VerifyMembership( ctx sdk.Context, clientID string, height exported.Height, // TODO: change to concrete type @@ -139,18 +139,18 @@ func (l LightClientModule) VerifyMembership( return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.VerifyMembership(ctx, clientStore, l.cdc, height, delayTimePeriod, delayBlockPeriod, proof, path, value) + return clientState.VerifyMembership(ctx, clientStore, lcm.cdc, height, delayTimePeriod, delayBlockPeriod, proof, path, value) } // VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -func (l LightClientModule) VerifyNonMembership( +func (lcm LightClientModule) VerifyNonMembership( ctx sdk.Context, clientID string, height exported.Height, // TODO: change to concrete type @@ -163,43 +163,43 @@ func (l LightClientModule) VerifyNonMembership( return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.VerifyNonMembership(ctx, clientStore, l.cdc, height, delayTimePeriod, delayBlockPeriod, proof, path) + return clientState.VerifyNonMembership(ctx, clientStore, lcm.cdc, height, delayTimePeriod, delayBlockPeriod, proof, path) } // Status must return the status of the client. Only Active clients are allowed to process packets. -func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { +func (lcm LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { if err := validateClientID(clientID); err != nil { return exported.Unknown // TODO: or panic } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { return exported.Unknown } - return clientState.Status(ctx, clientStore, l.cdc) + return clientState.Status(ctx, clientStore, lcm.cdc) } // TimestampAtHeight must return the timestamp for the consensus state associated with the provided height. -func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { +func (lcm LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { if err := validateClientID(clientID); err != nil { return 0, err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - clientState, found := getClientState(clientStore, l.cdc) + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + clientState, found := getClientState(clientStore, lcm.cdc) if !found { return 0, errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.GetTimestampAtHeight(ctx, clientStore, l.cdc, height) + return clientState.GetTimestampAtHeight(ctx, clientStore, lcm.cdc, height) } func validateClientID(clientID string) error { @@ -217,8 +217,8 @@ func validateClientID(clientID string) error { // // CheckSubstituteAndUpdateState must verify that the provided substitute may be used to update the subject client. // // The light client must set the updated client and consensus states within the clientStore for the subject client. -// // DEPRECATED: will be removed as performs internal functionality -func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { +// // Deprecated: will be removed as performs internal functionality +func (LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { return nil } @@ -229,7 +229,7 @@ func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteCl // // This is to ensure that no premature upgrades occur, since upgrade plans committed to by the counterparty // // may be cancelled or modified before the last planned height. // // If the upgrade is verified, the upgraded client and consensus states must be set in the client store. -// // DEPRECATED: will be removed as performs internal functionality -func (l LightClientModule) VerifyUpgradeAndUpdateState(ctx sdk.Context, clientID string, newClient []byte, newConsState []byte, upgradeClientProof, upgradeConsensusStateProof []byte) error { +// // Deprecated: will be removed as performs internal functionality +func (LightClientModule) VerifyUpgradeAndUpdateState(ctx sdk.Context, clientID string, newClient []byte, newConsState []byte, upgradeClientProof, upgradeConsensusStateProof []byte) error { return nil } diff --git a/modules/light-clients/08-wasm/light_client_module.go b/modules/light-clients/08-wasm/light_client_module.go index e302a38b8bc..141d78bfd38 100644 --- a/modules/light-clients/08-wasm/light_client_module.go +++ b/modules/light-clients/08-wasm/light_client_module.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -15,30 +15,30 @@ var _ exported.LightClientModule = (*LightClientModule)(nil) // LightClientModule implements the core IBC api.LightClientModule interface? type LightClientModule struct { - keeper keeper.Keeper + keeper wasmkeeper.Keeper storeProvider exported.ClientStoreProvider } // NewLightClientModule creates and returns a new 08-wasm LightClientModule. -func NewLightClientModule(keeper keeper.Keeper) LightClientModule { +func NewLightClientModule(keeper wasmkeeper.Keeper) LightClientModule { return LightClientModule{ keeper: keeper, } } -func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) { - l.storeProvider = storeProvider +func (lcm *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) { + lcm.storeProvider = storeProvider } // Initialize is called upon client creation, it allows the client to perform validation on the initial consensus state and set the // client state, consensus state and any client-specific metadata necessary for correct light client operation in the provided client store. -func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { +func (lcm LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { if err := validateClientID(clientID); err != nil { return err } var clientState types.ClientState - if err := l.keeper.Codec().Unmarshal(clientStateBz, &clientState); err != nil { + if err := lcm.keeper.Codec().Unmarshal(clientStateBz, &clientState); err != nil { return err } @@ -47,7 +47,7 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt } var consensusState types.ConsensusState - if err := l.keeper.Codec().Unmarshal(consensusStateBz, &consensusState); err != nil { + if err := lcm.keeper.Codec().Unmarshal(consensusStateBz, &consensusState); err != nil { return err } @@ -55,8 +55,8 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() return clientState.Initialize(ctx, cdc, clientStore, &consensusState) } @@ -65,31 +65,31 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt // It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour // will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned // if the ClientMessage fails to verify. -func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { +func (lcm LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { if err := validateClientID(clientID); err != nil { return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.VerifyClientMessage(ctx, l.keeper.Codec(), clientStore, clientMsg) + return clientState.VerifyClientMessage(ctx, lcm.keeper.Codec(), clientStore, clientMsg) } // Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage // has already been verified. -func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { +func (lcm LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -100,13 +100,13 @@ func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string } // UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified -func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { +func (lcm LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -118,13 +118,13 @@ func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID s // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. -func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { +func (lcm LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { if err := validateClientID(clientID); err != nil { panic(err) } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -136,7 +136,7 @@ func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientM // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -func (l LightClientModule) VerifyMembership( +func (lcm LightClientModule) VerifyMembership( ctx sdk.Context, clientID string, height exported.Height, // TODO: change to concrete type @@ -150,8 +150,8 @@ func (l LightClientModule) VerifyMembership( return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -163,7 +163,7 @@ func (l LightClientModule) VerifyMembership( // VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). -func (l LightClientModule) VerifyNonMembership( +func (lcm LightClientModule) VerifyNonMembership( ctx sdk.Context, clientID string, height exported.Height, // TODO: change to concrete type @@ -176,8 +176,8 @@ func (l LightClientModule) VerifyNonMembership( return err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -188,13 +188,13 @@ func (l LightClientModule) VerifyNonMembership( } // Status must return the status of the client. Only Active clients are allowed to process packets. -func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { +func (lcm LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { if err := validateClientID(clientID); err != nil { return exported.Unknown // TODO: or panic } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -205,13 +205,13 @@ func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Sta } // TimestampAtHeight must return the timestamp for the consensus state associated with the provided height. -func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { +func (lcm LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { if err := validateClientID(clientID); err != nil { return 0, err } - clientStore := l.storeProvider.ClientStore(ctx, clientID) - cdc := l.keeper.Codec() + clientStore := lcm.storeProvider.ClientStore(ctx, clientID) + cdc := lcm.keeper.Codec() clientState, found := types.GetClientState(clientStore, cdc) if !found { @@ -237,7 +237,7 @@ func validateClientID(clientID string) error { // // CheckSubstituteAndUpdateState must verify that the provided substitute may be used to update the subject client. // // The light client must set the updated client and consensus states within the clientStore for the subject client. // // DEPRECATED: will be removed as performs internal functionality -func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { +func (LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { return nil } @@ -249,6 +249,6 @@ func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteCl // // may be cancelled or modified before the last planned height. // // If the upgrade is verified, the upgraded client and consensus states must be set in the client store. // // DEPRECATED: will be removed as performs internal functionality -func (l LightClientModule) VerifyUpgradeAndUpdateState(ctx sdk.Context, clientID string, newClient []byte, newConsState []byte, upgradeClientProof, upgradeConsensusStateProof []byte) error { +func (LightClientModule) VerifyUpgradeAndUpdateState(ctx sdk.Context, clientID string, newClient []byte, newConsState []byte, upgradeClientProof, upgradeConsensusStateProof []byte) error { return nil } diff --git a/modules/light-clients/09-localhost/light_client_module.go b/modules/light-clients/09-localhost/light_client_module.go index 890f40de8e0..87dce96aa55 100644 --- a/modules/light-clients/09-localhost/light_client_module.go +++ b/modules/light-clients/09-localhost/light_client_module.go @@ -75,7 +75,7 @@ func (lcm LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID strin return clientState.VerifyClientMessage(ctx, cdc, clientStore, clientMsg) } -func (lcm LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { +func (LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { clientType, _, err := clienttypes.ParseClientIdentifier(clientID) if err != nil { panic(err) @@ -88,7 +88,7 @@ func (lcm LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID stri return false } -func (lcm LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { +func (LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { clientType, _, err := clienttypes.ParseClientIdentifier(clientID) if err != nil { panic(err) @@ -181,11 +181,11 @@ func (lcm LightClientModule) VerifyNonMembership( } // Status always returns Active. The 09-localhost status cannot be changed. -func (lcm LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { +func (LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { return exported.Active } -func (lcm LightClientModule) TimestampAtHeight( +func (LightClientModule) TimestampAtHeight( ctx sdk.Context, clientID string, height exported.Height, @@ -202,11 +202,11 @@ func (lcm LightClientModule) TimestampAtHeight( return uint64(ctx.BlockTime().UnixNano()), nil } -func (lcm LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { +func (LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") } -func (lcm LightClientModule) VerifyUpgradeAndUpdateState( +func (LightClientModule) VerifyUpgradeAndUpdateState( ctx sdk.Context, clientID string, newClient []byte, diff --git a/modules/light-clients/09-localhost/light_client_module_test.go b/modules/light-clients/09-localhost/light_client_module_test.go index 3de479f5fb8..6c4e46e0d93 100644 --- a/modules/light-clients/09-localhost/light_client_module_test.go +++ b/modules/light-clients/09-localhost/light_client_module_test.go @@ -2,6 +2,7 @@ package localhost_test import ( sdk "github.com/cosmos/cosmos-sdk/types" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -13,13 +14,13 @@ import ( "github.com/cosmos/ibc-go/v8/testing/mock" ) -func (s *LocalhostTestSuite) TestStatus() { - lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) - s.Require().True(found) - s.Require().Equal(exported.Active, lightClientModule.Status(s.chain.GetContext(), exported.LocalhostClientID)) +func (suite *LocalhostTestSuite) TestStatus() { + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) + suite.Require().True(found) + suite.Require().Equal(exported.Active, lightClientModule.Status(s.chain.GetContext(), exported.LocalhostClientID)) } -func (s *LocalhostTestSuite) TestVerifyMembership() { +func (suite *LocalhostTestSuite) TestVerifyMembership() { var ( path exported.Path value []byte @@ -33,14 +34,14 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { { "success: client state verification", func() { - clientState := s.chain.GetClientState(exported.LocalhostClientID) + clientState := suite.chain.GetClientState(exported.LocalhostClientID) merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(exported.LocalhostClientID)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath - value = clienttypes.MustMarshalClientState(s.chain.Codec, clientState) + value = clienttypes.MustMarshalClientState(suite.chain.Codec, clientState) }, true, }, @@ -50,18 +51,18 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { connectionEnd := connectiontypes.NewConnectionEnd( connectiontypes.OPEN, exported.LocalhostClientID, - connectiontypes.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, s.chain.GetPrefix()), + connectiontypes.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, suite.chain.GetPrefix()), connectiontypes.GetCompatibleVersions(), 0, ) - s.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(s.chain.GetContext(), exported.LocalhostConnectionID, connectionEnd) + suite.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chain.GetContext(), exported.LocalhostConnectionID, connectionEnd) merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(exported.LocalhostConnectionID)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath - value = s.chain.Codec.MustMarshal(&connectionEnd) + value = suite.chain.Codec.MustMarshal(&connectionEnd) }, true, }, @@ -76,14 +77,14 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { mock.Version, ) - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath - value = s.chain.Codec.MustMarshal(&channel) + value = suite.chain.Codec.MustMarshal(&channel) }, true, }, @@ -91,11 +92,11 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { "success: next sequence recv verification", func() { nextSeqRecv := uint64(100) - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetNextSequenceRecv(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, nextSeqRecv) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetNextSequenceRecv(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, nextSeqRecv) merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(mock.PortID, ibctesting.FirstChannelID)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath value = sdk.Uint64ToBigEndian(nextSeqRecv) @@ -116,12 +117,12 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { 0, ) - commitmentBz := channeltypes.CommitPacket(s.chain.Codec, packet) - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketCommitment(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, commitmentBz) + commitmentBz := channeltypes.CommitPacket(suite.chain.Codec, packet) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, commitmentBz) merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath value = commitmentBz @@ -131,11 +132,11 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { { "success: packet acknowledgement verification", func() { - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, ibctesting.MockAcknowledgement) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, ibctesting.MockAcknowledgement) merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 1)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath value = ibctesting.MockAcknowledgement @@ -160,8 +161,8 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { "no value found at provided key path", func() { merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 100)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath value = ibctesting.MockAcknowledgement @@ -179,17 +180,17 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { mock.Version, ) - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath // modify the channel before marshalling to value bz channel.State = channeltypes.CLOSED - value = s.chain.Codec.MustMarshal(&channel) + value = suite.chain.Codec.MustMarshal(&channel) }, false, }, @@ -198,16 +199,16 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { for _, tc := range testCases { tc := tc - s.Run(tc.name, func() { - s.SetupTest() + suite.Run(tc.name, func() { + suite.SetupTest() tc.malleate() - lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) - s.Require().True(found) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) + suite.Require().True(found) err := lightClientModule.VerifyMembership( - s.chain.GetContext(), + suite.chain.GetContext(), exported.LocalhostClientID, clienttypes.ZeroHeight(), 0, 0, // use zero values for delay periods @@ -217,15 +218,15 @@ func (s *LocalhostTestSuite) TestVerifyMembership() { ) if tc.expPass { - s.Require().NoError(err) + suite.Require().NoError(err) } else { - s.Require().Error(err) + suite.Require().Error(err) } }) } } -func (s *LocalhostTestSuite) TestVerifyNonMembership() { +func (suite *LocalhostTestSuite) TestVerifyNonMembership() { var path exported.Path testCases := []struct { @@ -237,8 +238,8 @@ func (s *LocalhostTestSuite) TestVerifyNonMembership() { "success: packet receipt absence verification", func() { merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath }, @@ -247,11 +248,11 @@ func (s *LocalhostTestSuite) TestVerifyNonMembership() { { "packet receipt absence verification fails", func() { - s.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketReceipt(s.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1) + suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketReceipt(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1) merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) - merklePath, err := commitmenttypes.ApplyPrefix(s.chain.GetPrefix(), merklePath) - s.Require().NoError(err) + merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) + suite.Require().NoError(err) path = merklePath }, @@ -276,16 +277,16 @@ func (s *LocalhostTestSuite) TestVerifyNonMembership() { for _, tc := range testCases { tc := tc - s.Run(tc.name, func() { - s.SetupTest() + suite.Run(tc.name, func() { + suite.SetupTest() tc.malleate() - lightClientModule, found := s.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) - s.Require().True(found) + lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) + suite.Require().True(found) err := lightClientModule.VerifyNonMembership( - s.chain.GetContext(), + suite.chain.GetContext(), exported.LocalhostClientID, clienttypes.ZeroHeight(), 0, 0, // use zero values for delay periods @@ -294,9 +295,9 @@ func (s *LocalhostTestSuite) TestVerifyNonMembership() { ) if tc.expPass { - s.Require().NoError(err) + suite.Require().NoError(err) } else { - s.Require().Error(err) + suite.Require().Error(err) } }) } diff --git a/modules/light-clients/09-localhost/store.go b/modules/light-clients/09-localhost/store.go index 0046ce0c093..b66674f7022 100644 --- a/modules/light-clients/09-localhost/store.go +++ b/modules/light-clients/09-localhost/store.go @@ -2,7 +2,9 @@ package localhost import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ) From e216908d87657de57b81b4d075d5f87eb6395dc7 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 7 Feb 2024 11:33:44 +0100 Subject: [PATCH 2/3] fix variable name --- modules/light-clients/09-localhost/light_client_module_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/light-clients/09-localhost/light_client_module_test.go b/modules/light-clients/09-localhost/light_client_module_test.go index 6c4e46e0d93..c56c76fa0a8 100644 --- a/modules/light-clients/09-localhost/light_client_module_test.go +++ b/modules/light-clients/09-localhost/light_client_module_test.go @@ -17,7 +17,7 @@ import ( func (suite *LocalhostTestSuite) TestStatus() { lightClientModule, found := suite.chain.GetSimApp().IBCKeeper.ClientKeeper.GetRouter().GetRoute(exported.Localhost) suite.Require().True(found) - suite.Require().Equal(exported.Active, lightClientModule.Status(s.chain.GetContext(), exported.LocalhostClientID)) + suite.Require().Equal(exported.Active, lightClientModule.Status(suite.chain.GetContext(), exported.LocalhostClientID)) } func (suite *LocalhostTestSuite) TestVerifyMembership() { From 0ba931aa890bf7de13f765d0293f49fe147a61a0 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 7 Feb 2024 11:43:46 +0100 Subject: [PATCH 3/3] return error --- modules/core/02-client/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 05ad97ee049..657c76672a6 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -66,7 +66,7 @@ func (k Keeper) GetRouter() *types.Router { func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { localhostModule, found := k.router.GetRoute(exported.Localhost) if !found { - errorsmod.Wrap(types.ErrRouteNotFound, exported.Localhost) + return errorsmod.Wrap(types.ErrRouteNotFound, exported.Localhost) } return localhostModule.Initialize(ctx, exported.LocalhostClientID, nil, nil)