Skip to content

Commit

Permalink
Merge branch 'main' into julien/go
Browse files Browse the repository at this point in the history
  • Loading branch information
facundomedica authored Feb 20, 2024
2 parents 7b589dc + 52106a6 commit 0f8ff1e
Show file tree
Hide file tree
Showing 44 changed files with 339 additions and 353 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### API Breaking Changes

* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services.
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does.
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.
* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.
Expand Down
8 changes: 4 additions & 4 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func NewSimApp(
}

// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{})
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger), authtypes.NewModuleAddress(govtypes.ModuleName).String())
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)

addressCodec := authcodec.NewBech32Codec(sdk.Bech32MainPrefix)
Expand Down Expand Up @@ -344,7 +344,7 @@ func NewSimApp(
appCodec, legacyAmino, app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), app.AuthKeeper)
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[feegrant.StoreKey]), logger), appCodec, app.AuthKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand All @@ -365,7 +365,7 @@ func NewSimApp(
config.MaxProposalTitleLen = 255 // example max title length in characters
config.MaxProposalSummaryLen = 10200 // example max summary length in characters
*/
app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewKVStoreService(keys[group.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper, groupConfig)
app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[group.StoreKey]), logger), appCodec, app.MsgServiceRouter(), app.AuthKeeper, groupConfig)

// get skipUpgradeHeights from the app options
skipUpgradeHeights := map[int64]bool{}
Expand Down Expand Up @@ -404,7 +404,7 @@ func NewSimApp(

// create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(),
appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(),
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func initFixture(tb testing.TB) *fixture {

stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(slashingKeeper.Hooks()))

evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr))
evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), log.NewNopLogger()), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr))
router := evidencetypes.NewRouter()
router = router.AddRoute(evidencetypes.RouteEquivocation, testEquivocationHandler(evidenceKeeper))
evidenceKeeper.SetRouter(router)
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
t.Parallel()
f := initFixture(t)

ctx := f.sdkCtx.WithIsCheckTx(false).WithBlockHeight(1).WithHeaderInfo(header.Info{Time: time.Now()})
ctx := f.sdkCtx.WithIsCheckTx(false).WithHeaderInfo(header.Info{Height: 1, Time: time.Now()})
populateValidators(t, f)

power := int64(100)
Expand Down Expand Up @@ -306,8 +306,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {

ctx = ctx.WithCometInfo(nci)
ctx = ctx.WithConsensusParams(cp)
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.Add(cp.Evidence.MaxAgeDuration + 1)})
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + cp.Evidence.MaxAgeNumBlocks + 1)
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))

Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewIntegrationApp(

if keys[consensusparamtypes.StoreKey] != nil {
// set baseApp param store
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger()), authtypes.NewModuleAddress("gov").String())
bApp.SetParamStore(consensusParamsKeeper.ParamsStore)

