laconicd/utils/context.go
Roy Crihfield 5aa2594073 Integrate go-nitro
- Add nitro server and x/nitro module
    - wire go-nitro p2p through cometbft

- Add distsig server, currently WIP
    - integrate DKG and DSS schemes into ABCI methods

- Remove deprecated features
    - crisis module
    - module invariants

- Update to use newer SDK patterns
    - upgrade sdk to v0.53.x
    - custom address codec
    - expand use of depinject
    - migrate e2e tests to system tests
    - use depinject to set up integration tests
    - change reserved protobuf field name `cerc.registry.v1.Record.type`

- Revise & add documentation
    - TransferCoinsToModuleAccount: clarify function

- Update init.sh script
2025-09-21 11:44:44 +08:00

40 lines
1.4 KiB
Go

package utils
import (
"context"
"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"
// WithCustomGasConfig returns a context with a zero-cost gas config, and a function to log all consumed gas.
//
// Note: as planned in server/v2, the gas meter will not be available on the STF-provided context
// during tx execution, and must be accessed via gas.Service instead. This arg is a placeholder
// to ensure modules using this include the gas service in anticipation of that change.
// https://github.com/cosmos/cosmos-sdk/pull/16310
func WithCustomGasConfig(ctx context.Context, _ gas.Service) (context.Context, func(log.Logger, string)) {
c := sdk.UnwrapSDKContext(ctx)
meter := c.GasMeter()
startGas := meter.GasConsumed()
logGas := func(logger log.Logger, method string) {
endGas := meter.GasConsumed()
meter.RefundGas(endGas-startGas, RefundModuleGasDescriptor)
LogTxGasConsumed(meter, logger, method)
}
// Set a zero-cost gas config on the returned context
return c.WithKVGasConfig(storetypes.GasConfig{}), logGas
}
func LogTxGasConsumed(gm gas.Meter, logger log.Logger, method string) {
gasConsumed := gm.GasConsumed()
logger.Info("tx executed", "method", method, "gas_consumed", fmt.Sprintf("%d", gasConsumed))
}