Skip to content

Commit

Permalink
Use Logger in EndBlocker
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Nov 28, 2023
1 parent 2070db6 commit b301d75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 9 additions & 7 deletions x/clock/abci.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package clock

import (
"log"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
Expand All @@ -11,18 +10,21 @@ import (
"github.com/CosmosContracts/juno/v18/x/clock/types"
)

var (

Check failure on line 13 in x/clock/abci.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
endBlockSudoMessage = []byte(types.EndBlockSudoMessage)
)

// EndBlocker executes on contracts at the end of the block.
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)

message := []byte(types.EndBlockSudoMessage)

logger := k.Logger(ctx)
p := k.GetParams(ctx)

// Get all contracts
contracts, err := k.GetAllContracts(ctx)
if err != nil {
log.Printf("[x/clock] Failed to get contracts: %v", err)
logger.Error("Failed to get contracts", "error", err)
return
}

Expand All @@ -42,7 +44,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
// Attempt to jail contract, log error if present
err := k.SetJailStatus(ctx, contractAddress, true)
if err != nil {
log.Printf("[x/clock] Failed to Error Contract %s: %v", contractAddress, err)
logger.Error("Failed to jail contract", "contract", contractAddress, "error", err)
}
}

Expand All @@ -67,14 +69,14 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
childCtx := ctx.WithGasMeter(sdk.NewGasMeter(p.ContractGasLimit))

// Execute contract
_, err = k.GetContractKeeper().Sudo(childCtx, contractAddr, message)
_, err = k.GetContractKeeper().Sudo(childCtx, contractAddr, endBlockSudoMessage)
if handleError(err, idx, contract.ContractAddress) {
continue
}
}

// Log errors if present
if errorExists {
log.Printf("[x/clock] Execute Errors: %v", errorExecs)
logger.Error("Failed to execute contracts", "contracts", errorExecs)
}
}
7 changes: 7 additions & 0 deletions x/clock/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

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

Check failure on line 4 in x/clock/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

Check failure on line 8 in x/clock/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
Expand Down Expand Up @@ -38,6 +40,11 @@ func NewKeeper(
}
}

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

// GetAuthority returns the x/clock module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
Expand Down

0 comments on commit b301d75

Please sign in to comment.