Skip to content

Commit

Permalink
bring back #581 pass tx source into msg handler via context (on top o…
Browse files Browse the repository at this point in the history
…f reverted master)
  • Loading branch information
ackratos committed May 27, 2019
1 parent 05f8cc7 commit cddb0eb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var dbHeaderKey = []byte("header")
const (
// we pass txHash of current handling message via context so that we can publish it as metadata of Msg
TxHashKey = "txHash"
// we pass txSrc of current handling message via context so that we can publish it as metadata of Msg
TxSourceKey = "txSrc"
//this number should be around the size of the transactions in a block, TODO: configurable
TxMsgCacheSize = 4000
)
Expand Down Expand Up @@ -726,7 +728,7 @@ func (app *BaseApp) getContextWithCache(mode sdk.RunTxMode, txBytes []byte, txHa
}

// Iterates through msgs and executes them
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, txHash string, mode sdk.RunTxMode) (result sdk.Result) {
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode) (result sdk.Result) {
// accumulate results
logs := make([]string, 0, len(msgs))
var data []byte // NOTE: we just append them all (?!)
Expand All @@ -740,7 +742,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, txHash string, mode
return sdk.ErrUnknownRequest("Unrecognized Msg type: " + msgRoute).Result()
}

msgResult := handler(ctx.WithValue(TxHashKey, txHash).WithRunTxMode(mode), msg)
msgResult := handler(ctx.WithRunTxMode(mode), msg)
msgResult.Tags = append(msgResult.Tags, sdk.MakeTag("action", []byte(msg.Type())))

// Append Data and Tags
Expand Down Expand Up @@ -830,7 +832,14 @@ func (app *BaseApp) RunTx(mode sdk.RunTxMode, txBytes []byte, tx sdk.Tx, txHash
}
}

result = app.runMsgs(ctx, msgs, txHash, mode)
var txSrc int64
if stdTx, ok := tx.(auth.StdTx); ok {
txSrc = stdTx.GetSource()
}
result = app.runMsgs(
ctx.WithValue(TxHashKey, txHash).WithValue(TxSourceKey, txSrc),
msgs,
mode)

if mode == sdk.RunTxModeSimulate {
return
Expand Down Expand Up @@ -884,7 +893,11 @@ func (app *BaseApp) ReRunTx(txBytes []byte, tx sdk.Tx) (result sdk.Result) {
}

var msgs = tx.GetMsgs()
result = app.runMsgs(ctx, msgs, txHash, mode)
var txSrc int64
if stdTx, ok := tx.(auth.StdTx); ok {
txSrc = stdTx.GetSource()
}
result = app.runMsgs(ctx.WithValue(TxHashKey, txHash).WithValue(TxSourceKey, txSrc), msgs, mode)

// only update state if all messages pass
if result.IsOK() {
Expand Down

0 comments on commit cddb0eb

Please sign in to comment.