Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
// performance benefits, but it'll be more difficult to get right.
anteCtx, msCache = app.cacheTxContext(ctx, txBytes)
anteCtx = anteCtx.WithEventManager(sdk.NewEventManager())
if mode == execModeSimulate {
anteCtx = anteCtx.WithExecMode(sdk.ExecMode(execModeSimulate))
}
newCtx, err := app.anteHandler(anteCtx, tx, mode == execModeSimulate)
Comment on lines 884 to 890
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).runTx (baseapp/baseapp.go:814)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).deliverTx (baseapp/baseapp.go:744)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).internalFinalizeBlock (baseapp/baseapp.go:713)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).FinalizeBlock (baseapp/baseapp.go:874)


if !newCtx.IsZero() {
Expand Down
8 changes: 4 additions & 4 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type Context struct {
voteInfo []abci.VoteInfo // Deprecated: use Cometinfo.LastCommit.Votes instead, will be removed after 0.51
gasMeter storetypes.GasMeter
blockGasMeter storetypes.GasMeter
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
checkTx bool // Deprecated: use execMode instead, will be removed after 0.51
Comment thread
tac0turtle marked this conversation as resolved.
recheckTx bool // if recheckTx == true, then checkTx must also be true // Depreacted: use execMode instead, will be removed after 0.51
sigverifyTx bool // when run simulation, because the private key corresponding to the account in the genesis.json randomly generated, we must skip the sigverify.
execMode ExecMode
minGasPrice DecCoins
Expand Down Expand Up @@ -78,8 +78,8 @@ func (c Context) Logger() log.Logger { return c.logge
func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
func (c Context) GasMeter() storetypes.GasMeter { return c.gasMeter }
func (c Context) BlockGasMeter() storetypes.GasMeter { return c.blockGasMeter }
func (c Context) IsCheckTx() bool { return c.checkTx }
func (c Context) IsReCheckTx() bool { return c.recheckTx }
func (c Context) IsCheckTx() bool { return c.checkTx } // Deprecated: use execMode instead
func (c Context) IsReCheckTx() bool { return c.recheckTx } // Deprecated: use execMode instead
func (c Context) IsSigverifyTx() bool { return c.sigverifyTx }
func (c Context) ExecMode() ExecMode { return c.execMode }
func (c Context) MinGasPrices() DecCoins { return c.minGasPrice }
Expand Down
1 change: 1 addition & 0 deletions x/auth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes

* [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig`
* [#19161](https://github.com/cosmos/cosmos-sdk/pull/19161) Remove `simulate` from `SetGasMeter`
Comment thread
tac0turtle marked this conversation as resolved.

### Consensus Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func TestAnteHandlerReCheck(t *testing.T) {
txBuilder, err := suite.clientCtx.TxConfig.WrapTxBuilder(tx)
require.NoError(t, err)

suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2)
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(3)
_, err = suite.anteHandler(suite.ctx, txBuilder.GetTx(), false)
require.Nil(t, err, "AnteHandler errored on recheck unexpectedly: %v", err)

Expand Down
4 changes: 2 additions & 2 deletions x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewValidateBasicDecorator() ValidateBasicDecorator {

func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
// no need to validate basic on recheck tx, call next antehandler
if ctx.IsReCheckTx() {
if ctx.ExecMode() == sdk.ExecModeReCheck {
return next(ctx, tx, simulate)
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*storetypes.Gas(len(ctx.TxBytes())), "txSize")

// simulate gas cost for signatures in simulate mode
if simulate {
if ctx.ExecMode() == sdk.ExecModeSimulate {
// in simulate mode, each element should be a nil signature
sigs, err := sigTx.GetSignaturesV2()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/auth/ante/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func TestConsumeGasForTxSize(t *testing.T) {

// Set suite.ctx with smaller simulated TxBytes manually
suite.ctx = suite.ctx.WithTxBytes(simTxBytes)
suite.ctx = suite.ctx.WithExecMode(sdk.ExecModeSimulate)

beforeSimGas := suite.ctx.GasMeter().GasConsumed()

Expand Down
4 changes: 2 additions & 2 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if !simulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 {
if ctx.ExecMode() != sdk.ExecModeSimulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 {
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas")
}

Expand All @@ -55,7 +55,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
)

fee := feeTx.GetFee()
if !simulate {
if ctx.ExecMode() != sdk.ExecModeSimulate {
fee, priority, err = dfd.txFeeChecker(ctx, tx)
if err != nil {
return ctx, err
Expand Down
12 changes: 3 additions & 9 deletions x/auth/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestDeductFeeDecorator_ZeroGas(t *testing.T) {
require.Error(t, err)

// zero gas is accepted in simulation mode
s.ctx = s.ctx.WithExecMode(sdk.ExecModeSimulate)
_, err = antehandler(s.ctx, tx, true)
require.NoError(t, err)
}
Expand Down Expand Up @@ -78,28 +79,21 @@ func TestEnsureMempoolFees(t *testing.T) {
highGasPrice := []sdk.DecCoin{atomPrice}
s.ctx = s.ctx.WithMinGasPrices(highGasPrice)

// Set IsCheckTx to true
s.ctx = s.ctx.WithIsCheckTx(true)

// antehandler errors with insufficient fees
_, err = antehandler(s.ctx, tx, false)
require.NotNil(t, err, "Decorator should have errored on too low fee for local gasPrice")

// antehandler should not error since we do not check minGasPrice in simulation mode
cacheCtx, _ := s.ctx.CacheContext()
cacheCtx = cacheCtx.WithExecMode(sdk.ExecModeSimulate)
_, err = antehandler(cacheCtx, tx, true)
require.Nil(t, err, "Decorator should not have errored in simulation mode")

// Set IsCheckTx to false
s.ctx = s.ctx.WithIsCheckTx(false)

// antehandler should not error since we do not check minGasPrice in DeliverTx
s.ctx = s.ctx.WithExecMode(sdk.ExecModeFinalize)
_, err = antehandler(s.ctx, tx, false)
require.Nil(t, err, "MempoolFeeDecorator returned error in DeliverTx")

// Set IsCheckTx back to true for testing sufficient mempool fee
s.ctx = s.ctx.WithIsCheckTx(true)

atomPrice = sdk.NewDecCoinFromDec("atom", math.LegacyNewDec(0).Quo(math.LegacyNewDec(100000)))
lowGasPrice := []sdk.DecCoin{atomPrice}
s.ctx = s.ctx.WithMinGasPrices(lowGasPrice)
Expand Down
8 changes: 4 additions & 4 deletions x/auth/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if !ok {
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
// during runTx.
newCtx = SetGasMeter(simulate, ctx, 0)
newCtx = SetGasMeter(ctx, 0)
return newCtx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
}

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())
newCtx = SetGasMeter(ctx, gasTx.GetGas())

if cp := ctx.ConsensusParams(); cp.Block != nil {
// If there exists a maximum block gas limit, we must ensure that the tx
Expand Down Expand Up @@ -71,10 +71,10 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
}

// SetGasMeter returns a new context with a gas meter set from a given context.
func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {
func SetGasMeter(ctx sdk.Context, gasLimit uint64) sdk.Context {
// In various cases such as simulation and during the genesis block, we do not
// meter any gas utilization.
if simulate || ctx.BlockHeight() == 0 {
if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.BlockHeight() == 0 {
return ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
}

Expand Down
17 changes: 8 additions & 9 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
}

for i := range signers {
err = svd.authenticate(ctx, sigTx, simulate, signers[i], signatures[i], pubKeys[i])
err = svd.authenticate(ctx, sigTx, signers[i], signatures[i], pubKeys[i])
if err != nil {
return ctx, err
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
}

// authenticate the authentication of the TX for a specific tx signer.
func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx authsigning.Tx, simulate bool, signer []byte, sig signing.SignatureV2, txPubKey cryptotypes.PubKey) error {
func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx authsigning.Tx, signer []byte, sig signing.SignatureV2, txPubKey cryptotypes.PubKey) error {
acc, err := GetSignerAcc(ctx, svd.ak, signer)
if err != nil {
return err
Expand All @@ -213,18 +213,18 @@ func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx authsigning
// the account is without a pubkey, let's attempt to check if in the
// tx we were correctly provided a valid pubkey.
if acc.GetPubKey() == nil {
err = svd.setPubKey(ctx.IsSigverifyTx(), simulate, acc, txPubKey)
err = svd.setPubKey(ctx.IsSigverifyTx(), ctx.ExecMode() == sdk.ExecModeSimulate, acc, txPubKey)
if err != nil {
return err
}
}

err = svd.consumeSignatureGas(ctx, simulate, acc.GetPubKey(), sig)
err = svd.consumeSignatureGas(ctx, acc.GetPubKey(), sig)
if err != nil {
return err
}

err = svd.verifySig(ctx, simulate, tx, acc, sig)
err = svd.verifySig(ctx, tx, acc, sig)
if err != nil {
return err
}
Expand All @@ -241,11 +241,10 @@ func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx authsigning
// consumeSignatureGas will consume gas according to the pub-key being verified.
func (svd SigVerificationDecorator) consumeSignatureGas(
ctx sdk.Context,
simulate bool,
pubKey cryptotypes.PubKey,
signature signing.SignatureV2,
) error {
if simulate && pubKey == nil {
if ctx.ExecMode() == sdk.ExecModeSimulate && pubKey == nil {
pubKey = simSecp256k1Pubkey
}

Expand All @@ -264,7 +263,7 @@ func (svd SigVerificationDecorator) consumeSignatureGas(
}

// verifySig will verify the signature of the provided signer account.
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, simulate bool, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2) error {
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2) error {
if sig.Sequence != acc.GetSequence() {
return errorsmod.Wrapf(
sdkerrors.ErrWrongSequence,
Expand All @@ -275,7 +274,7 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, simulate bool, tx
// we're in simulation mode, or in ReCheckTx, or context is not
// on sig verify tx, then we do not need to verify the signatures
// in the tx.
if simulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() {
if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/validator_tx_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins,
// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
// is only ran on check tx.
if ctx.IsCheckTx() {
if ctx.ExecMode() == sdk.ExecModeCheck {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
requiredFees := make(sdk.Coins, len(minGasPrices))
Expand Down