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
10 changes: 10 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type BaseApp struct { //nolint: maligned
// abciListeners for hooking into the ABCI message processing of the BaseApp
// and exposing the requests and responses to external consumers
abciListeners []ABCIListener

LastTxManager LastMsgMarkerContainer
}

type appStore struct {
Expand Down Expand Up @@ -742,8 +744,12 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
Data: make([]*sdk.MsgData, 0, len(msgs)),
}

// Set the marker as false - future messages may toggle this flag
app.LastTxManager.SetMarker(false)

// NOTE: GasWanted is determined by the AnteHandler and GasUsed by the GasMeter.
for i, msg := range msgs {

// skip actual execution for (Re)CheckTx mode
if mode == runTxModeCheck || mode == runTxModeReCheck {
break
Expand All @@ -755,6 +761,10 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
err error
)

if app.LastTxManager.GetMarker() {
return nil, sdkerrors.Wrapf(sdkerrors.ErrLastTx, "message was attempted but last message was marked by a contract; message index: %d", i)
}

if handler := app.msgServiceRouter.Handler(msg); handler != nil {
// ADR 031 request type routing
msgResult, err = handler(ctx, msg)
Expand Down
13 changes: 13 additions & 0 deletions baseapp/last_message_marker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package baseapp

type LastMsgMarkerContainer struct {
marker bool
}

func (mng *LastMsgMarkerContainer) SetMarker(value bool) {
mng.marker = value
}

func (mng *LastMsgMarkerContainer) GetMarker() bool {
return mng.marker
}
3 changes: 3 additions & 0 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ var (
// ErrPanic is only set when we recover from a panic, so we know to
// redact potentially sensitive system info
ErrPanic = Register(UndefinedCodespace, 111222, "panic")

// ErrLastTx defines an error occurred if we tried to execute another msg after the last one was set
ErrLastTx = Register(RootCodespace, 40404, "Cannot send messages after last tx marker was set")
)

// Register returns an error instance that should be used as the base for
Expand Down