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

feat: reverse search links #793

Merged
merged 25 commits into from
Mar 28, 2022
Merged

feat: reverse search links #793

merged 25 commits into from
Mar 28, 2022

Conversation

RiccardoM
Copy link
Contributor

@RiccardoM RiccardoM commented Mar 23, 2022

Description

This PR adds the ability to reverse search for app links and chain links owners. The new following queries have been added:

  • search for app link owners using an application name (optional), and username (optional, works only if the application is specified as well)
  • search for chain link owners using a chain name (optional), and target address (optional, works only if the chain name is specified as well)

Closes: #777
Closes: #794


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

…earch-app-links

# Conflicts:
#	x/profiles/keeper/keeper_app_links.go
…earch-app-links

# Conflicts:
#	x/profiles/keeper/migrations.go
#	x/profiles/legacy/v4/store_test.go
…reverse-search-app-links

� Conflicts:
�	proto/desmos/profiles/v1beta1/models_chain_links.proto
�	proto/desmos/profiles/v1beta1/models_profile.proto
�	proto/desmos/profiles/v1beta1/models_relationships.proto
�	x/profiles/keeper/keeper_app_links.go
�	x/profiles/keeper/keeper_chain_links.go
�	x/profiles/keeper/keeper_chain_links_test.go
�	x/profiles/keeper/keeper_dtag_transfers.go
�	x/profiles/keeper/migrations.go
�	x/profiles/legacy/v4/keeper.go
�	x/profiles/legacy/v4/models_chain_links.pb.go
�	x/profiles/legacy/v4/models_profile.pb.go
�	x/profiles/legacy/v4/models_relationships.pb.go
�	x/profiles/legacy/v4/store.go
�	x/profiles/legacy/v4/store_test.go
�	x/profiles/types/query.pb.go
�	x/profiles/types/query_app_links.pb.go
@github-actions github-actions bot added the x/profiles Module that allows to create and manage decentralized social profiles label Mar 23, 2022
@codecov
Copy link

codecov bot commented Mar 23, 2022

Codecov Report

Merging #793 (3ee9064) into master (73a6816) will increase coverage by 0.03%.
The diff coverage is 84.21%.

@@            Coverage Diff             @@
##           master     #793      +/-   ##
==========================================
+ Coverage   81.25%   81.28%   +0.03%     
==========================================
  Files          76       77       +1     
  Lines        6503     6610     +107     
==========================================
+ Hits         5284     5373      +89     
- Misses        977      989      +12     
- Partials      242      248       +6     
Impacted Files Coverage Δ
x/profiles/legacy/v5/store.go 75.51% <75.51%> (ø)
x/profiles/keeper/grpc_query.go 79.54% <89.65%> (+4.96%) ⬆️
x/profiles/keeper/keeper_app_links.go 81.94% <100.00%> (-0.25%) ⬇️
x/profiles/keeper/keeper_chain_links.go 84.48% <100.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43d6ddf...3ee9064. Read the comment docs.

Comment on lines 143 to 145
cleanedKey := bytes.TrimSuffix(bytes.TrimPrefix(keyWithPrefix, types.ChainLinkChainPrefix), value)
values := bytes.Split(cleanedKey, types.Separator)
chainName, target := values[0], values[1]
Copy link
Contributor

@dadamu dadamu Mar 28, 2022

Choose a reason for hiding this comment

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

I think it can be all implemented by bytes.Split instead of bytes.TrimSuffix, say:

values := bytes.Split(cleanedKey, types.Separator)
chainName, target, value := values[0], values[1], values[2]

Then, the value of the key can be simply 0x01 in order to reduce the storage on chain.

Copy link
Contributor Author

@RiccardoM RiccardoM Mar 28, 2022

Choose a reason for hiding this comment

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

Right now, links owners are stored using the following keys:

ChainLinkChainPrefix + Chain name + Separator + External Address + User address -> User address

So, if we use the bytes.Split it would return the following values:

1. Chain name
2. External Address + User address

We would have to remove the User address suffix anyway to get the external address.

Also, the key for chain link owners right now are:

ChainLinkChainPrefix     = []byte{0x15}
ApplicationLinkAppPrefix = []byte{0x16}

Which already are 1 byte each. We already use 0x01 for the IBCPortKey key. We can't re-use that. Also, 0x01 and 0x16 are both 1 byte each so that wouldn't impact the chain storage space

Copy link
Contributor

@dadamu dadamu Mar 28, 2022

Choose a reason for hiding this comment

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

@RiccardoM Sorry for that the explanation was not clear, I mean that we can store the key like:

ChainLinkChainPrefix + Chain name + Separator + External Address + Spearator + User address -> 0x01

Then the bytes.Split would return the values:

1. Chain name
2. External address
3. User address

As a result, the storage doesn't need to store user address as value again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dadamu You are completely right! Thanks for pointing that out, this way we can save up a lot of disk space. I've just implemented it this way (and also added some missing tests)

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this answer, should we look after other places where we use bytes.TrimSuffix and bytes.TrimPrefix and see if we can improve them as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bragaz All other keys instances do not trim prefixes unless necessary (eg. inside user group members). All the keys have already been reviewed inside their own PRs before being merged, and I don't think it would be appropriate to do it here anyway. I've checked though and didn't find any use of bytes.TrimPrefix aside from this case and user groups members anyway

Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
@@ -355,6 +355,14 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteChainLink() {
"cosmos",
ext.GetAddress().String(),
))

// Check the additional keys
store := suite.ctx.KVStore(suite.storeKey)
Copy link
Contributor

@dadamu dadamu Mar 28, 2022

Choose a reason for hiding this comment

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

We should have checking the additional keys in the StoreChainlink test function as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -487,6 +487,15 @@ func (suite *KeeperTestSuite) Test_DeleteApplicationLink() {
"twitter",
"twitteruser",
))

// Check the additional keys
store := suite.ctx.KVStore(suite.storeKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, we should have the checking in the SaveApplicationLink

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Copy link
Contributor

@dadamu dadamu left a comment

Choose a reason for hiding this comment

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

Looks good to me, ready to go.

@RiccardoM RiccardoM added the automerge Automatically merge PR once all prerequisites pass label Mar 28, 2022
@mergify mergify bot merged commit acdecc9 into master Mar 28, 2022
@mergify mergify bot deleted the riccardo/reverse-search-links branch March 28, 2022 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once all prerequisites pass x/CLI x/profiles Module that allows to create and manage decentralized social profiles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reverse search through chain links Reverse search through app links
3 participants