Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use separate prefix store for each client #5850

Closed
wants to merge 11 commits into from

Conversation

AdityaSripal
Copy link
Member

Closes: #5502

Description

Creates prefix store with prefix of clientID for each client instance.

Test case on 04-channel was failing. Fixed it by simply changing the expected value to match actual


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

The store keys need to be changed (in all instances I think), we don't want to duplicate the client identifier.

Also, the tests fail locally, not sure what's up with CI - failing tests should be expected anyways, as all of the paths for proofs will need to change. I suggest separate functions for calculating store keys & then prefixing them with a client identifier, which should also be used in the verification code (e.g. verifyClientConsensusState et al.)

x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
@cwgoes
Copy link
Contributor

cwgoes commented Mar 23, 2020

Also note my question on this issue, which is relevant - cosmos/ibc#387 (comment).

@@ -205,8 +205,9 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
connectionKey := ibctypes.KeyConnection(testConnectionIDB)
proofTry, proofHeight := queryProof(suite.chainB, connectionKey)

consensusKey := ibctypes.KeyConsensusState(testClientIDA, uint64(consensusHeight))
consensusKey := append([]byte(testClientIDA+"/"), ibctypes.KeyConsensusState(uint64(consensusHeight))...)
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary conversion (from unconvert)

@@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
connectionKey := ibctypes.KeyConnection(testConnectionIDA)
proofInit, proofHeight := queryProof(suite.chainA, connectionKey)

consensusKey := ibctypes.KeyConsensusState(testClientIDB, consensusHeight)
consensusKey := prefixedClientKey(testClientIDB, ibctypes.KeyConsensusState(uint64(consensusHeight)))
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary conversion (from unconvert)

@@ -205,7 +205,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
connectionKey := ibctypes.KeyConnection(testConnectionIDB)
proofTry, proofHeight := queryProof(suite.chainB, connectionKey)

consensusKey := ibctypes.KeyConsensusState(testClientIDA, uint64(consensusHeight))
consensusKey := prefixedClientKey(testClientIDA, ibctypes.KeyConsensusState(uint64(consensusHeight)))
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary conversion (from unconvert)

@@ -66,7 +66,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {

// TODO: is this the right consensus height
consensusHeight := uint64(suite.chainA.Header.Height)
consensusKey := ibctypes.KeyConsensusState(testClientIDA, consensusHeight)
consensusKey := prefixedClientKey(testClientIDA, ibctypes.KeyConsensusState(uint64(consensusHeight)))
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary conversion (from unconvert)

@@ -44,7 +44,7 @@ func QueryClientState(
) (types.StateResponse, error) {
req := abci.RequestQuery{
Path: "store/ibc/key",
Data: ibctypes.KeyClientState(clientID),
Data: ibctypes.KeyClientState(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This file need to be fixed to still prefix clientID

@@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
connectionKey := ibctypes.KeyConnection(testConnectionIDA)
proofInit, proofHeight := queryProof(suite.chainA, connectionKey)

consensusKey := ibctypes.KeyConsensusState(testClientIDB, consensusHeight)
consensusKey := prefixedClientKey(testClientIDB, ibctypes.KeyConsensusState(uint64(consensusHeight)))
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently using this helper function rather than creating a prefix and using ApplyPrefix

@@ -114,7 +114,8 @@ func (cs ClientState) VerifyClientConsensusState(
proof commitmentexported.Proof,
consensusState clientexported.ConsensusState,
) error {
path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ConsensusStatePath(counterpartyClientIdentifier, consensusHeight))
clientPrefixedPath := counterpartyClientIdentifier + "/" + ibctypes.ConsensusStatePath(consensusHeight)
Copy link
Member Author

Choose a reason for hiding this comment

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

Simply appending here rather than using ApplyPrefix since the Prefix that gets used by all paths is simply ibc. Not sure if i should create a seperate Prefix object for ClientConsensusState and pass it in here or if I should continue hardcoding this append

If I create a prefix, I must have some code in the caller that does something like:

ibcPrefix :=  prefix.Bytes()
clientPrefix := commitment.NewPrefix(append(ibcPrefix, counterPartyClientID....)
// pass in clientPrefix to VerifyClientConsensusState, ibcPrefix into VerifyConnectionState

Copy link
Contributor

Choose a reason for hiding this comment

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

I think from the perspective of the spec the full path just needs to be correct, I'm not sure what's considered more ergonomic in the SDK.

@@ -147,6 +148,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
// objects. For each State object, cb will be called. If the cb returns true,
// the iterator will close and stop.
func (k Keeper) IterateClients(ctx sdk.Context, cb func(exported.ClientState) bool) {
// TODO: determine how to fix this function with new key format
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure of best way to fix this function with current key format that puts clientID before "client_state"

Copy link
Contributor

@cwgoes cwgoes Mar 24, 2020

Choose a reason for hiding this comment

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

This should only be called outside of the state machine (e.g. in queriers), so I think it's OK if it's not the most efficient (note that all clients should still be prefixed by client/{clientID}, so you shouldn't need to iterate over other things).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm currently think clientstates are stored under ibc/{clientID}/client_state and consensus states are stored under ibc/{clientID}/consensus_state/{height}

Could add another client prefix in after ibc? then we would be iterating over client states and consensus states. would be somewhat inefficient but not terrible

Copy link
Contributor

Choose a reason for hiding this comment

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

ah - it should be ibc/clients/{clientID}/client_state and ibc/clients/{clientID}/consensus_state/{height}, I think

@AdityaSripal AdityaSripal changed the base branch from ibc-alpha to master April 9, 2020 17:20
@AdityaSripal AdityaSripal changed the base branch from master to ibc-alpha April 9, 2020 17:20
@AdityaSripal
Copy link
Member Author

Closing in favor of #5980 since it was too annoying to try and rebase to master

@AdityaSripal AdityaSripal deleted the aditya/prefix-client branch April 9, 2020 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants