Skip to content

Commit

Permalink
Merge pull request #140 from binance-chain/revert-133-issue581
Browse files Browse the repository at this point in the history
Revert "[R4R] #581 pass tx source into msg handler via context"
  • Loading branch information
ackratos authored May 27, 2019
2 parents eb85398 + be2fce3 commit 05f8cc7
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ 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 @@ -728,7 +726,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, mode sdk.RunTxMode) (result sdk.Result) {
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, txHash string, 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 @@ -742,7 +740,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode)
return sdk.ErrUnknownRequest("Unrecognized Msg type: " + msgRoute).Result()
}

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

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

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)
result = app.runMsgs(ctx, msgs, txHash, mode)

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

var msgs = tx.GetMsgs()
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)
result = app.runMsgs(ctx, msgs, txHash, mode)

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

0 comments on commit 05f8cc7

Please sign in to comment.