-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix: Make WithBlockTime() consistent with CometBFT canonical time #15124
Conversation
return c | ||
} | ||
|
||
// WithBlockTime returns a Context with an updated CometBFT block header time in UTC time | ||
// WithBlockTime returns a Context with an updated CometBFT block header time in UTC with no monotonic component. | ||
// Stripping the monotonic component is for time equality. | ||
func (c Context) WithBlockTime(newTime time.Time) Context { | ||
newHeader := c.BlockHeader() | ||
// https://github.com/gogo/protobuf/issues/519 | ||
newHeader.Time = newTime.UTC() | ||
newHeader.Time = newTime.Round(0).UTC() | ||
return c.WithBlockHeader(newHeader) | ||
} | ||
|
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.
Change potentially affects state.
Call sequence:
(github.com/cosmos/cosmos-sdk/types.Context).WithHeaderHash (types/context.go:137)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).BeginBlock (types/context.go:156)
func (c Context) WithBlockTime(newTime time.Time) Context { | ||
newHeader := c.BlockHeader() | ||
// https://github.com/gogo/protobuf/issues/519 | ||
newHeader.Time = newTime.UTC() | ||
newHeader.Time = newTime.Round(0).UTC() |
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.
Can we add a test to compare they give the same time?
@Mergifyio backport release/v0.47.x |
✅ Backports have been created
|
…ckport #15124) (#15156) Co-authored-by: Likhita Polavarapu <[email protected]> Co-authored-by: Julien Robert <[email protected]>
Description
Closes: #15057
This PR adds changes to make WithBlockTime() consistent with CometBFT canonical time and changes the spec for it
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change