Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement logger interface on keeper. #4625

Merged
merged 4 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions x/auth/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -42,6 +43,11 @@ func NewAccountKeeper(
}
}

// Logger returns a module-specific logger.
func (ak AccountKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/auth")
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}

// NewAccountWithAddress implements sdk.AccountKeeper.
func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) exported.Account {
acc := ak.proto()
Expand Down
7 changes: 7 additions & 0 deletions x/bank/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

"github.com/tendermint/tendermint/libs/log"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
Expand Down Expand Up @@ -209,6 +211,11 @@ func (keeper BaseViewKeeper) Codespace() sdk.CodespaceType {
return keeper.codespace
}

// Logger returns a module-specific logger.
func (keeper BaseViewKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/bank")
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}

func getCoins(ctx sdk.Context, am types.AccountKeeper, addr sdk.AccAddress) sdk.Coins {
acc := am.GetAccount(ctx, addr)
if acc == nil {
Expand Down
6 changes: 2 additions & 4 deletions x/crisis/abci.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package crisis

import (
"github.com/tendermint/tendermint/libs/log"

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

// check all registered invariants
func EndBlocker(ctx sdk.Context, k Keeper, logger log.Logger) {
func EndBlocker(ctx sdk.Context, k Keeper) {
if k.invCheckPeriod == 0 || ctx.BlockHeight()%int64(k.invCheckPeriod) != 0 {
// skip running the invariant check
return
}
k.AssertInvariants(ctx, logger)
k.AssertInvariants(ctx)
}
10 changes: 8 additions & 2 deletions x/crisis/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func NewKeeper(paramSpace params.Subspace, invCheckPeriod uint,
}
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/crisis")
}

// register routes for the
func (k *Keeper) RegisterRoute(moduleName, route string, invar sdk.Invariant) {
invarRoute := types.NewInvarRoute(moduleName, route, invar)
Expand All @@ -58,7 +63,8 @@ func (k Keeper) Invariants() []sdk.Invariant {
}

// assert all invariants
func (k Keeper) AssertInvariants(ctx sdk.Context, logger log.Logger) {
func (k Keeper) AssertInvariants(ctx sdk.Context) {
logger := k.Logger(ctx)

start := time.Now()
invarRoutes := k.Routes()
Expand All @@ -76,7 +82,7 @@ func (k Keeper) AssertInvariants(ctx sdk.Context, logger log.Logger) {
end := time.Now()
diff := end.Sub(start)

logger.With("module", "x/crisis").Info("asserted all invariants", "duration", diff, "height", ctx.BlockHeight())
logger.Info("asserted all invariants", "duration", diff, "height", ctx.BlockHeight())
}

// DONTCOVER
9 changes: 3 additions & 6 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/spf13/cobra"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -63,15 +62,13 @@ func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
type AppModule struct {
AppModuleBasic
keeper Keeper
logger log.Logger
}

// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper, logger log.Logger) AppModule {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func NewAppModule(keeper Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
logger: logger,
}
}

Expand Down Expand Up @@ -105,7 +102,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.keeper, genesisState)

am.keeper.AssertInvariants(ctx, am.logger)
am.keeper.AssertInvariants(ctx)
return []abci.ValidatorUpdate{}
}

Expand All @@ -122,6 +119,6 @@ func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) sdk.Tags {

// module end-block
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags) {
EndBlocker(ctx, am.keeper, am.logger)
EndBlocker(ctx, am.keeper)
return []abci.ValidatorUpdate{}, sdk.EmptyTags()
}
5 changes: 5 additions & 0 deletions x/mint/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/internal/types"
Expand Down Expand Up @@ -33,6 +35,9 @@ func NewKeeper(

//______________________________________________________________________

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/mint") }
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

// get the minter
func (k Keeper) GetMinter(ctx sdk.Context) (minter types.Minter) {
store := ctx.KVStore(k.storeKey)
Expand Down