From 2f049c567b2c968fcaecf98973011fb61352bcad Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Wed, 24 Oct 2018 18:02:35 +0800 Subject: [PATCH 1/3] Fix panic bug in wrong account number and add missing run mode checking before runMsg --- app/app.go | 7 +++-- baseapp/baseapp.go | 44 +++++++++++++--------------- baseapp/fee.go | 2 +- baseapp/helpers.go | 6 ++-- examples/irishub-bugfix-2/app/app.go | 7 +++-- examples/irishub1/app/app.go | 7 +++-- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/app/app.go b/app/app.go index fbc007167..78c278ea5 100644 --- a/app/app.go +++ b/app/app.go @@ -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 (?!) @@ -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 diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 514f3e57e..59855d41d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -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 { @@ -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{ @@ -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, @@ -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) @@ -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 @@ -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) } @@ -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 } @@ -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. @@ -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()) } } }() @@ -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() } diff --git a/baseapp/fee.go b/baseapp/fee.go index 0c74e51d1..49da4d592 100644 --- a/baseapp/fee.go +++ b/baseapp/fee.go @@ -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] diff --git a/baseapp/helpers.go b/baseapp/helpers.go index b20a38bb0..677d5b708 100644 --- a/baseapp/helpers.go +++ b/baseapp/helpers.go @@ -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 diff --git a/examples/irishub-bugfix-2/app/app.go b/examples/irishub-bugfix-2/app/app.go index e6f8b2015..69b89dad1 100644 --- a/examples/irishub-bugfix-2/app/app.go +++ b/examples/irishub-bugfix-2/app/app.go @@ -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 (?!) @@ -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 diff --git a/examples/irishub1/app/app.go b/examples/irishub1/app/app.go index 87894f05b..8fead84f1 100644 --- a/examples/irishub1/app/app.go +++ b/examples/irishub1/app/app.go @@ -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 (?!) @@ -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 From 36ef122034f2fa2e4c369f4b5a1df95a158930e0 Mon Sep 17 00:00:00 2001 From: Raymond Date: Wed, 24 Oct 2018 18:06:40 +0800 Subject: [PATCH 2/3] IRISHUB-543: prepare the 0.6.0-rc0 release --- CHANGELOG.md | 14 ++++++++------ Gopkg.lock | 22 ++++++++++------------ Gopkg.toml | 3 +-- version/version.go | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d492a2b4a..ee52914b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,23 +3,25 @@ ## 0.6.0-rc0 -*October 22th, 2018* +*October 24th, 2018* BREAKING CHANGES: -- [monitor] Use new executable binary for monitor +- [monitor] Use new executable binary in monitor FEATURES: -- [record] Add the record module for the data certification on blockchain -- [iservice] Add the feature of iservice definition +- [record] Add the record module of the data certification on blockchain +- [iservice] Add the feature of iService definition +- [cli] Add the example description in the cli help - [test] Add Cli/LCD/Sim auto-test BUG FIXES: - Fix software upgrade issue caused by tx fee -- Panic when building the lcd proof -- Fix bug of converting validator power to byte array +- 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 diff --git a/Gopkg.lock b/Gopkg.lock index 9073f2c72..1d4707244 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -68,8 +68,7 @@ revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4" [[projects]] - branch = "irisnet/v0.24.2-v0.6" - digest = "1:e487832acd654b5fc2bc296c34cc679808652f5571e3d18c37ec726e1697070d" + digest = "1:f2f4e260193eb9a9ad307b26bcfcf94e57da65d2ea16b51023268435d3a116cc" name = "github.com/cosmos/cosmos-sdk" packages = [ "baseapp", @@ -99,7 +98,6 @@ "x/gov/tags", "x/ibc", "x/mock", - "x/mock/simulation", "x/params", "x/slashing", "x/stake", @@ -111,6 +109,7 @@ pruneopts = "UT" revision = "7c39b51abdd5089636060470e294b2ea1fec7954" source = "https://github.com/irisnet/cosmos-sdk.git" + version = "v0.24.2-irisv0.6" [[projects]] digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" @@ -256,12 +255,13 @@ revision = "d9f6b97f8db22dd1e090fd0bbbe98f09cc7dd0a8" [[projects]] - digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8" + digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", + "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", @@ -401,8 +401,8 @@ name = "github.com/mr-tron/base58" packages = ["base58"] pruneopts = "UT" - revision = "d724c80ecac7b49e4e562d58b2b4f4ee4ed8c312" - version = "v1.0.0" + revision = "89529c6904fcd077434931b4eac8b4b2f0991baf" + version = "v1.1.0" [[projects]] digest = "1:e54be212eca970f4d5d39899666aef429c437969783e360a0cab075ba1423a80" @@ -472,7 +472,7 @@ [[projects]] branch = "master" - digest = "1:3307c587aea10ad16379bcda6ab59ae71beda5893c99767a4c908760c7b5b996" + digest = "1:db712fde5d12d6cdbdf14b777f0c230f4ff5ab0be8e35b239fc319953ed577a4" name = "github.com/prometheus/common" packages = [ "expfmt", @@ -480,7 +480,7 @@ "model", ] pruneopts = "UT" - revision = "c5df33d3bef320f5f0a7ddc06ccef10a0433286c" + revision = "7e9e6cabbd393fc208072eedef99188d0ce788b6" [[projects]] branch = "master" @@ -788,7 +788,7 @@ [[projects]] branch = "master" - digest = "1:08232b2c3ccc55a20aeec26a36b63e50510c36cfdd7797dcaee3802998144509" + digest = "1:317d73d5f30aa478da851362c17dbed491e43f599f07d99eeb06323fa51e1e4f" name = "golang.org/x/sys" packages = [ "cpu", @@ -796,7 +796,7 @@ "windows", ] pruneopts = "UT" - revision = "8f1d3d21f81be6e86ebcd6febee89c89bc50719f" + revision = "44b849a8bc13eb42e95e6c6c5e360481b73ec710" [[projects]] digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" @@ -876,7 +876,6 @@ analyzer-version = 1 input-imports = [ "github.com/bgentry/speakeasy", - "github.com/cosmos/cosmos-sdk/baseapp", "github.com/cosmos/cosmos-sdk/client", "github.com/cosmos/cosmos-sdk/client/context", "github.com/cosmos/cosmos-sdk/client/keys", @@ -898,7 +897,6 @@ "github.com/cosmos/cosmos-sdk/x/gov", "github.com/cosmos/cosmos-sdk/x/ibc", "github.com/cosmos/cosmos-sdk/x/mock", - "github.com/cosmos/cosmos-sdk/x/mock/simulation", "github.com/cosmos/cosmos-sdk/x/params", "github.com/cosmos/cosmos-sdk/x/slashing", "github.com/cosmos/cosmos-sdk/x/stake", diff --git a/Gopkg.toml b/Gopkg.toml index 8687548ad..670aeaec1 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -29,8 +29,7 @@ [[constraint]] name = "github.com/cosmos/cosmos-sdk" source = "https://github.com/irisnet/cosmos-sdk.git" - #version = "=v0.24.2-iris1" - branch = "irisnet/v0.24.2-v0.6" + version = "=v0.24.2-irisv0.6" [[override]] name = "github.com/golang/protobuf" diff --git a/version/version.go b/version/version.go index 26d2b2a11..bdec88836 100644 --- a/version/version.go +++ b/version/version.go @@ -7,7 +7,7 @@ import ( ) // Version - Iris Version -const Version = "0.5.0-rc0" +const Version = "0.6.0-rc0" // GitCommit set by build flags var GitCommit = "" From ba53d96915e6f68466102dd352d4748a50d8ae2a Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Wed, 24 Oct 2018 18:32:03 +0800 Subject: [PATCH 3/3] Change 0.0.0.0 to localhost --- client/clitest/irismon_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/clitest/irismon_test.go b/client/clitest/irismon_test.go index 1682c0352..38592dfbd 100644 --- a/client/clitest/irismon_test.go +++ b/client/clitest/irismon_test.go @@ -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) }