Use custom KV store config to handle progressively increasing gas usage (#30)

Part of [Create an external fixturenet-laconicd stack](https://www.notion.so/Create-an-external-fixturenet-laconicd-stack-3b33cc2317444f4da209c4472f4244ed)

Reviewed-on: cerc-io/laconic2d#30
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
2024-06-25 06:33:41 +00:00
committed by ashwin
parent 66df959d51
commit e63f51cacd
5 changed files with 93 additions and 0 deletions
+6
View File
@@ -10,6 +10,7 @@ import (
"cosmossdk.io/collections/indexes"
"cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -84,6 +85,11 @@ func NewKeeper(
return &k
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", bondtypes.ModuleName)
}
func (k *Keeper) SetUsageKeepers(usageKeepers []bondtypes.BondUsageKeeper) {
if k.usageKeepers != nil {
panic("cannot set bond hooks twice")
+13
View File
@@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconicd/utils"
"git.vdb.to/cerc-io/laconicd/x/bond"
)
@@ -25,6 +26,7 @@ func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bon
}
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@@ -49,6 +51,8 @@ func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bon
),
})
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CreateBond")
return &bond.MsgCreateBondResponse{Id: resp.Id}, nil
}
@@ -59,6 +63,7 @@ func (ms msgServer) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*bon
}
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@@ -84,6 +89,8 @@ func (ms msgServer) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*bon
),
})
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RefillBond")
return &bond.MsgRefillBondResponse{}, nil
}
@@ -94,6 +101,7 @@ func (ms msgServer) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond) (
}
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@@ -119,6 +127,8 @@ func (ms msgServer) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond) (
),
})
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "WithdrawBond")
return &bond.MsgWithdrawBondResponse{}, nil
}
@@ -129,6 +139,7 @@ func (ms msgServer) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*bon
}
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@@ -153,5 +164,7 @@ func (ms msgServer) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*bon
),
})
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CancelBond")
return &bond.MsgCancelBondResponse{}, nil
}