diff --git a/proto/ibc/channel/genesis.proto b/proto/ibc/channel/genesis.proto new file mode 100644 index 0000000000..53759f5ee2 --- /dev/null +++ b/proto/ibc/channel/genesis.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package ibc.channel; + +option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"; + +import "gogoproto/gogo.proto"; +import "ibc/channel/channel.proto"; + +// GenesisState defines the ibc channel submodule's genesis state. +message GenesisState { + repeated IdentifiedChannel channels = 1 [ + (gogoproto.casttype) = "IdentifiedChannel", + (gogoproto.nullable) = false + ]; + repeated PacketAckCommitment acknowledgements = 2 [ + (gogoproto.casttype) = "PacketAckCommitment", + (gogoproto.nullable) = false + ]; + repeated PacketAckCommitment commitments = 3 [(gogoproto.nullable) = false]; + repeated PacketSequence send_sequences = 4 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"send_sequences\"" + ]; + repeated PacketSequence recv_sequences = 5 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"recv_sequences\"" + ]; + repeated PacketSequence ack_sequences = 6 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"ack_sequences\"" + ]; +} + +// PacketSequence defines the genesis type necessary to retrieve and store +// next send and receive sequences. +message PacketSequence { + string port_id = 1 [ + (gogoproto.customname) = "PortID", + (gogoproto.moretags) = "yaml:\"port_id\"" + ]; + string channel_id = 2 [ + (gogoproto.customname) = "ChannelID", + (gogoproto.moretags) = "yaml:\"channel_id\"" + ]; + uint64 sequence = 3; +} diff --git a/proto/ibc/client/genesis.proto b/proto/ibc/client/genesis.proto new file mode 100644 index 0000000000..93ad136297 --- /dev/null +++ b/proto/ibc/client/genesis.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; +package ibc.client; + +option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"; + +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; + +// GenesisClientState defines an identified ClientState as protobuf Any format. +message GenesisClientState { + string client_id = 1 [ + (gogoproto.customname) = "ClientID", + (gogoproto.moretags) = "yaml:\"client_id\"" + ]; + google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""]; +} + +// ClientConsensusStates defines all the stored consensus states for a given client. +message ClientConsensusStates { + string client_id = 1 [ + (gogoproto.customname) = "ClientID" + ]; + repeated google.protobuf.Any consensus_states = 2 [ + (gogoproto.moretags) = "yaml:\"consensus_states\"" + ]; +} + +// GenesisState defines the ibc client submodule's genesis state. +message GenesisState { + repeated GenesisClientState clients = 1 [ + (gogoproto.nullable) = false + ]; + repeated ClientConsensusStates clients_consensus = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "ClientsConsensusStates", + (gogoproto.moretags) = "yaml:\"clients_consensus\"" + ]; + bool create_localhost = 3 [ + (gogoproto.moretags) = "yaml:\"create_localhost\"" + ]; +} diff --git a/proto/ibc/connection/genesis.proto b/proto/ibc/connection/genesis.proto new file mode 100644 index 0000000000..128605de68 --- /dev/null +++ b/proto/ibc/connection/genesis.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package ibc.connection; + +option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"; + +import "gogoproto/gogo.proto"; +import "ibc/connection/connection.proto"; + + +// GenesisState defines the ibc connection submodule's genesis state. +message GenesisState { + repeated IdentifiedConnection connections = 1 [ + (gogoproto.nullable) = false + ]; + repeated ConnectionPaths client_connection_paths = 2 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"client_connection_paths\"" + ]; +} diff --git a/proto/ibc/types/genesis.proto b/proto/ibc/types/genesis.proto new file mode 100644 index 0000000000..203d50f0b5 --- /dev/null +++ b/proto/ibc/types/genesis.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; +package ibc.types; + +option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/types"; + +import "gogoproto/gogo.proto"; +import "ibc/client/genesis.proto"; +import "ibc/connection/genesis.proto"; +import "ibc/channel/genesis.proto"; + +// GenesisState defines the ibc module's genesis state. +message GenesisState { + // ICS002 - Clients genesis state + ibc.client.GenesisState client_genesis = 1 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"client_genesis\"" + ]; + // ICS003 - Connections genesis state + ibc.connection.GenesisState connection_genesis = 2 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"connection_genesis\"" + ]; + // ICS004 - Channel genesis state + ibc.channel.GenesisState channel_genesis = 3 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"channel_genesis\"" + ]; +} diff --git a/simapp/app.go b/simapp/app.go index a5cfa4079d..992725a077 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -257,10 +257,8 @@ func NewSimApp( ) // Create IBC Keeper - // TODO: remove amino codec dependency once Tendermint version is upgraded with - // protobuf changes app.IBCKeeper = ibckeeper.NewKeeper( - app.cdc, appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper, + appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper, ) // Create Transfer Keepers diff --git a/x/ibc/02-client/genesis.go b/x/ibc/02-client/genesis.go index 448a910a88..1dcdb6f27d 100644 --- a/x/ibc/02-client/genesis.go +++ b/x/ibc/02-client/genesis.go @@ -12,12 +12,22 @@ import ( // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { for _, client := range gs.Clients { - k.SetClientState(ctx, client.ClientID, client.ClientState) - k.SetClientType(ctx, client.ClientID, client.ClientState.ClientType()) + cs, ok := client.ClientState.GetCachedValue().(exported.ClientState) + if !ok { + panic("invalid client state") + } + k.SetClientState(ctx, client.ClientID, cs) + k.SetClientType(ctx, client.ClientID, cs.ClientType()) } + for _, cs := range gs.ClientsConsensus { for _, consState := range cs.ConsensusStates { - k.SetClientConsensusState(ctx, cs.ClientID, consState.GetHeight(), consState) + consensusState, ok := consState.GetCachedValue().(exported.ConsensusState) + if !ok { + panic("invalid consensus state") + } + + k.SetClientConsensusState(ctx, cs.ClientID, consensusState.GetHeight(), consensusState) } } diff --git a/x/ibc/02-client/keeper/keeper.go b/x/ibc/02-client/keeper/keeper.go index 9f3017d9a0..4e070c4e67 100644 --- a/x/ibc/02-client/keeper/keeper.go +++ b/x/ibc/02-client/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" @@ -118,51 +119,37 @@ func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string, // GetAllGenesisClients returns all the clients in state with their client ids returned as GenesisClientState func (k Keeper) GetAllGenesisClients(ctx sdk.Context) (genClients []types.GenesisClientState) { k.IterateClients(ctx, func(clientID string, cs exported.ClientState) bool { - gc := types.GenesisClientState{ - ClientID: clientID, - ClientState: cs, - } - genClients = append(genClients, gc) + genClients = append(genClients, types.NewGenesisClientState(clientID, cs)) return false }) return } // GetAllConsensusStates returns all stored client consensus states. -// NOTE: non deterministic. -func (k Keeper) GetAllConsensusStates(ctx sdk.Context) (clientConsStates []types.ClientConsensusStates) { - var clientIDs []string - // create map to add consensus states to the existing clients - cons := make(map[string][]exported.ConsensusState) +func (k Keeper) GetAllConsensusStates(ctx sdk.Context) types.ClientsConsensusStates { + clientConsStates := make(types.ClientsConsensusStates, 0) + mapClientIDToConsStateIdx := make(map[string]int) k.IterateConsensusStates(ctx, func(clientID string, cs exported.ConsensusState) bool { - consensusStates, ok := cons[clientID] - if !ok { - clientIDs = append(clientIDs, clientID) - cons[clientID] = []exported.ConsensusState{cs} + anyClientState := types.MustPackConsensusState(cs) + + idx, ok := mapClientIDToConsStateIdx[clientID] + if ok { + clientConsStates[idx].ConsensusStates = append(clientConsStates[idx].ConsensusStates, anyClientState) return false } - cons[clientID] = append(consensusStates, cs) + clientConsState := types.ClientConsensusStates{ + ClientID: clientID, + ConsensusStates: []*codectypes.Any{anyClientState}, + } + + clientConsStates = append(clientConsStates, clientConsState) + mapClientIDToConsStateIdx[clientID] = len(clientConsStates) - 1 return false }) - // create ClientConsensusStates in the same order of iteration to prevent non-determinism - for len(clientIDs) > 0 { - id := clientIDs[len(clientIDs)-1] - consensusStates, ok := cons[id] - if !ok { - panic(fmt.Sprintf("consensus states from client id %s not found", id)) - } - - clientConsState := types.NewClientConsensusStates(id, consensusStates) - clientConsStates = append(clientConsStates, clientConsState) - - // remove the last element - clientIDs = clientIDs[:len(clientIDs)-1] - } - - return clientConsStates + return clientConsStates.Sort() } // HasClientConsensusState returns if keeper has a ConsensusState for a particular diff --git a/x/ibc/02-client/keeper/keeper_test.go b/x/ibc/02-client/keeper/keeper_test.go index 4f56a12a53..5b500d6150 100644 --- a/x/ibc/02-client/keeper/keeper_test.go +++ b/x/ibc/02-client/keeper/keeper_test.go @@ -223,35 +223,30 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() { } func (suite KeeperTestSuite) TestGetAllConsensusStates() { - expConsensus := []types.ClientConsensusStates{ - types.NewClientConsensusStates( - testClientID, - []exported.ConsensusState{ - ibctmtypes.NewConsensusState( - suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash")), suite.consensusState.GetHeight(), nil, - ), - ibctmtypes.NewConsensusState( - suite.consensusState.Timestamp.Add(time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash")), suite.consensusState.GetHeight()+1, nil, - ), - }, + expConsensus := []exported.ConsensusState{ + ibctmtypes.NewConsensusState( + suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash")), suite.consensusState.GetHeight(), nil, ), - types.NewClientConsensusStates( - testClientID2, - []exported.ConsensusState{ - ibctmtypes.NewConsensusState( - suite.consensusState.Timestamp.Add(2*time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash_2")), suite.consensusState.GetHeight()+2, nil, - ), - }, + ibctmtypes.NewConsensusState( + suite.consensusState.Timestamp.Add(time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash")), suite.consensusState.GetHeight()+1, nil, ), } - for i := range expConsensus { - for _, cons := range expConsensus[i].ConsensusStates { - suite.keeper.SetClientConsensusState(suite.ctx, expConsensus[i].ClientID, cons.GetHeight(), cons) - } + expConsensus2 := []exported.ConsensusState{ + ibctmtypes.NewConsensusState( + suite.consensusState.Timestamp.Add(2*time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash_2")), suite.consensusState.GetHeight()+2, nil, + ), } + expAnyConsensus := types.ClientsConsensusStates{ + types.NewClientConsensusStates(testClientID, expConsensus), + types.NewClientConsensusStates(testClientID2, expConsensus2), + }.Sort() + + suite.keeper.SetClientConsensusState(suite.ctx, testClientID, expConsensus[0].GetHeight(), expConsensus[0]) + suite.keeper.SetClientConsensusState(suite.ctx, testClientID, expConsensus[1].GetHeight(), expConsensus[1]) + suite.keeper.SetClientConsensusState(suite.ctx, testClientID2, expConsensus2[0].GetHeight(), expConsensus2[0]) + consStates := suite.keeper.GetAllConsensusStates(suite.ctx) - suite.Require().Len(consStates, len(expConsensus)) - suite.Require().Equal(expConsensus, consStates) + suite.Require().Equal(expAnyConsensus, consStates, "%s \n\n%s", expAnyConsensus, consStates) } diff --git a/x/ibc/02-client/simulation/decoder.go b/x/ibc/02-client/simulation/decoder.go index 3c9a0c9486..c2e8a5690f 100644 --- a/x/ibc/02-client/simulation/decoder.go +++ b/x/ibc/02-client/simulation/decoder.go @@ -4,29 +4,32 @@ import ( "bytes" "fmt" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) +// ClientUnmarshaler defines an interface for unmarshaling ICS02 interfaces. +type ClientUnmarshaler interface { + MustUnmarshalClientState([]byte) exported.ClientState + MustUnmarshalConsensusState([]byte) exported.ConsensusState +} + // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding client type. -func NewDecodeStore(cdc *codec.Codec, kvA, kvB kv.Pair) (string, bool) { +func NewDecodeStore(cdc ClientUnmarshaler, kvA, kvB kv.Pair) (string, bool) { switch { case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, host.KeyClientState()): - var clientStateA, clientStateB exported.ClientState - cdc.MustUnmarshalBinaryBare(kvA.Value, &clientStateA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &clientStateB) + clientStateA := cdc.MustUnmarshalClientState(kvA.Value) + clientStateB := cdc.MustUnmarshalClientState(kvB.Value) return fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientStateA, clientStateB), true case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, host.KeyClientType()): return fmt.Sprintf("Client type A: %s\nClient type B: %s", string(kvA.Value), string(kvB.Value)), true case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.Contains(kvA.Key, []byte("consensusState")): - var consensusStateA, consensusStateB exported.ConsensusState - cdc.MustUnmarshalBinaryBare(kvA.Value, &consensusStateA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &consensusStateB) + consensusStateA := cdc.MustUnmarshalConsensusState(kvA.Value) + consensusStateB := cdc.MustUnmarshalConsensusState(kvB.Value) return fmt.Sprintf("ConsensusState A: %v\nConsensusState B: %v", consensusStateA, consensusStateB), true default: diff --git a/x/ibc/02-client/simulation/decoder_test.go b/x/ibc/02-client/simulation/decoder_test.go index f1df3bd7eb..f1b2e21186 100644 --- a/x/ibc/02-client/simulation/decoder_test.go +++ b/x/ibc/02-client/simulation/decoder_test.go @@ -17,14 +17,13 @@ import ( func TestDecodeStore(t *testing.T) { app := simapp.Setup(false) - cdc := app.Codec() clientID := "clientidone" - clientState := ibctmtypes.ClientState{ + clientState := &ibctmtypes.ClientState{ FrozenHeight: 10, } - consState := ibctmtypes.ConsensusState{ + consState := &ibctmtypes.ConsensusState{ Height: 10, Timestamp: time.Now().UTC(), } @@ -32,7 +31,7 @@ func TestDecodeStore(t *testing.T) { kvPairs := kv.Pairs{ kv.Pair{ Key: host.FullKeyClientPath(clientID, host.KeyClientState()), - Value: cdc.MustMarshalBinaryBare(clientState), + Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState), }, kv.Pair{ Key: host.FullKeyClientPath(clientID, host.KeyClientType()), @@ -40,7 +39,7 @@ func TestDecodeStore(t *testing.T) { }, kv.Pair{ Key: host.FullKeyClientPath(clientID, host.KeyConsensusState(10)), - Value: cdc.MustMarshalBinaryBare(consState), + Value: app.IBCKeeper.ClientKeeper.MustMarshalConsensusState(consState), }, kv.Pair{ Key: []byte{0x99}, @@ -60,7 +59,7 @@ func TestDecodeStore(t *testing.T) { for i, tt := range tests { i, tt := i, tt t.Run(tt.name, func(t *testing.T) { - res, found := simulation.NewDecodeStore(cdc, kvPairs[i], kvPairs[i]) + res, found := simulation.NewDecodeStore(app.IBCKeeper.ClientKeeper, kvPairs[i], kvPairs[i]) if i == len(tests)-1 { require.False(t, found, string(kvPairs[i].Key)) require.Empty(t, res, string(kvPairs[i].Key)) diff --git a/x/ibc/02-client/types/codec.go b/x/ibc/02-client/types/codec.go index da341afa79..7450a775ae 100644 --- a/x/ibc/02-client/types/codec.go +++ b/x/ibc/02-client/types/codec.go @@ -1,9 +1,12 @@ package types import ( + "fmt" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" + proto "github.com/gogo/protobuf/proto" ) // RegisterCodec registers the IBC client interfaces and types @@ -26,6 +29,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { "cosmos_sdk.ibc.v1.client.ConsensusState", (*exported.ConsensusState)(nil), ) + registry.RegisterInterface( + "cosmos_sdk.ibc.v1.client.Header", + (*exported.Header)(nil), + ) } var ( @@ -37,10 +44,37 @@ var ( // // The actual codec used for serialization should be provided to x/ibc/02-client and // defined at the application level. - SubModuleCdc = codec.NewHybridCodec(amino, codectypes.NewInterfaceRegistry()) + SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) ) func init() { RegisterCodec(amino) amino.Seal() } + +// PackConsensusState constructs a new Any packed with the given consensus state value. It returns +// an error if the consensus state can't be casted to a protobuf message or if the concrete +// implemention is not registered to the protobuf codec. +func PackConsensusState(consensusState exported.ConsensusState) (*codectypes.Any, error) { + msg, ok := consensusState.(proto.Message) + if !ok { + return nil, fmt.Errorf("cannot proto marshal %T", consensusState) + } + + anyConsensusState, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return anyConsensusState, nil +} + +// MustPackConsensusState calls PackConsensusState and panics on error. +func MustPackConsensusState(consensusState exported.ConsensusState) *codectypes.Any { + anyConsensusState, err := PackConsensusState(consensusState) + if err != nil { + panic(err) + } + + return anyConsensusState +} diff --git a/x/ibc/02-client/types/genesis.go b/x/ibc/02-client/types/genesis.go index cecdf6a8c8..efbcc75317 100644 --- a/x/ibc/02-client/types/genesis.go +++ b/x/ibc/02-client/types/genesis.go @@ -2,47 +2,109 @@ package types import ( "fmt" + "sort" + proto "github.com/gogo/protobuf/proto" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) -type GenesisClientState struct { - ClientID string `json:"client_id" yaml:"client_id"` - ClientState exported.ClientState `json:"client_state" yaml:"client_state"` -} +var ( + _ codectypes.UnpackInterfacesMessage = GenesisClientState{} + _ codectypes.UnpackInterfacesMessage = ClientsConsensusStates{} + _ codectypes.UnpackInterfacesMessage = ClientConsensusStates{} + _ codectypes.UnpackInterfacesMessage = GenesisState{} +) + +// NewGenesisClientState creates a new GenesisClientState instance. +func NewGenesisClientState(clientID string, clientState exported.ClientState) GenesisClientState { + msg, ok := clientState.(proto.Message) + if !ok { + panic(fmt.Errorf("cannot proto marshal %T", clientState)) + } + + anyClientState, err := codectypes.NewAnyWithValue(msg) + if err != nil { + panic(err) + } -func NewGenesisClientState(id string, cs exported.ClientState) GenesisClientState { return GenesisClientState{ - ClientID: id, - ClientState: cs, + ClientID: clientID, + ClientState: anyClientState, } } -// ClientConsensusStates defines all the stored consensus states for a given client. -type ClientConsensusStates struct { - ClientID string `json:"client_id" yaml:"client_id"` - ConsensusStates []exported.ConsensusState `json:"consensus_states" yaml:"consensus_states"` +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (gs GenesisClientState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var clientState exported.ClientState + err := unpacker.UnpackAny(gs.ClientState, &clientState) + if err != nil { + return err + } + return nil +} + +var _ sort.Interface = ClientsConsensusStates{} + +// ClientsConsensusStates defines a slice of ClientConsensusStates that supports the sort interface +type ClientsConsensusStates []ClientConsensusStates + +// Len implements sort.Interface +func (ccs ClientsConsensusStates) Len() int { return len(ccs) } + +// Less implements sort.Interface +func (ccs ClientsConsensusStates) Less(i, j int) bool { return ccs[i].ClientID < ccs[j].ClientID } + +// Swap implements sort.Interface +func (ccs ClientsConsensusStates) Swap(i, j int) { ccs[i], ccs[j] = ccs[j], ccs[i] } + +// Sort is a helper function to sort the set of ClientsConsensusStates in place +func (ccs ClientsConsensusStates) Sort() ClientsConsensusStates { + sort.Sort(ccs) + return ccs +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (ccs ClientsConsensusStates) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, clientConsensus := range ccs { + if err := clientConsensus.UnpackInterfaces(unpacker); err != nil { + return err + } + } + return nil } // NewClientConsensusStates creates a new ClientConsensusStates instance. -func NewClientConsensusStates(id string, states []exported.ConsensusState) ClientConsensusStates { +func NewClientConsensusStates(clientID string, consensusStates []exported.ConsensusState) ClientConsensusStates { + anyConsensusStates := make([]*codectypes.Any, len(consensusStates)) + + for i := range consensusStates { + anyConsensusStates[i] = MustPackConsensusState(consensusStates[i]) + } + return ClientConsensusStates{ - ClientID: id, - ConsensusStates: states, + ClientID: clientID, + ConsensusStates: anyConsensusStates, } } -// GenesisState defines the ibc client submodule's genesis state. -type GenesisState struct { - Clients []GenesisClientState `json:"clients" yaml:"clients"` - ClientsConsensus []ClientConsensusStates `json:"clients_consensus" yaml:"clients_consensus"` - CreateLocalhost bool `json:"create_localhost" yaml:"create_localhost"` +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (ccs ClientConsensusStates) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, any := range ccs.ConsensusStates { + var consensusState exported.ConsensusState + err := unpacker.UnpackAny(any, &consensusState) + if err != nil { + return err + } + } + return nil } // NewGenesisState creates a GenesisState instance. func NewGenesisState( - clients []GenesisClientState, clientsConsensus []ClientConsensusStates, createLocalhost bool, + clients []GenesisClientState, clientsConsensus ClientsConsensusStates, createLocalhost bool, ) GenesisState { return GenesisState{ Clients: clients, @@ -55,11 +117,22 @@ func NewGenesisState( func DefaultGenesisState() GenesisState { return GenesisState{ Clients: []GenesisClientState{}, - ClientsConsensus: []ClientConsensusStates{}, + ClientsConsensus: ClientsConsensusStates{}, CreateLocalhost: true, } } +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (gs GenesisState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, client := range gs.Clients { + if err := client.UnpackInterfaces(unpacker); err != nil { + return err + } + } + + return gs.ClientsConsensus.UnpackInterfaces(unpacker) +} + // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { @@ -67,7 +140,12 @@ func (gs GenesisState) Validate() error { if err := host.ClientIdentifierValidator(client.ClientID); err != nil { return fmt.Errorf("invalid client consensus state identifier %s index %d: %w", client.ClientID, i, err) } - if err := client.ClientState.Validate(); err != nil { + + clientState, ok := client.ClientState.GetCachedValue().(exported.ClientState) + if !ok { + return fmt.Errorf("invalid client state") + } + if err := clientState.Validate(); err != nil { return fmt.Errorf("invalid client %v index %d: %w", client, i, err) } } @@ -76,9 +154,15 @@ func (gs GenesisState) Validate() error { if err := host.ClientIdentifierValidator(cs.ClientID); err != nil { return fmt.Errorf("invalid client consensus state identifier %s index %d: %w", cs.ClientID, i, err) } + for _, consensusState := range cs.ConsensusStates { - if err := consensusState.ValidateBasic(); err != nil { - return fmt.Errorf("invalid client consensus state %v index %d: %w", consensusState, i, err) + cs, ok := consensusState.GetCachedValue().(exported.ConsensusState) + if !ok { + return fmt.Errorf("invalid consensus state") + } + + if err := cs.ValidateBasic(); err != nil { + return fmt.Errorf("invalid client consensus state %v index %d: %w", cs, i, err) } } } diff --git a/x/ibc/02-client/types/genesis.pb.go b/x/ibc/02-client/types/genesis.pb.go new file mode 100644 index 0000000000..0dab5c70b2 --- /dev/null +++ b/x/ibc/02-client/types/genesis.pb.go @@ -0,0 +1,922 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/client/genesis.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisClientState defines an identified ClientState as protobuf Any format. +type GenesisClientState struct { + ClientID string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"` + ClientState *types.Any `protobuf:"bytes,2,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty" yaml:"client_state"` +} + +func (m *GenesisClientState) Reset() { *m = GenesisClientState{} } +func (m *GenesisClientState) String() string { return proto.CompactTextString(m) } +func (*GenesisClientState) ProtoMessage() {} +func (*GenesisClientState) Descriptor() ([]byte, []int) { + return fileDescriptor_2eb5d7ff040be5c2, []int{0} +} +func (m *GenesisClientState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisClientState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisClientState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisClientState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisClientState.Merge(m, src) +} +func (m *GenesisClientState) XXX_Size() int { + return m.Size() +} +func (m *GenesisClientState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisClientState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisClientState proto.InternalMessageInfo + +func (m *GenesisClientState) GetClientID() string { + if m != nil { + return m.ClientID + } + return "" +} + +func (m *GenesisClientState) GetClientState() *types.Any { + if m != nil { + return m.ClientState + } + return nil +} + +// ClientConsensusStates defines all the stored consensus states for a given client. +type ClientConsensusStates struct { + ClientID string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + ConsensusStates []*types.Any `protobuf:"bytes,2,rep,name=consensus_states,json=consensusStates,proto3" json:"consensus_states,omitempty" yaml:"consensus_states"` +} + +func (m *ClientConsensusStates) Reset() { *m = ClientConsensusStates{} } +func (m *ClientConsensusStates) String() string { return proto.CompactTextString(m) } +func (*ClientConsensusStates) ProtoMessage() {} +func (*ClientConsensusStates) Descriptor() ([]byte, []int) { + return fileDescriptor_2eb5d7ff040be5c2, []int{1} +} +func (m *ClientConsensusStates) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClientConsensusStates) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClientConsensusStates.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClientConsensusStates) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientConsensusStates.Merge(m, src) +} +func (m *ClientConsensusStates) XXX_Size() int { + return m.Size() +} +func (m *ClientConsensusStates) XXX_DiscardUnknown() { + xxx_messageInfo_ClientConsensusStates.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientConsensusStates proto.InternalMessageInfo + +func (m *ClientConsensusStates) GetClientID() string { + if m != nil { + return m.ClientID + } + return "" +} + +func (m *ClientConsensusStates) GetConsensusStates() []*types.Any { + if m != nil { + return m.ConsensusStates + } + return nil +} + +// GenesisState defines the ibc client submodule's genesis state. +type GenesisState struct { + Clients []GenesisClientState `protobuf:"bytes,1,rep,name=clients,proto3" json:"clients"` + ClientsConsensus ClientsConsensusStates `protobuf:"bytes,2,rep,name=clients_consensus,json=clientsConsensus,proto3,castrepeated=ClientsConsensusStates" json:"clients_consensus" yaml:"clients_consensus"` + CreateLocalhost bool `protobuf:"varint,3,opt,name=create_localhost,json=createLocalhost,proto3" json:"create_localhost,omitempty" yaml:"create_localhost"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_2eb5d7ff040be5c2, []int{2} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetClients() []GenesisClientState { + if m != nil { + return m.Clients + } + return nil +} + +func (m *GenesisState) GetClientsConsensus() ClientsConsensusStates { + if m != nil { + return m.ClientsConsensus + } + return nil +} + +func (m *GenesisState) GetCreateLocalhost() bool { + if m != nil { + return m.CreateLocalhost + } + return false +} + +func init() { + proto.RegisterType((*GenesisClientState)(nil), "ibc.client.GenesisClientState") + proto.RegisterType((*ClientConsensusStates)(nil), "ibc.client.ClientConsensusStates") + proto.RegisterType((*GenesisState)(nil), "ibc.client.GenesisState") +} + +func init() { proto.RegisterFile("ibc/client/genesis.proto", fileDescriptor_2eb5d7ff040be5c2) } + +var fileDescriptor_2eb5d7ff040be5c2 = []byte{ + // 445 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xc1, 0x6a, 0xd4, 0x40, + 0x18, 0xc7, 0x33, 0x5b, 0xd1, 0xed, 0x74, 0xc1, 0x18, 0xab, 0x8d, 0x15, 0x92, 0x38, 0xa7, 0xf5, + 0xd0, 0x19, 0x59, 0x6f, 0x05, 0x05, 0x53, 0x51, 0x0a, 0x3d, 0x48, 0xbc, 0x89, 0xb0, 0x24, 0xb3, + 0x63, 0x1a, 0xcc, 0x66, 0x4a, 0x67, 0x16, 0xcc, 0x2b, 0x78, 0xf2, 0x11, 0x04, 0xf1, 0xe2, 0x93, + 0xf4, 0xd8, 0xa3, 0xa7, 0x28, 0xd9, 0x37, 0xc8, 0x13, 0x48, 0x66, 0x92, 0xdd, 0x6c, 0xd6, 0x9e, + 0x32, 0xf9, 0xbe, 0xef, 0xff, 0xff, 0x7e, 0xfc, 0x87, 0x81, 0x76, 0x12, 0x51, 0x42, 0xd3, 0x84, + 0x65, 0x92, 0xc4, 0x2c, 0x63, 0x22, 0x11, 0xf8, 0xe2, 0x92, 0x4b, 0x6e, 0xc1, 0x24, 0xa2, 0x58, + 0x77, 0x0e, 0xf7, 0x63, 0x1e, 0x73, 0x55, 0x26, 0xf5, 0x49, 0x4f, 0x1c, 0x3e, 0x8a, 0x39, 0x8f, + 0x53, 0x46, 0xd4, 0x5f, 0xb4, 0xf8, 0x44, 0xc2, 0x2c, 0xd7, 0x2d, 0xf4, 0x13, 0x40, 0xeb, 0xad, + 0xb6, 0x3b, 0x51, 0x16, 0xef, 0x65, 0x28, 0x99, 0xf5, 0x02, 0xee, 0x6a, 0xc7, 0x69, 0x32, 0xb3, + 0x81, 0x07, 0xc6, 0xbb, 0xbe, 0x57, 0x16, 0xee, 0x50, 0xcf, 0x9c, 0xbe, 0xae, 0x0a, 0xd7, 0xcc, + 0xc3, 0x79, 0x7a, 0x8c, 0x56, 0x63, 0x28, 0x18, 0xea, 0xf3, 0xe9, 0xcc, 0x7a, 0x07, 0x47, 0x4d, + 0x5d, 0xd4, 0x76, 0xf6, 0xc0, 0x03, 0xe3, 0xbd, 0xc9, 0x3e, 0xd6, 0x1c, 0xb8, 0xe5, 0xc0, 0xaf, + 0xb2, 0xdc, 0x3f, 0xa8, 0x0a, 0xf7, 0xfe, 0x86, 0x97, 0xd2, 0xa0, 0x60, 0x8f, 0xae, 0x81, 0xd0, + 0x77, 0x00, 0x1f, 0xe8, 0xe5, 0x27, 0x3c, 0x13, 0x2c, 0x13, 0x0b, 0xa1, 0x1a, 0xc2, 0x7a, 0xba, + 0x8d, 0x3a, 0xea, 0xa2, 0x76, 0xb0, 0x3e, 0x42, 0x93, 0xb6, 0x6a, 0xbd, 0x45, 0xd8, 0x03, 0x6f, + 0xe7, 0x46, 0xb4, 0xc7, 0x55, 0xe1, 0x1e, 0x34, 0x68, 0x3d, 0x1d, 0x0a, 0xee, 0xd2, 0x4d, 0x10, + 0xf4, 0x63, 0x00, 0x47, 0x4d, 0x94, 0x3a, 0xc4, 0x97, 0xf0, 0x8e, 0x5e, 0x2d, 0x6c, 0xa0, 0xb6, + 0x38, 0x78, 0x7d, 0x55, 0x78, 0x3b, 0x75, 0xff, 0xd6, 0x55, 0xe1, 0x1a, 0x41, 0x2b, 0xb2, 0xbe, + 0x02, 0x78, 0xaf, 0x39, 0x4f, 0x57, 0xcb, 0x1a, 0xe0, 0x27, 0x5d, 0xab, 0xff, 0x06, 0xe3, 0x1f, + 0xd7, 0x6e, 0x55, 0xe1, 0xda, 0xdd, 0x70, 0x3b, 0x4e, 0xe8, 0xd7, 0x1f, 0xf7, 0xa1, 0x96, 0x8a, + 0x9e, 0x36, 0x30, 0x69, 0xaf, 0x6e, 0xbd, 0x81, 0x26, 0xbd, 0x64, 0xa1, 0x64, 0xd3, 0x94, 0xd3, + 0x30, 0x3d, 0xe7, 0x42, 0xda, 0x3b, 0x1e, 0x18, 0x0f, 0x37, 0x52, 0xea, 0x4d, 0xd4, 0x29, 0xa9, + 0xd2, 0x59, 0x5b, 0xf1, 0xcf, 0xae, 0x4a, 0x07, 0x5c, 0x97, 0x0e, 0xf8, 0x5b, 0x3a, 0xe0, 0xdb, + 0xd2, 0x31, 0xae, 0x97, 0x8e, 0xf1, 0x7b, 0xe9, 0x18, 0x1f, 0x26, 0x71, 0x22, 0xcf, 0x17, 0x11, + 0xa6, 0x7c, 0x4e, 0x28, 0x17, 0x73, 0x2e, 0x9a, 0xcf, 0x91, 0x98, 0x7d, 0x26, 0x5f, 0x48, 0xfd, + 0x00, 0x9e, 0x4d, 0x8e, 0x9a, 0x37, 0x20, 0xf3, 0x0b, 0x26, 0xa2, 0xdb, 0xea, 0xbe, 0x9e, 0xff, + 0x0b, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x10, 0x3e, 0x4c, 0x1e, 0x03, 0x00, 0x00, +} + +func (m *GenesisClientState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisClientState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ClientState != nil { + { + size, err := m.ClientState.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ClientID) > 0 { + i -= len(m.ClientID) + copy(dAtA[i:], m.ClientID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ClientID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ClientConsensusStates) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClientConsensusStates) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClientConsensusStates) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConsensusStates) > 0 { + for iNdEx := len(m.ConsensusStates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ConsensusStates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ClientID) > 0 { + i -= len(m.ClientID) + copy(dAtA[i:], m.ClientID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ClientID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CreateLocalhost { + i-- + if m.CreateLocalhost { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if len(m.ClientsConsensus) > 0 { + for iNdEx := len(m.ClientsConsensus) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ClientsConsensus[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Clients) > 0 { + for iNdEx := len(m.Clients) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Clients[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisClientState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.ClientState != nil { + l = m.ClientState.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *ClientConsensusStates) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.ConsensusStates) > 0 { + for _, e := range m.ConsensusStates { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Clients) > 0 { + for _, e := range m.Clients { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ClientsConsensus) > 0 { + for _, e := range m.ClientsConsensus { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if m.CreateLocalhost { + n += 2 + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisClientState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisClientState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisClientState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ClientState == nil { + m.ClientState = &types.Any{} + } + if err := m.ClientState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ClientConsensusStates) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClientConsensusStates: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClientConsensusStates: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusStates", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusStates = append(m.ConsensusStates, &types.Any{}) + if err := m.ConsensusStates[len(m.ConsensusStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Clients", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Clients = append(m.Clients, GenesisClientState{}) + if err := m.Clients[len(m.Clients)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientsConsensus", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientsConsensus = append(m.ClientsConsensus, ClientConsensusStates{}) + if err := m.ClientsConsensus[len(m.ClientsConsensus)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreateLocalhost", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.CreateLocalhost = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ibc/02-client/types/genesis_test.go b/x/ibc/02-client/types/genesis_test.go index fc358c3ce0..570e684550 100644 --- a/x/ibc/02-client/types/genesis_test.go +++ b/x/ibc/02-client/types/genesis_test.go @@ -13,6 +13,7 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" + ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing" ) const ( @@ -20,10 +21,6 @@ const ( clientID = "ethbridge" height = 10 - - trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 - ubdPeriod time.Duration = time.Hour * 24 * 7 * 3 - maxClockDrift time.Duration = time.Second * 10 ) func TestValidateGenesis(t *testing.T) { @@ -53,21 +50,21 @@ func TestValidateGenesis(t *testing.T) { genState: types.NewGenesisState( []types.GenesisClientState{ types.NewGenesisClientState( - clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + clientID, ibctmtypes.NewClientState(chainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), types.NewGenesisClientState( exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10), ), }, []types.ClientConsensusStates{ - { + types.NewClientConsensusStates( clientID, []exported.ConsensusState{ ibctmtypes.NewConsensusState( header.Time, commitmenttypes.NewMerkleRoot(header.AppHash), header.GetHeight(), header.NextValidatorsHash, ), }, - }, + ), }, true, ), @@ -78,33 +75,32 @@ func TestValidateGenesis(t *testing.T) { genState: types.NewGenesisState( []types.GenesisClientState{ types.NewGenesisClientState( - "/~@$*", ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + "/~@$*", ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), types.NewGenesisClientState( exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10), ), }, []types.ClientConsensusStates{ - { + types.NewClientConsensusStates( clientID, []exported.ConsensusState{ ibctmtypes.NewConsensusState( header.Time, commitmenttypes.NewMerkleRoot(header.AppHash), header.GetHeight(), header.NextValidatorsHash, ), }, - }, + ), }, true, ), expPass: false, }, - { name: "invalid client", genState: types.NewGenesisState( []types.GenesisClientState{ types.NewGenesisClientState( - clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), types.NewGenesisClientState(exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 0)), }, @@ -118,21 +114,21 @@ func TestValidateGenesis(t *testing.T) { genState: types.NewGenesisState( []types.GenesisClientState{ types.NewGenesisClientState( - clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), types.NewGenesisClientState( exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10), ), }, []types.ClientConsensusStates{ - { - "CLIENTID2", + types.NewClientConsensusStates( + "(CLIENTID2)", []exported.ConsensusState{ ibctmtypes.NewConsensusState( header.Time, commitmenttypes.NewMerkleRoot(header.AppHash), 0, header.NextValidatorsHash, ), }, - }, + ), }, true, ), @@ -143,7 +139,7 @@ func TestValidateGenesis(t *testing.T) { genState: types.NewGenesisState( []types.GenesisClientState{ types.NewGenesisClientState( - clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), types.NewGenesisClientState( exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10), diff --git a/x/ibc/03-connection/types/genesis.go b/x/ibc/03-connection/types/genesis.go index 7a1a010e7b..cd309c47b9 100644 --- a/x/ibc/03-connection/types/genesis.go +++ b/x/ibc/03-connection/types/genesis.go @@ -14,12 +14,6 @@ func NewConnectionPaths(id string, paths []string) ConnectionPaths { } } -// GenesisState defines the ibc connection submodule's genesis state. -type GenesisState struct { - Connections []IdentifiedConnection `json:"connections" yaml:"connections"` - ClientConnectionPaths []ConnectionPaths `json:"client_connection_paths" yaml:"client_connection_paths"` -} - // NewGenesisState creates a GenesisState instance. func NewGenesisState( connections []IdentifiedConnection, connPaths []ConnectionPaths, diff --git a/x/ibc/03-connection/types/genesis.pb.go b/x/ibc/03-connection/types/genesis.pb.go new file mode 100644 index 0000000000..2fbff67f57 --- /dev/null +++ b/x/ibc/03-connection/types/genesis.pb.go @@ -0,0 +1,399 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/connection/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the ibc connection submodule's genesis state. +type GenesisState struct { + Connections []IdentifiedConnection `protobuf:"bytes,1,rep,name=connections,proto3" json:"connections"` + ClientConnectionPaths []ConnectionPaths `protobuf:"bytes,2,rep,name=client_connection_paths,json=clientConnectionPaths,proto3" json:"client_connection_paths" yaml:"client_connection_paths"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_7a83da0d52c27d9b, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetConnections() []IdentifiedConnection { + if m != nil { + return m.Connections + } + return nil +} + +func (m *GenesisState) GetClientConnectionPaths() []ConnectionPaths { + if m != nil { + return m.ClientConnectionPaths + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "ibc.connection.GenesisState") +} + +func init() { proto.RegisterFile("ibc/connection/genesis.proto", fileDescriptor_7a83da0d52c27d9b) } + +var fileDescriptor_7a83da0d52c27d9b = []byte{ + // 265 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc9, 0x4c, 0x4a, 0xd6, + 0x4f, 0xce, 0xcf, 0xcb, 0x4b, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, + 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xcb, 0x4c, 0x4a, 0xd6, 0x43, 0xc8, + 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0xa5, 0xf4, 0x41, 0x2c, 0x88, 0x2a, 0x29, 0x79, 0x34, + 0x33, 0x10, 0x4c, 0x88, 0x02, 0xa5, 0xbb, 0x8c, 0x5c, 0x3c, 0xee, 0x10, 0x83, 0x83, 0x4b, 0x12, + 0x4b, 0x52, 0x85, 0x7c, 0xb8, 0xb8, 0x11, 0x8a, 0x8a, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, + 0x54, 0xf4, 0x50, 0x6d, 0xd3, 0xf3, 0x4c, 0x49, 0xcd, 0x2b, 0xc9, 0x4c, 0xcb, 0x4c, 0x4d, 0x71, + 0x86, 0x0b, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x84, 0xac, 0x5d, 0xa8, 0x9e, 0x4b, 0x3c, + 0x39, 0x27, 0x33, 0x35, 0xaf, 0x24, 0x1e, 0x21, 0x1a, 0x5f, 0x90, 0x58, 0x92, 0x51, 0x2c, 0xc1, + 0x04, 0x36, 0x59, 0x1e, 0xdd, 0x64, 0x84, 0x79, 0x01, 0x20, 0x65, 0x4e, 0x6a, 0x20, 0x43, 0x3f, + 0xdd, 0x93, 0x97, 0xab, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0xc2, 0x61, 0x9a, 0x52, 0x90, 0x28, 0x44, + 0x06, 0x5d, 0x7b, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, + 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, 0xa5, + 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, + 0x43, 0x29, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x0a, 0x7d, 0x50, 0xc8, 0x19, 0x18, 0xeb, 0x22, 0x05, + 0x5e, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0xe0, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, + 0xff, 0xc8, 0x26, 0xf8, 0x5d, 0x9f, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClientConnectionPaths) > 0 { + for iNdEx := len(m.ClientConnectionPaths) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ClientConnectionPaths[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Connections) > 0 { + for iNdEx := len(m.Connections) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Connections[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Connections) > 0 { + for _, e := range m.Connections { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ClientConnectionPaths) > 0 { + for _, e := range m.ClientConnectionPaths { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Connections", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Connections = append(m.Connections, IdentifiedConnection{}) + if err := m.Connections[len(m.Connections)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientConnectionPaths", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientConnectionPaths = append(m.ClientConnectionPaths, ConnectionPaths{}) + if err := m.ClientConnectionPaths[len(m.ClientConnectionPaths)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ibc/04-channel/types/genesis.go b/x/ibc/04-channel/types/genesis.go index 8e678d1282..1c297faab0 100644 --- a/x/ibc/04-channel/types/genesis.go +++ b/x/ibc/04-channel/types/genesis.go @@ -26,14 +26,6 @@ func (pa PacketAckCommitment) Validate() error { return validateGenFields(pa.PortID, pa.ChannelID, pa.Sequence) } -// PacketSequence defines the genesis type necessary to retrieve and store -// next send and receive sequences. -type PacketSequence struct { - PortID string `json:"port_id" yaml:"port_id"` - ChannelID string `json:"channel_id" yaml:"channel_id"` - Sequence uint64 `json:"sequence" yaml:"sequence"` -} - // NewPacketSequence creates a new PacketSequences instance. func NewPacketSequence(portID, channelID string, seq uint64) PacketSequence { return PacketSequence{ @@ -49,16 +41,6 @@ func (ps PacketSequence) Validate() error { return validateGenFields(ps.PortID, ps.ChannelID, ps.Sequence) } -// GenesisState defines the ibc channel submodule's genesis state. -type GenesisState struct { - Channels []IdentifiedChannel `json:"channels" yaml:"channels"` - Acknowledgements []PacketAckCommitment `json:"acknowledgements" yaml:"acknowledgements"` - Commitments []PacketAckCommitment `json:"commitments" yaml:"commitments"` - SendSequences []PacketSequence `json:"send_sequences" yaml:"send_sequences"` - RecvSequences []PacketSequence `json:"recv_sequences" yaml:"recv_sequences"` - AckSequences []PacketSequence `json:"ack_sequences" yaml:"ack_sequences"` -} - // NewGenesisState creates a GenesisState instance. func NewGenesisState( channels []IdentifiedChannel, acks, commitments []PacketAckCommitment, diff --git a/x/ibc/04-channel/types/genesis.pb.go b/x/ibc/04-channel/types/genesis.pb.go new file mode 100644 index 0000000000..5345c81fec --- /dev/null +++ b/x/ibc/04-channel/types/genesis.pb.go @@ -0,0 +1,921 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/channel/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the ibc channel submodule's genesis state. +type GenesisState struct { + Channels []IdentifiedChannel `protobuf:"bytes,1,rep,name=channels,proto3,casttype=IdentifiedChannel" json:"channels"` + Acknowledgements []PacketAckCommitment `protobuf:"bytes,2,rep,name=acknowledgements,proto3,casttype=PacketAckCommitment" json:"acknowledgements"` + Commitments []PacketAckCommitment `protobuf:"bytes,3,rep,name=commitments,proto3" json:"commitments"` + SendSequences []PacketSequence `protobuf:"bytes,4,rep,name=send_sequences,json=sendSequences,proto3" json:"send_sequences" yaml:"send_sequences"` + RecvSequences []PacketSequence `protobuf:"bytes,5,rep,name=recv_sequences,json=recvSequences,proto3" json:"recv_sequences" yaml:"recv_sequences"` + AckSequences []PacketSequence `protobuf:"bytes,6,rep,name=ack_sequences,json=ackSequences,proto3" json:"ack_sequences" yaml:"ack_sequences"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_60ebf40b29ae9ba5, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetChannels() []IdentifiedChannel { + if m != nil { + return m.Channels + } + return nil +} + +func (m *GenesisState) GetAcknowledgements() []PacketAckCommitment { + if m != nil { + return m.Acknowledgements + } + return nil +} + +func (m *GenesisState) GetCommitments() []PacketAckCommitment { + if m != nil { + return m.Commitments + } + return nil +} + +func (m *GenesisState) GetSendSequences() []PacketSequence { + if m != nil { + return m.SendSequences + } + return nil +} + +func (m *GenesisState) GetRecvSequences() []PacketSequence { + if m != nil { + return m.RecvSequences + } + return nil +} + +func (m *GenesisState) GetAckSequences() []PacketSequence { + if m != nil { + return m.AckSequences + } + return nil +} + +// PacketSequence defines the genesis type necessary to retrieve and store +// next send and receive sequences. +type PacketSequence struct { + PortID string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ChannelID string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` + Sequence uint64 `protobuf:"varint,3,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *PacketSequence) Reset() { *m = PacketSequence{} } +func (m *PacketSequence) String() string { return proto.CompactTextString(m) } +func (*PacketSequence) ProtoMessage() {} +func (*PacketSequence) Descriptor() ([]byte, []int) { + return fileDescriptor_60ebf40b29ae9ba5, []int{1} +} +func (m *PacketSequence) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketSequence) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketSequence.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PacketSequence) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketSequence.Merge(m, src) +} +func (m *PacketSequence) XXX_Size() int { + return m.Size() +} +func (m *PacketSequence) XXX_DiscardUnknown() { + xxx_messageInfo_PacketSequence.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketSequence proto.InternalMessageInfo + +func (m *PacketSequence) GetPortID() string { + if m != nil { + return m.PortID + } + return "" +} + +func (m *PacketSequence) GetChannelID() string { + if m != nil { + return m.ChannelID + } + return "" +} + +func (m *PacketSequence) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "ibc.channel.GenesisState") + proto.RegisterType((*PacketSequence)(nil), "ibc.channel.PacketSequence") +} + +func init() { proto.RegisterFile("ibc/channel/genesis.proto", fileDescriptor_60ebf40b29ae9ba5) } + +var fileDescriptor_60ebf40b29ae9ba5 = []byte{ + // 472 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xb1, 0x6e, 0xd3, 0x40, + 0x18, 0xc7, 0xe3, 0x26, 0x84, 0xe6, 0xd2, 0x44, 0xd4, 0x14, 0xc9, 0x4d, 0x8b, 0x1d, 0xdd, 0x94, + 0xa5, 0x36, 0xa2, 0xb0, 0xb0, 0xd5, 0x45, 0x82, 0x0c, 0x48, 0xd5, 0x55, 0x2c, 0x0c, 0x54, 0xce, + 0xf9, 0xc3, 0x3d, 0x39, 0xf6, 0x85, 0xdc, 0x15, 0xe8, 0x5b, 0xf0, 0x14, 0x3c, 0x07, 0x63, 0xc7, + 0x8e, 0x4c, 0x16, 0x72, 0xde, 0xa0, 0x23, 0x13, 0x3a, 0xfb, 0x92, 0xda, 0x6a, 0x24, 0xe8, 0x64, + 0xfb, 0xfb, 0xfe, 0xff, 0xdf, 0xef, 0x06, 0x1f, 0xda, 0x65, 0x13, 0xea, 0xd1, 0xf3, 0x20, 0x4d, + 0x61, 0xea, 0x45, 0x90, 0x82, 0x60, 0xc2, 0x9d, 0xcd, 0xb9, 0xe4, 0x66, 0x97, 0x4d, 0xa8, 0xab, + 0x57, 0x83, 0x9d, 0x88, 0x47, 0xbc, 0x98, 0x7b, 0xea, 0xad, 0x8c, 0x0c, 0x6a, 0x6d, 0xfd, 0x2c, + 0x57, 0xf8, 0x67, 0x0b, 0x6d, 0xbd, 0x29, 0x79, 0xa7, 0x32, 0x90, 0x60, 0xbe, 0x47, 0x9b, 0x3a, + 0x21, 0x2c, 0x63, 0xd8, 0x1c, 0x75, 0x9f, 0xdb, 0x6e, 0xc5, 0xe0, 0x8e, 0x43, 0x48, 0x25, 0xfb, + 0xc4, 0x20, 0x3c, 0x2e, 0x27, 0xfe, 0xee, 0x55, 0xe6, 0x34, 0xfe, 0x64, 0xce, 0xf6, 0x9d, 0x15, + 0x59, 0xa1, 0x4c, 0x86, 0x1e, 0x05, 0x34, 0x4e, 0xf9, 0xd7, 0x29, 0x84, 0x11, 0x24, 0x90, 0x4a, + 0x61, 0x6d, 0x14, 0xf8, 0x61, 0x0d, 0x7f, 0x12, 0xd0, 0x18, 0xe4, 0x11, 0x8d, 0x8f, 0x79, 0x92, + 0x30, 0xa9, 0x82, 0xfe, 0x9e, 0x16, 0x3c, 0x5e, 0xb3, 0x24, 0x77, 0xb0, 0xe6, 0x5b, 0xd4, 0xa5, + 0xab, 0xbd, 0xb0, 0x9a, 0xff, 0x69, 0x69, 0x29, 0x0b, 0xa9, 0x56, 0xcd, 0x00, 0xf5, 0x05, 0xa4, + 0xe1, 0x99, 0x80, 0xcf, 0x17, 0x90, 0x52, 0x10, 0x56, 0xab, 0x80, 0xed, 0xad, 0x81, 0x9d, 0xea, + 0x8c, 0xff, 0x54, 0x71, 0x6e, 0x32, 0xe7, 0xc9, 0x65, 0x90, 0x4c, 0x5f, 0xe1, 0x3a, 0x00, 0x93, + 0x9e, 0x1a, 0x2c, 0xc3, 0x85, 0x62, 0x0e, 0xf4, 0x4b, 0x45, 0xf1, 0xe0, 0xde, 0x8a, 0x3a, 0x00, + 0x93, 0x9e, 0x1a, 0xdc, 0x2a, 0x3e, 0xa2, 0x5e, 0x40, 0xe3, 0x8a, 0xa1, 0xfd, 0x6f, 0xc3, 0xbe, + 0x36, 0xec, 0x94, 0x86, 0x5a, 0x1f, 0x93, 0xad, 0x80, 0xc6, 0x2b, 0x3e, 0xfe, 0x61, 0xa0, 0x7e, + 0xbd, 0x6e, 0xbe, 0x44, 0x0f, 0x67, 0x7c, 0x2e, 0xcf, 0x58, 0x68, 0x19, 0x43, 0x63, 0xd4, 0xf1, + 0xf7, 0xf3, 0xcc, 0x69, 0x9f, 0xf0, 0xb9, 0x1c, 0xbf, 0xbe, 0xc9, 0x9c, 0x7e, 0x49, 0xd5, 0x11, + 0x4c, 0xda, 0xea, 0x6d, 0x1c, 0x9a, 0x47, 0x08, 0xe9, 0xf3, 0xa8, 0xe6, 0x46, 0xd1, 0xc4, 0x79, + 0xe6, 0x74, 0xf4, 0xff, 0x54, 0x94, 0xb7, 0xcb, 0xf2, 0x6d, 0x10, 0x93, 0x8e, 0xfe, 0x18, 0x87, + 0xe6, 0x00, 0x6d, 0x2e, 0x0f, 0x6a, 0x35, 0x87, 0xc6, 0xa8, 0x45, 0x56, 0xdf, 0xfe, 0xbb, 0xab, + 0xdc, 0x36, 0xae, 0x73, 0xdb, 0xf8, 0x9d, 0xdb, 0xc6, 0xf7, 0x85, 0xdd, 0xb8, 0x5e, 0xd8, 0x8d, + 0x5f, 0x0b, 0xbb, 0xf1, 0xe1, 0x30, 0x62, 0xf2, 0xfc, 0x62, 0xe2, 0x52, 0x9e, 0x78, 0x94, 0x8b, + 0x84, 0x0b, 0xfd, 0x38, 0x10, 0x61, 0xec, 0x7d, 0xf3, 0xd4, 0xfd, 0x79, 0xf6, 0xe2, 0x60, 0x79, + 0x85, 0xe4, 0xe5, 0x0c, 0xc4, 0xa4, 0x5d, 0xdc, 0xa0, 0xc3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x01, 0x7e, 0xa5, 0xb6, 0x9c, 0x03, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AckSequences) > 0 { + for iNdEx := len(m.AckSequences) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AckSequences[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.RecvSequences) > 0 { + for iNdEx := len(m.RecvSequences) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RecvSequences[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.SendSequences) > 0 { + for iNdEx := len(m.SendSequences) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SendSequences[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.Commitments) > 0 { + for iNdEx := len(m.Commitments) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Commitments[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Acknowledgements) > 0 { + for iNdEx := len(m.Acknowledgements) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Acknowledgements[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Channels) > 0 { + for iNdEx := len(m.Channels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Channels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *PacketSequence) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PacketSequence) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketSequence) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x18 + } + if len(m.ChannelID) > 0 { + i -= len(m.ChannelID) + copy(dAtA[i:], m.ChannelID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelID))) + i-- + dAtA[i] = 0x12 + } + if len(m.PortID) > 0 { + i -= len(m.PortID) + copy(dAtA[i:], m.PortID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Channels) > 0 { + for _, e := range m.Channels { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Acknowledgements) > 0 { + for _, e := range m.Acknowledgements { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Commitments) > 0 { + for _, e := range m.Commitments { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.SendSequences) > 0 { + for _, e := range m.SendSequences { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.RecvSequences) > 0 { + for _, e := range m.RecvSequences { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.AckSequences) > 0 { + for _, e := range m.AckSequences { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *PacketSequence) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChannelID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovGenesis(uint64(m.Sequence)) + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Channels = append(m.Channels, IdentifiedChannel{}) + if err := m.Channels[len(m.Channels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Acknowledgements", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Acknowledgements = append(m.Acknowledgements, PacketAckCommitment{}) + if err := m.Acknowledgements[len(m.Acknowledgements)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commitments", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commitments = append(m.Commitments, PacketAckCommitment{}) + if err := m.Commitments[len(m.Commitments)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SendSequences", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SendSequences = append(m.SendSequences, PacketSequence{}) + if err := m.SendSequences[len(m.SendSequences)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RecvSequences", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RecvSequences = append(m.RecvSequences, PacketSequence{}) + if err := m.RecvSequences[len(m.RecvSequences)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AckSequences", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AckSequences = append(m.AckSequences, PacketSequence{}) + if err := m.AckSequences[len(m.AckSequences)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketSequence) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PacketSequence: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketSequence: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ibc/09-localhost/types/codec.go b/x/ibc/09-localhost/types/codec.go index c8952a7562..7cac129d52 100644 --- a/x/ibc/09-localhost/types/codec.go +++ b/x/ibc/09-localhost/types/codec.go @@ -7,13 +7,6 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ) -// RegisterCodec registers client state on the provided Amino codec. This type is used for -// Amino JSON serialization. -// TODO: remove after genesis and exporting use proto -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(ClientState{}, "ibc/client/localhost/ClientState", nil) -} - // RegisterInterfaces register the ibc interfaces submodule implementations to protobuf // Any. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { @@ -28,9 +21,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { } var ( - // SubModuleCdc references the global x/ibc/09-localhost module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding. - // + // SubModuleCdc references the global x/ibc/09-localhost module codec. // The actual codec used for serialization should be provided to x/ibc/09-localhost and // defined at the application level. SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) diff --git a/x/ibc/genesis_test.go b/x/ibc/genesis_test.go index ef4865ce87..fe51ab8acd 100644 --- a/x/ibc/genesis_test.go +++ b/x/ibc/genesis_test.go @@ -1,7 +1,14 @@ package ibc_test import ( - "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" + "fmt" + + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/ibc" + clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" @@ -33,13 +40,13 @@ func (suite *IBCTestSuite) TestValidateGenesis() { clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), clienttypes.NewGenesisClientState( - exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10), + clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10), ), }, []clienttypes.ClientConsensusStates{ clienttypes.NewClientConsensusStates( clientID, - []exported.ConsensusState{ + []clientexported.ConsensusState{ ibctmtypes.NewConsensusState( suite.header.Time, commitmenttypes.NewMerkleRoot(suite.header.AppHash), suite.header.GetHeight(), suite.header.NextValidatorsHash, ), @@ -93,7 +100,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), ), clienttypes.NewGenesisClientState( - exported.ClientTypeLocalHost, localhosttypes.NewClientState("(chaindID)", 0), + clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("(chaindID)", 0), ), }, nil, @@ -143,3 +150,130 @@ func (suite *IBCTestSuite) TestValidateGenesis() { } } } + +func (suite *IBCTestSuite) TestInitGenesis() { + testCases := []struct { + name string + genState types.GenesisState + }{ + { + name: "default", + genState: types.DefaultGenesisState(), + }, + { + name: "valid genesis", + genState: types.GenesisState{ + ClientGenesis: clienttypes.NewGenesisState( + []clienttypes.GenesisClientState{ + clienttypes.NewGenesisClientState( + clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()), + ), + clienttypes.NewGenesisClientState( + clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10), + ), + }, + []clienttypes.ClientConsensusStates{ + clienttypes.NewClientConsensusStates( + clientID, + []clientexported.ConsensusState{ + ibctmtypes.NewConsensusState( + suite.header.Time, commitmenttypes.NewMerkleRoot(suite.header.AppHash), suite.header.GetHeight(), suite.header.ValidatorSet.Hash(), + ), + }, + ), + }, + true, + ), + ConnectionGenesis: connectiontypes.NewGenesisState( + []connectiontypes.IdentifiedConnection{ + connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{ibctesting.ConnectionVersion})), + }, + []connectiontypes.ConnectionPaths{ + connectiontypes.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), + }, + ), + ChannelGenesis: channeltypes.NewGenesisState( + []channeltypes.IdentifiedChannel{ + channeltypes.NewIdentifiedChannel( + port1, channel1, channeltypes.NewChannel( + channeltypes.INIT, channelOrder, + channeltypes.NewCounterparty(port2, channel2), []string{connectionID}, channelVersion, + ), + ), + }, + []channeltypes.PacketAckCommitment{ + channeltypes.NewPacketAckCommitment(port2, channel2, 1, []byte("ack")), + }, + []channeltypes.PacketAckCommitment{ + channeltypes.NewPacketAckCommitment(port1, channel1, 1, []byte("commit_hash")), + }, + []channeltypes.PacketSequence{ + channeltypes.NewPacketSequence(port1, channel1, 1), + }, + []channeltypes.PacketSequence{ + channeltypes.NewPacketSequence(port2, channel2, 1), + }, + []channeltypes.PacketSequence{ + channeltypes.NewPacketSequence(port2, channel2, 1), + }, + ), + }, + }, + } + + for _, tc := range testCases { + app := simapp.Setup(false) + + suite.NotPanics(func() { + ibc.InitGenesis(app.BaseApp.NewContext(false, abci.Header{Height: 1}), *app.IBCKeeper, true, tc.genState) + }) + } +} + +// TODO: HandlerTestSuite should replace IBCTestSuite +func (suite *HandlerTestSuite) TestExportGenesis() { + testCases := []struct { + msg string + malleate func() + }{ + { + "success", + func() { + // creates clients + suite.coordinator.Setup(suite.chainA, suite.chainB) + // create extra clients + suite.coordinator.CreateClient(suite.chainA, suite.chainB, clientexported.Tendermint) + suite.coordinator.CreateClient(suite.chainA, suite.chainB, clientexported.Tendermint) + }, + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() + + tc.malleate() + + var gs types.GenesisState + suite.NotPanics(func() { + gs = ibc.ExportGenesis(suite.chainA.GetContext(), *suite.chainA.App.IBCKeeper) + }) + + // init genesis based on export + suite.NotPanics(func() { + ibc.InitGenesis(suite.chainA.GetContext(), *suite.chainA.App.IBCKeeper, true, gs) + }) + + suite.NotPanics(func() { + cdc := codec.NewProtoCodec(suite.chainA.App.InterfaceRegistry()) + genState := cdc.MustMarshalJSON(&gs) + cdc.MustUnmarshalJSON(genState, &gs) + }) + + // init genesis based on marshal and unmarshal + suite.NotPanics(func() { + ibc.InitGenesis(suite.chainA.GetContext(), *suite.chainA.App.IBCKeeper, true, gs) + }) + }) + } +} diff --git a/x/ibc/keeper/keeper.go b/x/ibc/keeper/keeper.go index 3e9f1ee1f3..cd4d1aea45 100644 --- a/x/ibc/keeper/keeper.go +++ b/x/ibc/keeper/keeper.go @@ -20,8 +20,7 @@ type Keeper struct { // implements gRPC QueryServer interface types.QueryServer - aminoCdc *codec.Codec - cdc codec.BinaryMarshaler + cdc codec.BinaryMarshaler ClientKeeper clientkeeper.Keeper ConnectionKeeper connectionkeeper.Keeper @@ -32,7 +31,7 @@ type Keeper struct { // NewKeeper creates a new ibc Keeper func NewKeeper( - aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, + cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) *Keeper { clientKeeper := clientkeeper.NewKeeper(cdc, key, stakingKeeper) connectionKeeper := connectionkeeper.NewKeeper(cdc, key, clientKeeper) @@ -40,7 +39,6 @@ func NewKeeper( channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) return &Keeper{ - aminoCdc: aminoCdc, cdc: cdc, ClientKeeper: clientKeeper, ConnectionKeeper: connectionKeeper, @@ -49,9 +47,9 @@ func NewKeeper( } } -// Codecs returns the IBC module codec. -func (k Keeper) Codecs() (codec.BinaryMarshaler, *codec.Codec) { - return k.cdc, k.aminoCdc +// Codec returns the IBC module codec. +func (k Keeper) Codec() codec.BinaryMarshaler { + return k.cdc } // SetRouter sets the Router in IBC Keeper and seals it. The method panics if diff --git a/x/ibc/module.go b/x/ibc/module.go index 52f50ebff4..a7e85c7c7d 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -179,7 +179,7 @@ func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for ibc module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[host.StoreKey] = simulation.NewDecodeStore(am.keeper.Codecs()) + sdr[host.StoreKey] = simulation.NewDecodeStore(*am.keeper) } // WeightedOperations returns the all the ibc module operations with their respective weights. diff --git a/x/ibc/simulation/decoder.go b/x/ibc/simulation/decoder.go index 29048025ab..2f2f1fcb43 100644 --- a/x/ibc/simulation/decoder.go +++ b/x/ibc/simulation/decoder.go @@ -3,27 +3,27 @@ package simulation import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" clientsim "github.com/cosmos/cosmos-sdk/x/ibc/02-client/simulation" connectionsim "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/simulation" channelsim "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/simulation" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/ibc/keeper" ) // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding ibc type. -func NewDecodeStore(cdc codec.BinaryMarshaler, aminoCdc *codec.Codec) func(kvA, kvB kv.Pair) string { +func NewDecodeStore(k keeper.Keeper) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { - if res, found := clientsim.NewDecodeStore(aminoCdc, kvA, kvB); found { + if res, found := clientsim.NewDecodeStore(k.ClientKeeper, kvA, kvB); found { return res } - if res, found := connectionsim.NewDecodeStore(cdc, kvA, kvB); found { + if res, found := connectionsim.NewDecodeStore(k.Codec(), kvA, kvB); found { return res } - if res, found := channelsim.NewDecodeStore(cdc, kvA, kvB); found { + if res, found := channelsim.NewDecodeStore(k.Codec(), kvA, kvB); found { return res } diff --git a/x/ibc/simulation/decoder_test.go b/x/ibc/simulation/decoder_test.go index 4e34ee6113..d92b82daab 100644 --- a/x/ibc/simulation/decoder_test.go +++ b/x/ibc/simulation/decoder_test.go @@ -17,17 +17,14 @@ import ( func TestDecodeStore(t *testing.T) { app := simapp.Setup(false) - cdc := app.AppCodec() - aminoCdc := app.Codec() - - dec := simulation.NewDecodeStore(app.IBCKeeper.Codecs()) + dec := simulation.NewDecodeStore(*app.IBCKeeper) clientID := "clientidone" connectionID := "connectionidone" channelID := "channelidone" portID := "portidone" - clientState := ibctmtypes.ClientState{ + clientState := &ibctmtypes.ClientState{ FrozenHeight: 10, } connection := connectiontypes.ConnectionEnd{ @@ -42,15 +39,15 @@ func TestDecodeStore(t *testing.T) { kvPairs := kv.Pairs{ kv.Pair{ Key: host.FullKeyClientPath(clientID, host.KeyClientState()), - Value: aminoCdc.MustMarshalBinaryBare(clientState), + Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState), }, kv.Pair{ Key: host.KeyConnection(connectionID), - Value: cdc.MustMarshalBinaryBare(&connection), + Value: app.IBCKeeper.Codec().MustMarshalBinaryBare(&connection), }, kv.Pair{ Key: host.KeyChannel(portID, channelID), - Value: cdc.MustMarshalBinaryBare(&channel), + Value: app.IBCKeeper.Codec().MustMarshalBinaryBare(&channel), }, kv.Pair{ Key: []byte{0x99}, diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go index 661e7b18b2..a401f09b0e 100644 --- a/x/ibc/types/codec.go +++ b/x/ibc/types/codec.go @@ -16,7 +16,6 @@ import ( func RegisterCodec(cdc *codec.Codec) { clienttypes.RegisterCodec(cdc) ibctmtypes.RegisterCodec(cdc) - localhosttypes.RegisterCodec(cdc) commitmenttypes.RegisterCodec(cdc) } diff --git a/x/ibc/types/genesis.go b/x/ibc/types/genesis.go index b5e9983262..4f997283ae 100644 --- a/x/ibc/types/genesis.go +++ b/x/ibc/types/genesis.go @@ -1,17 +1,13 @@ package types import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ) -// GenesisState defines the ibc module's genesis state. -type GenesisState struct { - ClientGenesis clienttypes.GenesisState `json:"client_genesis" yaml:"client_genesis"` - ConnectionGenesis connectiontypes.GenesisState `json:"connection_genesis" yaml:"connection_genesis"` - ChannelGenesis channeltypes.GenesisState `json:"channel_genesis" yaml:"channel_genesis"` -} +var _ codectypes.UnpackInterfacesMessage = GenesisState{} // DefaultGenesisState returns the ibc module's default genesis state. func DefaultGenesisState() GenesisState { @@ -22,6 +18,11 @@ func DefaultGenesisState() GenesisState { } } +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (gs GenesisState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return gs.ClientGenesis.UnpackInterfaces(unpacker) +} + // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { diff --git a/x/ibc/types/genesis.pb.go b/x/ibc/types/genesis.pb.go new file mode 100644 index 0000000000..550d300e44 --- /dev/null +++ b/x/ibc/types/genesis.pb.go @@ -0,0 +1,442 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/types/genesis.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" + types1 "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" + types2 "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the ibc module's genesis state. +type GenesisState struct { + // ICS002 - Clients genesis state + ClientGenesis types.GenesisState `protobuf:"bytes,1,opt,name=client_genesis,json=clientGenesis,proto3" json:"client_genesis" yaml:"client_genesis"` + // ICS003 - Connections genesis state + ConnectionGenesis types1.GenesisState `protobuf:"bytes,2,opt,name=connection_genesis,json=connectionGenesis,proto3" json:"connection_genesis" yaml:"connection_genesis"` + // ICS004 - Channel genesis state + ChannelGenesis types2.GenesisState `protobuf:"bytes,3,opt,name=channel_genesis,json=channelGenesis,proto3" json:"channel_genesis" yaml:"channel_genesis"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_56f925134b8f719f, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetClientGenesis() types.GenesisState { + if m != nil { + return m.ClientGenesis + } + return types.GenesisState{} +} + +func (m *GenesisState) GetConnectionGenesis() types1.GenesisState { + if m != nil { + return m.ConnectionGenesis + } + return types1.GenesisState{} +} + +func (m *GenesisState) GetChannelGenesis() types2.GenesisState { + if m != nil { + return m.ChannelGenesis + } + return types2.GenesisState{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "ibc.types.GenesisState") +} + +func init() { proto.RegisterFile("ibc/types/genesis.proto", fileDescriptor_56f925134b8f719f) } + +var fileDescriptor_56f925134b8f719f = []byte{ + // 301 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0xbd, 0x4e, 0xc3, 0x30, + 0x14, 0x85, 0x93, 0x22, 0x21, 0x11, 0xa0, 0x88, 0x88, 0x9f, 0x24, 0x2a, 0x2e, 0x64, 0xea, 0x42, + 0x2c, 0xc1, 0xc6, 0x98, 0x85, 0x3d, 0x6c, 0x0c, 0xa0, 0xc4, 0x58, 0xa9, 0x45, 0x62, 0x57, 0xd8, + 0x48, 0xf4, 0x2d, 0x78, 0x26, 0xa6, 0x8e, 0x1d, 0x99, 0x2a, 0x94, 0xbc, 0x01, 0x4f, 0x80, 0x62, + 0x5f, 0x52, 0x4c, 0xa7, 0x44, 0xe7, 0xbb, 0x27, 0xdf, 0x8d, 0x6c, 0xef, 0x94, 0x15, 0x04, 0xab, + 0xf9, 0x8c, 0x4a, 0x5c, 0x52, 0x4e, 0x25, 0x93, 0xc9, 0xec, 0x45, 0x28, 0xe1, 0xef, 0xb0, 0x82, + 0x24, 0x1a, 0x44, 0x47, 0xa5, 0x28, 0x85, 0x4e, 0x71, 0xf7, 0x66, 0x06, 0xa2, 0xa0, 0x6b, 0x92, + 0x8a, 0x51, 0xae, 0xec, 0x6a, 0x34, 0xd2, 0x44, 0x70, 0x4e, 0x89, 0x62, 0x82, 0xff, 0xa3, 0xa1, + 0xa6, 0xd3, 0x9c, 0x73, 0x5a, 0xd9, 0x28, 0xfe, 0x18, 0x78, 0x7b, 0xb7, 0x26, 0xb9, 0x53, 0xb9, + 0xa2, 0xfe, 0x83, 0x37, 0x34, 0x86, 0x47, 0x18, 0x0c, 0xdc, 0x73, 0x77, 0xb2, 0x7b, 0x15, 0x24, + 0xdd, 0x76, 0x06, 0x25, 0x7f, 0x1b, 0xe9, 0xd9, 0x62, 0x35, 0x76, 0xbe, 0x57, 0xe3, 0xe3, 0x79, + 0x5e, 0x57, 0x37, 0xb1, 0xdd, 0x8e, 0xb3, 0x7d, 0x13, 0x40, 0xc5, 0xe7, 0x9e, 0xbf, 0xde, 0xb3, + 0x77, 0x0c, 0xb4, 0x63, 0x64, 0x1c, 0x3d, 0xb6, 0x3d, 0x17, 0xe0, 0x09, 0xc1, 0xb3, 0xf1, 0x95, + 0x38, 0x3b, 0x5c, 0x87, 0xbf, 0xbe, 0xc2, 0x3b, 0x80, 0x3f, 0xef, 0x65, 0x5b, 0x5a, 0x16, 0x1a, + 0x99, 0x61, 0xb6, 0x09, 0x81, 0xe9, 0x04, 0x4c, 0x76, 0x3f, 0xce, 0x86, 0x90, 0x40, 0x29, 0x4d, + 0x17, 0x0d, 0x72, 0x97, 0x0d, 0x72, 0xbf, 0x1a, 0xe4, 0xbe, 0xb7, 0xc8, 0x59, 0xb6, 0xc8, 0xf9, + 0x6c, 0x91, 0x73, 0x3f, 0x29, 0x99, 0x9a, 0xbe, 0x16, 0x09, 0x11, 0x35, 0x26, 0x42, 0xd6, 0x42, + 0xc2, 0xe3, 0x52, 0x3e, 0x3d, 0xe3, 0x37, 0xdc, 0x5f, 0x85, 0x62, 0x5b, 0x9f, 0xc7, 0xf5, 0x4f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xd4, 0x78, 0xa0, 0x1e, 0x02, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ChannelGenesis.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.ConnectionGenesis.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ClientGenesis.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ClientGenesis.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.ConnectionGenesis.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.ChannelGenesis.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientGenesis", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ClientGenesis.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionGenesis", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ConnectionGenesis.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelGenesis", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ChannelGenesis.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +)