refactor!: deprecate blocktime on context (#17738)
This commit is contained in:
+8
-19
@@ -45,7 +45,7 @@ type Context struct {
|
||||
chainID string // Deprecated: Use HeaderService for chainID and CometService for the rest
|
||||
txBytes []byte
|
||||
logger log.Logger
|
||||
voteInfo []abci.VoteInfo // Deprecated: use Cometinfo.GetLastCommit().Votes() instead, will be removed in 0.51
|
||||
voteInfo []abci.VoteInfo // Deprecated: use Cometinfo.LastCommit.Votes instead, will be removed after 0.51
|
||||
gasMeter storetypes.GasMeter
|
||||
blockGasMeter storetypes.GasMeter
|
||||
checkTx bool
|
||||
@@ -66,15 +66,13 @@ type Context struct {
|
||||
type Request = Context
|
||||
|
||||
// Read-only accessors
|
||||
func (c Context) Context() context.Context { return c.baseCtx }
|
||||
func (c Context) MultiStore() storetypes.MultiStore { return c.ms }
|
||||
func (c Context) BlockHeight() int64 { return c.header.Height }
|
||||
func (c Context) BlockTime() time.Time { return c.header.Time }
|
||||
func (c Context) ChainID() string { return c.chainID }
|
||||
func (c Context) TxBytes() []byte { return c.txBytes }
|
||||
func (c Context) Logger() log.Logger { return c.logger }
|
||||
|
||||
// Deprecated: use Cometinfo.GetLastCommit().Votes() instead, will be removed after 0.51
|
||||
func (c Context) Context() context.Context { return c.baseCtx }
|
||||
func (c Context) MultiStore() storetypes.MultiStore { return c.ms }
|
||||
func (c Context) BlockHeight() int64 { return c.header.Height }
|
||||
func (c Context) BlockTime() time.Time { return c.headerInfo.Time } // Deprecated: use HeaderInfo().Time
|
||||
func (c Context) ChainID() string { return c.chainID }
|
||||
func (c Context) TxBytes() []byte { return c.txBytes }
|
||||
func (c Context) Logger() log.Logger { return c.logger }
|
||||
func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
|
||||
func (c Context) GasMeter() storetypes.GasMeter { return c.gasMeter }
|
||||
func (c Context) BlockGasMeter() storetypes.GasMeter { return c.blockGasMeter }
|
||||
@@ -173,15 +171,6 @@ func (c Context) WithHeaderHash(hash []byte) Context {
|
||||
return c
|
||||
}
|
||||
|
||||
// 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.Round(0).UTC()
|
||||
return c.WithBlockHeader(newHeader)
|
||||
}
|
||||
|
||||
// WithProposer returns a Context with an updated proposer consensus address.
|
||||
func (c Context) WithProposer(addr ConsAddress) Context {
|
||||
newHeader := c.BlockHeader()
|
||||
|
||||
+2
-14
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttime "github.com/cometbft/cometbft/types/time"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@@ -147,7 +146,6 @@ func (s *contextTestSuite) TestContextHeader() {
|
||||
var ctx types.Context
|
||||
|
||||
height := int64(5)
|
||||
time := time.Now()
|
||||
addr := secp256k1.GenPrivKey().PubKey().Address()
|
||||
proposer := types.ConsAddress(addr)
|
||||
|
||||
@@ -155,22 +153,12 @@ func (s *contextTestSuite) TestContextHeader() {
|
||||
|
||||
ctx = ctx.
|
||||
WithBlockHeight(height).
|
||||
WithBlockTime(time).
|
||||
WithProposer(proposer)
|
||||
s.Require().Equal(height, ctx.BlockHeight())
|
||||
s.Require().Equal(height, ctx.BlockHeader().Height)
|
||||
s.Require().Equal(time.UTC(), ctx.BlockHeader().Time)
|
||||
s.Require().Equal(proposer.Bytes(), ctx.BlockHeader().ProposerAddress)
|
||||
}
|
||||
|
||||
func (s *contextTestSuite) TestWithBlockTime() {
|
||||
now := time.Now()
|
||||
ctx := types.NewContext(nil, false, nil)
|
||||
ctx = ctx.WithBlockTime(now)
|
||||
cmttime2 := cmttime.Canonical(now)
|
||||
s.Require().Equal(ctx.BlockTime(), cmttime2)
|
||||
}
|
||||
|
||||
func (s *contextTestSuite) TestContextHeaderClone() {
|
||||
cases := map[string]struct {
|
||||
h cmtproto.Header
|
||||
@@ -216,13 +204,13 @@ func (s *contextTestSuite) TestContextHeaderClone() {
|
||||
s.T().Run(name, func(t *testing.T) {
|
||||
ctx := types.NewContext(nil, false, nil).WithBlockHeader(tc.h)
|
||||
s.Require().Equal(tc.h.Height, ctx.BlockHeight())
|
||||
s.Require().Equal(tc.h.Time.UTC(), ctx.BlockTime())
|
||||
s.Require().Equal(tc.h.Time.UTC(), ctx.BlockHeader().Time)
|
||||
|
||||
// update only changes one field
|
||||
var newHeight int64 = 17
|
||||
ctx = ctx.WithBlockHeight(newHeight)
|
||||
s.Require().Equal(newHeight, ctx.BlockHeight())
|
||||
s.Require().Equal(tc.h.Time.UTC(), ctx.BlockTime())
|
||||
s.Require().Equal(tc.h.Time.UTC(), ctx.BlockHeader().Time)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user