Skip to content

Commit

Permalink
reset debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
ysv committed Nov 8, 2023
1 parent bdaf64d commit 5bd6bcd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
16 changes: 1 addition & 15 deletions pkg/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,10 @@ func CalculateGas(ctx context.Context, clientCtx Context, txf Factory, msgs ...s
signature,
},
})
fmt.Printf("tx bytes len: %v\n", len(txBytes))
if err != nil {
return nil, 0, errors.WithStack(err)
}

txTx, err := clientCtx.TxConfig().TxDecoder()(txBytes)
if err != nil {
fmt.Printf("err: %v\n", err)
}

txJSON, err := clientCtx.TxConfig().TxJSONEncoder()(txTx)
if err != nil {
fmt.Printf("err: %v\n", err)
} else {
_ = txJSON
fmt.Printf("txJSON: %s\n", txJSON)
}

txSvcClient := sdktx.NewServiceClient(clientCtx)
simRes, err := txSvcClient.Simulate(ctx, &sdktx.SimulateRequest{
TxBytes: txBytes,
Expand Down Expand Up @@ -327,7 +313,7 @@ func AwaitNextBlocks(
if res.SdkBlock != nil {
currentHeight = res.SdkBlock.Header.Height
} else {
// TODO: Remove this in v4 version of cored. Now it is needed because we might still use it in integration tests together with v2 cored binary.
// TODO(v4): Remove this in v4 version of cored. Now it is needed because we might still use it in integration tests together with v2 cored binary.
currentHeight = res.Block.Header.Height //nolint:staticcheck // Yes, we know that this is deprecated
}

Expand Down
27 changes: 5 additions & 22 deletions x/deterministicgas/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
package ante

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"

"github.com/CoreumFoundation/coreum/v3/x/deterministicgas"
)

type debuggingGasMeter struct {
sdk.GasMeter
}

func newDGM(g sdk.GasMeter) debuggingGasMeter {
return debuggingGasMeter{g}
}

func (d debuggingGasMeter) ConsumeGas(amount sdk.Gas, descriptor string) {
fmt.Printf("Consumig gas descriptor: %q, amount: %d\n", descriptor, amount)
d.GasMeter.ConsumeGas(amount, descriptor)
}

// SetInfiniteGasMeterDecorator sets the infinite gas limit for ante handler
// CONTRACT: Must be the first decorator in the chain.
// CONTRACT: Tx must implement GasTx interface.
Expand All @@ -43,7 +28,7 @@ func (sigmd SetInfiniteGasMeterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx,
ctx.GasMeter().ConsumeGas(sigmd.deterministicGasConfig.FixedGas, "Fixed")

// Set infinite gas meter for ante handler
return next(ctx.WithGasMeter(newDGM(sdk.NewInfiniteGasMeter())), tx, simulate)
return next(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()), tx, simulate)
}

// AddBaseGasDecorator adds free gas to gas meter.
Expand All @@ -67,14 +52,14 @@ func (abgd AddBaseGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if simulate || ctx.BlockHeight() == 0 {
// During simulation and genesis initialization infinite gas meter is set inside context by `SetUpContextDecorator`.
// Here, we reset it to initial state with 0 gas consumed.
gasMeter = newDGM(sdk.NewInfiniteGasMeter())
gasMeter = sdk.NewInfiniteGasMeter()
} else {
params := abgd.ak.GetParams(ctx)

// It is not needed to verify that tx really implements `GasTx` interface because it has been already done by
// `SetUpContextDecorator`
gasTx := tx.(authante.GasTx)
gasMeter = newDGM(sdk.NewGasMeter(gasTx.GetGas() + abgd.deterministicGasConfig.TxBaseGas(params)))
gasMeter = sdk.NewGasMeter(gasTx.GetGas() + abgd.deterministicGasConfig.TxBaseGas(params))
}
return next(ctx.WithGasMeter(gasMeter), tx, simulate)
}
Expand Down Expand Up @@ -106,9 +91,9 @@ func (cfgd ChargeFixedGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
if simulate || ctx.BlockHeight() == 0 {
// During simulation and genesis initialization infinite gas meter is set inside context by `SetUpContextDecorator`.
// We reset it to initial state with 0 gas consumed.
gasMeter = newDGM(sdk.NewInfiniteGasMeter())
gasMeter = sdk.NewInfiniteGasMeter()
} else {
gasMeter = newDGM(sdk.NewGasMeter(gasTx.GetGas()))
gasMeter = sdk.NewGasMeter(gasTx.GetGas())
}

gasConsumed := ctx.GasMeter().GasConsumed()
Expand All @@ -118,7 +103,5 @@ func (cfgd ChargeFixedGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
}
gasMeter.ConsumeGas(cfgd.deterministicGasConfig.FixedGas, "Fixed")

fmt.Printf("ChargeFixedGasDecorator: simulate: %v\n. gasMeter: %v\n", simulate, gasMeter.String())

return next(ctx.WithGasMeter(gasMeter), tx, simulate)
}

0 comments on commit 5bd6bcd

Please sign in to comment.