feat: Prefix-based routing in IBCv2 Router#8303
Conversation
8032f27 to
434610f
Compare
AdityaSripal
left a comment
There was a problem hiding this comment.
Should we have some way to ensure that there is no portID that is a prefix of another portID?
6d5ffb8 to
717d783
Compare
Good point - I've added a check for that and updated the interface a little bit. |
AdityaSripal
left a comment
There was a problem hiding this comment.
lgtm so far, will discuss internally if we want to use the new dependency or just implement prefix check directly as we did with the IBC v1 router
|
Hi @kulikthebird can you please remove this external dependency and just use a for-loop as we had originally. We decided internally not to add the additional third-party library for now. Thanks! I will approve and merge once that change is in |
16b6ae6 to
1b445a6
Compare
1b445a6 to
94d58cc
Compare
AdityaSripal
left a comment
There was a problem hiding this comment.
Thank you @kulikthebird !!
| for prefix, module := range rtr.routes { | ||
| if strings.HasPrefix(portID, prefix) { | ||
| return prefix, module, true | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
There was a problem hiding this comment.
Is there any scenario where this could actually cause any problems?
@AdityaSripal?
There was a problem hiding this comment.
The issue here as I understand is that order is not deterministic here. So the first match will pass. But this is why we ensure that no two portIDs on the router are prefixes of each other. Thus the first portID to match the prefix check should be the only portID to match the prefix check.
cc: @kulikthebird
There was a problem hiding this comment.
I've just realized, that it is possible to add a shorter prefix using AddRoute method i.e.
1. Add prefix "port01"
2. Try to add prefix "port01somesuffix" - this won't pass, because we have a prefix "port01"
3. Add prefix "port" - this would pass, because non of the already added prefixes is a prefix for "port"
I'll add an additional check and test case for that scenario
There was a problem hiding this comment.
Seems reasonable to me. I want to make sure we are confident that the map iteration is safe though. Maybe even put a comment on why it is safe, and under what types of usage it might not (to prevent someone from accidentally using it for something else)
| for prefix, module := range rtr.routes { | ||
| if strings.HasPrefix(portID, prefix) { | ||
| return prefix, module, true | ||
| } | ||
| } |
There was a problem hiding this comment.
Is there any scenario where this could actually cause any problems?
@AdityaSripal?
4466d66 to
567fd62
Compare
567fd62 to
840d24a
Compare
gjermundgaraba
left a comment
There was a problem hiding this comment.
This looks good! One last ask, could you please add a changelog entry as well? 🙏
* imp: Prefix based routing for IBCv2 * docs: Update docs * chore: Prohibit registering of overlapping paths * chore: Use a map instead of radix tree * chore: Remove type casting * chore: Add an extra check for prefix existence * chore: Update CHANGELOG --------- Co-authored-by: Aditya <14364734+AdityaSripal@users.noreply.github.com> Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
Description
This PR introduces a prefix-based routing for the IBCv2 Router. Before this change only the exact port IDs could be associated with a given IBCModule. This change make it possible to associate port ID prefixes with the modules.
closes: #8302
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/).godoccomments.Files changedin the GitHub PR explorer.SonarCloud Reportin the comment section below once CI passes.