Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 6, 2024
1 parent 3416353 commit 69863a1
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 160 deletions.
10 changes: 5 additions & 5 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, c
}

initialHeight := clientModule.LatestHeight(ctx, clientID)
k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", initialHeight.String())
k.Logger.Info("client created at height", "client-id", clientID, "height", initialHeight.String())

defer telemetry.ReportCreateClient(clientType)
emitCreateClientEvent(ctx, k.Environment, clientID, clientType, initialHeight)
Expand All @@ -63,7 +63,7 @@ func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg export
if foundMisbehaviour {
clientModule.UpdateStateOnMisbehaviour(ctx, clientID, clientMsg)

k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", clientID)
k.Logger.Info("client frozen due to misbehaviour", "client-id", clientID)

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpdateClient(foundMisbehaviour, clientType, clientID)
Expand All @@ -74,7 +74,7 @@ func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg export

consensusHeights := clientModule.UpdateState(ctx, clientID, clientMsg)

k.Logger(ctx).Info("client state updated", "client-id", clientID, "heights", consensusHeights)
k.Logger.Info("client state updated", "client-id", clientID, "heights", consensusHeights)

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpdateClient(foundMisbehaviour, clientType, clientID)
Expand Down Expand Up @@ -104,7 +104,7 @@ func (k *Keeper) UpgradeClient(
}

latestHeight := clientModule.LatestHeight(ctx, clientID)
k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", latestHeight.String())
k.Logger.Info("client state upgraded", "client-id", clientID, "height", latestHeight.String())

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpgradeClient(clientType, clientID)
Expand Down Expand Up @@ -142,7 +142,7 @@ func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClien
return err
}

k.Logger(ctx).Info("client recovered", "client-id", subjectClientID)
k.Logger.Info("client recovered", "client-id", subjectClientID)

clientType := types.MustParseClientIdentifier(subjectClientID)
defer telemetry.ReportRecoverClient(clientType, subjectClientID)
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (q *queryServer) VerifyMembership(c context.Context, req *types.QueryVerify
)

if err := clientModule.VerifyMembership(cachedCtx, req.ClientId, req.ProofHeight, req.TimeDelay, req.BlockDelay, req.Proof, req.MerklePath, req.Value); err != nil {
q.Logger(ctx).Debug("proof verification failed", "key", req.MerklePath, "error", err)
q.Logger.Debug("proof verification failed", "key", req.MerklePath, "error", err)
return &types.QueryVerifyMembershipResponse{
Success: false,
}, nil
Expand Down
17 changes: 8 additions & 9 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"cosmossdk.io/core/appmodule"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand Down Expand Up @@ -55,11 +54,11 @@ func (k *Keeper) Codec() codec.BinaryCodec {
return k.cdc
}

// Logger returns a module-specific logger.
func (Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName)
}
// // Logger returns a module-specific logger.
// func (Keeper) Logger(ctx context.Context) log.Logger {
// sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
// return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName)
// }

