From ea30697b509be4371d41682c00223cebb054f206 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 3 Apr 2024 11:44:03 +0530 Subject: [PATCH] Use custom KV store gas config for all laconic txs --- utils/context.go | 20 +++++++++++++++++ x/auction/keeper/msg_server.go | 6 ++++- x/bond/keeper/msg_server.go | 12 +++++++++- x/registry/keeper/msg_server.go | 39 +++++++++++++++++++-------------- 4 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 utils/context.go diff --git a/utils/context.go b/utils/context.go new file mode 100644 index 00000000..f7393662 --- /dev/null +++ b/utils/context.go @@ -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 +} diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go index 75a97ab6..08fa8755 100644 --- a/x/auction/keeper/msg_server.go +++ b/x/auction/keeper/msg_server.go @@ -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 { diff --git a/x/bond/keeper/msg_server.go b/x/bond/keeper/msg_server.go index 7db7394f..cc197237 100644 --- a/x/bond/keeper/msg_server.go +++ b/x/bond/keeper/msg_server.go @@ -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 diff --git a/x/registry/keeper/msg_server.go b/x/registry/keeper/msg_server.go index 647e3354..7f695ee8 100644 --- a/x/registry/keeper/msg_server.go +++ b/x/registry/keeper/msg_server.go @@ -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 -}