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

Consumer handles expired client to provider #452

Closed

Conversation

mpoke
Copy link
Contributor

@mpoke mpoke commented Nov 9, 2022

Partial fix for #435 (see #448 for the other part). The consumer collects the IBC packets that cannot be sent to the provider due to the client being expired. Once the client is upgraded, these packets are sent in the next block.

@mpoke
Copy link
Contributor Author

mpoke commented Nov 9, 2022

@sainoe This PR removes the SlashRequests from the genesis state. Instead, we need to add the pending data packets, but it's a bit more involved. See #264 (comment) for more details.

// IBC client expired:
if i != 0 {
// this should never happen
panic(fmt.Errorf("client expired while sending pending packets: %w", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an edgecase also handled in #448.

I'm wondering if this should invoke a panic?

We could simply delete packets that were sent so we don't resend them when a new client is established?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should never happen. The client cannot expired in the middle of a block as the time doesn't change. Also, it cannot expire in the middle of a loop as the SDK is sequential. I guess we could remove this check to save space :)

tests/e2e/expired_client.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jtremback jtremback left a comment

Choose a reason for hiding this comment

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

The code structure here is very hard to follow IMO. As one example, the call to SendPendingDataPackets on line 89 of relay.go can return false for its clientExpired return value, even if the client is expired, if the queue is empty. This is then checked again lower down in the function, leading to a pretty circuitous logic path. There are other examples as well.

I believe that all of this could be made much simpler if the functions SendVSCMaturedPackets and SendSlashPacket would only ever append to the PendingDataPacket queue. Then, another endblock method would deal with sending everything in the PendingDataPacket queue and dealing with expired clients etc.

@mpoke
Copy link
Contributor Author

mpoke commented Nov 11, 2022

I believe that all of this could be made much simpler if the functions SendVSCMaturedPackets and SendSlashPacket would only ever append to the PendingDataPacket queue. Then, another endblock method would deal with sending everything in the PendingDataPacket queue and dealing with expired clients etc.

I agree this would simplify the logic. The only downside is that we'll do a read and write to the store for every packet (even when the client is not expired).

@sainoe
Copy link
Contributor

sainoe commented Nov 11, 2022

Maybe I missed sthg but sending the pending packet in Endblock won't work due to the channel order property. For instance, in a block h1 the channel isn't established so all packets are appended to the queue. Then in the next block h2 the channel is ready and a SlashPacket for downtime infraction is sent in BeginBlock. In this case the packets order isn't respected.

@mpoke
Copy link
Contributor Author

mpoke commented Nov 11, 2022

Maybe I missed sthg but sending the pending packet in Endblock won't work due to the channel order property. For instance, in a block h1 the channel isn't established so all packets are appended to the queue. Then in the next block h2 the channel is ready and a SlashPacket for downtime infraction is sent in BeginBlock. In this case the packets order isn't respected.

The idea is that all packets to be send are added to the queue and then in EndBlock all the packets in the queue are sent. The order is maintain by the queue. In your example, the SlashPacket for downtime infraction is appended at the end of the queue in the BeginBlock of h2.

@sainoe
Copy link
Contributor

sainoe commented Nov 11, 2022

Okay I got it! Thanks for the correction.

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

I did read through and I like the semantic changes but I agree with other comments that it could do with some substantial refactoring. I'd accept a merge as long as it was followed up with refactoring immediately afterwards.

Nit: I think DataPackets as a term is a bit weird: all packets have data so it's not informative. Just Packets is fine

@danwt
Copy link
Contributor

danwt commented Nov 11, 2022

By the way, will the changes here affect the fact that currently pending consumer slash requests are sent in reverse order?

@mpoke
Copy link
Contributor Author

mpoke commented Nov 11, 2022

By the way, will the changes here affect the fact that currently pending consumer slash requests are sent in reverse order?

Yes. That was just a stupid optimization. Was not necessary for safety.

@MSalopek MSalopek force-pushed the marius/435-client-expired branch from 92f569b to 7f918c2 Compare November 16, 2022 10:46
@MSalopek
Copy link
Contributor

MSalopek commented Nov 16, 2022

Merged into marius/435-client-expired (#448) as advised by the rest of the team.

@jtremback jtremback marked this pull request as draft November 16, 2022 23:11
@MSalopek MSalopek force-pushed the marius/435-client-expired branch from 6e9c1df to c46c0f0 Compare November 17, 2022 13:20
@MSalopek
Copy link
Contributor

Closing in favor of #448 which has all changes in a single PR.

@MSalopek MSalopek closed this Nov 17, 2022
sainoe added a commit that referenced this pull request Nov 18, 2022
@mpoke mpoke deleted the marius/435-client-expired-consumer branch September 12, 2024 16:43
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.

5 participants