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

refactor: deprecate Voteinfo in favour of Cometinfo on Context #17670

Merged
merged 19 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ but please do not over-use it. We try to keep all data structured
and standard additions here would be better just to add to the Context struct
*/
type Context struct {
baseCtx context.Context
ms storetypes.MultiStore
// Deprecated: Use HeaderService for height, time, and chainID and CometService for the rest
header cmtproto.Header
// Deprecated: Use HeaderService for hash
headerHash []byte
// Deprecated: Use HeaderService for chainID and CometService for the rest
chainID string
baseCtx context.Context
ms storetypes.MultiStore
header cmtproto.Header // Deprecated: Use HeaderService for height, time, and chainID and CometService for the rest
headerHash []byte // Deprecated: Use HeaderService for hash
chainID string // Deprecated: Use HeaderService for chainID and CometService for the rest
txBytes []byte
logger log.Logger
voteInfo []abci.VoteInfo
voteInfo []abci.VoteInfo // Deprecated: use Cometinfo.GetLastCommit().Votes() instead, will be removed in 0.51
gasMeter storetypes.GasMeter
blockGasMeter storetypes.GasMeter
checkTx bool
Expand All @@ -69,13 +66,15 @@ 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 }
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
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
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 }
Expand Down
5 changes: 3 additions & 2 deletions x/distribution/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

// determine the total power signing the block
var previousTotalPower int64
for _, voteInfo := range ctx.VoteInfos() {
previousTotalPower += voteInfo.Validator.Power
for i := 0; i < ctx.CometInfo().GetLastCommit().Votes().Len(); i++ {
vote := ctx.CometInfo().GetLastCommit().Votes().Get(i)
previousTotalPower += vote.Validator().Power()
}

// TODO this is Tendermint-dependent
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
if ctx.BlockHeight() > 1 {
if err := k.AllocateTokens(ctx, previousTotalPower, ctx.VoteInfos()); err != nil {

Check failure on line 27 in x/distribution/abci.go

View workflow job for this annotation

GitHub Actions / Analyze

SA1019: ctx.VoteInfos is deprecated: use Cometinfo.GetLastCommit().Votes() instead, will be removed after 0.51 (staticcheck)
return err
}
}
Expand Down
5 changes: 3 additions & 2 deletions x/slashing/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
// store whether or not they have actually signed it and slash/unbond any
// which have missed too many blocks in a row (downtime slashing)
sdkCtx := sdk.UnwrapSDKContext(ctx)
for _, voteInfo := range sdkCtx.VoteInfos() {
err := k.HandleValidatorSignature(ctx, voteInfo.Validator.Address, voteInfo.Validator.Power, comet.BlockIDFlag(voteInfo.BlockIdFlag))
for i := 0; i < sdkCtx.CometInfo().GetLastCommit().Votes().Len(); i++ {
vote := sdkCtx.CometInfo().GetLastCommit().Votes().Get(i)
err := k.HandleValidatorSignature(ctx, vote.Validator().Address(), vote.Validator().Power(), comet.BlockIDFlag(vote.GetBlockIDFlag()))

Check failure on line 26 in x/slashing/abci.go

View workflow job for this annotation

GitHub Actions / Analyze

unnecessary conversion (unconvert)
Fixed Show fixed Hide fixed
if err != nil {
return err
}
Expand Down
Loading