Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ibc): add debug log and reason when client fails to be made canonical #1349

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions x/lightclient/keeper/canonical_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
func (k Keeper) GetProspectiveCanonicalClient(ctx sdk.Context, rollappId string, maxHeight uint64) (clientID string, stateCompatible bool) {
k.ibcClientKeeper.IterateClientStates(ctx, nil, func(client string, cs exported.ClientState) bool {
err := k.validClient(ctx, client, cs, rollappId, maxHeight)
if err != nil && !errorsmod.IsOf(err, errChainIDMismatch) {
ctx.Logger().Debug("tried to validate rollapp against light client for same chain id: rollapp: %s: client: %s", rollappId, client, "err", err)
}
if err == nil {
clientID = client
stateCompatible = true
Expand Down Expand Up @@ -63,13 +66,15 @@ func (k Keeper) expectedClient(ctx sdk.Context) ibctm.ClientState {
return types.ExpectedCanonicalClientParams(k.sequencerKeeper.UnbondingTime(ctx))
}

var errChainIDMismatch = errors.New("chain id mismatch")

func (k Keeper) validClient(ctx sdk.Context, clientID string, cs exported.ClientState, rollappId string, maxHeight uint64) error {
tmClientState, ok := cs.(*ibctm.ClientState)
if !ok {
return errors.New("not tm client")
}
if tmClientState.ChainId != rollappId {
return errors.New("wrong chain id")
return errChainIDMismatch
}

expClient := k.expectedClient(ctx)
Expand All @@ -94,24 +99,24 @@ func (k Keeper) validClient(ctx sdk.Context, clientID string, cs exported.Client
tmConsensusState, _ := consensusState.(*ibctm.ConsensusState)
stateInfoH, err := k.rollappKeeper.FindStateInfoByHeight(ctx, rollappId, h)
if err != nil {
return errorsmod.Wrap(err, "find state info by height h")
return errorsmod.Wrapf(err, "find state info by height h: %d", h)
}
stateInfoHplus1, err := k.rollappKeeper.FindStateInfoByHeight(ctx, rollappId, h+1)
if err != nil {
return errorsmod.Wrap(err, "find state info by height h+1")
return errorsmod.Wrapf(err, "find state info by height h+1: %d", h+1)
}
bd, _ := stateInfoH.GetBlockDescriptor(h)
oldSequencer, err := k.GetSequencerPubKey(ctx, stateInfoHplus1.Sequencer)
nextSeq, err := k.GetSequencerPubKey(ctx, stateInfoHplus1.Sequencer)
if err != nil {
return errorsmod.Wrap(err, "get sequencer pubkey")
}
rollappState := types.RollappState{
BlockDescriptor: bd,
NextBlockSequencer: oldSequencer,
NextBlockSequencer: nextSeq,
}
err = types.CheckCompatibility(*tmConsensusState, rollappState)
if err != nil {
return errorsmod.Wrap(err, "check compatibility")
return errorsmod.Wrapf(err, "check compatibility: height: %d", h)
}
atLeastOneMatch = true
}
Expand Down
2 changes: 1 addition & 1 deletion x/lightclient/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CheckCompatibility(ibcState ibctm.ConsensusState, raState RollappState) err
return errors.Join(ErrValidatorHashMismatch, err)
}
if !bytes.Equal(ibcState.NextValidatorsHash, nextValHashFromStateInfo) {
return errorsmod.Wrap(ErrValidatorHashMismatch, "next validator hash does not match the sequencer for h+1")
return errorsmod.Wrap(ErrValidatorHashMismatch, "cons state next validator hash does not match the state info hash for sequencer for h+1")
}
if !raState.BlockDescriptor.Timestamp.IsZero() && !ibcState.Timestamp.Equal(raState.BlockDescriptor.Timestamp) {
return errorsmod.Wrap(ErrTimestampMismatch, "block descriptor timestamp does not match tendermint header timestamp")
Expand Down
Loading