-
Notifications
You must be signed in to change notification settings - Fork 592
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
refactor: restructure timeout type #5404
refactor: restructure timeout type #5404
Conversation
|
||
// ErrTimeoutNotReached returns a timeout not reached error indicating which timeout value | ||
// has not been reached. | ||
func (t Timeout) ErrTimeoutNotReached(height clienttypes.Height, timestamp uint64) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be ErrTimeoutNotElapsed
if folks want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I like about this now is that we have a generic timeout type rather than a timeout specific to channel upgrades
…go into colin/3483-timeout-type-impl
// ErrTimeoutElapsed returns a timeout elapsed error indicating which timeout value | ||
// has elapsed. | ||
func (t Timeout) ErrTimeoutElapsed(height clienttypes.Height, timestamp uint64) error { | ||
if t.heightElapsed(height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to add an additional statement if folks want to indicate both height and timestamp elapsed. I just opted for this for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm, thanks 💪, left a couple of minor comments
tc := tc | ||
suite.Run(tc.name, func() { | ||
err := tc.timeout.ErrTimeoutElapsed(height, timestamp) | ||
suite.Require().Equal(err.Error(), tc.expError.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switcharoo on Equal args.
suite.Require().Equal(err.Error(), tc.expError.Error()) | |
suite.Require().Equal(tc.expError.Error(), err.Error()) |
tc := tc | ||
suite.Run(tc.name, func() { | ||
err := tc.timeout.ErrTimeoutNotReached(height, timestamp) | ||
suite.Require().Equal(err.Error(), tc.expError.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto re switcharoo
// ErrTimeoutNotReached returns a timeout not reached error indicating which timeout value | ||
// has not been reached. | ||
func (t Timeout) ErrTimeoutNotReached(height clienttypes.Height, timestamp uint64) error { | ||
if !t.Height.IsZero() && !t.heightElapsed(height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this just !t.heightElapsed(height)
? Currently would expand to:
!t.Height.IsZero() && !t.Height.IsZero() && height.GTE(t.Height)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is: !t.Height.IsZero() && !(!t.Height.IsZero() && height.GTE(t.Height))
When t.Height.IsZero(), the second statement returns !false. This caught me while writing tests as I originally just had !t.heightElapsed(height)
. It's quite unfortunate and also odd. When height is 0, heightElapsed
returning false makes sense, but in the case of ErrTimeoutNotReached
it doesn't as the height is not being used to determine the timeout
I could pull out the !IsZero() checks out of heightElapsed
and timestampElapsed
or I could add a comment to explain that when asserting timeout has not been reached, we must filter out the height if it is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha! indeed. These are slightly tricky to read, thanks for adding a comment here!
…olin/3483-timeout-type-impl
…go into colin/3483-timeout-type-impl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think there's spots in Send/RecvPacket that could make use of the new type also! Glad to see this finally in. Thanks @colin-axner
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 04-channel-upgrades #5404 +/- ##
=======================================================
+ Coverage 80.67% 80.77% +0.10%
=======================================================
Files 197 197
Lines 15101 15114 +13
=======================================================
+ Hits 12183 12209 +26
+ Misses 2453 2440 -13
Partials 465 465
|
Description
Applies discussion in #3483. Primarily,
HasPassed
is renamed toElapsed
. In addition, I added two functions to the timeout typeErrTimeoutElapsed
andErrTimeoutNotReached
which will return an error msg based on whether the height or the timestamp is responsible for the error. In the case of both, it defaults to reporting the height firsthere are example diffs of when used by the other handlers as well:
closes: #3483
Commit Message / Changelog Entry
see the guidelines for commit messages. (view raw markdown for examples)
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.
docs/
) or specification (x/<module>/spec/
).godoc
comments.Files changed
in the Github PR explorer.Codecov Report
in the comment section below once CI passes.