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

lp-gateway: Drop session ID invalidation #1965

Conversation

cdamian
Copy link
Contributor

@cdamian cdamian commented Aug 14, 2024

Addressing some comments from - #1961.

@cdamian cdamian marked this pull request as ready for review August 14, 2024 10:22
@cdamian cdamian mentioned this pull request Aug 14, 2024
4 tasks
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Thanks Cosmin! I like the new direction. A couple of questions

Question 1. Can you elaborate on why we need the InboundEntry as an enum?

Could we not have something like (Option<Message>, SessionId, DomainAddress, count), avoiding to deal with the enum variants?

Question 2. How are we ensuring two proofs are not comming from the same router? Should not that information be stored somehow in the InboundEntry? (maybe a list of RouterId of the read proofs or similar)

Comment on lines +25 to 28
session_id: T::SessionId,
domain_address: DomainAddress,
message: T::Message,
expected_proof_count: u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could not always the expected_proof_count be infered by knowing the number of routers under domain_address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but if we want to support duplicate messages and ensure they don't get lost, we need to keep track of this and increment it accordingly, as per this.

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

Question 1. Can you elaborate on why we need the InboundEntry as an enum?
Could we not have something like (Option, SessionId, DomainAddress, count), avoiding to deal with the enum variants?

The enum made sense to me since it's a lot easier to deal with a struct-like entity like this instead of a tuple. Furthermore, it creates a clear distinction between message and message proof entries. Given that we have certain rules in place for defining which router can send what, such as these, this distinction allows us to perform validation such as this.

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

Question 2. How are we ensuring two proofs are not comming from the same router? Should not that information be stored somehow in the InboundEntry? (maybe a list of RouterId of the read proofs or similar)

We don't need to ensure this, if we would, we wouldn't be able to support duplicate messages.

@lemunozm
Copy link
Contributor

struct-like entity like this instead of a tuple

Yeah, when I wrote a tuple I wanted to write mostly a struct.

We don't need to ensure this, if we would, we wouldn't be able to support duplicate messages.

I'm pretty sure we need it... This is where the "vote" concept comes into play. Suppose you have 2 duplicated messages. Then you dispatch the first one to be processed once you have at least one vote from all associated routers. At least this is how it works in Solidity.

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

struct-like entity like this instead of a tuple

Yeah, when I wrote a tuple I wanted to write mostly a struct.

We don't need to ensure this, if we would, we wouldn't be able to support duplicate messages.

I'm pretty sure we need it... This is where the "vote" concept comes into play. Suppose you have 2 duplicated messages. Then you dispatch the first one to be processed once you have at least one vote from all associated routers. At least this is how it works in Solidity.

We should expect multiple proofs from the same router. Given a setup with 3 routers x, y, z, where x is supposed to send the message, y and z are supposed to send the proofs, we would expect 1 message + 2 proofs in order to process 1 message. Given this, we can have a scenario where we receive 4 proofs from y and z, 2 each, and then 2 messages from x.

Cases similar to what I described above are covered in the unit tests - here.

@lemunozm
Copy link
Contributor

We should expect multiple proofs from the same router.

Yes, and that is where the vote for that pair (message_hash, router) increments to 2.

In the current implementation, we can receive a message from x, two proofs from y, and the message will be processed without waiting for z, or am I missing something?

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

In the current implementation, we can receive a message from x, two proofs from y, and the message will be processed without waiting for z, or am I missing something?

No, we also have a test that covers the case that you mentioned here.

The logic that counts votes can be found here.

@lemunozm
Copy link
Contributor

lemunozm commented Aug 14, 2024

Ah ok, you're right! I didn't see well that part 👍🏻

So, to double-check. The current implementation can:

  • Receive multiple same messages.
  • Receive multiple proofs for the same messages.
  • Will only process a message when at least one proof for each router is received.

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

Ah ok, you're right! I didn't see well that part 👍🏻

So, to double-check. The current implementation can:

  • Receive multiple same messages.
  • Receive multiple proofs for the same messages.
  • Will only process a message when at least one proof for each router is received.

Correct!

@cdamian
Copy link
Contributor Author

cdamian commented Aug 14, 2024

Anyway @lemunozm, this PR is dealing with some other changes not necessarily related to votes etc. Do you mind if I merge this in the main branch and continue discussions there?

@lemunozm
Copy link
Contributor

Yeah, sure! Having understood that, I think everything now is working as it should 👍🏻 Let's merge it

@cdamian cdamian merged commit 6541a7f into feat/lp-v2-gateway-multi-router Aug 14, 2024
1 of 9 checks passed
@cdamian cdamian deleted the feat/lp-v2-gateway-multi-router-drop-session-id-invalidation branch August 14, 2024 11:33
@lemunozm
Copy link
Contributor

Also, I think now InboundEntry makes more sense to be an enum 👍🏻

cdamian added a commit that referenced this pull request Aug 14, 2024
* lp-gateway: Drop session ID invalidation

* lp-gateway: Add test for invalid router
cdamian added a commit that referenced this pull request Aug 15, 2024
* lp-gateway: Drop session ID invalidation

* lp-gateway: Add test for invalid router
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