Skip to content

Commit

Permalink
chore: caching paramset (#198)
Browse files Browse the repository at this point in the history
* chore: implement cache for param set

* chore: caching copied object

* fix: invalidate cached param set when it's field is updated

* chore: implement Subspace pointer receiver

* fix: modify cache method

* chore: fix lint error

* chore: fix lint error

* chore: add comment about concurrency of cache functions
  • Loading branch information
Woosang Son authored May 21, 2021
1 parent 623dd8c commit dc15595
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 70 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (app *SimApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
// GetSubspace returns a param subspace for a given module name.
//
// NOTE: This is solely to be used for testing purposes.
func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace {
func (app *SimApp) GetSubspace(moduleName string) *paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}
Expand Down
4 changes: 2 additions & 2 deletions x/auth/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type AccountKeeperI interface {
type AccountKeeper struct {
key sdk.StoreKey
cdc codec.BinaryMarshaler
paramSubspace paramtypes.Subspace
paramSubspace *paramtypes.Subspace
permAddrs map[string]types.PermissionsForAddress

// The prototypical AccountI constructor.
Expand All @@ -61,7 +61,7 @@ var _ AccountKeeperI = &AccountKeeper{}
// NewAccountKeeper returns a new AccountKeeperI that uses go-amino to
// (binary) encode and decode concrete sdk.Accounts.
func NewAccountKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI,
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramstore *paramtypes.Subspace, proto func() types.AccountI,
maccPerms map[string][]string,
) AccountKeeper {

Expand Down
4 changes: 3 additions & 1 deletion x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (suite *IntegrationTestSuite) TestQueryParams() {
res, err := suite.queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(suite.app.BankKeeper.GetParams(suite.ctx), res.GetParams())
param := suite.app.BankKeeper.GetParams(suite.ctx)
suite.Require().Equal(len(param.SendEnabled), len(res.GetParams().SendEnabled))
suite.Require().Equal(param.DefaultSendEnabled, res.GetParams().DefaultSendEnabled)
}

func (suite *IntegrationTestSuite) QueryDenomsMetadataRequest() {
Expand Down
4 changes: 2 additions & 2 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ type BaseKeeper struct {
ak types.AccountKeeper
cdc codec.BinaryMarshaler
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace
}

func NewBaseKeeper(
cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace,
cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace *paramtypes.Subspace,
blockedAddrs map[string]bool,
) BaseKeeper {

Expand Down
4 changes: 2 additions & 2 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ type BaseSendKeeper struct {
cdc codec.BinaryMarshaler
ak types.AccountKeeper
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace

// list of addresses that are restricted from receiving transactions
blockedAddrs map[string]bool
}

func NewBaseSendKeeper(
cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool,
cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace *paramtypes.Subspace, blockedAddrs map[string]bool,
) BaseSendKeeper {

return BaseSendKeeper{
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Keeper - crisis keeper
type Keeper struct {
routes []types.InvarRoute
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace
invCheckPeriod uint

supplyKeeper types.SupplyKeeper
Expand All @@ -24,7 +24,7 @@ type Keeper struct {

// NewKeeper creates a new Keeper object
func NewKeeper(
paramSpace paramtypes.Subspace, invCheckPeriod uint, supplyKeeper types.SupplyKeeper,
paramSpace *paramtypes.Subspace, invCheckPeriod uint, supplyKeeper types.SupplyKeeper,
feeCollectorName string,
) Keeper {

Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
Expand All @@ -28,7 +28,7 @@ type Keeper struct {

// NewKeeper creates a new distribution Keeper instance
func NewKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace *paramtypes.Subspace,
ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
feeCollectorName string, blockedAddrs map[string]bool,
) Keeper {
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/applications/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace

channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
Expand All @@ -32,7 +32,7 @@ type Keeper struct {

// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace *paramtypes.Subspace,
channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
) Keeper {
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace
stakingKeeper types.StakingKeeper
}

// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper) Keeper {
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace *paramtypes.Subspace, sk types.StakingKeeper) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Keeper struct {

// NewKeeper creates a new ibc Keeper
func NewKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace *paramtypes.Subspace,
stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
) *Keeper {
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper)
Expand Down
4 changes: 2 additions & 2 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
type Keeper struct {
cdc codec.BinaryMarshaler
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
paramSpace *paramtypes.Subspace
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
}

// NewKeeper creates a new mint Keeper instance
func NewKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace *paramtypes.Subspace,
sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper,
feeCollectorName string,
) Keeper {
Expand Down
2 changes: 1 addition & 1 deletion x/params/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
var (
req *proposal.QueryParamsRequest
expValue string
space types.Subspace
space *types.Subspace
)
key := []byte("key")

Expand Down
10 changes: 5 additions & 5 deletions x/params/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// Allocate subspace used for keepers
func (k Keeper) Subspace(s string) types.Subspace {
func (k Keeper) Subspace(s string) *types.Subspace {
_, ok := k.spaces[s]
if ok {
panic("subspace already occupied")
Expand All @@ -46,16 +46,16 @@ func (k Keeper) Subspace(s string) types.Subspace {
}

space := types.NewSubspace(k.cdc, k.legacyAmino, k.key, k.tkey, s)
k.spaces[s] = &space
k.spaces[s] = space

return space
}

// Get existing substore from keeper
func (k Keeper) GetSubspace(s string) (types.Subspace, bool) {
func (k Keeper) GetSubspace(s string) (*types.Subspace, bool) {
space, ok := k.spaces[s]
if !ok {
return types.Subspace{}, false
return &types.Subspace{}, false
}
return *space, ok
return space, ok
}
Loading

0 comments on commit dc15595

Please sign in to comment.