Skip to content

Commit 5f5e082

Browse files
author
Cashmaney
authored
Merge pull request #293 from scrtlabs/last-msg-in-tx-marker
Feat: Added support for a last msg in tx marker in baseapp
2 parents e345f17 + d31ea3f commit 5f5e082

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

baseapp/baseapp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ type BaseApp struct { //nolint: maligned
111111
// abciListeners for hooking into the ABCI message processing of the BaseApp
112112
// and exposing the requests and responses to external consumers
113113
abciListeners []ABCIListener
114+
115+
LastTxManager LastMsgMarkerContainer
114116
}
115117

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

747+
// Set the marker as false - future messages may toggle this flag
748+
app.LastTxManager.SetMarker(false)
749+
745750
// NOTE: GasWanted is determined by the AnteHandler and GasUsed by the GasMeter.
746751
for i, msg := range msgs {
752+
747753
// skip actual execution for (Re)CheckTx mode
748754
if mode == runTxModeCheck || mode == runTxModeReCheck {
749755
break
@@ -755,6 +761,10 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
755761
err error
756762
)
757763

764+
if app.LastTxManager.GetMarker() {
765+
return nil, sdkerrors.Wrapf(sdkerrors.ErrLastTx, "message was attempted but last message was marked by a contract; message index: %d", i)
766+
}
767+
758768
if handler := app.msgServiceRouter.Handler(msg); handler != nil {
759769
// ADR 031 request type routing
760770
msgResult, err = handler(ctx, msg)

baseapp/last_message_marker.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package baseapp
2+
3+
type LastMsgMarkerContainer struct {
4+
marker bool
5+
}
6+
7+
func (mng *LastMsgMarkerContainer) SetMarker(value bool) {
8+
mng.marker = value
9+
}
10+
11+
func (mng *LastMsgMarkerContainer) GetMarker() bool {
12+
return mng.marker
13+
}

types/errors/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ var (
147147
// ErrPanic is only set when we recover from a panic, so we know to
148148
// redact potentially sensitive system info
149149
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
150+
151+
// ErrLastTx defines an error occurred if we tried to execute another msg after the last one was set
152+
ErrLastTx = Register(RootCodespace, 40404, "Cannot send messages after last tx marker was set")
150153
)
151154

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

0 commit comments

Comments
 (0)