Skip to content

feat: Prefix-based routing in IBCv2 Router#8303

Merged
gjermundgaraba merged 9 commits intocosmos:mainfrom
kulikthebird:tkulik/feat/prefix_based_routing_ibcv2
May 8, 2025
Merged

feat: Prefix-based routing in IBCv2 Router#8303
gjermundgaraba merged 9 commits intocosmos:mainfrom
kulikthebird:tkulik/feat/prefix_based_routing_ibcv2

Conversation

@kulikthebird
Copy link
Copy Markdown
Contributor

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.

  • Targeted PR against the 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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@kulikthebird kulikthebird changed the title feat: feat: Prefix-based routing in IBCv2 Router Apr 15, 2025
@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 8032f27 to 434610f Compare April 16, 2025 10:42
Copy link
Copy Markdown
Contributor

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Should we have some way to ensure that there is no portID that is a prefix of another portID?

@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 6d5ffb8 to 717d783 Compare April 18, 2025 13:10
@kulikthebird
Copy link
Copy Markdown
Contributor Author

Should we have some way to ensure that there is no portID that is a prefix of another portID?

Good point - I've added a check for that and updated the interface a little bit.

Copy link
Copy Markdown
Contributor

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

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

@AdityaSripal
Copy link
Copy Markdown
Contributor

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

@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 16b6ae6 to 1b445a6 Compare May 5, 2025 08:28
@kulikthebird kulikthebird requested a review from AdityaSripal May 5, 2025 08:29
@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 1b445a6 to 94d58cc Compare May 5, 2025 08:58
Copy link
Copy Markdown
Contributor

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Thank you @kulikthebird !!

Comment on lines +58 to +62
for prefix, module := range rtr.routes {
if strings.HasPrefix(portID, prefix) {
return prefix, module, true
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any scenario where this could actually cause any problems?
@AdityaSripal?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

@gjermundgaraba gjermundgaraba left a comment

Choose a reason for hiding this comment

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

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)

Comment on lines +58 to +62
for prefix, module := range rtr.routes {
if strings.HasPrefix(portID, prefix) {
return prefix, module, true
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any scenario where this could actually cause any problems?
@AdityaSripal?

@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 4466d66 to 567fd62 Compare May 5, 2025 14:41
@kulikthebird kulikthebird force-pushed the tkulik/feat/prefix_based_routing_ibcv2 branch from 567fd62 to 840d24a Compare May 5, 2025 14:47
@kulikthebird kulikthebird requested a review from AdityaSripal May 5, 2025 14:48
Copy link
Copy Markdown
Contributor

@gjermundgaraba gjermundgaraba left a comment

Choose a reason for hiding this comment

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

This looks good! One last ask, could you please add a changelog entry as well? 🙏

@gjermundgaraba gjermundgaraba enabled auto-merge May 7, 2025 17:21
@gjermundgaraba gjermundgaraba added this pull request to the merge queue May 8, 2025
Merged via the queue into cosmos:main with commit bb1e4ac May 8, 2025
53 of 54 checks passed
DeshErBojhaa pushed a commit that referenced this pull request May 12, 2025
* 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>
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.

Prefix-based routing in IBCv2 Router

4 participants