Skip to content

Commit

Permalink
refactor: use client module for status checks in 02-client handlers (#…
Browse files Browse the repository at this point in the history
…6919) (#6981)

* refactor: use client module for status checks in 02-client handlers

* Update modules/core/02-client/keeper/client.go

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
(cherry picked from commit f4f0d04)

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
mergify[bot] and damiannolan authored Jul 29, 2024
1 parent f08a319 commit 09326c8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit 09326c8

Please sign in to comment.