if err := bApp.LoadLatestVersion(); err != nil {
Expand Down
11 changes: 4 additions & 7 deletions x/consensus/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package consensus
import (
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
authtypes "cosmossdk.io/x/auth/types"
Expand All @@ -30,10 +28,9 @@ func init() {
type ModuleInputs struct {
depinject.In

Config *modulev1.Module
Cdc codec.Codec
StoreService storetypes.KVStoreService
EventManager event.Service
Config *modulev1.Module
Cdc codec.Codec
Environment appmodule.Environment
}

type ModuleOutputs struct {
Expand All @@ -51,7 +48,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String(), in.EventManager)
k := keeper.NewKeeper(in.Cdc, in.Environment, authority.String())
m := NewAppModule(in.Cdc, k)
baseappOpt := func(app *baseapp.BaseApp) {
app.SetParamStore(k.ParamsStore)
Expand Down
18 changes: 8 additions & 10 deletions x/consensus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"google.golang.org/grpc/status"

"cosmossdk.io/collections"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
storetypes "cosmossdk.io/core/store"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/consensus/exported"
Expand All @@ -21,22 +21,20 @@ import (
var StoreKey = "Consensus"

type Keeper struct {
storeService storetypes.KVStoreService
event event.Service
environment appmodule.Environment

authority string
ParamsStore collections.Item[cmtproto.ConsensusParams]
}

var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore

func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, em event.Service) Keeper {
sb := collections.NewSchemaBuilder(storeService)
func NewKeeper(cdc codec.BinaryCodec, env appmodule.Environment, authority string) Keeper {
sb := collections.NewSchemaBuilder(env.KVStoreService)
return Keeper{
storeService: storeService,
authority: authority,
event: em,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
environment: env,
authority: authority,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
}
}

Expand Down Expand Up @@ -79,7 +77,7 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*
return nil, err
}

if err := k.event.EventManager(ctx).EmitKV(
if err := k.environment.EventService.EventManager(ctx).EmitKV(
"update_consensus_params",
event.NewAttribute("authority", msg.Authority),
event.NewAttribute("parameters", consensusParams.String())); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions x/consensus/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
cmttypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/suite"

"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
authtypes "cosmossdk.io/x/auth/types"

Expand All @@ -32,9 +33,9 @@ func (s *KeeperTestSuite) SetupTest() {
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
ctx := testCtx.Ctx
encCfg := moduletestutil.MakeTestEncodingConfig()
storeService := runtime.NewKVStoreService(key)
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())

keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authtypes.NewModuleAddress("gov").String())

s.ctx = ctx
s.consensusParamsKeeper = &keeper
Expand Down
6 changes: 5 additions & 1 deletion x/evidence/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Api Breaking Changes

* [#19482](https://github.com/cosmos/cosmos-sdk/pull/19482) `appmodule.Environment` is passed to `NewKeeper` instead of individual services

## [v0.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/x/evidence/v0.1.0) - 2023-11-07

### Features

* (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module.
* [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module.
* (keeper) [#15420](https://github.com/cosmos/cosmos-sdk/pull/15420) Move `BeginBlocker` to the keeper folder & make HandleEquivocation private

### API Breaking Changes
Expand Down
7 changes: 3 additions & 4 deletions x/evidence/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
modulev1 "cosmossdk.io/api/cosmos/evidence/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
"cosmossdk.io/x/evidence/keeper"
Expand All @@ -27,8 +26,8 @@ func init() {
type ModuleInputs struct {
depinject.In

StoreService store.KVStoreService
Cdc codec.Codec
Environment appmodule.Environment
Cdc codec.Codec

StakingKeeper types.StakingKeeper
SlashingKeeper types.SlashingKeeper
Expand All @@ -43,7 +42,7 @@ type ModuleOutputs struct {
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.StoreService, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec)
k := keeper.NewKeeper(in.Cdc, in.Environment, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec)
m := NewAppModule(*k)

return ModuleOutputs{EvidenceKeeper: *k, Module: m}
Expand Down
3 changes: 1 addition & 2 deletions x/evidence/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func (k Keeper) BeginBlocker(ctx context.Context) error {
bi := sdk.UnwrapSDKContext(ctx).CometInfo()

evidences := bi.Evidence
sdkCtx := sdk.UnwrapSDKContext(ctx)
for _, evidence := range evidences {
switch evidence.Type {
// It's still ongoing discussion how should we treat and slash attacks with
Expand All @@ -32,7 +31,7 @@ func (k Keeper) BeginBlocker(ctx context.Context) error {
return err
}
default:
k.Logger(sdkCtx).Error(fmt.Sprintf("ignored unknown evidence type: %x", evidence.Type))
k.Logger().Error(fmt.Sprintf("ignored unknown evidence type: %x", evidence.Type))
}
}
return nil
Expand Down
11 changes: 6 additions & 5 deletions x/evidence/keeper/infraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
// TODO: Some of the invalid constraints listed above may need to be reconsidered
// in the case of a lunatic attack.
func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types.Equivocation) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
logger := k.Logger(ctx)
logger := k.Logger()
consAddr := evidence.GetConsensusAddress(k.stakingKeeper.ConsensusAddressCodec())

validator, err := k.stakingKeeper.ValidatorByConsAddr(ctx, consAddr)
Expand Down Expand Up @@ -64,16 +63,18 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types.
}
}

headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
// calculate the age of the evidence
infractionHeight := evidence.GetHeight()
infractionTime := evidence.GetTime()
ageDuration := sdkCtx.HeaderInfo().Time.Sub(infractionTime)
ageBlocks := sdkCtx.BlockHeader().Height - infractionHeight
ageDuration := headerInfo.Time.Sub(infractionTime)
ageBlocks := headerInfo.Height - infractionHeight

// Reject evidence if the double-sign is too old. Evidence is considered stale
// if the difference in time and number of blocks is greater than the allowed
// parameters defined.
cp := sdkCtx.ConsensusParams()
sdkCtx := sdk.UnwrapSDKContext(ctx)
cp := sdkCtx.ConsensusParams() // TODO: remove in favor of querying consensus module
if cp.Evidence != nil {
if ageDuration > cp.Evidence.MaxAgeDuration && ageBlocks > cp.Evidence.MaxAgeNumBlocks {
logger.Info(
Expand Down
30 changes: 14 additions & 16 deletions x/evidence/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import (

"cosmossdk.io/collections"
"cosmossdk.io/core/address"
"cosmossdk.io/core/store"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
"cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/x/evidence/exported"
"cosmossdk.io/x/evidence/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Keeper defines the evidence module's keeper. The keeper is responsible for
// managing persistence, state transitions and query handling for the evidence
// module.
type Keeper struct {
cdc codec.BinaryCodec
storeService store.KVStoreService
environment appmodule.Environment
router types.Router
stakingKeeper types.StakingKeeper
slashingKeeper types.SlashingKeeper
Expand All @@ -36,13 +36,13 @@ type Keeper struct {

// NewKeeper creates a new Keeper object.
func NewKeeper(
cdc codec.BinaryCodec, storeService store.KVStoreService, stakingKeeper types.StakingKeeper,
cdc codec.BinaryCodec, env appmodule.Environment, stakingKeeper types.StakingKeeper,
slashingKeeper types.SlashingKeeper, ac address.Codec,
) *Keeper {
sb := collections.NewSchemaBuilder(storeService)
sb := collections.NewSchemaBuilder(env.KVStoreService)
k := &Keeper{
cdc: cdc,
storeService: storeService,
environment: env,
stakingKeeper: stakingKeeper,
slashingKeeper: slashingKeeper,
addressCodec: ac,
Expand All @@ -57,9 +57,8 @@ func NewKeeper(
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return sdkCtx.Logger().With("module", "x/"+types.ModuleName)
func (k Keeper) Logger() log.Logger {
return k.environment.Logger.With("module", "x/"+types.ModuleName)
}

// SetRouter sets the Evidence Handler router for the x/evidence module. Note,
Expand Down Expand Up @@ -107,13 +106,12 @@ func (k Keeper) SubmitEvidence(ctx context.Context, evidence exported.Evidence)
return errors.Wrap(types.ErrInvalidEvidence, err.Error())
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSubmitEvidence,
sdk.NewAttribute(types.AttributeKeyEvidenceHash, strings.ToUpper(hex.EncodeToString(evidence.Hash()))),
),
)
if err := k.environment.EventService.EventManager(ctx).EmitKV(
types.EventTypeSubmitEvidence,
event.NewAttribute(types.AttributeKeyEvidenceHash, strings.ToUpper(hex.EncodeToString(evidence.Hash()))),
); err != nil {
return err
}

return k.Evidences.Set(ctx, evidence.Hash(), evidence)
}
7 changes: 4 additions & 3 deletions x/evidence/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"cosmossdk.io/collections"
"cosmossdk.io/core/header"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/evidence"
"cosmossdk.io/x/evidence/exported"
Expand Down Expand Up @@ -85,7 +86,7 @@ type KeeperTestSuite struct {
func (suite *KeeperTestSuite) SetupTest() {
encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
tkey := storetypes.NewTransientStoreKey("evidence_transient_store")
testCtx := testutil.DefaultContextWithDB(suite.T(), key, tkey)
suite.ctx = testCtx.Ctx
Expand All @@ -99,7 +100,7 @@ func (suite *KeeperTestSuite) SetupTest() {

evidenceKeeper := keeper.NewKeeper(
encCfg.Codec,
storeService,
env,
stakingKeeper,
slashingKeeper,
address.NewBech32Codec("cosmos"),
Expand All @@ -124,7 +125,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.evidenceKeeper = *evidenceKeeper

suite.Require().Equal(testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName),
suite.evidenceKeeper.Logger(testCtx.Ctx))
suite.evidenceKeeper.Logger())

suite.msgServer = keeper.NewMsgServerImpl(suite.evidenceKeeper)
}
Expand Down
4 changes: 4 additions & 0 deletions x/feegrant/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### API Breaking Changes

* [#19450](https://github.com/cosmos/cosmos-sdk/pull/19450) Migrate module to use `appmodule.Environment` instead of passing individual services.

### Consens Breaking Changes

* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
Expand Down
Loading

0 comments on commit 0f8ff1e

Please sign in to comment.