laconicd/utils/context.go
Roy Crihfield b55e05e4ec [wip] laconic module fixes
- msg & query servers

- clean up logging, errors

- don't use sdk global config
2025-02-13 11:41:58 +08:00

42 lines
1016 B
Go

package utils
import (
"fmt"
"cosmossdk.io/core/gas"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const RefundModuleGasDescriptor = "laconic module gas refund"
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
}
func LogTxGasConsumed(gm gas.Meter, logger log.Logger, method string) {
gasConsumed := gm.Consumed()
logger.Info("tx executed", "method", method, "gas_consumed", fmt.Sprintf("%d", gasConsumed))
}
func TrackGasConsumption(meter gas.Meter) func(log.Logger, string) {
startGas := meter.Consumed()
return func(logger log.Logger, method string) {
endGas := meter.Consumed()
meter.Refund(endGas-startGas, RefundModuleGasDescriptor)
LogTxGasConsumed(meter, logger, method)
}
}