From bd3bee369c3bf719520217d6710e6d734ca53e0f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 1 May 2024 15:41:28 -0400 Subject: [PATCH 01/13] introduce runtime v1 service to fetch comet info from context --- core/appmodule/v2/environment.go | 2 ++ runtime/comet.go | 15 +++++++++++++++ runtime/environment.go | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 runtime/comet.go diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index e3592eb210ad..38f6734f8fe9 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -2,6 +2,7 @@ package appmodule import ( "cosmossdk.io/core/branch" + "cosmossdk.io/core/comet" "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" @@ -15,6 +16,7 @@ import ( type Environment struct { Logger log.Logger + CometInfoService comet.Service BranchService branch.Service EventService event.Service GasService gas.Service diff --git a/runtime/comet.go b/runtime/comet.go new file mode 100644 index 000000000000..265266d3e106 --- /dev/null +++ b/runtime/comet.go @@ -0,0 +1,15 @@ +package runtime + +import ( + "context" + corecomet "cosmossdk.io/core/comet" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ corecomet.Service = &ContextAwareCometInfoService{} + +type ContextAwareCometInfoService struct{} + +func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info { + return sdk.UnwrapSDKContext(ctx).CometInfo() +} diff --git a/runtime/environment.go b/runtime/environment.go index 6fce64b35dec..011164cde382 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -18,6 +18,7 @@ func NewEnvironment( ) appmodule.Environment { env := appmodule.Environment{ Logger: logger, + CometInfoService: ContextAwareCometInfoService{}, EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, @@ -35,7 +36,10 @@ func NewEnvironment( type EnvOption func(*appmodule.Environment) -func EnvWithRouterService(queryServiceRouter *baseapp.GRPCQueryRouter, msgServiceRouter *baseapp.MsgServiceRouter) EnvOption { +func EnvWithRouterService( + queryServiceRouter *baseapp.GRPCQueryRouter, + msgServiceRouter *baseapp.MsgServiceRouter, +) EnvOption { return func(env *appmodule.Environment) { env.RouterService = NewRouterService(env.KVStoreService, queryServiceRouter, msgServiceRouter) } From 19927df509a4886ed1f5b41744edb940ec4f8479 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 1 May 2024 15:51:32 -0400 Subject: [PATCH 02/13] use cometInfoService to fetch comet info --- x/evidence/keeper/abci.go | 3 +-- x/slashing/abci.go | 5 ++--- x/staking/keeper/historical_info.go | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/x/evidence/keeper/abci.go b/x/evidence/keeper/abci.go index a759e13ace05..99136f8b407f 100644 --- a/x/evidence/keeper/abci.go +++ b/x/evidence/keeper/abci.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/x/evidence/types" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" ) // BeginBlocker iterates through and handles any newly discovered evidence of @@ -16,7 +15,7 @@ import ( func (k Keeper) BeginBlocker(ctx context.Context) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) - bi := sdk.UnwrapSDKContext(ctx).CometInfo() + bi := k.CometInfoService.CometInfo(ctx) evidences := bi.Evidence for _, evidence := range evidences { diff --git a/x/slashing/abci.go b/x/slashing/abci.go index 72645213d82b..c8000be01963 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/x/slashing/types" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" ) // BeginBlocker check for infraction evidence or downtime of validators @@ -22,8 +21,8 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error { if err != nil { return err } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO remove by passing the comet service - for _, vote := range sdkCtx.CometInfo().LastCommit.Votes { + ci := k.CometInfoService.CometInfo(ctx) + for _, vote := range ci.LastCommit.Votes { err := k.HandleValidatorSignatureWithParams(ctx, params, vote.Validator.Address, vote.Validator.Power, vote.BlockIDFlag) if err != nil { return err diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index 9e556b8f88b3..998ca46ca3b8 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -4,8 +4,6 @@ import ( "context" "cosmossdk.io/x/staking/types" - - sdk "github.com/cosmos/cosmos-sdk/types" ) // TrackHistoricalInfo saves the latest historical-info and deletes the oldest @@ -43,9 +41,10 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { return nil } + ci := k.CometInfoService.CometInfo(ctx) historicalEntry := types.HistoricalRecord{ Time: &headerInfo.Time, - ValidatorsHash: sdk.UnwrapSDKContext(ctx).CometInfo().ValidatorsHash, + ValidatorsHash: ci.ValidatorsHash, Apphash: headerInfo.AppHash, } From 02fd92dbe9b440e2651ec18052ebd0a3192f6759 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 1 May 2024 16:03:04 -0400 Subject: [PATCH 03/13] linting --- runtime/comet.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/comet.go b/runtime/comet.go index 265266d3e106..24c3c32e041b 100644 --- a/runtime/comet.go +++ b/runtime/comet.go @@ -2,7 +2,9 @@ package runtime import ( "context" + corecomet "cosmossdk.io/core/comet" + sdk "github.com/cosmos/cosmos-sdk/types" ) From ec593987350ae0d108deeec51fc22c7923cb6dd1 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 1 May 2024 16:17:52 -0400 Subject: [PATCH 04/13] Add changlog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a20e7d9ee71..d24877a9142a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. ### Features +* (runtime) [#20238](https://github.com/cosmos/cosmos-sdk/pull/20238) Add `core/comet.Service` to the runtime Environment. * (tests) [#20013](https://github.com/cosmos/cosmos-sdk/pull/20013) Introduce system tests to run multi node local testnet in CI * (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime. * (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. From 13fd30269777af2df0cafb15fa9c5f22f4389e3e Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 1 May 2024 16:18:48 -0400 Subject: [PATCH 05/13] add godoc --- runtime/comet.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/comet.go b/runtime/comet.go index 24c3c32e041b..c7c27f3ac54f 100644 --- a/runtime/comet.go +++ b/runtime/comet.go @@ -10,6 +10,8 @@ import ( var _ corecomet.Service = &ContextAwareCometInfoService{} +// ContextAwareCometInfoService provides CometInfo which is embedded as a value in a Context. +// This the legacy (server v1, baseapp) way of accessing CometInfo at the module level. type ContextAwareCometInfoService struct{} func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info { From fb6f2a7ca79d20181082488402e8be9b94bf65cb Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 10:58:11 -0400 Subject: [PATCH 06/13] introduce core/abci package - alias core/comet to core/abci - refactor usages of core/comet throughout SDK --- baseapp/abci_utils.go | 4 +- baseapp/abci_utils_test.go | 9 ++-- core/abci/doc.go | 7 +++ core/abci/service.go | 70 +++++++++++++++++++++++++++++ core/appmodule/v2/environment.go | 4 +- core/comet/service.go | 53 +++++++--------------- runtime/comet.go | 19 +++++--- runtime/environment.go | 2 +- types/context.go | 33 +++++++------- x/evidence/keeper/abci.go | 4 +- x/evidence/types/evidence_test.go | 7 +-- x/slashing/abci.go | 2 +- x/slashing/keeper/infractions.go | 8 ++-- x/staking/keeper/historical_info.go | 2 +- 14 files changed, 145 insertions(+), 79 deletions(-) create mode 100644 core/abci/doc.go create mode 100644 core/abci/service.go diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index dd554ce3ad0f..3ee0f06490f8 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -15,7 +15,7 @@ import ( protoio "github.com/cosmos/gogoproto/io" "github.com/cosmos/gogoproto/proto" - "cosmossdk.io/core/comet" + coreabci "cosmossdk.io/core/abci" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" @@ -150,7 +150,7 @@ func ValidateVoteExtensions( // it checks that the ExtendedCommit + LastCommit (for the same height), are consistent with each other + that // they are ordered correctly (by voting power) in accordance with // [comet](https://github.com/cometbft/cometbft/blob/4ce0277b35f31985bbf2c25d3806a184a4510010/types/validator_set.go#L784). -func validateExtendedCommitAgainstLastCommit(ec abci.ExtendedCommitInfo, lc comet.CommitInfo) error { +func validateExtendedCommitAgainstLastCommit(ec abci.ExtendedCommitInfo, lc coreabci.CommitInfo) error { // check that the rounds are the same if ec.Round != lc.Round { return fmt.Errorf("extended commit round %d does not match last commit round %d", ec.Round, lc.Round) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index a99177ac5225..14d719304748 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + coreabci "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" "cosmossdk.io/log" @@ -755,14 +756,14 @@ func extendedCommitToLastCommit(ec abci.ExtendedCommitInfo) (abci.ExtendedCommit sort.Sort(extendedVoteInfos(ec.Votes)) // convert the extended commit info to last commit info - lastCommit := comet.CommitInfo{ + lastCommit := coreabci.CommitInfo{ Round: ec.Round, - Votes: make([]comet.VoteInfo, len(ec.Votes)), + Votes: make([]coreabci.VoteInfo, len(ec.Votes)), } for i, vote := range ec.Votes { - lastCommit.Votes[i] = comet.VoteInfo{ - Validator: comet.Validator{ + lastCommit.Votes[i] = coreabci.VoteInfo{ + Validator: coreabci.Validator{ Address: vote.Validator.Address, Power: vote.Validator.Power, }, diff --git a/core/abci/doc.go b/core/abci/doc.go new file mode 100644 index 000000000000..2fdb65bbb85e --- /dev/null +++ b/core/abci/doc.go @@ -0,0 +1,7 @@ +/* +Package abci defines the ABCIInfo Service interface and BlockInfo types which applications +should use in order to get access to the current block's evidence, validators hash, proposer address. + +This information is specific to ABCI +*/ +package abci diff --git a/core/abci/service.go b/core/abci/service.go new file mode 100644 index 000000000000..dcea1b792218 --- /dev/null +++ b/core/abci/service.go @@ -0,0 +1,70 @@ +package abci + +import ( + "context" + "time" +) + +// Service is an interface that can be used to get information specific to Comet +type Service interface { + ABCIInfo(context.Context) Info +} + +// Info is the information comet provides apps in ABCI +type Info struct { + Evidence []Evidence // Evidence misbehavior of the block + // ValidatorsHash returns the hash of the validators + // For Comet, it is the hash of the next validator set + ValidatorsHash []byte + ProposerAddress []byte // ProposerAddress is the address of the block proposer + LastCommit CommitInfo // DecidedLastCommit returns the last commit info +} + +// MisbehaviorType is the type of misbehavior for a validator +type MisbehaviorType int32 + +const ( + Unknown MisbehaviorType = 0 + DuplicateVote MisbehaviorType = 1 + LightClientAttack MisbehaviorType = 2 +) + +// Evidence is the misbehavior information of ABCI +type Evidence struct { + Type MisbehaviorType + Validator Validator + Height int64 + Time time.Time + TotalVotingPower int64 +} + +// CommitInfo is the commit information of ABCI +type CommitInfo struct { + Round int32 + Votes []VoteInfo +} + +// VoteInfo is the vote information of ABCI +type VoteInfo struct { + Validator Validator + BlockIDFlag BlockIDFlag +} + +// BlockIDFlag indicates which BlockID the signature is for +type BlockIDFlag int32 + +const ( + BlockIDFlagUnknown BlockIDFlag = 0 + // BlockIDFlagAbsent - no vote was received from a validator. + BlockIDFlagAbsent BlockIDFlag = 1 + // BlockIDFlagCommit - voted for the Commit.BlockID. + BlockIDFlagCommit BlockIDFlag = 2 + // BlockIDFlagNil - voted for nil. + BlockIDFlagNil BlockIDFlag = 3 +) + +// Validator is the validator information of ABCI +type Validator struct { + Address []byte + Power int64 +} diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index 38f6734f8fe9..018980ae7b83 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -1,8 +1,8 @@ package appmodule import ( + "cosmossdk.io/core/abci" "cosmossdk.io/core/branch" - "cosmossdk.io/core/comet" "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" @@ -16,7 +16,7 @@ import ( type Environment struct { Logger log.Logger - CometInfoService comet.Service + ABCIInfoService abci.Service BranchService branch.Service EventService event.Service GasService gas.Service diff --git a/core/comet/service.go b/core/comet/service.go index 772ceec325a6..693f7fae1053 100644 --- a/core/comet/service.go +++ b/core/comet/service.go @@ -2,7 +2,8 @@ package comet import ( "context" - "time" + + "cosmossdk.io/core/abci" ) // Service is an interface that can be used to get information specific to Comet @@ -11,60 +12,38 @@ type Service interface { } // Info is the information comet provides apps in ABCI -type Info struct { - Evidence []Evidence // Evidence misbehavior of the block - // ValidatorsHash returns the hash of the validators - // For Comet, it is the hash of the next validator set - ValidatorsHash []byte - ProposerAddress []byte // ProposerAddress is the address of the block proposer - LastCommit CommitInfo // DecidedLastCommit returns the last commit info -} +type Info abci.Info // MisbehaviorType is the type of misbehavior for a validator -type MisbehaviorType int32 +type MisbehaviorType abci.MisbehaviorType const ( - Unknown MisbehaviorType = 0 - DuplicateVote MisbehaviorType = 1 - LightClientAttack MisbehaviorType = 2 + Unknown = abci.Unknown + DuplicateVote = abci.DuplicateVote + LightClientAttack = abci.LightClientAttack ) // Evidence is the misbehavior information of ABCI -type Evidence struct { - Type MisbehaviorType - Validator Validator - Height int64 - Time time.Time - TotalVotingPower int64 -} +type Evidence abci.Evidence // CommitInfo is the commit information of ABCI -type CommitInfo struct { - Round int32 - Votes []VoteInfo -} +type CommitInfo abci.CommitInfo // VoteInfo is the vote information of ABCI -type VoteInfo struct { - Validator Validator - BlockIDFlag BlockIDFlag -} +type VoteInfo abci.VoteInfo // BlockIDFlag indicates which BlockID the signature is for -type BlockIDFlag int32 +type BlockIDFlag abci.BlockIDFlag const ( - BlockIDFlagUnknown BlockIDFlag = 0 + BlockIDFlagUnknown = abci.BlockIDFlagUnknown // BlockIDFlagAbsent - no vote was received from a validator. - BlockIDFlagAbsent BlockIDFlag = 1 + BlockIDFlagAbsent = abci.BlockIDFlagAbsent // BlockIDFlagCommit - voted for the Commit.BlockID. - BlockIDFlagCommit BlockIDFlag = 2 + BlockIDFlagCommit = abci.BlockIDFlagCommit // BlockIDFlagNil - voted for nil. - BlockIDFlagNil BlockIDFlag = 3 + BlockIDFlagNil = abci.BlockIDFlagNil ) // Validator is the validator information of ABCI -type Validator struct { - Address []byte - Power int64 -} +type Validator abci.Validator diff --git a/runtime/comet.go b/runtime/comet.go index c7c27f3ac54f..87a3b13d905b 100644 --- a/runtime/comet.go +++ b/runtime/comet.go @@ -3,17 +3,24 @@ package runtime import ( "context" - corecomet "cosmossdk.io/core/comet" + "cosmossdk.io/core/abci" + corecomet "cosmossdk.io/core/abci" sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ corecomet.Service = &ContextAwareCometInfoService{} +var _ corecomet.Service = &ContextAwareABCIInfoService{} -// ContextAwareCometInfoService provides CometInfo which is embedded as a value in a Context. +// ContextAwareABCIInfoService provides CometInfo which is embedded as a value in a Context. // This the legacy (server v1, baseapp) way of accessing CometInfo at the module level. -type ContextAwareCometInfoService struct{} +type ContextAwareABCIInfoService struct{} -func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info { - return sdk.UnwrapSDKContext(ctx).CometInfo() +func (c ContextAwareABCIInfoService) ABCIInfo(ctx context.Context) abci.Info { + ci := sdk.UnwrapSDKContext(ctx).CometInfo() + return abci.Info{ + Evidence: ci.Evidence, + ValidatorsHash: ci.ValidatorsHash, + ProposerAddress: ci.ProposerAddress, + LastCommit: ci.LastCommit, + } } diff --git a/runtime/environment.go b/runtime/environment.go index 011164cde382..a72a50ceba4e 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -18,7 +18,7 @@ func NewEnvironment( ) appmodule.Environment { env := appmodule.Environment{ Logger: logger, - CometInfoService: ContextAwareCometInfoService{}, + ABCIInfoService: ContextAwareABCIInfoService{}, EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, diff --git a/types/context.go b/types/context.go index 33ab2f9c6c3b..6f5079f741db 100644 --- a/types/context.go +++ b/types/context.go @@ -7,6 +7,7 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + coreabci "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" "cosmossdk.io/log" @@ -394,15 +395,15 @@ func UnwrapSDKContext(ctx context.Context) Context { } // ToSDKEvidence takes comet evidence and returns sdk evidence -func ToSDKEvidence(ev []abci.Misbehavior) []comet.Evidence { - evidence := make([]comet.Evidence, len(ev)) +func ToSDKEvidence(ev []abci.Misbehavior) []coreabci.Evidence { + evidence := make([]coreabci.Evidence, len(ev)) for i, e := range ev { - evidence[i] = comet.Evidence{ - Type: comet.MisbehaviorType(e.Type), + evidence[i] = coreabci.Evidence{ + Type: coreabci.MisbehaviorType(e.Type), Height: e.Height, Time: e.Time, TotalVotingPower: e.TotalVotingPower, - Validator: comet.Validator{ + Validator: coreabci.Validator{ Address: e.Validator.Address, Power: e.Validator.Power, }, @@ -412,37 +413,37 @@ func ToSDKEvidence(ev []abci.Misbehavior) []comet.Evidence { } // ToSDKCommitInfo takes comet commit info and returns sdk commit info -func ToSDKCommitInfo(commit abci.CommitInfo) comet.CommitInfo { - ci := comet.CommitInfo{ +func ToSDKCommitInfo(commit abci.CommitInfo) coreabci.CommitInfo { + ci := coreabci.CommitInfo{ Round: commit.Round, } for _, v := range commit.Votes { - ci.Votes = append(ci.Votes, comet.VoteInfo{ - Validator: comet.Validator{ + ci.Votes = append(ci.Votes, coreabci.VoteInfo{ + Validator: coreabci.Validator{ Address: v.Validator.Address, Power: v.Validator.Power, }, - BlockIDFlag: comet.BlockIDFlag(v.BlockIdFlag), + BlockIDFlag: coreabci.BlockIDFlag(v.BlockIdFlag), }) } return ci } // ToSDKExtendedCommitInfo takes comet extended commit info and returns sdk commit info -func ToSDKExtendedCommitInfo(commit abci.ExtendedCommitInfo) comet.CommitInfo { - ci := comet.CommitInfo{ +func ToSDKExtendedCommitInfo(commit abci.ExtendedCommitInfo) coreabci.CommitInfo { + ci := coreabci.CommitInfo{ Round: commit.Round, - Votes: make([]comet.VoteInfo, len(commit.Votes)), + Votes: make([]coreabci.VoteInfo, len(commit.Votes)), } for i, v := range commit.Votes { - ci.Votes[i] = comet.VoteInfo{ - Validator: comet.Validator{ + ci.Votes[i] = coreabci.VoteInfo{ + Validator: coreabci.Validator{ Address: v.Validator.Address, Power: v.Validator.Power, }, - BlockIDFlag: comet.BlockIDFlag(v.BlockIdFlag), + BlockIDFlag: coreabci.BlockIDFlag(v.BlockIdFlag), } } diff --git a/x/evidence/keeper/abci.go b/x/evidence/keeper/abci.go index 99136f8b407f..f09272855fe0 100644 --- a/x/evidence/keeper/abci.go +++ b/x/evidence/keeper/abci.go @@ -15,7 +15,7 @@ import ( func (k Keeper) BeginBlocker(ctx context.Context) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) - bi := k.CometInfoService.CometInfo(ctx) + bi := k.ABCIInfoService.ABCIInfo(ctx) evidences := bi.Evidence for _, evidence := range evidences { @@ -23,7 +23,7 @@ func (k Keeper) BeginBlocker(ctx context.Context) error { // It's still ongoing discussion how should we treat and slash attacks with // premeditation. So for now we agree to treat them in the same way. case comet.LightClientAttack, comet.DuplicateVote: - evidence := types.FromABCIEvidence(evidence, k.stakingKeeper.ConsensusAddressCodec()) + evidence := types.FromABCIEvidence(comet.Evidence(evidence), k.stakingKeeper.ConsensusAddressCodec()) err := k.handleEquivocationEvidence(ctx, evidence) if err != nil { return err diff --git a/x/evidence/types/evidence_test.go b/x/evidence/types/evidence_test.go index bfa20f82a98d..75fb584df4c8 100644 --- a/x/evidence/types/evidence_test.go +++ b/x/evidence/types/evidence_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" + "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/x/evidence/types" @@ -79,8 +80,8 @@ func TestEquivocationValidateBasic(t *testing.T) { func TestEvidenceAddressConversion(t *testing.T) { sdk.GetConfig().SetBech32PrefixForConsensusNode("testcnclcons", "testcnclconspub") - tmEvidence := NewCometMisbehavior(1, 100, time.Now(), comet.DuplicateVote, - comet.Validator{Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Power: 100}) + tmEvidence := newCometMisbehavior(1, 100, time.Now(), comet.DuplicateVote, + abci.Validator{Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Power: 100}) evidence := types.FromABCIEvidence(tmEvidence, address.NewBech32Codec("testcnclcons")) consAddr := evidence.GetConsensusAddress(address.NewBech32Codec("testcnclcons")) @@ -89,7 +90,7 @@ func TestEvidenceAddressConversion(t *testing.T) { sdk.GetConfig().SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub) } -func NewCometMisbehavior(height, tvp int64, t time.Time, tpe comet.MisbehaviorType, val comet.Validator) comet.Evidence { +func newCometMisbehavior(height, tvp int64, t time.Time, tpe abci.MisbehaviorType, val abci.Validator) comet.Evidence { return comet.Evidence{ Height: height, Time: t, diff --git a/x/slashing/abci.go b/x/slashing/abci.go index c8000be01963..0a267d87a1d6 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -21,7 +21,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error { if err != nil { return err } - ci := k.CometInfoService.CometInfo(ctx) + ci := k.ABCIInfoService.ABCIInfo(ctx) for _, vote := range ci.LastCommit.Votes { err := k.HandleValidatorSignatureWithParams(ctx, params, vote.Validator.Address, vote.Validator.Power, vote.BlockIDFlag) if err != nil { diff --git a/x/slashing/keeper/infractions.go b/x/slashing/keeper/infractions.go index f044210cb9cd..b71fb1b09ca5 100644 --- a/x/slashing/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -7,7 +7,7 @@ import ( "github.com/cockroachdb/errors" st "cosmossdk.io/api/cosmos/staking/v1beta1" - "cosmossdk.io/core/comet" + "cosmossdk.io/core/abci" "cosmossdk.io/core/event" "cosmossdk.io/x/slashing/types" @@ -16,7 +16,7 @@ import ( ) // HandleValidatorSignature handles a validator signature, must be called once per validator per block. -func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.Address, power int64, signed comet.BlockIDFlag) error { +func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.Address, power int64, signed abci.BlockIDFlag) error { params, err := k.Params.Get(ctx) if err != nil { return err @@ -24,7 +24,7 @@ func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.A return k.HandleValidatorSignatureWithParams(ctx, params, addr, power, signed) } -func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params types.Params, addr cryptotypes.Address, power int64, signed comet.BlockIDFlag) error { +func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params types.Params, addr cryptotypes.Address, power int64, signed abci.BlockIDFlag) error { height := k.HeaderService.HeaderInfo(ctx).Height // fetch the validator public key @@ -80,7 +80,7 @@ func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params t } modifiedSignInfo := false - missed := signed == comet.BlockIDFlagAbsent + missed := signed == abci.BlockIDFlagAbsent switch { case !previous && missed: // Bitmap value has changed from not missed to missed, so we flip the bit diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index 998ca46ca3b8..c285bb7999cb 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -41,7 +41,7 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { return nil } - ci := k.CometInfoService.CometInfo(ctx) + ci := k.ABCIInfoService.ABCIInfo(ctx) historicalEntry := types.HistoricalRecord{ Time: &headerInfo.Time, ValidatorsHash: ci.ValidatorsHash, From 75cfec20b5636090fa2f2f6697fe7b38b54881ba Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 12:55:18 -0400 Subject: [PATCH 07/13] Revert "introduce core/abci package" This reverts commit fb6f2a7ca79d20181082488402e8be9b94bf65cb. --- baseapp/abci_utils.go | 4 +- baseapp/abci_utils_test.go | 9 ++-- core/abci/doc.go | 7 --- core/abci/service.go | 70 ----------------------------- core/appmodule/v2/environment.go | 4 +- core/comet/service.go | 53 +++++++++++++++------- runtime/comet.go | 19 +++----- runtime/environment.go | 2 +- types/context.go | 33 +++++++------- x/evidence/keeper/abci.go | 4 +- x/evidence/types/evidence_test.go | 7 ++- x/slashing/abci.go | 2 +- x/slashing/keeper/infractions.go | 8 ++-- x/staking/keeper/historical_info.go | 2 +- 14 files changed, 79 insertions(+), 145 deletions(-) delete mode 100644 core/abci/doc.go delete mode 100644 core/abci/service.go diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index 3ee0f06490f8..dd554ce3ad0f 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -15,7 +15,7 @@ import ( protoio "github.com/cosmos/gogoproto/io" "github.com/cosmos/gogoproto/proto" - coreabci "cosmossdk.io/core/abci" + "cosmossdk.io/core/comet" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" @@ -150,7 +150,7 @@ func ValidateVoteExtensions( // it checks that the ExtendedCommit + LastCommit (for the same height), are consistent with each other + that // they are ordered correctly (by voting power) in accordance with // [comet](https://github.com/cometbft/cometbft/blob/4ce0277b35f31985bbf2c25d3806a184a4510010/types/validator_set.go#L784). -func validateExtendedCommitAgainstLastCommit(ec abci.ExtendedCommitInfo, lc coreabci.CommitInfo) error { +func validateExtendedCommitAgainstLastCommit(ec abci.ExtendedCommitInfo, lc comet.CommitInfo) error { // check that the rounds are the same if ec.Round != lc.Round { return fmt.Errorf("extended commit round %d does not match last commit round %d", ec.Round, lc.Round) diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 14d719304748..a99177ac5225 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -17,7 +17,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - coreabci "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" "cosmossdk.io/log" @@ -756,14 +755,14 @@ func extendedCommitToLastCommit(ec abci.ExtendedCommitInfo) (abci.ExtendedCommit sort.Sort(extendedVoteInfos(ec.Votes)) // convert the extended commit info to last commit info - lastCommit := coreabci.CommitInfo{ + lastCommit := comet.CommitInfo{ Round: ec.Round, - Votes: make([]coreabci.VoteInfo, len(ec.Votes)), + Votes: make([]comet.VoteInfo, len(ec.Votes)), } for i, vote := range ec.Votes { - lastCommit.Votes[i] = coreabci.VoteInfo{ - Validator: coreabci.Validator{ + lastCommit.Votes[i] = comet.VoteInfo{ + Validator: comet.Validator{ Address: vote.Validator.Address, Power: vote.Validator.Power, }, diff --git a/core/abci/doc.go b/core/abci/doc.go deleted file mode 100644 index 2fdb65bbb85e..000000000000 --- a/core/abci/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -/* -Package abci defines the ABCIInfo Service interface and BlockInfo types which applications -should use in order to get access to the current block's evidence, validators hash, proposer address. - -This information is specific to ABCI -*/ -package abci diff --git a/core/abci/service.go b/core/abci/service.go deleted file mode 100644 index dcea1b792218..000000000000 --- a/core/abci/service.go +++ /dev/null @@ -1,70 +0,0 @@ -package abci - -import ( - "context" - "time" -) - -// Service is an interface that can be used to get information specific to Comet -type Service interface { - ABCIInfo(context.Context) Info -} - -// Info is the information comet provides apps in ABCI -type Info struct { - Evidence []Evidence // Evidence misbehavior of the block - // ValidatorsHash returns the hash of the validators - // For Comet, it is the hash of the next validator set - ValidatorsHash []byte - ProposerAddress []byte // ProposerAddress is the address of the block proposer - LastCommit CommitInfo // DecidedLastCommit returns the last commit info -} - -// MisbehaviorType is the type of misbehavior for a validator -type MisbehaviorType int32 - -const ( - Unknown MisbehaviorType = 0 - DuplicateVote MisbehaviorType = 1 - LightClientAttack MisbehaviorType = 2 -) - -// Evidence is the misbehavior information of ABCI -type Evidence struct { - Type MisbehaviorType - Validator Validator - Height int64 - Time time.Time - TotalVotingPower int64 -} - -// CommitInfo is the commit information of ABCI -type CommitInfo struct { - Round int32 - Votes []VoteInfo -} - -// VoteInfo is the vote information of ABCI -type VoteInfo struct { - Validator Validator - BlockIDFlag BlockIDFlag -} - -// BlockIDFlag indicates which BlockID the signature is for -type BlockIDFlag int32 - -const ( - BlockIDFlagUnknown BlockIDFlag = 0 - // BlockIDFlagAbsent - no vote was received from a validator. - BlockIDFlagAbsent BlockIDFlag = 1 - // BlockIDFlagCommit - voted for the Commit.BlockID. - BlockIDFlagCommit BlockIDFlag = 2 - // BlockIDFlagNil - voted for nil. - BlockIDFlagNil BlockIDFlag = 3 -) - -// Validator is the validator information of ABCI -type Validator struct { - Address []byte - Power int64 -} diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index 018980ae7b83..38f6734f8fe9 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -1,8 +1,8 @@ package appmodule import ( - "cosmossdk.io/core/abci" "cosmossdk.io/core/branch" + "cosmossdk.io/core/comet" "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" @@ -16,7 +16,7 @@ import ( type Environment struct { Logger log.Logger - ABCIInfoService abci.Service + CometInfoService comet.Service BranchService branch.Service EventService event.Service GasService gas.Service diff --git a/core/comet/service.go b/core/comet/service.go index 693f7fae1053..772ceec325a6 100644 --- a/core/comet/service.go +++ b/core/comet/service.go @@ -2,8 +2,7 @@ package comet import ( "context" - - "cosmossdk.io/core/abci" + "time" ) // Service is an interface that can be used to get information specific to Comet @@ -12,38 +11,60 @@ type Service interface { } // Info is the information comet provides apps in ABCI -type Info abci.Info +type Info struct { + Evidence []Evidence // Evidence misbehavior of the block + // ValidatorsHash returns the hash of the validators + // For Comet, it is the hash of the next validator set + ValidatorsHash []byte + ProposerAddress []byte // ProposerAddress is the address of the block proposer + LastCommit CommitInfo // DecidedLastCommit returns the last commit info +} // MisbehaviorType is the type of misbehavior for a validator -type MisbehaviorType abci.MisbehaviorType +type MisbehaviorType int32 const ( - Unknown = abci.Unknown - DuplicateVote = abci.DuplicateVote - LightClientAttack = abci.LightClientAttack + Unknown MisbehaviorType = 0 + DuplicateVote MisbehaviorType = 1 + LightClientAttack MisbehaviorType = 2 ) // Evidence is the misbehavior information of ABCI -type Evidence abci.Evidence +type Evidence struct { + Type MisbehaviorType + Validator Validator + Height int64 + Time time.Time + TotalVotingPower int64 +} // CommitInfo is the commit information of ABCI -type CommitInfo abci.CommitInfo +type CommitInfo struct { + Round int32 + Votes []VoteInfo +} // VoteInfo is the vote information of ABCI -type VoteInfo abci.VoteInfo +type VoteInfo struct { + Validator Validator + BlockIDFlag BlockIDFlag +} // BlockIDFlag indicates which BlockID the signature is for -type BlockIDFlag abci.BlockIDFlag +type BlockIDFlag int32 const ( - BlockIDFlagUnknown = abci.BlockIDFlagUnknown + BlockIDFlagUnknown BlockIDFlag = 0 // BlockIDFlagAbsent - no vote was received from a validator. - BlockIDFlagAbsent = abci.BlockIDFlagAbsent + BlockIDFlagAbsent BlockIDFlag = 1 // BlockIDFlagCommit - voted for the Commit.BlockID. - BlockIDFlagCommit = abci.BlockIDFlagCommit + BlockIDFlagCommit BlockIDFlag = 2 // BlockIDFlagNil - voted for nil. - BlockIDFlagNil = abci.BlockIDFlagNil + BlockIDFlagNil BlockIDFlag = 3 ) // Validator is the validator information of ABCI -type Validator abci.Validator +type Validator struct { + Address []byte + Power int64 +} diff --git a/runtime/comet.go b/runtime/comet.go index 87a3b13d905b..c7c27f3ac54f 100644 --- a/runtime/comet.go +++ b/runtime/comet.go @@ -3,24 +3,17 @@ package runtime import ( "context" - "cosmossdk.io/core/abci" - corecomet "cosmossdk.io/core/abci" + corecomet "cosmossdk.io/core/comet" sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ corecomet.Service = &ContextAwareABCIInfoService{} +var _ corecomet.Service = &ContextAwareCometInfoService{} -// ContextAwareABCIInfoService provides CometInfo which is embedded as a value in a Context. +// ContextAwareCometInfoService provides CometInfo which is embedded as a value in a Context. // This the legacy (server v1, baseapp) way of accessing CometInfo at the module level. -type ContextAwareABCIInfoService struct{} +type ContextAwareCometInfoService struct{} -func (c ContextAwareABCIInfoService) ABCIInfo(ctx context.Context) abci.Info { - ci := sdk.UnwrapSDKContext(ctx).CometInfo() - return abci.Info{ - Evidence: ci.Evidence, - ValidatorsHash: ci.ValidatorsHash, - ProposerAddress: ci.ProposerAddress, - LastCommit: ci.LastCommit, - } +func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info { + return sdk.UnwrapSDKContext(ctx).CometInfo() } diff --git a/runtime/environment.go b/runtime/environment.go index a72a50ceba4e..011164cde382 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -18,7 +18,7 @@ func NewEnvironment( ) appmodule.Environment { env := appmodule.Environment{ Logger: logger, - ABCIInfoService: ContextAwareABCIInfoService{}, + CometInfoService: ContextAwareCometInfoService{}, EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, diff --git a/types/context.go b/types/context.go index 6f5079f741db..33ab2f9c6c3b 100644 --- a/types/context.go +++ b/types/context.go @@ -7,7 +7,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - coreabci "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" "cosmossdk.io/log" @@ -395,15 +394,15 @@ func UnwrapSDKContext(ctx context.Context) Context { } // ToSDKEvidence takes comet evidence and returns sdk evidence -func ToSDKEvidence(ev []abci.Misbehavior) []coreabci.Evidence { - evidence := make([]coreabci.Evidence, len(ev)) +func ToSDKEvidence(ev []abci.Misbehavior) []comet.Evidence { + evidence := make([]comet.Evidence, len(ev)) for i, e := range ev { - evidence[i] = coreabci.Evidence{ - Type: coreabci.MisbehaviorType(e.Type), + evidence[i] = comet.Evidence{ + Type: comet.MisbehaviorType(e.Type), Height: e.Height, Time: e.Time, TotalVotingPower: e.TotalVotingPower, - Validator: coreabci.Validator{ + Validator: comet.Validator{ Address: e.Validator.Address, Power: e.Validator.Power, }, @@ -413,37 +412,37 @@ func ToSDKEvidence(ev []abci.Misbehavior) []coreabci.Evidence { } // ToSDKCommitInfo takes comet commit info and returns sdk commit info -func ToSDKCommitInfo(commit abci.CommitInfo) coreabci.CommitInfo { - ci := coreabci.CommitInfo{ +func ToSDKCommitInfo(commit abci.CommitInfo) comet.CommitInfo { + ci := comet.CommitInfo{ Round: commit.Round, } for _, v := range commit.Votes { - ci.Votes = append(ci.Votes, coreabci.VoteInfo{ - Validator: coreabci.Validator{ + ci.Votes = append(ci.Votes, comet.VoteInfo{ + Validator: comet.Validator{ Address: v.Validator.Address, Power: v.Validator.Power, }, - BlockIDFlag: coreabci.BlockIDFlag(v.BlockIdFlag), + BlockIDFlag: comet.BlockIDFlag(v.BlockIdFlag), }) } return ci } // ToSDKExtendedCommitInfo takes comet extended commit info and returns sdk commit info -func ToSDKExtendedCommitInfo(commit abci.ExtendedCommitInfo) coreabci.CommitInfo { - ci := coreabci.CommitInfo{ +func ToSDKExtendedCommitInfo(commit abci.ExtendedCommitInfo) comet.CommitInfo { + ci := comet.CommitInfo{ Round: commit.Round, - Votes: make([]coreabci.VoteInfo, len(commit.Votes)), + Votes: make([]comet.VoteInfo, len(commit.Votes)), } for i, v := range commit.Votes { - ci.Votes[i] = coreabci.VoteInfo{ - Validator: coreabci.Validator{ + ci.Votes[i] = comet.VoteInfo{ + Validator: comet.Validator{ Address: v.Validator.Address, Power: v.Validator.Power, }, - BlockIDFlag: coreabci.BlockIDFlag(v.BlockIdFlag), + BlockIDFlag: comet.BlockIDFlag(v.BlockIdFlag), } } diff --git a/x/evidence/keeper/abci.go b/x/evidence/keeper/abci.go index f09272855fe0..99136f8b407f 100644 --- a/x/evidence/keeper/abci.go +++ b/x/evidence/keeper/abci.go @@ -15,7 +15,7 @@ import ( func (k Keeper) BeginBlocker(ctx context.Context) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) - bi := k.ABCIInfoService.ABCIInfo(ctx) + bi := k.CometInfoService.CometInfo(ctx) evidences := bi.Evidence for _, evidence := range evidences { @@ -23,7 +23,7 @@ func (k Keeper) BeginBlocker(ctx context.Context) error { // It's still ongoing discussion how should we treat and slash attacks with // premeditation. So for now we agree to treat them in the same way. case comet.LightClientAttack, comet.DuplicateVote: - evidence := types.FromABCIEvidence(comet.Evidence(evidence), k.stakingKeeper.ConsensusAddressCodec()) + evidence := types.FromABCIEvidence(evidence, k.stakingKeeper.ConsensusAddressCodec()) err := k.handleEquivocationEvidence(ctx, evidence) if err != nil { return err diff --git a/x/evidence/types/evidence_test.go b/x/evidence/types/evidence_test.go index 75fb584df4c8..bfa20f82a98d 100644 --- a/x/evidence/types/evidence_test.go +++ b/x/evidence/types/evidence_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/core/abci" "cosmossdk.io/core/comet" "cosmossdk.io/x/evidence/types" @@ -80,8 +79,8 @@ func TestEquivocationValidateBasic(t *testing.T) { func TestEvidenceAddressConversion(t *testing.T) { sdk.GetConfig().SetBech32PrefixForConsensusNode("testcnclcons", "testcnclconspub") - tmEvidence := newCometMisbehavior(1, 100, time.Now(), comet.DuplicateVote, - abci.Validator{Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Power: 100}) + tmEvidence := NewCometMisbehavior(1, 100, time.Now(), comet.DuplicateVote, + comet.Validator{Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Power: 100}) evidence := types.FromABCIEvidence(tmEvidence, address.NewBech32Codec("testcnclcons")) consAddr := evidence.GetConsensusAddress(address.NewBech32Codec("testcnclcons")) @@ -90,7 +89,7 @@ func TestEvidenceAddressConversion(t *testing.T) { sdk.GetConfig().SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub) } -func newCometMisbehavior(height, tvp int64, t time.Time, tpe abci.MisbehaviorType, val abci.Validator) comet.Evidence { +func NewCometMisbehavior(height, tvp int64, t time.Time, tpe comet.MisbehaviorType, val comet.Validator) comet.Evidence { return comet.Evidence{ Height: height, Time: t, diff --git a/x/slashing/abci.go b/x/slashing/abci.go index 0a267d87a1d6..c8000be01963 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -21,7 +21,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error { if err != nil { return err } - ci := k.ABCIInfoService.ABCIInfo(ctx) + ci := k.CometInfoService.CometInfo(ctx) for _, vote := range ci.LastCommit.Votes { err := k.HandleValidatorSignatureWithParams(ctx, params, vote.Validator.Address, vote.Validator.Power, vote.BlockIDFlag) if err != nil { diff --git a/x/slashing/keeper/infractions.go b/x/slashing/keeper/infractions.go index b71fb1b09ca5..f044210cb9cd 100644 --- a/x/slashing/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -7,7 +7,7 @@ import ( "github.com/cockroachdb/errors" st "cosmossdk.io/api/cosmos/staking/v1beta1" - "cosmossdk.io/core/abci" + "cosmossdk.io/core/comet" "cosmossdk.io/core/event" "cosmossdk.io/x/slashing/types" @@ -16,7 +16,7 @@ import ( ) // HandleValidatorSignature handles a validator signature, must be called once per validator per block. -func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.Address, power int64, signed abci.BlockIDFlag) error { +func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.Address, power int64, signed comet.BlockIDFlag) error { params, err := k.Params.Get(ctx) if err != nil { return err @@ -24,7 +24,7 @@ func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.A return k.HandleValidatorSignatureWithParams(ctx, params, addr, power, signed) } -func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params types.Params, addr cryptotypes.Address, power int64, signed abci.BlockIDFlag) error { +func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params types.Params, addr cryptotypes.Address, power int64, signed comet.BlockIDFlag) error { height := k.HeaderService.HeaderInfo(ctx).Height // fetch the validator public key @@ -80,7 +80,7 @@ func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params t } modifiedSignInfo := false - missed := signed == abci.BlockIDFlagAbsent + missed := signed == comet.BlockIDFlagAbsent switch { case !previous && missed: // Bitmap value has changed from not missed to missed, so we flip the bit diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index c285bb7999cb..998ca46ca3b8 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -41,7 +41,7 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { return nil } - ci := k.ABCIInfoService.ABCIInfo(ctx) + ci := k.CometInfoService.CometInfo(ctx) historicalEntry := types.HistoricalRecord{ Time: &headerInfo.Time, ValidatorsHash: ci.ValidatorsHash, From 50427ef0e452e89b56aa8d4a218f866f8505a76e Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 13:51:53 -0400 Subject: [PATCH 08/13] provide cometService in app_di - refactor appModules and Keepers --- core/appmodule/v2/environment.go | 2 -- runtime/environment.go | 1 - runtime/module.go | 6 ++++++ x/evidence/depinject.go | 4 +++- x/evidence/keeper/abci.go | 4 ++-- x/evidence/module.go | 7 +++++-- x/slashing/abci.go | 5 +++-- x/slashing/depinject.go | 14 ++++++++------ x/slashing/module.go | 10 +++++++--- x/staking/depinject.go | 3 +++ x/staking/keeper/historical_info.go | 2 +- x/staking/keeper/keeper.go | 4 ++++ x/staking/keeper/keeper_test.go | 1 + 13 files changed, 43 insertions(+), 20 deletions(-) diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index 38f6734f8fe9..e3592eb210ad 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -2,7 +2,6 @@ package appmodule import ( "cosmossdk.io/core/branch" - "cosmossdk.io/core/comet" "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" @@ -16,7 +15,6 @@ import ( type Environment struct { Logger log.Logger - CometInfoService comet.Service BranchService branch.Service EventService event.Service GasService gas.Service diff --git a/runtime/environment.go b/runtime/environment.go index 011164cde382..b8814df0b7e1 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -18,7 +18,6 @@ func NewEnvironment( ) appmodule.Environment { env := appmodule.Environment{ Logger: logger, - CometInfoService: ContextAwareCometInfoService{}, EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, diff --git a/runtime/module.go b/runtime/module.go index aff84e730862..3aede2ccf7cb 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -16,6 +16,7 @@ import ( stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/core/genesis" "cosmossdk.io/core/store" "cosmossdk.io/depinject" @@ -101,6 +102,7 @@ func init() { ProvideModuleManager, ProvideAppVersionModifier, ProvideAddressCodec, + ProvideCometService, ), appconfig.Invoke(SetupAppBuilder), ) @@ -275,6 +277,10 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { return app.app } +func ProvideCometService() comet.Service { + return ContextAwareCometInfoService{} +} + type AddressCodecInputs struct { depinject.In diff --git a/x/evidence/depinject.go b/x/evidence/depinject.go index 335cef402ef5..9f72496a21a1 100644 --- a/x/evidence/depinject.go +++ b/x/evidence/depinject.go @@ -4,6 +4,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/evidence/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" eviclient "cosmossdk.io/x/evidence/client" @@ -30,6 +31,7 @@ type ModuleInputs struct { Environment appmodule.Environment Cdc codec.Codec EvidenceHandlers []eviclient.EvidenceHandler `optional:"true"` + CometService comet.Service StakingKeeper types.StakingKeeper SlashingKeeper types.SlashingKeeper @@ -45,7 +47,7 @@ type ModuleOutputs struct { func ProvideModule(in ModuleInputs) ModuleOutputs { k := keeper.NewKeeper(in.Cdc, in.Environment, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec) - m := NewAppModule(in.Cdc, *k, in.EvidenceHandlers...) + m := NewAppModule(in.Cdc, *k, in.CometService, in.EvidenceHandlers...) return ModuleOutputs{EvidenceKeeper: *k, Module: m} } diff --git a/x/evidence/keeper/abci.go b/x/evidence/keeper/abci.go index 99136f8b407f..86dbd78adf36 100644 --- a/x/evidence/keeper/abci.go +++ b/x/evidence/keeper/abci.go @@ -12,10 +12,10 @@ import ( // BeginBlocker iterates through and handles any newly discovered evidence of // misbehavior submitted by CometBFT. Currently, only equivocation is handled. -func (k Keeper) BeginBlocker(ctx context.Context) error { +func (k Keeper) BeginBlocker(ctx context.Context, cometService comet.Service) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) - bi := k.CometInfoService.CometInfo(ctx) + bi := cometService.CometInfo(ctx) evidences := bi.Evidence for _, evidence := range evidences { diff --git a/x/evidence/module.go b/x/evidence/module.go index b78e0060a013..4482fbf36fd8 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/core/registry" eviclient "cosmossdk.io/x/evidence/client" "cosmossdk.io/x/evidence/client/cli" @@ -42,14 +43,16 @@ type AppModule struct { cdc codec.Codec evidenceHandlers []eviclient.EvidenceHandler keeper keeper.Keeper + cometService comet.Service } // NewAppModule creates a new AppModule object. -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, evidenceHandlers ...eviclient.EvidenceHandler) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, cometService comet.Service, evidenceHandlers ...eviclient.EvidenceHandler) AppModule { return AppModule{ keeper: keeper, evidenceHandlers: evidenceHandlers, cdc: cdc, + cometService: cometService, } } @@ -135,7 +138,7 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock executes all ABCI BeginBlock logic respective to the evidence module. func (am AppModule) BeginBlock(ctx context.Context) error { - return am.keeper.BeginBlocker(ctx) + return am.keeper.BeginBlocker(ctx, am.cometService) } // AppModuleSimulation functions diff --git a/x/slashing/abci.go b/x/slashing/abci.go index c8000be01963..66cf3feff616 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -3,6 +3,7 @@ package slashing import ( "context" + "cosmossdk.io/core/comet" "cosmossdk.io/x/slashing/keeper" "cosmossdk.io/x/slashing/types" @@ -11,7 +12,7 @@ import ( // BeginBlocker check for infraction evidence or downtime of validators // on every begin block -func BeginBlocker(ctx context.Context, k keeper.Keeper) error { +func BeginBlocker(ctx context.Context, k keeper.Keeper, cometService comet.Service) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // Iterate over all the validators which *should* have signed this block @@ -21,7 +22,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error { if err != nil { return err } - ci := k.CometInfoService.CometInfo(ctx) + ci := cometService.CometInfo(ctx) for _, vote := range ci.LastCommit.Votes { err := k.HandleValidatorSignatureWithParams(ctx, params, vote.Validator.Address, vote.Validator.Power, vote.BlockIDFlag) if err != nil { diff --git a/x/slashing/depinject.go b/x/slashing/depinject.go index 60f865aff140..d1af9fa19b94 100644 --- a/x/slashing/depinject.go +++ b/x/slashing/depinject.go @@ -5,6 +5,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" authtypes "cosmossdk.io/x/auth/types" @@ -31,11 +32,12 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Environment appmodule.Environment - Cdc codec.Codec - LegacyAmino *codec.LegacyAmino - Registry cdctypes.InterfaceRegistry + Config *modulev1.Module + Environment appmodule.Environment + Cdc codec.Codec + LegacyAmino *codec.LegacyAmino + Registry cdctypes.InterfaceRegistry + CometService comet.Service AccountKeeper types.AccountKeeper BankKeeper types.BankKeeper @@ -63,7 +65,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { } k := keeper.NewKeeper(in.Environment, in.Cdc, in.LegacyAmino, in.StakingKeeper, authStr) - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.Registry) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.Registry, in.CometService) return ModuleOutputs{ Keeper: k, Module: m, diff --git a/x/slashing/module.go b/x/slashing/module.go index c5ae4fef1919..c38157b2d8b6 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/core/registry" "cosmossdk.io/x/slashing/keeper" "cosmossdk.io/x/slashing/simulation" @@ -40,8 +41,9 @@ var ( // AppModule implements an application module for the slashing module. type AppModule struct { - cdc codec.Codec - registry cdctypes.InterfaceRegistry + cdc codec.Codec + registry cdctypes.InterfaceRegistry + cometService comet.Service keeper keeper.Keeper accountKeeper types.AccountKeeper @@ -57,6 +59,7 @@ func NewAppModule( bk types.BankKeeper, sk types.StakingKeeper, registry cdctypes.InterfaceRegistry, + cs comet.Service, ) AppModule { return AppModule{ cdc: cdc, @@ -65,6 +68,7 @@ func NewAppModule( accountKeeper: ak, bankKeeper: bk, stakingKeeper: sk, + cometService: cs, } } @@ -158,7 +162,7 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock returns the begin blocker for the slashing module. func (am AppModule) BeginBlock(ctx context.Context) error { - return BeginBlocker(ctx, am.keeper) + return BeginBlocker(ctx, am.keeper, am.cometService) } // AppModuleSimulation functions diff --git a/x/staking/depinject.go b/x/staking/depinject.go index 1eaf44baa87e..a4dfc2630d52 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -9,6 +9,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" authtypes "cosmossdk.io/x/auth/types" @@ -44,6 +45,7 @@ type ModuleInputs struct { BankKeeper types.BankKeeper Cdc codec.Codec Environment appmodule.Environment + CometInfoService comet.Service } // Dependency Injection Outputs @@ -74,6 +76,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { as, in.ValidatorAddressCodec, in.ConsensusAddressCodec, + in.CometInfoService, ) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper) return ModuleOutputs{StakingKeeper: k, Module: m} diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index 998ca46ca3b8..d0d500ebad89 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -41,7 +41,7 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { return nil } - ci := k.CometInfoService.CometInfo(ctx) + ci := k.cometInfoService.CometInfo(ctx) historicalEntry := types.HistoricalRecord{ Time: &headerInfo.Time, ValidatorsHash: ci.ValidatorsHash, diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 8db9e7dbaa07..0ac1aae23b51 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/collections/indexes" addresscodec "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/math" "cosmossdk.io/x/staking/types" @@ -76,6 +77,7 @@ type Keeper struct { authority string validatorAddressCodec addresscodec.Codec consensusAddressCodec addresscodec.Codec + cometInfoService comet.Service Schema collections.Schema @@ -138,6 +140,7 @@ func NewKeeper( authority string, validatorAddressCodec addresscodec.Codec, consensusAddressCodec addresscodec.Codec, + cometInfoService comet.Service, ) *Keeper { sb := collections.NewSchemaBuilder(env.KVStoreService) // ensure bonded and not bonded module accounts are set @@ -167,6 +170,7 @@ func NewKeeper( authority: authority, validatorAddressCodec: validatorAddressCodec, consensusAddressCodec: consensusAddressCodec, + cometInfoService: cometInfoService, LastTotalPower: collections.NewItem(sb, types.LastTotalPowerKey, "last_total_power", sdk.IntValue), HistoricalInfo: collections.NewMap(sb, types.HistoricalInfoKey, "historical_info", collections.Uint64Key, HistoricalInfoCodec(cdc)), Delegations: collections.NewMap( diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 0c75f5c28b00..95dbe9309c7c 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -98,6 +98,7 @@ func (s *KeeperTestSuite) SetupTest() { authority, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmosvalcons"), + runtime.ContextAwareCometInfoService{}, ) require.NoError(keeper.Params.Set(ctx, stakingtypes.DefaultParams())) From 0541b0b4027982c83dbf8606ac45dcbbaffc61cc Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 14:00:14 -0400 Subject: [PATCH 09/13] fixes for simapp v1 --- simapp/app.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index fcb756cb7ba3..09a357874821 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -281,6 +281,7 @@ func NewSimApp( interfaceRegistry: interfaceRegistry, keys: keys, } + cometService := runtime.ContextAwareCometInfoService{} // set the BaseApp's parameter store app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), authtypes.NewModuleAddress(govtypes.ModuleName).String()) @@ -338,8 +339,19 @@ func NewSimApp( app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger.With(log.ModuleKey, "x/staking"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + appCodec, + runtime.NewEnvironment( + runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), + logger.With(log.ModuleKey, "x/staking"), + runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), + app.AuthKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + signingCtx.ValidatorAddressCodec(), + authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + cometService, ) + app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger.With(log.ModuleKey, "x/mint")), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.PoolKeeper = poolkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), logger.With(log.ModuleKey, "x/protocolpool")), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) @@ -436,11 +448,11 @@ func NewSimApp( feegrantmodule.NewAppModule(appCodec, app.AuthKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, &app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AuthKeeper, nil), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry, cometService), distr.NewAppModule(appCodec, app.DistrKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AuthKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), - evidence.NewAppModule(appCodec, app.EvidenceKeeper), + evidence.NewAppModule(appCodec, app.EvidenceKeeper, cometService), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), From de0a14519e2d57000906bac62d07cf63ffcdf2b4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 14:11:41 -0400 Subject: [PATCH 10/13] fix integration tests --- .../distribution/keeper/msg_server_test.go | 3 ++- .../evidence/keeper/infraction_test.go | 21 ++++++++++--------- tests/integration/gov/keeper/keeper_test.go | 2 +- tests/integration/slashing/abci_test.go | 8 ++++--- .../slashing/keeper/keeper_test.go | 6 ++++-- .../integration/staking/keeper/common_test.go | 2 +- .../staking/keeper/deterministic_test.go | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 281ade5b9c4d..7310c65ab041 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -118,8 +118,9 @@ func initFixture(t *testing.T) *fixture { msgRouter := baseapp.NewMsgServiceRouter() grpcRouter := baseapp.NewGRPCQueryRouter() + cometService := runtime.ContextAwareCometInfoService{} - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometService) require.NoError(t, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 4e40b006faf4..a8fec430ddcd 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -69,8 +69,9 @@ var ( } // The default power validators are initialized to have within tests - initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) - initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) + initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) + initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) + cometInfoService = runtime.ContextAwareCometInfoService{} ) type fixture struct { @@ -136,7 +137,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, codec.NewLegacyAmino(), stakingKeeper, authority.String()) @@ -150,8 +151,8 @@ func initFixture(tb testing.TB) *fixture { authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) - evidenceModule := evidence.NewAppModule(cdc, *evidenceKeeper) + slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService) + evidenceModule := evidence.NewAppModule(cdc, *evidenceKeeper, cometInfoService) integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), @@ -241,7 +242,7 @@ func TestHandleDoubleSign(t *testing.T) { } ctx = ctx.WithCometInfo(nci) - assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci))) + assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci), cometInfoService)) // should be jailed and tombstoned val, err = f.stakingKeeper.Validator(ctx, operatorAddr) @@ -254,7 +255,7 @@ func TestHandleDoubleSign(t *testing.T) { assert.Assert(t, newTokens.LT(oldTokens)) // submit duplicate evidence - assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx)) + assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx, cometInfoService)) // tokens should be the same (capped slash) val, err = f.stakingKeeper.Validator(ctx, operatorAddr) @@ -329,7 +330,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) { ctx = ctx.WithConsensusParams(cp) ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.BlockHeight() + cp.Evidence.MaxAgeNumBlocks + 1, Time: ctx.HeaderInfo().Time.Add(cp.Evidence.MaxAgeDuration + 1)}) - assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx)) + assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx, cometInfoService)) val, err = f.stakingKeeper.Validator(ctx, operatorAddr) assert.NilError(t, err) @@ -404,7 +405,7 @@ func TestHandleDoubleSignAfterRotation(t *testing.T) { }}, } - err = f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci)) + err = f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci), cometInfoService) assert.NilError(t, err) // should be jailed and tombstoned @@ -420,7 +421,7 @@ func TestHandleDoubleSignAfterRotation(t *testing.T) { assert.Assert(t, newTokens.LT(oldTokens)) // submit duplicate evidence - err = f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci)) + err = f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci), cometInfoService) assert.NilError(t, err) // tokens should be the same (capped slash) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index c29953cf139f..c27f3de68b77 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -100,7 +100,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) diff --git a/tests/integration/slashing/abci_test.go b/tests/integration/slashing/abci_test.go index 51facaf45cbc..ae768e8c26dd 100644 --- a/tests/integration/slashing/abci_test.go +++ b/tests/integration/slashing/abci_test.go @@ -19,6 +19,7 @@ import ( stakingtestutil "cosmossdk.io/x/staking/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -83,8 +84,9 @@ func TestBeginBlocker(t *testing.T) { BlockIDFlag: comet.BlockIDFlagCommit, }}}, }) + cometInfoService := runtime.ContextAwareCometInfoService{} - err = slashing.BeginBlocker(ctx, slashingKeeper) + err = slashing.BeginBlocker(ctx, slashingKeeper, cometInfoService) require.NoError(t, err) info, err := slashingKeeper.ValidatorSigningInfo.Get(ctx, sdk.ConsAddress(pk.Address())) @@ -102,7 +104,7 @@ func TestBeginBlocker(t *testing.T) { for ; height < signedBlocksWindow; height++ { ctx = ctx.WithHeaderInfo(coreheader.Info{Height: height}) - err = slashing.BeginBlocker(ctx, slashingKeeper) + err = slashing.BeginBlocker(ctx, slashingKeeper, cometInfoService) require.NoError(t, err) } @@ -117,7 +119,7 @@ func TestBeginBlocker(t *testing.T) { }}}, }) - err = slashing.BeginBlocker(ctx, slashingKeeper) + err = slashing.BeginBlocker(ctx, slashingKeeper, cometInfoService) require.NoError(t, err) } diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 294dbbccb8ee..1f1a62ac4fcf 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -106,13 +106,15 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + cometInfoService := runtime.ContextAwareCometInfoService{} + + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometInfoService) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String()) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) + slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService) integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 1ff2b47a13b8..45bed0717f2a 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -155,7 +155,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index b8fe56f48eea..c661bcb3d061 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -115,7 +115,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) From 99db87f03188d19e288839181ffa1dcc018af2cd Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 14:17:23 -0400 Subject: [PATCH 11/13] use construcor instead of struct initializer --- runtime/comet.go | 4 +++ runtime/module.go | 14 ++++++++--- simapp/app.go | 2 +- .../distribution/keeper/msg_server_test.go | 2 +- .../evidence/keeper/infraction_test.go | 9 ++++--- tests/integration/gov/keeper/keeper_test.go | 2 +- tests/integration/slashing/abci_test.go | 2 +- .../slashing/keeper/keeper_test.go | 2 +- .../integration/staking/keeper/common_test.go | 8 ++++-- .../staking/keeper/deterministic_test.go | 25 ++++++++++++++++--- x/staking/keeper/keeper_test.go | 2 +- 11 files changed, 54 insertions(+), 18 deletions(-) diff --git a/runtime/comet.go b/runtime/comet.go index c7c27f3ac54f..e0143d44df1b 100644 --- a/runtime/comet.go +++ b/runtime/comet.go @@ -17,3 +17,7 @@ type ContextAwareCometInfoService struct{} func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info { return sdk.UnwrapSDKContext(ctx).CometInfo() } + +func NewContextAwareCometInfoService() *ContextAwareCometInfoService { + return &ContextAwareCometInfoService{} +} diff --git a/runtime/module.go b/runtime/module.go index 3aede2ccf7cb..435515e4cb53 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -174,7 +174,11 @@ func SetupAppBuilder(inputs AppInputs) { app.ModuleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino) } -func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec address.ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) { +func ProvideInterfaceRegistry( + addressCodec address.Codec, + validatorAddressCodec address.ValidatorAddressCodec, + customGetSigners []signing.CustomGetSigner, +) (codectypes.InterfaceRegistry, error) { signingOptions := signing.Options{ AddressCodec: addressCodec, ValidatorAddressCodec: validatorAddressCodec, @@ -211,7 +215,11 @@ func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtim return nil } -func ProvideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) *storetypes.KVStoreKey { +func ProvideKVStoreKey( + config *runtimev1alpha1.Module, + key depinject.ModuleKey, + app *AppBuilder, +) *storetypes.KVStoreKey { override := storeKeyOverride(config, key.Name()) var storeKeyName string @@ -278,7 +286,7 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { } func ProvideCometService() comet.Service { - return ContextAwareCometInfoService{} + return NewContextAwareCometInfoService() } type AddressCodecInputs struct { diff --git a/simapp/app.go b/simapp/app.go index 09a357874821..b51977a48861 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -281,7 +281,7 @@ func NewSimApp( interfaceRegistry: interfaceRegistry, keys: keys, } - cometService := runtime.ContextAwareCometInfoService{} + cometService := runtime.NewContextAwareCometInfoService() // set the BaseApp's parameter store app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), authtypes.NewModuleAddress(govtypes.ModuleName).String()) diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 7310c65ab041..19dd57a6c7ca 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -118,7 +118,7 @@ func initFixture(t *testing.T) *fixture { msgRouter := baseapp.NewMsgServiceRouter() grpcRouter := baseapp.NewGRPCQueryRouter() - cometService := runtime.ContextAwareCometInfoService{} + cometService := runtime.NewContextAwareCometInfoService() stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometService) require.NoError(t, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index a8fec430ddcd..20d3d2188b22 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -71,7 +71,7 @@ var ( // The default power validators are initialized to have within tests initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) - cometInfoService = runtime.ContextAwareCometInfoService{} + cometInfoService = runtime.NewContextAwareCometInfoService() ) type fixture struct { @@ -137,7 +137,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, codec.NewLegacyAmino(), stakingKeeper, authority.String()) @@ -450,7 +450,10 @@ func TestHandleDoubleSignAfterRotation(t *testing.T) { // query evidence from store var evidences []exported.Evidence - assert.NilError(t, f.evidenceKeeper.Evidences.Walk(ctx, nil, func(key []byte, value exported.Evidence) (stop bool, err error) { + assert.NilError(t, f.evidenceKeeper.Evidences.Walk(ctx, nil, func( + key []byte, + value exported.Evidence, + ) (stop bool, err error) { evidences = append(evidences, value) return false, nil })) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index c27f3de68b77..911bcc763219 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -100,7 +100,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) diff --git a/tests/integration/slashing/abci_test.go b/tests/integration/slashing/abci_test.go index ae768e8c26dd..2d45d09b1811 100644 --- a/tests/integration/slashing/abci_test.go +++ b/tests/integration/slashing/abci_test.go @@ -84,7 +84,7 @@ func TestBeginBlocker(t *testing.T) { BlockIDFlag: comet.BlockIDFlagCommit, }}}, }) - cometInfoService := runtime.ContextAwareCometInfoService{} + cometInfoService := runtime.NewContextAwareCometInfoService() err = slashing.BeginBlocker(ctx, slashingKeeper, cometInfoService) require.NoError(t, err) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 1f1a62ac4fcf..8f95d921cf9d 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -106,7 +106,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - cometInfoService := runtime.ContextAwareCometInfoService{} + cometInfoService := runtime.NewContextAwareCometInfoService() stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometInfoService) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 45bed0717f2a..f85f66a8d227 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -70,7 +70,11 @@ func generateAddresses(f *fixture, numAddrs int) ([]sdk.AccAddress, []sdk.ValAdd return addrDels, addrVals } -func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { +func createValidators( + t *testing.T, + f *fixture, + powers []int64, +) ([]sdk.AccAddress, []sdk.ValAddress, []types.Validator) { t.Helper() addrs := simtestutil.AddTestAddrsIncremental(f.bankKeeper, f.stakingKeeper, f.sdkCtx, 5, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 300)) valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) @@ -155,7 +159,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index c661bcb3d061..6cb8bd374bd1 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -115,7 +115,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.ContextAwareCometInfoService{}) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) @@ -230,7 +230,12 @@ func createValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) staking } // createAndSetValidatorWithStatus creates a validator with random values but with given status and sets to the state -func createAndSetValidatorWithStatus(t *testing.T, rt *rapid.T, f *deterministicFixture, status stakingtypes.BondStatus) stakingtypes.Validator { +func createAndSetValidatorWithStatus( + t *testing.T, + rt *rapid.T, + f *deterministicFixture, + status stakingtypes.BondStatus, +) stakingtypes.Validator { t.Helper() val := createValidator(t, rt, f) val.Status = status @@ -338,14 +343,26 @@ func getStaticValidator2(t *testing.T, f *deterministicFixture) stakingtypes.Val } // createDelegationAndDelegate funds the delegator account with a random delegation in range 100-1000 and delegates. -func createDelegationAndDelegate(t *testing.T, rt *rapid.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator) (newShares math.LegacyDec, err error) { +func createDelegationAndDelegate( + t *testing.T, + rt *rapid.T, + f *deterministicFixture, + delegator sdk.AccAddress, + validator stakingtypes.Validator, +) (newShares math.LegacyDec, err error) { t.Helper() amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, rapid.Int64Range(100, 1000).Draw(rt, "amount")) return fundAccountAndDelegate(t, f, delegator, validator, amt) } // fundAccountAndDelegate funds the delegator account with the specified delegation and delegates. -func fundAccountAndDelegate(t *testing.T, f *deterministicFixture, delegator sdk.AccAddress, validator stakingtypes.Validator, amt math.Int) (newShares math.LegacyDec, err error) { +func fundAccountAndDelegate( + t *testing.T, + f *deterministicFixture, + delegator sdk.AccAddress, + validator stakingtypes.Validator, + amt math.Int, +) (newShares math.LegacyDec, err error) { t.Helper() coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amt)) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 95dbe9309c7c..4bb2c4bf67b0 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -98,7 +98,7 @@ func (s *KeeperTestSuite) SetupTest() { authority, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmosvalcons"), - runtime.ContextAwareCometInfoService{}, + runtime.NewContextAwareCometInfoService(), ) require.NoError(keeper.Params.Set(ctx, stakingtypes.DefaultParams())) From f896734f5417e226203bb5c89089714d318a6bf1 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 20:28:14 -0400 Subject: [PATCH 12/13] Update CHANGELOG.md Co-authored-by: Marko --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d24877a9142a..4a20e7d9ee71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. ### Features -* (runtime) [#20238](https://github.com/cosmos/cosmos-sdk/pull/20238) Add `core/comet.Service` to the runtime Environment. * (tests) [#20013](https://github.com/cosmos/cosmos-sdk/pull/20013) Introduce system tests to run multi node local testnet in CI * (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime. * (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. From bb5368f1c9d72493a54c51c00d70020f45eb5b3f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 May 2024 21:06:22 -0400 Subject: [PATCH 13/13] add changelog entries --- x/evidence/CHANGELOG.md | 1 + x/slashing/CHANGELOG.md | 1 + x/staking/CHANGELOG.md | 1 + 3 files changed, 3 insertions(+) diff --git a/x/evidence/CHANGELOG.md b/x/evidence/CHANGELOG.md index ae72299b60a2..cd91ad4345ac 100644 --- a/x/evidence/CHANGELOG.md +++ b/x/evidence/CHANGELOG.md @@ -27,6 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Api Breaking Changes +* [#20238](https://github.com/cosmos/cosmos-sdk/pull/20238) `NewAppModule` now takes in a `core/comet.Service` an argument. `BeginBlocker` now takes in a `core/comet.Service`. * [#20016](https://github.com/cosmos/cosmos-sdk/pull/20016) `NewMsgSubmitEvidence` now takes a string as argument instead of an `AccAddress`. * [#19482](https://github.com/cosmos/cosmos-sdk/pull/19482) `appmodule.Environment` is passed to `NewKeeper` instead of individual services * [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) `NewAppModule` now takes in a `codec.Codec` as its first argument diff --git a/x/slashing/CHANGELOG.md b/x/slashing/CHANGELOG.md index 0ba949ddaa75..787d75997332 100644 --- a/x/slashing/CHANGELOG.md +++ b/x/slashing/CHANGELOG.md @@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#20238](https://github.com/cosmos/cosmos-sdk/pull/20238) `NewAppModule` now takes in a `core/comet.Service` an argument. `BeginBlocker` now takes in a `core/comet.Service`. * [#20026](https://github.com/cosmos/cosmos-sdk/pull/20026) Removal of the Address.String() method and related changes: * `Migrate` now takes a `ValidatorAddressCodec` as argument. * `Migrator` has a new field of `ValidatorAddressCodec` type. diff --git a/x/staking/CHANGELOG.md b/x/staking/CHANGELOG.md index aa45a5df806d..dda05c42d915 100644 --- a/x/staking/CHANGELOG.md +++ b/x/staking/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#20238](https://github.com/cosmos/cosmos-sdk/pull/20238) `NewKeeper` now accepts a `core/comet.Service` as its last argument. * [#19788](https://github.com/cosmos/cosmos-sdk/pull/19788) Remove `ABCIValidatorUpdate` and `ABCIValidatorUpdateZero`, use `ModuleValidatorUpdate` and `ModuleValidatorUpdateIsZero` instead. * [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) Update to use `[]appmodule.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`. * [#19414](https://github.com/cosmos/cosmos-sdk/pull/19414) `NewStakingKeeper` takes an environment variable instead of individual services.