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

Don't use domain when storing routers #1962

Merged

Conversation

cdamian
Copy link
Contributor

@cdamian cdamian commented Aug 13, 2024

No description provided.

@cdamian cdamian changed the title Dont use domain when storing routers Don't use domain when storing routers Aug 13, 2024
ensure!(domain != Domain::Centrifuge, Error::<T>::DomainNotSupported);

//TODO(cdamian): Outbound - Call router.init() for each router?
<Routers<T>>::set(router_ids.clone());
Copy link
Contributor Author

@cdamian cdamian Aug 13, 2024

Choose a reason for hiding this comment

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

Still a bit confused by this setup since the routers that we're storing are not the ones that we are using when processing...

Anyway, here I'm storing all the available routers right @lemunozm?

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 when processing, you should check the router to process is on that Routers list. We do not want to process a message if the user removes that router. But just that 👍🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

So if a message comes from a not configured router, then the gateway will discard it

fn get_expected_proof_count(domain: &Domain) -> Result<u32, DispatchError> {
let routers = Routers::<T>::get(domain).ok_or(Error::<T>::RoutersNotFound)?;
fn get_expected_proof_count() -> Result<u32, DispatchError> {
let routers = Routers::<T>::get();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And here, for example, I should instead use T::RouterId::for_domain...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because we want to get only the valid routers for the domain where the message comes

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

Main question would be, when to use Routers::<T>::get() and when to use T::RouterId::for_domain().

@cdamian cdamian requested review from wischli and lemunozm August 13, 2024 11:59
@lemunozm
Copy link
Contributor

lemunozm commented Aug 13, 2024

Routers::::get() and when to use T::RouterId::for_domain()

  • Routers::<T>::get() the list of all configured routers, something like a whitelist for the gateway.
  • T::RouterId::for_domain() the list of all configured static routers for a specific domain. Used each time you need to know the routers for a domain.
    • More accurate will be to always filter this list with the Router::<T>::get(). I mean, each router returned by the T::RouterId::for_domain() that is not in Router::<T>::get() must be discarded
      • Maybe an auxiliary method that does that or similar, replacing for_domain() for that auxiliary method

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

Routers::::get() and when to use T::RouterId::for_domain()

  • Routers::<T>::get() the list of all configured routers, something like a whitelist for the gateway.

  • T::RouterId::for_domain() the list of all configured routers for a specific domain. Used each time you need to know the routers for a domain.

    • More accurate will be to always filter this list with the Router::<T>::get(). I mean, each router returned by the T::RouterId::for_domain() that is not in Router::<T>::get() must be discarded

      • Maybe an auxiliary method that does that or similar, replacing for_domain() for that auxiliary method

Still not sure what the benefit is from doing all of this, instead of keeping track which router IDs are set for each domain, in storage, like the current approach.

@lemunozm
Copy link
Contributor

lemunozm commented Aug 13, 2024

Because basically, T::RouterId::for_domain() is representing the static relation between routers and domains, it's something that the gateway doesn't know (and something it can not ensure either). The gateway knows configured routers.

This list: T::RouterId::for_domain(), exists independently of the routers configured in the gateway

T::RouterId::for_domain() is something hardcoded at runtime type level and not configurable for the user

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

Because basically, T::RouterId::for_domain() is representing the static relation between routers and domains, it's something that the gateway doesn't know (and something it can not ensure either). The gateway knows configured routers.

This list: T::RouterId::for_domain(), exists independently of the routers configured in the gateway

But what's wrong about having this relation in storage?

If this changes at any time, we'll have to do a RU right? If we store this, we just update the storage with whatever we need.

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

Because basically, T::RouterId::for_domain() is representing the static relation between routers and domains, it's something that the gateway doesn't know (and something it can not ensure either). The gateway knows configured routers.

In the current implementation, the gateway knows about this relation. And I would also argue that the gateway should know, going forward.

@lemunozm
Copy link
Contributor

The gateway doesn't know because not all Domain can be mapped to all Routers

@lemunozm
Copy link
Contributor

The relation is not something the operator can choose, is something inherent from how the chain is coded, statically

@lemunozm
Copy link
Contributor

Suppose, you use that storage. The user operator can add an entry Domain::Centrifuge with router AxelarEvm, which could not exists. Also the gateway can not check the relation is wrong

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

The gateway doesn't know because not all Domain can be mapped to all Routers
Suppose, you use that storage. The user operator can add an entry Domain::Centrifuge with router AxelarEvm, which could not exists. Also the gateway can not check the relation is wrong

OK, this is the case in the current implementation and one can definitely screw up the domain to router relationship.

The relation is not something the operator can choose, is something inherent from how the chain is coded, statically

^ fixes that.

Thank you for clarifying @lemunozm!

@cdamian
Copy link
Contributor Author

cdamian commented Aug 13, 2024

Will adjust some things here then merge so I can continue working on the initial branch for multi-routers.

@cdamian cdamian marked this pull request as ready for review August 13, 2024 12:59
@cdamian cdamian merged commit 317631c into feat/lp-v2-gateway-multi-router Aug 13, 2024
4 of 12 checks passed
@cdamian cdamian deleted the dont-use-domain-when-storing-routers branch August 13, 2024 13:00
cdamian added a commit that referenced this pull request Aug 13, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 13, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 13, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 14, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 14, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 15, 2024
* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip
cdamian added a commit that referenced this pull request Aug 16, 2024
* wip

* lp-gateway: Add router hash for inbound messages, extrinsic to set inbound routers, session ID storage

* lp-gateway: Add router hash for inbound messages, extrinsic to set inbound routers, session ID storage

* lp-gateway: Use router hashes for inbound, use session ID, update inbound message processing logic

* lp-gateway: Add and use InboundProcessingInfo

* lp-gateway: Unit tests WIP

* lp-gateway: Unit tests WIP 2

* docs: Improve comments

* lp-gateway: Move message processing logic to a new file

* lp-gateway: Merge inbound/outbound routers extrinsics into one, add logic for removing invalid session IDs on idle

* lp-gateway: Unit tests WIP

* lp-gateway: Add extrinsic for executing message recovery

* rebase: WIP

* Don't use domain when storing routers (#1962)

* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip

* wip

* lp-gateway: Unit test WIP

* lp-gateway: Rename RouterSupport to RouterProvider, add separate entity that implements it

* lp-gateway: Add more asserts in unit tests

* lp-gateway: Attempt to execute message during recovery

* lp-gateway: Remove extra constraints from SessionId

* lp-gateway: Drop session ID invalidation (#1965)

* lp-gateway: Drop session ID invalidation

* lp-gateway: Add test for invalid router

* lp-gateway: Add more unit tests

* lp-gateway: Move InboundEntry logic to implementation

* lp-gateway: Use safe math

* lp-gateway: Add more unit tests

* checks: Fix clippy, taplo, formatting

* review: Remove mock-builder dep, rename LP encoding proof methods

* lp-gateway: Remove Default impls for RouterId and GatewayMessage

* lp-gateway: Allow empty list of routers

* lp-gateway: Drop InboundProcessingInfo

* lp-gateway: Rename LP encoding methods to get_proof and to_proof_message

* lp-gateway: Move outbound processing logic back to pallet

* review: Small fixes

* lp-gateway: Add comment for post voting dispatch error case

* lp-gatway: Drop session ID check in create_post_voting_entry

* lp: Remove unused import

* integration-tests: Register routers during setup (#1968)

* integration-tests: Set routers in all setup funcs and tests
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.

2 participants