// AddRoute adds a new route to the underlying router.
func (k *Keeper) AddRoute(clientType string, module exported.LightClientModule) {
Expand Down Expand Up @@ -170,7 +169,7 @@ func (k *Keeper) IterateConsensusStates(ctx context.Context, cb func(clientID st
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix)

defer coretypes.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() })
defer coretypes.LogDeferred(k.Logger, func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")
// consensus key is in the format "clients/<clientID>/consensusStates/<height>"
Expand All @@ -195,7 +194,7 @@ func (k *Keeper) iterateMetadata(ctx context.Context, cb func(clientID string, k
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix)

defer coretypes.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() })
defer coretypes.LogDeferred(k.Logger, func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
split := strings.Split(string(iterator.Key()), "/")
if len(split) == 3 && split[2] == string(host.KeyClientState) {
Expand Down Expand Up @@ -361,7 +360,7 @@ func (k *Keeper) IterateClientStates(ctx context.Context, storePrefix []byte, cb
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
iterator := storetypes.KVStorePrefixIterator(store, host.PrefixedClientStoreKey(storePrefix))

defer coretypes.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() })
defer coretypes.LogDeferred(k.Logger, func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
path := string(iterator.Key())
if !strings.Contains(path, host.KeyClientState) {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (m Migrator) MigrateParams(ctx sdk.Context) error {
}

m.keeper.SetParams(ctx, params)
m.keeper.Logger(ctx).Info("successfully migrated client to self-manage params")
m.keeper.Logger.Info("successfully migrated client to self-manage params")
return nil
}

Expand Down
24 changes: 7 additions & 17 deletions modules/core/03-connection/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"cosmossdk.io/store/prefix"

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

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
Expand All @@ -34,7 +33,7 @@ func NewQueryServer(k *Keeper) types.QueryServer {
}

// Connection implements the Query/Connection gRPC method
func (q *queryServer) Connection(c context.Context, req *types.QueryConnectionRequest) (*types.QueryConnectionResponse, error) {
func (q *queryServer) Connection(ctx context.Context, req *types.QueryConnectionRequest) (*types.QueryConnectionResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -43,7 +42,6 @@ func (q *queryServer) Connection(c context.Context, req *types.QueryConnectionRe
return nil, status.Error(codes.InvalidArgument, err.Error())
}

ctx := sdk.UnwrapSDKContext(c)
connection, found := q.GetConnection(ctx, req.ConnectionId)
if !found {
return nil, status.Error(
Expand All @@ -59,16 +57,14 @@ func (q *queryServer) Connection(c context.Context, req *types.QueryConnectionRe
}

// Connections implements the Query/Connections gRPC method
func (q *queryServer) Connections(c context.Context, req *types.QueryConnectionsRequest) (*types.QueryConnectionsResponse, error) {
func (q *queryServer) Connections(ctx context.Context, req *types.QueryConnectionsRequest) (*types.QueryConnectionsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

var connections []*types.IdentifiedConnection

store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), []byte(host.KeyConnectionPrefix))
store := prefix.NewStore(runtime.KVStoreAdapter(q.KVStoreService.OpenKVStore(ctx)), []byte(host.KeyConnectionPrefix))

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
var result types.ConnectionEnd
Expand Down Expand Up @@ -97,7 +93,7 @@ func (q *queryServer) Connections(c context.Context, req *types.QueryConnections
}

// ClientConnections implements the Query/ClientConnections gRPC method
func (q *queryServer) ClientConnections(c context.Context, req *types.QueryClientConnectionsRequest) (*types.QueryClientConnectionsResponse, error) {
func (q *queryServer) ClientConnections(ctx context.Context, req *types.QueryClientConnectionsRequest) (*types.QueryClientConnectionsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -106,7 +102,6 @@ func (q *queryServer) ClientConnections(c context.Context, req *types.QueryClien
return nil, status.Error(codes.InvalidArgument, err.Error())
}

ctx := sdk.UnwrapSDKContext(c)
clientConnectionPaths, found := q.GetClientConnectionPaths(ctx, req.ClientId)
if !found {
return nil, status.Error(
Expand All @@ -122,7 +117,7 @@ func (q *queryServer) ClientConnections(c context.Context, req *types.QueryClien
}

// ConnectionClientState implements the Query/ConnectionClientState gRPC method
func (q *queryServer) ConnectionClientState(c context.Context, req *types.QueryConnectionClientStateRequest) (*types.QueryConnectionClientStateResponse, error) {
func (q *queryServer) ConnectionClientState(ctx context.Context, req *types.QueryConnectionClientStateRequest) (*types.QueryConnectionClientStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -131,8 +126,6 @@ func (q *queryServer) ConnectionClientState(c context.Context, req *types.QueryC
return nil, status.Error(codes.InvalidArgument, err.Error())
}

ctx := sdk.UnwrapSDKContext(c)

connection, found := q.GetConnection(ctx, req.ConnectionId)
if !found {
return nil, status.Error(
Expand All @@ -156,7 +149,7 @@ func (q *queryServer) ConnectionClientState(c context.Context, req *types.QueryC
}

// ConnectionConsensusState implements the Query/ConnectionConsensusState gRPC method
func (q *queryServer) ConnectionConsensusState(c context.Context, req *types.QueryConnectionConsensusStateRequest) (*types.QueryConnectionConsensusStateResponse, error) {
func (q *queryServer) ConnectionConsensusState(ctx context.Context, req *types.QueryConnectionConsensusStateRequest) (*types.QueryConnectionConsensusStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -165,8 +158,6 @@ func (q *queryServer) ConnectionConsensusState(c context.Context, req *types.Que
return nil, status.Error(codes.InvalidArgument, err.Error())
}

ctx := sdk.UnwrapSDKContext(c)

connection, found := q.GetConnection(ctx, req.ConnectionId)
if !found {
return nil, status.Error(
Expand Down Expand Up @@ -194,8 +185,7 @@ func (q *queryServer) ConnectionConsensusState(c context.Context, req *types.Que
}

// ConnectionParams implements the Query/ConnectionParams gRPC method.
func (q *queryServer) ConnectionParams(c context.Context, req *types.QueryConnectionParamsRequest) (*types.QueryConnectionParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
func (q *queryServer) ConnectionParams(ctx context.Context, req *types.QueryConnectionParamsRequest) (*types.QueryConnectionParamsResponse, error) {
params := q.GetParams(ctx)

return &types.QueryConnectionParamsResponse{
Expand Down
8 changes: 4 additions & 4 deletions modules/core/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (k *Keeper) ConnOpenInit(
connection := types.NewConnectionEnd(types.INIT, clientID, counterparty, versions, delayPeriod)
k.SetConnection(ctx, connectionID, connection)

k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.UNINITIALIZED, "new-state", types.INIT)
k.Logger.Info("connection state updated", "connection-id", connectionID, "previous-state", types.UNINITIALIZED, "new-state", types.INIT)

defer telemetry.IncrCounter(1, "ibc", "connection", "open-init")

Expand Down Expand Up @@ -106,7 +106,7 @@ func (k *Keeper) ConnOpenTry(
}

k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.UNINITIALIZED, "new-state", types.TRYOPEN)
k.Logger.Info("connection state updated", "connection-id", connectionID, "previous-state", types.UNINITIALIZED, "new-state", types.TRYOPEN)

defer telemetry.IncrCounter(1, "ibc", "connection", "open-try")

Expand Down Expand Up @@ -161,7 +161,7 @@ func (k *Keeper) ConnOpenAck(
return err
}

k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.INIT, "new-state", types.OPEN)
k.Logger.Info("connection state updated", "connection-id", connectionID, "previous-state", types.INIT, "new-state", types.OPEN)

defer telemetry.IncrCounter(1, "ibc", "connection", "open-ack")

Expand Down Expand Up @@ -215,7 +215,7 @@ func (k *Keeper) ConnOpenConfirm(
// Update ChainB's connection to Open
connection.State = types.OPEN
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.TRYOPEN, "new-state", types.OPEN)
k.Logger.Info("connection state updated", "connection-id", connectionID, "previous-state", types.TRYOPEN, "new-state", types.OPEN)

defer telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")

Expand Down
Loading

0 comments on commit 69863a1

Please sign in to comment.