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

imp: remove height from header and merge header with misbehaviour #4049

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

var _ exported.ClientMessage = &Header{}
var _ exported.ClientMessage = &ClientMessage{}

// ClientType defines that the Header is a Wasm client consensus algorithm
func (h Header) ClientType() string {
// ClientType defines that the client message is a Wasm client consensus algorithm
func (c ClientMessage) ClientType() string {
return exported.Wasm
}

// ValidateBasic defines a basic validation for the wasm client header.
func (h Header) ValidateBasic() error {
if len(h.Data) == 0 {
// ValidateBasic defines a basic validation for the wasm client message.
func (c ClientMessage) ValidateBasic() error {
if len(c.Data) == 0 {
return errorsmod.Wrap(ErrInvalidData, "data cannot be empty")
}

Expand Down
51 changes: 51 additions & 0 deletions modules/light-clients/08-wasm/types/client_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package types_test

import (
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

func (suite *TypesTestSuite) TestClientMessageValidateBasic() {
testCases := []struct {
name string
clientMessage *types.ClientMessage
expPass bool
}{
{
"valid client message",
&types.ClientMessage{
Data: []byte("data"),
},
true,
},
{
"data is nil",
&types.ClientMessage{
Data: nil,
},
false,
},
{
"data is empty",
&types.ClientMessage{
Data: []byte{},
},
false,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
clientMessage := tc.clientMessage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant var, but feel free to ignore, its probably fine


suite.Require().Equal(exported.Wasm, clientMessage.ClientType())
err := clientMessage.ValidateBasic()

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type (
func (cs ClientState) Status(ctx sdk.Context, clientStore sdk.KVStore, _ codec.BinaryCodec) exported.Status {
payload := statusPayload{Status: statusInnerPayload{}}

result, err := wasmQuery[statusQueryResponse](ctx, clientStore, &cs, payload)
result, err := wasmQuery[statusResult](ctx, clientStore, &cs, payload)
if err != nil {
return exported.Unknown
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (cs ClientState) GetTimestampAtHeight(
},
}

result, err := wasmQuery[timestampAtHeightQueryResponse](ctx, clientStore, &cs, payload)
result, err := wasmQuery[timestampAtHeightResult](ctx, clientStore, &cs, payload)
if err != nil {
return 0, errorsmod.Wrapf(err, "height (%s)", height)
}
Expand Down
6 changes: 1 addition & 5 deletions modules/light-clients/08-wasm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
)
registry.RegisterImplementations(
(*exported.ClientMessage)(nil),
&Header{},
)
registry.RegisterImplementations(
(*exported.ClientMessage)(nil),
&Misbehaviour{},
&ClientMessage{},
)
registry.RegisterImplementations(
(*sdk.Msg)(nil),
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (cs ClientState) ExportMetadata(store sdk.KVStore) []exported.GenesisMetada
var payload exportMetadataPayload

ctx := sdk.NewContext(nil, tmproto.Header{Height: 1, Time: time.Now()}, true, nil) // context with infinite gas meter
result, err := wasmQuery[metadataQueryResponse](ctx, store, &cs, payload)
result, err := wasmQuery[metadataResult](ctx, store, &cs, payload)
if err != nil {
panic(err)
}
Expand Down
55 changes: 0 additions & 55 deletions modules/light-clients/08-wasm/types/header_test.go

This file was deleted.

22 changes: 0 additions & 22 deletions modules/light-clients/08-wasm/types/misbehaviour.go

This file was deleted.

27 changes: 8 additions & 19 deletions modules/light-clients/08-wasm/types/misbehaviour_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type (
checkForMisbehaviourInnerPayload struct {
ClientMessage clientMessage `json:"client_message"`
ClientMessage *ClientMessage `json:"client_message"`
}
checkForMisbehaviourPayload struct {
CheckForMisbehaviour checkForMisbehaviourInnerPayload `json:"check_for_misbehaviour"`
Expand All @@ -18,30 +18,19 @@ type (

// CheckForMisbehaviour detects misbehaviour in a submitted Header message and verifies
// the correctness of a submitted Misbehaviour ClientMessage
func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool {
clientMsgConcrete := clientMessage{
Header: nil,
Misbehaviour: nil,
}
switch clientMsg := msg.(type) {
case *Header:
clientMsgConcrete.Header = clientMsg
case *Misbehaviour:
clientMsgConcrete.Misbehaviour = clientMsg
}

if clientMsgConcrete.Header == nil && clientMsgConcrete.Misbehaviour == nil {
func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) bool {
clientMessage, ok := clientMsg.(*ClientMessage)
if !ok {
return false
}

inner := checkForMisbehaviourInnerPayload{
ClientMessage: clientMsgConcrete,
}
payload := checkForMisbehaviourPayload{
CheckForMisbehaviour: inner,
CheckForMisbehaviour: checkForMisbehaviourInnerPayload{
ClientMessage: clientMessage,
},
}

result, err := wasmQuery[checkForMisbehaviourQueryResponse](ctx, clientStore, &cs, payload)
result, err := wasmQuery[checkForMisbehaviourResult](ctx, clientStore, &cs, payload)
if err != nil {
panic(err)
}
Expand Down
Loading
Loading