Skip to content

Commit

Permalink
chg: make runTx private again
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Oct 14, 2024
1 parent c57d7e6 commit 4fb1b9e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (app *BaseApp) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, er
return nil, fmt.Errorf("unknown RequestCheckTx type: %s", req.Type)
}

gInfo, result, anteEvents, err := app.RunTx(mode, req.Tx)
gInfo, result, anteEvents, err := app.runTx(mode, req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil
}
Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func TestABCI_TxGasLimits(t *testing.T) {
// AnteHandlers must have their own defer/recover in order for the BaseApp
// to know how much gas was used! This is because the GasMeter is created in
// the AnteHandler, but if it panics the context won't be set properly in
// RunTx's recover call.
// runTx's recover call.
defer func() {
if r := recover(); r != nil {
switch rType := r.(type) {
Expand Down
4 changes: 2 additions & 2 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (h *DefaultProposalHandler) SetTxSelector(ts TxSelector) {
// transactions are added to the proposal. Transactions are valid if they:
//
// 1) Successfully encode to bytes.
// 2) Are valid (i.e. pass RunTx, AnteHandler only).
// 2) Are valid (i.e. pass runTx, AnteHandler only).
//
// Enumeration is halted once RequestPrepareProposal.MaxBytes of transactions is
// reached or the mempool is exhausted.
Expand Down Expand Up @@ -250,7 +250,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
// ABCI proposal. Every transaction in the proposal must pass 2 conditions:
//
// 1. The transaction bytes must decode to a valid transaction.
// 2. The transaction must be valid (i.e. pass RunTx, AnteHandler only)
// 2. The transaction must be valid (i.e. pass runTx, AnteHandler only)
//
// If any transaction fails to pass either condition, the proposal is rejected.
// Note that step (2) is identical to the validation step performed in
Expand Down
16 changes: 8 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type BaseApp struct {
// if BaseApp is passed to the upgrade keeper's NewKeeper method.
appVersion uint64

// recovery handler for app.RunTx method
// recovery handler for app.runTx method
runTxRecoveryMiddleware recoveryMiddleware

// trace set will return full stack traces for errors in ABCI Log field
Expand Down Expand Up @@ -534,7 +534,7 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp cmtproto.ConsensusP
return app.paramStore.Set(ctx, cp)
}

// AddRunTxRecoveryHandler adds custom app.RunTx method panic handlers.
// AddRunTxRecoveryHandler adds custom app.runTx method panic handlers.
func (app *BaseApp) AddRunTxRecoveryHandler(handlers ...RecoveryHandler) {
for _, h := range handlers {
app.runTxRecoveryMiddleware = newRecoveryMiddleware(h, app.runTxRecoveryMiddleware)
Expand Down Expand Up @@ -738,7 +738,7 @@ func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult {
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
}()

gInfo, result, anteEvents, err := app.RunTx(execModeFinalize, tx)
gInfo, result, anteEvents, err := app.runTx(execModeFinalize, tx)
if err != nil {
resultStr = "failed"
resp = sdkerrors.ResponseExecTxResultWithEvents(
Expand Down Expand Up @@ -788,14 +788,14 @@ func (app *BaseApp) endBlock(ctx context.Context) (sdk.EndBlock, error) {
return endblock, nil
}

// RunTx processes a transaction within a given execution mode, encoded transaction
// runTx processes a transaction within a given execution mode, encoded transaction
// bytes, and the decoded transaction itself. All state transitions occur through
// a cached Context depending on the mode provided. State only gets persisted
// if all messages get executed successfully and the execution mode is DeliverTx.
// Note, gas execution info is always returned. A reference to a Result is
// returned if the tx does not run out of gas and if all the messages are valid
// and execute successfully. An error is returned otherwise.
func (app *BaseApp) RunTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) {
// NOTE: GasWanted should be returned by the AnteHandler. GasUsed is
// determined by the GasMeter. We need access to the context to get the gas
// meter, so we initialize upfront.
Expand All @@ -813,7 +813,7 @@ func (app *BaseApp) RunTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
if r := recover(); r != nil {
recoveryMW := newOutOfGasRecoveryMiddleware(gasWanted, ctx, app.runTxRecoveryMiddleware)
err, result = processRecovery(r, recoveryMW), nil
ctx.Logger().Error("panic recovered in RunTx", "err", err)
ctx.Logger().Error("panic recovered in runTx", "err", err)
}

gInfo = sdk.GasInfo{GasWanted: gasWanted, GasUsed: ctx.GasMeter().GasConsumed()}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) {
return nil, err
}

_, _, _, err = app.RunTx(execModePrepareProposal, bz)
_, _, _, err = app.runTx(execModePrepareProposal, bz)
if err != nil {
return nil, err
}
Expand All @@ -1092,7 +1092,7 @@ func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) {
return nil, err
}

_, _, _, err = app.RunTx(execModeProcessProposal, txBz)
_, _, _, err = app.runTx(execModeProcessProposal, txBz)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions baseapp/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newRecoveryMiddleware(handler RecoveryHandler, next recoveryMiddleware) rec
}
}

// newOutOfGasRecoveryMiddleware creates a standard OutOfGas recovery middleware for app.RunTx method.
// newOutOfGasRecoveryMiddleware creates a standard OutOfGas recovery middleware for app.runTx method.
func newOutOfGasRecoveryMiddleware(gasWanted uint64, ctx sdk.Context, next recoveryMiddleware) recoveryMiddleware {
handler := func(recoveryObj interface{}) error {
err, ok := recoveryObj.(storetypes.ErrorOutOfGas)
Expand All @@ -66,7 +66,7 @@ func newOutOfGasRecoveryMiddleware(gasWanted uint64, ctx sdk.Context, next recov
return newRecoveryMiddleware(handler, next)
}

// newDefaultRecoveryMiddleware creates a default (last in chain) recovery middleware for app.RunTx method.
// newDefaultRecoveryMiddleware creates a default (last in chain) recovery middleware for app.runTx method.
func newDefaultRecoveryMiddleware() recoveryMiddleware {
handler := func(recoveryObj interface{}) error {
return errorsmod.Wrap(
Expand Down
12 changes: 6 additions & 6 deletions baseapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import (

// SimCheck defines a CheckTx helper function that used in tests and simulations.
func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
// RunTx expects tx bytes as argument, so we encode the tx argument into
// bytes. Note that RunTx will actually decode those bytes again. But since
// runTx expects tx bytes as argument, so we encode the tx argument into
// bytes. Note that runTx will actually decode those bytes again. But since
// this helper is only used in tests/simulation, it's fine.
bz, err := txEncoder(tx)
if err != nil {
return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
}

gasInfo, result, _, err := app.RunTx(execModeCheck, bz)
gasInfo, result, _, err := app.runTx(execModeCheck, bz)
return gasInfo, result, err
}

// Simulate executes a tx in simulate mode to get result and gas info.
func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) {
gasInfo, result, _, err := app.RunTx(execModeSimulate, txBytes)
gasInfo, result, _, err := app.runTx(execModeSimulate, txBytes)
return gasInfo, result, err
}

Expand All @@ -35,7 +35,7 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo,
if err != nil {
return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
}
gasInfo, result, _, err := app.RunTx(execModeFinalize, bz)
gasInfo, result, _, err := app.runTx(execModeFinalize, bz)
return gasInfo, result, err
}

Expand All @@ -46,7 +46,7 @@ func (app *BaseApp) SimTxFinalizeBlock(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.
return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
}

gasInfo, result, _, err := app.RunTx(execModeFinalize, bz)
gasInfo, result, _, err := app.runTx(execModeFinalize, bz)
return gasInfo, result, err
}

Expand Down

0 comments on commit 4fb1b9e

Please sign in to comment.