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

fix: Make WithBlockTime() consistent with CometBFT canonical time #15124

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

likhita-809
Copy link
Contributor

@likhita-809 likhita-809 commented Feb 22, 2023

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Comment on lines 142 to 153
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)
}

Copy link
Contributor

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)

@likhita-809 likhita-809 marked this pull request as ready for review February 22, 2023 07:58
@likhita-809 likhita-809 requested a review from a team as a code owner February 22, 2023 07:58
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()
Copy link
Member

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?

@julienrbrt julienrbrt merged commit e55b1a9 into main Feb 22, 2023
@julienrbrt julienrbrt deleted the likhita/fix-blocktime branch February 22, 2023 11:49
@julienrbrt
Copy link
Member

@Mergifyio backport release/v0.47.x

@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2023

backport release/v0.47.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Feb 24, 2023
…5124)

(cherry picked from commit e55b1a9)

# Conflicts:
#	types/context.go
#	types/context_test.go
julienrbrt added a commit that referenced this pull request Feb 24, 2023
…ckport #15124) (#15156)

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
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.

make context WithBlockTime() provide guarantees consistent with CometBFT block time
3 participants