Skip to content

Commit

Permalink
ConsensusState is retrieved by light clients in verifyXYZ as necessary (
Browse files Browse the repository at this point in the history
cosmos#7005)

* move con state retrieval to verify funcs

* refactor tm client state tests

* fix build

* Apply suggestions from code review

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: Aditya <[email protected]>

* apply @fedekunze review comments

* apply @AdityaSripal review comment

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: Aditya <[email protected]>
  • Loading branch information
3 people authored Aug 12, 2020
1 parent 308c879 commit d752a7b
Show file tree
Hide file tree
Showing 10 changed files with 578 additions and 497 deletions.
6 changes: 0 additions & 6 deletions x/ibc/02-client/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type ClientState interface {
proof []byte,
connectionID string,
connectionEnd connectionexported.ConnectionI,
consensusState ConsensusState,
) error
VerifyChannelState(
store sdk.KVStore,
Expand All @@ -57,7 +56,6 @@ type ClientState interface {
portID,
channelID string,
channel channelexported.ChannelI,
consensusState ConsensusState,
) error
VerifyPacketCommitment(
store sdk.KVStore,
Expand All @@ -69,7 +67,6 @@ type ClientState interface {
channelID string,
sequence uint64,
commitmentBytes []byte,
consensusState ConsensusState,
) error
VerifyPacketAcknowledgement(
store sdk.KVStore,
Expand All @@ -81,7 +78,6 @@ type ClientState interface {
channelID string,
sequence uint64,
acknowledgement []byte,
consensusState ConsensusState,
) error
VerifyPacketAcknowledgementAbsence(
store sdk.KVStore,
Expand All @@ -92,7 +88,6 @@ type ClientState interface {
portID,
channelID string,
sequence uint64,
consensusState ConsensusState,
) error
VerifyNextSequenceRecv(
store sdk.KVStore,
Expand All @@ -103,7 +98,6 @@ type ClientState interface {
portID,
channelID string,
nextSequenceRecv uint64,
consensusState ConsensusState,
) error
}

Expand Down
92 changes: 13 additions & 79 deletions x/ibc/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k Keeper) VerifyClientConsensusState(
k.clientKeeper.ClientStore(ctx, clientID), k.cdc, targetConsState.GetRoot(), height,
connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
); err != nil {
return sdkerrors.Wrap(err, "failed consensus state verification")
return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -55,22 +55,11 @@ func (k Keeper) VerifyConnectionState(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyConnectionState(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, connectionID, connectionEnd, consensusState,
connection.GetCounterparty().GetPrefix(), proof, connectionID, connectionEnd,
); err != nil {
return sdkerrors.Wrap(err, "failed connection state verification")
return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -92,23 +81,12 @@ func (k Keeper) VerifyChannelState(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyChannelState(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof,
portID, channelID, channel, consensusState,
portID, channelID, channel,
); err != nil {
return sdkerrors.Wrap(err, "failed channel state verification")
return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -131,23 +109,12 @@ func (k Keeper) VerifyPacketCommitment(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyPacketCommitment(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, commitmentBytes, consensusState,
sequence, commitmentBytes,
); err != nil {
return sdkerrors.Wrap(err, "failed packet commitment verification")
return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -170,23 +137,12 @@ func (k Keeper) VerifyPacketAcknowledgement(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyPacketAcknowledgement(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, acknowledgement, consensusState,
sequence, acknowledgement,
); err != nil {
return sdkerrors.Wrap(err, "failed packet acknowledgement verification")
return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -209,23 +165,12 @@ func (k Keeper) VerifyPacketAcknowledgementAbsence(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyPacketAcknowledgementAbsence(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, consensusState,
sequence,
); err != nil {
return sdkerrors.Wrap(err, "failed packet acknowledgement absence verification")
return sdkerrors.Wrapf(err, "failed packet acknowledgement absence verification for client (%s)", connection.GetClientID())
}

return nil
Expand All @@ -247,23 +192,12 @@ func (k Keeper) VerifyNextSequenceRecv(
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, connection.GetClientID())
}

// TODO: move to specific clients; blocked by #5502
consensusState, found := k.clientKeeper.GetClientConsensusState(
ctx, connection.GetClientID(), height,
)
if !found {
return sdkerrors.Wrapf(
clienttypes.ErrConsensusStateNotFound,
"clientID (%s), height (%d)", connection.GetClientID(), height,
)
}

if err := clientState.VerifyNextSequenceRecv(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
nextSequenceRecv, consensusState,
nextSequenceRecv,
); err != nil {
return sdkerrors.Wrap(err, "failed next sequence receive verification")
return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", connection.GetClientID())
}

return nil
Expand Down
Loading

0 comments on commit d752a7b

Please sign in to comment.