From f4f0d047ca618169c155daf50ef1be81df856a0a Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 29 Jul 2024 15:30:13 +0200 Subject: [PATCH] refactor: use client module for status checks in 02-client handlers (#6919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: use client module for status checks in 02-client handlers * Update modules/core/02-client/keeper/client.go --------- Co-authored-by: Carlos Rodriguez Co-authored-by: DimitrisJim Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/core/02-client/keeper/client.go | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index d91c141301f..422fca31ba3 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -31,7 +31,7 @@ func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, c return "", err } - if status := k.GetClientStatus(ctx, clientID); status != exported.Active { + if status := clientModule.Status(ctx, clientID); status != exported.Active { return "", errorsmod.Wrapf(types.ErrClientNotActive, "cannot create client (%s) with status %s", clientID, status) } @@ -46,15 +46,15 @@ func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, c // UpdateClient updates the consensus state and the state root from a provided header. func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { - if status := k.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) - } - clientModule, err := k.Route(ctx, clientID) if err != nil { return err } + if status := clientModule.Status(ctx, clientID); status != exported.Active { + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) + } + if err := clientModule.VerifyClientMessage(ctx, clientID, clientMsg); err != nil { return err } @@ -90,15 +90,15 @@ func (k *Keeper) UpgradeClient( clientID string, upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof []byte, ) error { - if status := k.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) - } - clientModule, err := k.Route(ctx, clientID) if err != nil { return err } + if status := clientModule.Status(ctx, clientID); status != exported.Active { + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) + } + if err := clientModule.VerifyUpgradeAndUpdateState(ctx, clientID, upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof); err != nil { return errorsmod.Wrapf(err, "cannot upgrade client with ID %s", clientID) } @@ -119,17 +119,17 @@ func (k *Keeper) UpgradeClient( // as well as copying the necessary consensus states from the substitute to the subject client store. // The substitute must be Active and the subject must not be Active. func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error { - if status := k.GetClientStatus(ctx, subjectClientID); status == exported.Active { - return errorsmod.Wrapf(types.ErrInvalidRecoveryClient, "cannot recover %s subject client", exported.Active) + clientModule, err := k.Route(ctx, subjectClientID) + if err != nil { + return errorsmod.Wrap(types.ErrRouteNotFound, subjectClientID) } - if status := k.GetClientStatus(ctx, substituteClientID); status != exported.Active { - return errorsmod.Wrapf(types.ErrClientNotActive, "substitute client is not %s, status is %s", exported.Active, status) + if status := clientModule.Status(ctx, subjectClientID); status == exported.Active { + return errorsmod.Wrapf(types.ErrInvalidRecoveryClient, "cannot recover subject client (%s) with status %s", subjectClientID, status) } - clientModule, err := k.Route(ctx, subjectClientID) - if err != nil { - return errorsmod.Wrap(types.ErrRouteNotFound, subjectClientID) + if status := clientModule.Status(ctx, substituteClientID); status != exported.Active { + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot recover client using substitute client (%s) with status %s", substituteClientID, status) } subjectLatestHeight := clientModule.LatestHeight(ctx, subjectClientID)