-
Notifications
You must be signed in to change notification settings - Fork 643
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
Compare Timeout timestamps in seconds instead of nanoseconds #7857
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"bytes" | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
||
|
@@ -53,15 +54,17 @@ | |
return 0, "", errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", sourceClient) | ||
} | ||
|
||
// client timestamps are in nanoseconds while packet timeouts are in seconds | ||
// thus to compare them, we convert the client timestamp to seconds in uint64 | ||
// to be consistent with IBC V2 specified timeout behaviour | ||
latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, sourceClient, latestHeight) | ||
if err != nil { | ||
return 0, "", err | ||
} | ||
latestTimestampSecs := uint64(time.Unix(0, int64(latestTimestamp)).Unix()) | ||
|
||
// client timestamps are in nanoseconds while packet timeouts are in seconds | ||
// thus to compare them, we convert the packet timeout to nanoseconds | ||
timeoutTimestamp = types.TimeoutTimestampToNanos(packet.TimeoutTimestamp) | ||
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / lint
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (03)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (00)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (01)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (01)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
Check failure on line 66 in modules/core/04-channel/v2/keeper/packet.go GitHub Actions / tests (02)
|
||
if latestTimestamp >= timeoutTimestamp { | ||
if latestTimestampSecs >= packet.TimeoutTimestamp { | ||
return 0, "", errorsmod.Wrapf(types.ErrTimeoutElapsed, "latest timestamp: %d, timeout timestamp: %d", latestTimestamp, timeoutTimestamp) | ||
} | ||
|
||
|
@@ -264,15 +267,18 @@ | |
return errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty id (%s) does not match packet destination id (%s)", counterparty.ClientId, packet.DestinationClient) | ||
} | ||
|
||
// check that timeout height or timeout timestamp has passed on the other end | ||
// check that timeout timestamp has passed on the other end | ||
// client timestamps are in nanoseconds while packet timeouts are in seconds | ||
// so we convert client timestamp to seconds in uint64 to be consistent | ||
// with IBC V2 timeout behaviour | ||
proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, packet.SourceClient, proofHeight) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
if err != nil { | ||
return err | ||
} | ||
proofTimestampSecs := uint64(time.Unix(0, int64(proofTimestamp)).Unix()) | ||
|
||
timeoutTimestamp := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp) | ||
if proofTimestamp < timeoutTimestamp { | ||
return errorsmod.Wrapf(types.ErrTimeoutNotReached, "proof timestamp: %d, timeout timestamp: %d", proofTimestamp, timeoutTimestamp) | ||
if proofTimestampSecs < packet.TimeoutTimestamp { | ||
return errorsmod.Wrapf(types.ErrTimeoutNotReached, "proof timestamp: %d, timeout timestamp: %d", proofTimestamp, packet.TimeoutTimestamp) | ||
} | ||
|
||
// check that the commitment has not been cleared and that it matches the packet sent by relayer | ||
|
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.
nit: would be slightly easier to read the code below if this was called latestTimestampNano (and would avoid accidental usage later)