Skip to content

Commit

Permalink
Merge pull request #72 from PeggyJV/bez/fix-mod-logging
Browse files Browse the repository at this point in the history
x/gravity: logger
  • Loading branch information
zmanian authored Jul 14, 2021
2 parents f7bd892 + 7872f35 commit c9c2c74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion module/x/gravity/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func createSignerSetTxs(ctx sdk.Context, k keeper.Keeper) {
powerDiff := types.EthereumSigners(k.CurrentSignerSet(ctx)).PowerDiff(latestSignerSetTx.Signers)

shouldCreate := (lastUnbondingHeight == blockHeight) || (powerDiff > 0.05)
ctx.Logger().Info("considering signer set tx creation",
k.Logger(ctx).Info(
"considering signer set tx creation",
"blockHeight", blockHeight,
"lastUnbondingHeight", lastUnbondingHeight,
"latestSignerSetTx.Nonce", latestSignerSetTx.Nonce,
Expand Down
3 changes: 2 additions & 1 deletion module/x/gravity/keeper/ethereum_event_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func (k Keeper) processEthereumEvent(ctx sdk.Context, event types.EthereumEvent)
// If the attestation fails, something has gone wrong and we can't recover it. Log and move on
// The attestation will still be marked "Observed", and validators can still be slashed for not
// having voted for it.
k.logger(ctx).Error("ethereum event vote record failed",
k.Logger(ctx).Error(
"ethereum event vote record failed",
"cause", err.Error(),
"event type", fmt.Sprintf("%T", event),
"id", types.MakeEthereumEventVoteRecordKey(event.GetEventNonce(), event.Hash()),
Expand Down
23 changes: 10 additions & 13 deletions module/x/gravity/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import (
"sort"
"strconv"

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

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

"github.com/ethereum/go-ethereum/common"

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/tendermint/tendermint/libs/log"

"github.com/peggyjv/gravity-bridge/module/x/gravity/types"
Expand Down Expand Up @@ -61,6 +58,10 @@ func NewKeeper(cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, paramSpace para
return k
}

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

/////////////////////////////
// SignerSetTxNonce //
/////////////////////////////
Expand Down Expand Up @@ -217,13 +218,13 @@ func (k Keeper) getEthereumAddressesByOrchestrator(ctx sdk.Context, orch sdk.Acc
return
}


// CreateSignerSetTx gets the current signer set from the staking keeper, increments the nonce,
// creates the signer set tx object, emits an event and sets the signer set in state
func (k Keeper) CreateSignerSetTx(ctx sdk.Context) *types.SignerSetTx {
nonce := k.incrementLatestSignerSetTxNonce(ctx)
currSignerSet := k.CurrentSignerSet(ctx)
newSignerSetTx := types.NewSignerSetTx(nonce, uint64(ctx.BlockHeight()), currSignerSet)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeMultisigUpdateRequest,
Expand All @@ -234,7 +235,8 @@ func (k Keeper) CreateSignerSetTx(ctx sdk.Context) *types.SignerSetTx {
),
)
k.SetOutgoingTx(ctx, newSignerSetTx)
ctx.Logger().Info("SignerSetTx created",
k.Logger(ctx).Info(
"SignerSetTx created",
"nonce", newSignerSetTx.Nonce,
"height", newSignerSetTx.Height,
"signers", len(newSignerSetTx.Signers),
Expand Down Expand Up @@ -333,11 +335,6 @@ func (k Keeper) getGravityID(ctx sdk.Context) string {
return a
}

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

// getDelegateKeys iterates both the EthAddress and Orchestrator address indexes to produce
// a vector of MsgDelegateKeys entries containing all the delgate keys for state
// export / import. This may seem at first glance to be excessively complicated, why not combine
Expand Down

0 comments on commit c9c2c74

Please sign in to comment.