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

chore: use sdk.LogDeferred when closing store iterators #3021

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (stri
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.PortKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var ports []string
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (k Keeper) IsActiveChannelClosed(ctx sdk.Context, connectionID, portID stri
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var activeChannels []genesistypes.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func MigrateICS27ChannelCapability(
// construct a prefix store using the x/capability index prefix: index->capability owners
prefixStore := prefix.NewStore(ctx.KVStore(capabilityStoreKey), capabilitytypes.KeyPrefixIndexCapability)
iterator := sdk.KVStorePrefixIterator(prefixStore, nil)
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

for ; iterator.Valid(); iterator.Next() {
// unmarshal the capability index value and set of owners
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v6_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -191,7 +192,7 @@ func (suite *MigrationsTestSuite) ResetMemStore() {
memStore.Delete(capabilitytypes.KeyMemInitialized)

iterator := memStore.Iterator(nil, nil)
defer iterator.Close()
defer sdk.LogDeferred(suite.chainA.GetContext().Logger(), func() error { return iterator.Close() })

for ; iterator.Valid(); iterator.Next() {
memStore.Delete(iterator.Key())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var activeChannels []genesistypes.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
Expand Down
12 changes: 6 additions & 6 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool {
func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeEnabledKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var enabledChArr []types.FeeEnabledChannel
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -171,7 +171,7 @@ func (k Keeper) SetPayeeAddress(ctx sdk.Context, relayerAddr, payeeAddr, channel
func (k Keeper) GetAllPayees(ctx sdk.Context) []types.RegisteredPayee {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PayeeKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var registeredPayees []types.RegisteredPayee
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID
func (k Keeper) GetAllCounterpartyPayees(ctx sdk.Context) []types.RegisteredCounterpartyPayee {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.CounterpartyPayeeKeyPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var registeredCounterpartyPayees []types.RegisteredCounterpartyPayee
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -259,7 +259,7 @@ func (k Keeper) GetRelayerAddressForAsyncAck(ctx sdk.Context, packetID channelty
func (k Keeper) GetAllForwardRelayerAddresses(ctx sdk.Context) []types.ForwardRelayerAddress {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.ForwardRelayerPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var forwardRelayerAddr []types.ForwardRelayerAddress
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -327,7 +327,7 @@ func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, chann
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyFeesInEscrowChannelPrefix(portID, channelID))

defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
packetID, err := types.ParseKeyFeesInEscrow(string(iterator.Key()))
if err != nil {
Expand All @@ -347,7 +347,7 @@ func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, chann
func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPacketFees {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var identifiedFees []types.IdentifiedPacketFees
for ; iterator.Valid(); iterator.Next() {
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (k Keeper) IterateDenomTraces(ctx sdk.Context, cb func(denomTrace types.Den
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.DenomTraceKey)

defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {

denomTrace := k.MustUnmarshalDenomTrace(iterator.Value())
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string,
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix)

defer iterator.Close()
defer sdk.LogDeferred(ctx.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 Down Expand Up @@ -357,7 +357,7 @@ func (k Keeper) IterateClientStates(ctx sdk.Context, prefix []byte, cb func(clie
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, host.PrefixedClientStoreKey(prefix))

defer iterator.Close()
defer sdk.LogDeferred(ctx.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/migrations/v7/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func collectClients(ctx sdk.Context, store sdk.KVStore, clientType string) (clie
clientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, clientType))
iterator := sdk.KVStorePrefixIterator(store, clientPrefix)

defer iterator.Close()
defer sdk.LogDeferred(ctx.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/03-connection/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (k Keeper) IterateConnections(ctx sdk.Context, cb func(types.IdentifiedConn
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(host.KeyConnectionPrefix))

defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
var connection types.ConnectionEnd
k.cdc.MustUnmarshal(iterator.Value(), &connection)
Expand Down
10 changes: 5 additions & 5 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (k Keeper) HasPacketAcknowledgement(ctx sdk.Context, portID, channelID stri
// For each sequence, cb will be called. If the cb returns true, the iterator
// will close and stop.
func (k Keeper) IteratePacketSequence(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64) bool) {
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
portID, channelID, err := host.ParseChannelPath(string(iterator.Key()))
if err != nil {
Expand Down Expand Up @@ -371,7 +371,7 @@ func (k Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(host.KeyChannelEndPrefix))

defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })
for ; iterator.Valid(); iterator.Next() {
var channel types.Channel
k.cdc.MustUnmarshal(iterator.Value(), &channel)
Expand All @@ -392,7 +392,7 @@ func (k Keeper) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string)
}
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.FilteredPortPrefix(portPrefix))
defer iterator.Close()
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

var filteredChannels []types.IdentifiedChannel
for ; iterator.Valid(); iterator.Next() {
Expand Down Expand Up @@ -473,8 +473,8 @@ func (k Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string)
}

// common functionality for IteratePacketCommitment and IteratePacketAcknowledgement
func (k Keeper) iterateHashes(_ sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) {
defer iterator.Close()
func (k Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) {
defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() })

for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")
Expand Down