@@ -5,21 +5,17 @@ import (
55
66 storetypes "cosmossdk.io/store/types"
77 sdk "github.com/cosmos/cosmos-sdk/types"
8- gnostore "github.com/gnolang/gno/tm2/pkg/store"
98
10- "github.com/ignite/gnovm/x/gnovm/keeper"
119 "github.com/ignite/gnovm/x/gnovm/types"
1210)
1311
14- func NewAnteHandler (k * keeper. Keeper ) sdk.AnteDecorator {
15- return & gnoAnteHandler {keeper : k }
12+ func NewAnteHandler () sdk.AnteDecorator {
13+ return & gnoAnteHandler {}
1614}
1715
18- type gnoAnteHandler struct {
19- keeper * keeper.Keeper
20- }
16+ type gnoAnteHandler struct {}
2117
22- func (gad * gnoAnteHandler ) AnteHandle (ctx sdk.Context , tx sdk.Tx , simulate bool , next sdk.AnteHandler ) (newCtx sdk.Context , err error ) {
18+ func (gnoAnteHandler ) AnteHandle (ctx sdk.Context , tx sdk.Tx , simulate bool , next sdk.AnteHandler ) (newCtx sdk.Context , err error ) {
2319 msgs := tx .GetMsgs ()
2420
2521 gnoVMCount := 0
@@ -37,56 +33,13 @@ func (gad *gnoAnteHandler) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
3733 }
3834
3935 // Reject transactions that mix GnoVM and non-GnoVM messages
40- // This is necessary because they use different gas accounting mechanisms
4136 if gnoVMCount > 0 && nonGnoVMCount > 0 {
4237 return ctx , fmt .Errorf ("cannot mix GnoVM messages with non-GnoVM messages in the same transaction" )
4338 }
4439
45- if gnoVMCount == 0 {
46- return next (ctx , tx , simulate )
47- }
48-
49- // Get the gas limit from the current SDK context
50- // This was set by earlier ante handlers based on the transaction's gas wanted
51- gasLimit := ctx .GasMeter ().Limit ()
52-
53- // Use infinite gas meter in the SDK context to prevent double-counting
54- // The GnoVM has its own internal gas tracking mechanism through the transaction store
55- newCtx = ctx .WithGasMeter (storetypes .NewInfiniteGasMeter ())
56- gnoCtx , err := gad .keeper .BuildGnoContext (newCtx )
57- if err != nil {
58- return ctx , fmt .Errorf ("failed to build gno context: %w" , err )
59- }
60-
61- if ! simulate {
62- gnoCtx = gnoCtx .WithGasMeter (gnostore .NewGasMeter (gnostore .Gas (gasLimit )))
63- }
64-
65- // Set up defer/recover to handle gas consumption and out-of-gas errors
66- // This pattern follows the Gno tm2/pkg/sdk/auth/ante.go implementation
67- defer func () {
68- if r := recover (); r != nil {
69- switch ex := r .(type ) {
70- case gnostore.OutOfGasError :
71- gasConsumed := gnoCtx .GasMeter ().GasConsumed ()
72-
73- log := fmt .Sprintf (
74- "out of gas in location: %s; gasConsumed: %d, gasLimit: %d" ,
75- ex .Descriptor , gasConsumed , gasLimit ,
76- )
77- err = fmt .Errorf ("out of gas: %s" , log )
78- default :
79- panic (r )
80- }
81- }
82- }()
83-
84- // After transaction execution, sync the gas consumed from GnoVM to SDK context
85- newCtx , err = next (newCtx , tx , simulate )
86- if err == nil {
87- gasConsumed := gnoCtx .GasMeter ().GasConsumed ()
88- ctx .GasMeter ().ConsumeGas (storetypes .Gas (gasConsumed ), "gnovm execution" )
40+ if gnoVMCount > 0 && simulate {
41+ newCtx = ctx .WithGasMeter (storetypes .NewInfiniteGasMeter ())
8942 }
9043
91- return newCtx , err
44+ return next ( newCtx , tx , simulate )
9245}
0 commit comments