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

Packet.timeoutHeight should have type Option<Height> (or equivalent) #776

Open
plafer opened this issue Jun 24, 2022 · 4 comments
Open

Packet.timeoutHeight should have type Option<Height> (or equivalent) #776

plafer opened this issue Jun 24, 2022 · 4 comments

Comments

@plafer
Copy link
Contributor

plafer commented Jun 24, 2022

Packet.timeoutHeight treats the minimum height 0 specially: a height of 0 means "no timeout". This is taken from this check in timeoutPacket():

abortTransactionUnless(
      (packet.timeoutHeight > 0 && proofHeight >= packet.timeoutHeight) ||
      (packet.timeoutTimestamp > 0 && connection.getTimestampAtHeight(proofHeight) > packet.timeoutTimestamp))

This is inconsistent with the ICS-2 definition of Height, which specifies that 0 is a valid height. It would be cleaner to represent this special case directly in the type: anything equivalent to Rust's Option<Height> (or Option<NonZeroHeight> depending on if we want to allow a timeout at height 0 or not).

@AdityaSripal
Copy link
Member

AdityaSripal commented Jul 13, 2022

Hmm, but even if height 0 is valid it would still be sensible to error if it was passed as the timeoutHeight correct? Since -1 is not a valid height, there could be no sensible timeout height that was the lowest valid height possible.

It seems like we could change the implementation to reflect this. Though it is a very minor improvement

@plafer
Copy link
Contributor Author

plafer commented Jul 25, 2022

Hmm, but even if height 0 is valid it would still be sensible to error if it was passed as the timeoutHeight correct?

I would personally wouldn't error on height 0, and instead just follow the expected semantics of "this packet is always timed out", even though not a very useful packet. This isn't too different from a timeoutHeight of 1 or 2 (which similarly pretty much is always timed out).

Since -1 is not a valid height, there could be no sensible timeout height that was the lowest valid height possible.

I'm not sure I understand what you mean here.

To rephrase my suggestion, timeoutHeight == None would encode "no timeout", and timeoutHeight == Some(height) would encode a timeout, with all valid Height values (including 0) possible for height.

It seems like we could change the implementation to reflect this. Though it is a very minor improvement

I consider it relatively important, as currently timeout heights don't work like all other heights. In the Rust implementation, we had to create a new type TimeoutHeight with special encoding/decoding code to capture the difference.

@AdityaSripal
Copy link
Member

How would this work with the current ibc-go implementation where the type is a uint64 at the moment?

@plafer
Copy link
Contributor Author

plafer commented Nov 1, 2022

Indeed it would be a breaking change to fix this. I opted to flag it regardless, in case there ever is a backward incompatible v2 of the protocol.

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

No branches or pull requests

2 participants