Skip to content

Commit

Permalink
Final IBC migration and Amino removal (#7157)
Browse files Browse the repository at this point in the history
* migrate tm messages and change header/evidence to pointers

* remove amino

* add nil checks and test for pointer changes

* fix format
  • Loading branch information
colin-axner authored Aug 25, 2020
1 parent 2df04d6 commit 1f7a278
Show file tree
Hide file tree
Showing 41 changed files with 1,654 additions and 664 deletions.
4 changes: 2 additions & 2 deletions proto/ibc/lightclients/solomachine/v1/solomachine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ message MsgCreateClient {
message MsgUpdateClient {
option (gogoproto.goproto_getters) = false;
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
Header header = 2 [(gogoproto.nullable) = false];
Header header = 2;
}

// MsgSubmitClientMisbehaviour defines an sdk.Msg type that supports submitting
Expand All @@ -87,6 +87,6 @@ message MsgSubmitClientMisbehaviour {
option (gogoproto.goproto_getters) = false;
bytes submitter = 1
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
Evidence evidence = 2 [(gogoproto.nullable) = false];
Evidence evidence = 2;
}

55 changes: 52 additions & 3 deletions proto/ibc/tendermint/tendermint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ message Evidence {
string chain_id = 2 [(gogoproto.moretags) = "yaml:\"chain_id\""];
Header header_1 = 3 [
(gogoproto.customname) = "Header1",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"header_1\""
];
Header header_2 = 4 [
(gogoproto.customname) = "Header2",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"header_2\""
];
}
Expand All @@ -103,7 +101,6 @@ message Evidence {
message Header {
.tendermint.types.SignedHeader signed_header = 1 [
(gogoproto.embed) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"signed_header\""
];

Expand All @@ -119,3 +116,55 @@ message Fraction {
int64 numerator = 1;
int64 denominator = 2;
}

// MsgCreateClient defines a message to create a tendermint client.
message MsgCreateClient {
option (gogoproto.goproto_getters) = false;

string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
Header header = 2;
Fraction trust_level = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"trust_level\""
];
google.protobuf.Duration trusting_period = 4 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.moretags) = "yaml:\"trusting_period\""
];
google.protobuf.Duration unbonding_period = 5 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.moretags) = "yaml:\"unbonding_period\""
];
google.protobuf.Duration max_clock_drift = 6 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.moretags) = "yaml:\"max_clock_drift\""
];
repeated ics23.ProofSpec proof_specs = 8
[(gogoproto.moretags) = "yaml:\"proof_specs\""];
bytes signer = 7
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgCreateClient defines an sdk.Msg to update a tendermint client state to
// the given header.
message MsgUpdateClient {
option (gogoproto.goproto_getters) = false;

string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
Header header = 2;
bytes signer = 3
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgSubmitClientMisbehaviour defines an sdk.Msg type that submits Evidence for
// light client misbehaviour.
message MsgSubmitClientMisbehaviour {
option (gogoproto.goproto_getters) = false;

Evidence evidence = 1;
bytes submitter = 2
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
21 changes: 13 additions & 8 deletions x/ibc/02-client/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
Expand Down Expand Up @@ -47,8 +48,10 @@ func QueryClientStateABCI(
return nil, err
}

var clientState exported.ClientState
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &clientState); err != nil {
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

clientState, err := types.UnmarshalClientState(cdc, res.Value)
if err != nil {
return nil, err
}

Expand All @@ -57,7 +60,7 @@ func QueryClientStateABCI(
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -102,8 +105,10 @@ func QueryConsensusStateABCI(
return nil, err
}

var cs exported.ConsensusState
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &cs); err != nil {
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

cs, err := types.UnmarshalConsensusState(cdc, res.Value)
if err != nil {
return nil, err
}

Expand All @@ -112,7 +117,7 @@ func QueryConsensusStateABCI(
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -155,7 +160,7 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64,
}

header := ibctmtypes.Header{
SignedHeader: *protoCommit,
SignedHeader: protoCommit,
ValidatorSet: protoValset,
}

Expand Down
6 changes: 3 additions & 3 deletions x/ibc/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ func (suite *KeeperTestSuite) TestCreateClient() {

func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
// Must create header creation functions since suite.header gets recreated on each test case
createFutureUpdateFn := func(s *KeeperTestSuite) ibctmtypes.Header {
createFutureUpdateFn := func(s *KeeperTestSuite) *ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(testChainID, int64(suite.header.GetHeight()+3), int64(suite.header.GetHeight()), suite.header.Header.Time.Add(time.Hour),
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
}
createPastUpdateFn := func(s *KeeperTestSuite) ibctmtypes.Header {
createPastUpdateFn := func(s *KeeperTestSuite) *ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(testChainID, int64(suite.header.GetHeight()-2), int64(suite.header.GetHeight())-4, suite.header.Header.Time,
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
}
var (
updateHeader ibctmtypes.Header
updateHeader *ibctmtypes.Header
clientState *ibctmtypes.ClientState
)

Expand Down
2 changes: 1 addition & 1 deletion x/ibc/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type KeeperTestSuite struct {
ctx sdk.Context
keeper *keeper.Keeper
consensusState *ibctmtypes.ConsensusState
header ibctmtypes.Header
header *ibctmtypes.Header
valSet *tmtypes.ValidatorSet
valSetHash tmbytes.HexBytes
privVal tmtypes.PrivValidator
Expand Down
20 changes: 1 addition & 19 deletions x/ibc/02-client/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
)

// RegisterCodec registers the IBC client interfaces and types
func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*exported.ClientState)(nil), nil) // remove after genesis migration
cdc.RegisterInterface((*exported.MsgCreateClient)(nil), nil)
cdc.RegisterInterface((*exported.MsgUpdateClient)(nil), nil)
cdc.RegisterInterface((*exported.ConsensusState)(nil), nil)
cdc.RegisterInterface((*exported.Header)(nil), nil)
cdc.RegisterInterface((*exported.Misbehaviour)(nil), nil)
}

// RegisterInterfaces registers the client interfaces to protobuf Any.
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterInterface(
Expand All @@ -37,22 +27,14 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
}

var (
amino = codec.New()

// SubModuleCdc references the global x/ibc/02-client module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
// ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/02-client and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)

func init() {
RegisterCodec(amino)
amino.Seal()
}

// PackClientState constructs a new Any packed with the given client state value. It returns
// an error if the client state can't be casted to a protobuf message or if the concrete
// implemention is not registered to the protobuf codec.
Expand Down
10 changes: 7 additions & 3 deletions x/ibc/03-connection/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func queryConnectionABCI(clientCtx client.Context, connectionID string) (*types.
return nil, err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var connection types.ConnectionEnd
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &connection); err != nil {
if err := cdc.UnmarshalBinaryBare(res.Value, &connection); err != nil {
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -92,12 +94,14 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ
return nil, err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var paths []string
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &paths); err != nil {
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down
15 changes: 11 additions & 4 deletions x/ibc/04-channel/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
clientutils "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
Expand Down Expand Up @@ -49,7 +50,9 @@ func queryPacketCommitmentABCI(
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -90,12 +93,14 @@ func queryChannelABCI(clientCtx client.Context, portID, channelID string) (*type
return nil, err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var channel types.Channel
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &channel); err != nil {
if err := cdc.UnmarshalBinaryBare(res.Value, &channel); err != nil {
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -229,7 +234,9 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin
return nil, err
}

proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 1f7a278

Please sign in to comment.