Fix progressively increasing gas usage #146

Merged
ashwin merged 4 commits from deep-stack/laconicd:pm-registry-hot-fix into main 2024-04-03 12:14:50 +00:00
4 changed files with 58 additions and 19 deletions
Showing only changes of commit ea30697b50 - Show all commits

20
utils/context.go Normal file
View File

@ -0,0 +1,20 @@
package utils
import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
updatedCtx := ctx.WithKVGasConfig(storetypes.GasConfig{
HasCost: 0,
DeleteCost: 0,
ReadCostFlat: 0,
ReadCostPerByte: 0,
WriteCostFlat: 0,
WriteCostPerByte: 0,
IterNextCostFlat: 0,
})
return &updatedCtx
}

View File

@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cerc-io/laconicd/utils"
"github.com/cerc-io/laconicd/x/auction/types"
)
@ -20,6 +21,7 @@ var _ types.MsgServer = msgServer{}
func (s msgServer) CreateAuction(c context.Context, msg *types.MsgCreateAuction) (*types.MsgCreateAuctionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@ -53,6 +55,7 @@ func (s msgServer) CreateAuction(c context.Context, msg *types.MsgCreateAuction)
//nolint: all
func (s msgServer) CommitBid(c context.Context, msg *types.MsgCommitBid) (*types.MsgCommitBidResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@ -80,10 +83,11 @@ func (s msgServer) CommitBid(c context.Context, msg *types.MsgCommitBid) (*types
return &types.MsgCommitBidResponse{Bid: resp}, nil
}
//RevealBid is the command for revealing a bid
// RevealBid is the command for revealing a bid
//nolint: all
func (s msgServer) RevealBid(c context.Context, msg *types.MsgRevealBid) (*types.MsgRevealBidResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {

View File

@ -3,8 +3,10 @@ package keeper
import (
"context"
"github.com/cerc-io/laconicd/x/bond/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cerc-io/laconicd/utils"
"github.com/cerc-io/laconicd/x/bond/types"
)
type msgServer struct {
@ -20,6 +22,8 @@ var _ types.MsgServer = msgServer{}
func (k msgServer) CreateBond(c context.Context, msg *types.MsgCreateBond) (*types.MsgCreateBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -48,6 +52,8 @@ func (k msgServer) CreateBond(c context.Context, msg *types.MsgCreateBond) (*typ
//nolint: all
func (k msgServer) RefillBond(c context.Context, msg *types.MsgRefillBond) (*types.MsgRefillBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -78,6 +84,8 @@ func (k msgServer) RefillBond(c context.Context, msg *types.MsgRefillBond) (*typ
//nolint: all
func (k msgServer) WithdrawBond(c context.Context, msg *types.MsgWithdrawBond) (*types.MsgWithdrawBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -107,6 +115,8 @@ func (k msgServer) WithdrawBond(c context.Context, msg *types.MsgWithdrawBond) (
func (k msgServer) CancelBond(c context.Context, msg *types.MsgCancelBond) (*types.MsgCancelBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err

View File

@ -3,10 +3,10 @@ package keeper
import (
"context"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cerc-io/laconicd/x/registry/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cerc-io/laconicd/utils"
"github.com/cerc-io/laconicd/x/registry/types"
)
type msgServer struct {
@ -22,7 +22,7 @@ var _ types.MsgServer = msgServer{}
func (m msgServer) SetRecord(c context.Context, msg *types.MsgSetRecord) (*types.MsgSetRecordResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *m.ctxWithCustomKVGasConfig(&ctx)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
@ -54,6 +54,8 @@ func (m msgServer) SetRecord(c context.Context, msg *types.MsgSetRecord) (*types
//nolint: all
func (m msgServer) SetName(c context.Context, msg *types.MsgSetName) (*types.MsgSetNameResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -80,6 +82,8 @@ func (m msgServer) SetName(c context.Context, msg *types.MsgSetName) (*types.Msg
func (m msgServer) ReserveName(c context.Context, msg *types.MsgReserveAuthority) (*types.MsgReserveAuthorityResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -111,6 +115,8 @@ func (m msgServer) ReserveName(c context.Context, msg *types.MsgReserveAuthority
//nolint: all
func (m msgServer) SetAuthorityBond(c context.Context, msg *types.MsgSetAuthorityBond) (*types.MsgSetAuthorityBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -137,6 +143,8 @@ func (m msgServer) SetAuthorityBond(c context.Context, msg *types.MsgSetAuthorit
func (m msgServer) DeleteName(c context.Context, msg *types.MsgDeleteNameAuthority) (*types.MsgDeleteNameAuthorityResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -162,6 +170,8 @@ func (m msgServer) DeleteName(c context.Context, msg *types.MsgDeleteNameAuthori
func (m msgServer) RenewRecord(c context.Context, msg *types.MsgRenewRecord) (*types.MsgRenewRecordResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -188,6 +198,8 @@ func (m msgServer) RenewRecord(c context.Context, msg *types.MsgRenewRecord) (*t
//nolint: all
func (m msgServer) AssociateBond(c context.Context, msg *types.MsgAssociateBond) (*types.MsgAssociateBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -215,6 +227,8 @@ func (m msgServer) AssociateBond(c context.Context, msg *types.MsgAssociateBond)
func (m msgServer) DissociateBond(c context.Context, msg *types.MsgDissociateBond) (*types.MsgDissociateBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -240,6 +254,8 @@ func (m msgServer) DissociateBond(c context.Context, msg *types.MsgDissociateBon
func (m msgServer) DissociateRecords(c context.Context, msg *types.MsgDissociateRecords) (*types.MsgDissociateRecordsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -265,6 +281,8 @@ func (m msgServer) DissociateRecords(c context.Context, msg *types.MsgDissociate
func (m msgServer) ReAssociateRecords(c context.Context, msg *types.MsgReAssociateRecords) (*types.MsgReAssociateRecordsResponse, error) { //nolint: all
ctx := sdk.UnwrapSDKContext(c)
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -288,16 +306,3 @@ func (m msgServer) ReAssociateRecords(c context.Context, msg *types.MsgReAssocia
})
return &types.MsgReAssociateRecordsResponse{}, nil
}
func (m msgServer) ctxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
updatedCtx := ctx.WithKVGasConfig(storetypes.GasConfig{
HasCost: 0,
DeleteCost: 0,
ReadCostFlat: 0,
ReadCostPerByte: 0,
WriteCostFlat: 0,
WriteCostPerByte: 0,
IterNextCostFlat: 0,
})
return &updatedCtx
}