Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/irisnet/irishub into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
wukongcheng committed Oct 24, 2018
2 parents 40f3345 + ddb384e commit 77239b8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BUG FIXES:
- Fix software upgrade issue caused by tx fee
- Report Panic when building the lcd proof
- Fix bugs in converting validator power to byte array
- Fix panic bug in wrong account number


## 0.5.0-rc1
Expand Down
7 changes: 5 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (app *IrisApp) ExportAppStateAndValidators() (appState json.RawMessage, val
}

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

msgResult := handler(ctx, msg)
var msgResult sdk.Result
if mode != bam.RunTxModeCheck {
msgResult = handler(ctx, msg)
}

// NOTE: GasWanted is determined by ante handler and
// GasUsed by the GasMeter
Expand Down
44 changes: 21 additions & 23 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ import (
var dbHeaderKey = []byte("header")

// Enum mode for app.runTx
type runTxMode uint8
type RunTxMode uint8

const (
// Check a transaction
runTxModeCheck runTxMode = iota
RunTxModeCheck RunTxMode = iota
// Simulate a transaction
runTxModeSimulate runTxMode = iota
RunTxModeSimulate RunTxMode = iota
// Deliver a transaction
runTxModeDeliver runTxMode = iota
RunTxModeDeliver RunTxMode = iota
)

type RunMsg func(ctx sdk.Context, msgs []sdk.Msg) sdk.Result
type RunMsg func(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) sdk.Result

// BaseApp reflects the ABCI application implementation.
type BaseApp struct {
Expand Down Expand Up @@ -477,7 +477,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
if err != nil {
result = err.Result()
} else {
result = app.runTx(runTxModeCheck, txBytes, tx)
result = app.runTx(RunTxModeCheck, txBytes, tx)
}

return abci.ResponseCheckTx{
Expand All @@ -498,7 +498,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
if err != nil {
result = err.Result()
} else {
result = app.runTx(runTxModeDeliver, txBytes, tx)
result = app.runTx(RunTxModeDeliver, txBytes, tx)
}

// Even though the Result.Code is not OK, there are still effects,
Expand Down Expand Up @@ -534,9 +534,9 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error {
return nil
}

func (app *BaseApp) getContextForAnte(mode runTxMode, txBytes []byte) (ctx sdk.Context) {
func (app *BaseApp) getContextForAnte(mode RunTxMode, txBytes []byte) (ctx sdk.Context) {
// Get the context
if mode == runTxModeCheck || mode == runTxModeSimulate {
if mode == RunTxModeCheck || mode == RunTxModeSimulate {
ctx = app.checkState.ctx.WithTxBytes(txBytes)
} else {
ctx = app.deliverState.ctx.WithTxBytes(txBytes)
Expand All @@ -547,9 +547,9 @@ func (app *BaseApp) getContextForAnte(mode runTxMode, txBytes []byte) (ctx sdk.C
}

// Iterates through msgs and executes them
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (result sdk.Result) {
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (result sdk.Result) {
if app.runMsg != nil {
return app.runMsg(ctx, msgs)
return app.runMsg(ctx, msgs, mode)
}

// accumulate results
Expand All @@ -567,7 +567,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re

var msgResult sdk.Result
// Skip actual execution for CheckTx
if mode != runTxModeCheck {
if mode != RunTxModeCheck {
msgResult = handler(ctx, msg)
}

Expand Down Expand Up @@ -604,8 +604,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re

// Returns the applicantion's deliverState if app is in runTxModeDeliver,
// otherwise it returns the application's checkstate.
func getState(app *BaseApp, mode runTxMode) *state {
if mode == runTxModeCheck || mode == runTxModeSimulate {
func getState(app *BaseApp, mode RunTxMode) *state {
if mode == RunTxModeCheck || mode == RunTxModeSimulate {
return app.checkState
}

Expand All @@ -615,7 +615,7 @@ func getState(app *BaseApp, mode runTxMode) *state {
// runTx processes a transaction. The transactions is proccessed via an
// anteHandler. txBytes may be nil in some cases, eg. in tests. Also, in the
// future we may support "internal" transactions.
func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk.Result) {
// 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 @@ -638,16 +638,14 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
result.GasUsed = ctxWithNoCache.GasMeter().GasConsumed()

// Refund unspent fee
if app.feeRefundHandler != nil {
refundCoin, err := app.feeRefundHandler(ctxWithNoCache, tx, result)
if err != nil {
if mode != RunTxModeCheck && app.feeRefundHandler != nil {
actualCostFee, err := app.feeRefundHandler(ctxWithNoCache, tx, result)
if err == nil {
result.Tags = result.Tags.AppendTag("completeConsumedTxFee-"+actualCostFee.Denom, actualCostFee.Amount.BigInt().Bytes())
} else {
result = sdk.ErrInternal(err.Error()).Result()
result.GasWanted = gasWanted
result.GasUsed = ctxWithNoCache.GasMeter().GasConsumed()
result.Tags.AppendTag("consumedTxFee-"+refundCoin.Denom, refundCoin.Amount.BigInt().Bytes())
} else {
//TODO: add tag to get completeConsumedTxFee, will modify result.FeeAmount type to BigInt
result.Tags = result.Tags.AppendTag("completeConsumedTxFee-"+refundCoin.Denom, refundCoin.Amount.BigInt().Bytes())
}
}
}()
Expand Down Expand Up @@ -695,7 +693,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
result.GasWanted = gasWanted

// only update state if all messages pass and we're not in a simulation
if result.IsOK() && mode != runTxModeSimulate {
if result.IsOK() && mode != RunTxModeSimulate {
msCache.Write()
}

Expand Down
2 changes: 1 addition & 1 deletion baseapp/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewFeeRefundHandler(am auth.AccountMapper, fck auth.FeeCollectionKeeper, fm
txAccounts := auth.GetSigners(ctx)
// If this tx failed in anteHandler, txAccount length will be less than 1
if len(txAccounts) < 1 {
return sdk.Coin{}, nil
panic("invalid transaction, should not reach here")
}
firstAccount := txAccounts[0]

Expand Down
6 changes: 3 additions & 3 deletions baseapp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (

// nolint - Mostly for testing
func (app *BaseApp) Check(tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeCheck, nil, tx)
return app.runTx(RunTxModeCheck, nil, tx)
}

// nolint - full tx execution
func (app *BaseApp) Simulate(tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeSimulate, nil, tx)
return app.runTx(RunTxModeSimulate, nil, tx)
}

// nolint
func (app *BaseApp) Deliver(tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeDeliver, nil, tx)
return app.runTx(RunTxModeDeliver, nil, tx)
}

// RunForever - BasecoinApp execution and cleanup
Expand Down
2 changes: 1 addition & 1 deletion client/clitest/irismon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestIrismon(t *testing.T) {
time.Sleep(time.Second * 20)

// irismon test
resp, err := http.Get(fmt.Sprintf("http://0.0.0.0:%s", port1))
resp, err := http.Get(fmt.Sprintf("http://localhost:%s", port1))
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode)
}
7 changes: 5 additions & 2 deletions examples/irishub-bugfix-2/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (app *IrisApp) ExportAppStateAndValidators() (appState json.RawMessage, val
}

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

msgResult := handler(ctx, msg)
var msgResult sdk.Result
if mode != bam.RunTxModeCheck {
msgResult = handler(ctx, msg)
}

// NOTE: GasWanted is determined by ante handler and
// GasUsed by the GasMeter
Expand Down
7 changes: 5 additions & 2 deletions examples/irishub1/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (app *IrisApp) ExportAppStateAndValidators() (appState json.RawMessage, val
}

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

msgResult := handler(ctx, msg)
var msgResult sdk.Result
if mode != bam.RunTxModeCheck {
msgResult = handler(ctx, msg)
}

// NOTE: GasWanted is determined by ante handler and
// GasUsed by the GasMeter
Expand Down

0 comments on commit 77239b8

Please sign in to comment.