Skip to content

Commit

Permalink
Use generated client identifiers (#8034)
Browse files Browse the repository at this point in the history
* add client identifier generation

* update proto and start fixing tests

* fix ibc tests

* fix auth rest test

* update spec

* fix lint

* add parsing tests and fix bugs

* fix regexp

* add godoc

* address @AdityaSripal review suggestions for identifier parsing

* address rest of @AdityaSripal's review comments

* remove unnecessary comment

* typos

* fix lint

* Apply suggestions from code review

Co-authored-by: Aditya <adityasripal@gmail.com>

* add more heigh tests as per @AdityaSripal suggestion

Co-authored-by: Aditya <adityasripal@gmail.com>
  • Loading branch information
colin-axner and AdityaSripal authored Nov 30, 2020
1 parent a648325 commit bcb3240
Show file tree
Hide file tree
Showing 39 changed files with 583 additions and 337 deletions.
2 changes: 2 additions & 0 deletions proto/ibc/core/client/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ message GenesisState {
Params params = 3 [(gogoproto.nullable) = false];
// create localhost on initialization
bool create_localhost = 4 [(gogoproto.moretags) = "yaml:\"create_localhost\""];
// the sequence for the next generated client identifier
uint64 next_client_sequence = 5 [(gogoproto.moretags) = "yaml:\"next_client_sequence\""];
}
8 changes: 3 additions & 5 deletions proto/ibc/core/client/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ message MsgCreateClient {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// light client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
google.protobuf.Any client_state = 1 [(gogoproto.moretags) = "yaml:\"client_state\""];
// consensus state associated with the client that corresponds to a given
// height.
google.protobuf.Any consensus_state = 3 [(gogoproto.moretags) = "yaml:\"consensus_state\""];
google.protobuf.Any consensus_state = 2 [(gogoproto.moretags) = "yaml:\"consensus_state\""];
// signer address
string signer = 4;
string signer = 3;
}

// MsgCreateClientResponse defines the Msg/CreateClient response type.
Expand Down
2 changes: 1 addition & 1 deletion types/query/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion x/auth/client/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ func (s *IntegrationTestSuite) TestLegacyRestErrMessages() {
"Successful IBC message",
ibcsolomachinecli.NewCreateClientCmd(),
[]string{
"21212121212", // dummy client-id
"1", // dummy sequence
consensusJSON.Name(), // path to consensus json,
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
Expand Down
26 changes: 3 additions & 23 deletions x/ibc/core/02-client/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/09-localhost/types"
)

// InitGenesis initializes the ibc client submodule's state from a provided genesis
Expand Down Expand Up @@ -39,29 +38,10 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
}
}

if !gs.CreateLocalhost {
return
}

// NOTE: return if the localhost client was already imported. The chain-id and
// block height will be overwriten to the correct values during BeginBlock.
if _, found := k.GetClientState(ctx, exported.Localhost); found {
return
}

// client id is always "localhost"
revision := types.ParseChainID(ctx.ChainID())
clientState := localhosttypes.NewClientState(
ctx.ChainID(), types.NewHeight(revision, uint64(ctx.BlockHeight())),
)
k.SetNextClientSequence(ctx, gs.NextClientSequence)

if err := clientState.Validate(); err != nil {
panic(err)
}

if err := k.CreateClient(ctx, exported.Localhost, clientState, nil); err != nil {
panic(err)
}
// NOTE: localhost creation is specifically disallowed for the time being.
// Issue: https://github.com/cosmos/cosmos-sdk/issues/7871
}

// ExportGenesis returns the ibc client submodule's exported genesis.
Expand Down
13 changes: 5 additions & 8 deletions x/ibc/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ import (
//
// CONTRACT: ClientState was constructed correctly from given initial consensusState
func (k Keeper) CreateClient(
ctx sdk.Context, clientID string, clientState exported.ClientState, consensusState exported.ConsensusState,
) error {
ctx sdk.Context, clientState exported.ClientState, consensusState exported.ConsensusState,
) (string, error) {
params := k.GetParams(ctx)
if !params.IsAllowedClient(clientState.ClientType()) {
return sdkerrors.Wrapf(
return "", sdkerrors.Wrapf(
types.ErrInvalidClientType,
"client state type %s is not registered in the allowlist", clientState.ClientType(),
)
}

_, found := k.GetClientState(ctx, clientID)
if found {
return sdkerrors.Wrapf(types.ErrClientExists, "cannot create client with ID %s", clientID)
}
clientID := k.GenerateClientIdentifier(ctx, clientState.ClientType())

// check if consensus state is nil in case the created client is Localhost
if consensusState != nil {
Expand All @@ -46,7 +43,7 @@ func (k Keeper) CreateClient(
)
}()

return nil
return clientID, nil
}

// UpdateClient updates the consensus state and the state root from a provided header.
Expand Down
Loading

0 comments on commit bcb3240

Please sign in to comment.