- msg & query servers - clean up logging, errors - don't use sdk global config
42 lines
1016 B
Go
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)
|
|
}
|
|
}
|