-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
…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
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
…reverse-search-links
…nto riccardo/reverse-search-links
x/profiles/keeper/grpc_query.go
Outdated
cleanedKey := bytes.TrimSuffix(bytes.TrimPrefix(keyWithPrefix, types.ChainLinkChainPrefix), value) | ||
values := bytes.Split(cleanedKey, types.Separator) | ||
chainName, target := values[0], values[1] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 <[email protected]>
@@ -355,6 +355,14 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteChainLink() { | |||
"cosmos", | |||
ext.GetAddress().String(), | |||
)) | |||
|
|||
// Check the additional keys | |||
store := suite.ctx.KVStore(suite.storeKey) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 <[email protected]>
There was a problem hiding this 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.
Description
This PR adds the ability to reverse search for app links and chain links owners. The new following queries have been added:
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change