From e9b9758bb6a7943d249c129846a4b1384ce2b498 Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Tue, 11 Dec 2018 17:38:49 +0800 Subject: [PATCH 1/5] Merge https://github.com/cosmos/cosmos-sdk/pull/2781 --- app/baseapp.go | 55 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/app/baseapp.go b/app/baseapp.go index 0bc9cb2e7..98b58a2e2 100644 --- a/app/baseapp.go +++ b/app/baseapp.go @@ -10,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" @@ -543,7 +542,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error { // the vote infos if the tx runs within the deliverTx() state. func (app *BaseApp) getContextForAnte(mode RunTxMode, txBytes []byte) (ctx sdk.Context) { // Get the context - ctx = getState(app, mode).ctx.WithTxBytes(txBytes) + ctx = app.getState(mode).ctx.WithTxBytes(txBytes) if mode == RunTxModeDeliver { ctx = ctx.WithVoteInfos(app.voteInfos) } @@ -612,7 +611,7 @@ 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 { +func (app *BaseApp) getState(mode RunTxMode) *state { if mode == RunTxModeCheck || mode == RunTxModeSimulate { return app.checkState } @@ -622,11 +621,30 @@ func getState(app *BaseApp, mode RunTxMode) *state { func (app *BaseApp) initializeContext(ctx sdk.Context, mode RunTxMode) sdk.Context { if mode == RunTxModeSimulate { - ctx = ctx.WithMultiStore(getState(app, RunTxModeSimulate).CacheMultiStore()) + ctx = ctx.WithMultiStore(app.getState(RunTxModeSimulate).CacheMultiStore()) } return ctx } +// cacheTxContext returns a new context based off of the provided context with a +// cache wrapped multi-store and the store itself to allow the caller to write +// changes from the cached multi-store. +func (app *BaseApp) cacheTxContext( + ctx sdk.Context, txBytes []byte, mode RunTxMode, +) (sdk.Context, sdk.CacheMultiStore) { + msCache := app.getState(mode).CacheMultiStore() + if msCache.TracingEnabled() { + msCache = msCache.WithTracingContext( + sdk.TraceContext( + map[string]interface{}{ + "txHash": fmt.Sprintf("%X", tmhash.Sum(txBytes)), + }, + ), + ).(sdk.CacheMultiStore) + } + return ctx.WithMultiStore(msCache), msCache +} + // 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. @@ -685,7 +703,17 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk anteHandler := app.Engine.GetCurrent().GetAnteHandler() // run the ante handler if anteHandler != nil { - newCtx, result, abort := anteHandler(ctx, tx, (mode == RunTxModeSimulate)) + var anteCtx sdk.Context + var msCache sdk.CacheMultiStore + // Cache wrap context before anteHandler call in case it aborts. + // This is required for both CheckTx and DeliverTx. + // https://github.com/cosmos/cosmos-sdk/issues/2772 + // NOTE: Alternatively, we could require that anteHandler ensures that + // writes do not happen if aborted/failed. This may have some + // performance benefits, but it'll be more difficult to get right. + anteCtx, msCache = app.cacheTxContext(ctx, txBytes, mode) + + newCtx, result, abort := anteHandler(anteCtx, tx, (mode == RunTxModeSimulate)) if abort { return result } @@ -693,7 +721,7 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk ctx = newCtx ctxWithNoCache = newCtx } - + msCache.Write() gasWanted = result.GasWanted } @@ -703,17 +731,10 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk return } - // Keep the state in a transient CacheWrap in case processing the messages - // fails. - msCache = getState(app, mode).CacheMultiStore() - if msCache.TracingEnabled() { - msCache = msCache.WithTracingContext(sdk.TraceContext( - map[string]interface{}{"txHash": cmn.HexBytes(tmhash.Sum(txBytes)).String()}, - )).(sdk.CacheMultiStore) - } - - ctx = ctx.WithMultiStore(msCache) - result = app.runMsgs(ctx, msgs, mode) + // Create a new context based off of the existing context with a cache wrapped + // multi-store in case message processing fails. + runMsgCtx, msCache := app.cacheTxContext(ctx, txBytes, mode) + result = app.runMsgs(runMsgCtx, msgs, mode) result.GasWanted = gasWanted // only update state if all messages pass From 64ab312567eff21c9363fc038465dd27a08d7be9 Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Tue, 11 Dec 2018 17:53:45 +0800 Subject: [PATCH 2/5] Merge https://github.com/cosmos/cosmos-sdk/pull/2905 --- modules/distribution/keeper/allocation.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/distribution/keeper/allocation.go b/modules/distribution/keeper/allocation.go index 512e7c2d2..0cf27d985 100644 --- a/modules/distribution/keeper/allocation.go +++ b/modules/distribution/keeper/allocation.go @@ -18,6 +18,14 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s feesCollected := k.feeCollectionKeeper.GetCollectedFees(ctx) feesCollectedDec := types.NewDecCoins(feesCollected) + feePool := k.GetFeePool(ctx) + if k.stakeKeeper.GetLastTotalPower(ctx).IsZero() { + feePool.CommunityPool = feePool.CommunityPool.Plus(feesCollectedDec) + k.SetFeePool(ctx, feePool) + k.feeCollectionKeeper.ClearCollectedFees(ctx) + return + } + // allocated rewards to proposer baseProposerReward := k.GetBaseProposerReward(ctx) bonusProposerReward := k.GetBonusProposerReward(ctx) @@ -33,7 +41,6 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s // allocate community funding communityTax := k.GetCommunityTax(ctx) communityFunding := feesCollectedDec.MulDec(communityTax) - feePool := k.GetFeePool(ctx) feePool.CommunityPool = feePool.CommunityPool.Plus(communityFunding) // set the global pool within the distribution module From 3297c611a16abf79c234b39855493fbfc4926242 Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Tue, 11 Dec 2018 18:17:30 +0800 Subject: [PATCH 3/5] Merge https://github.com/cosmos/cosmos-sdk/pull/2949 --- app/baseapp.go | 63 +++++++++++++++++++++++++----------------------- types/context.go | 8 +++--- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/app/baseapp.go b/app/baseapp.go index 98b58a2e2..0ef3728bc 100644 --- a/app/baseapp.go +++ b/app/baseapp.go @@ -207,6 +207,10 @@ func (st *state) CacheMultiStore() sdk.CacheMultiStore { return st.ms.CacheMultiStore() } +func (st *state) Context() sdk.Context { + return st.ctx +} + func (app *BaseApp) setCheckState(header abci.Header) { ms := app.cms.CacheMultiStore() app.checkState = &state{ @@ -391,6 +395,7 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res return sdk.ErrUnknownRequest(fmt.Sprintf("no custom querier found for route %s", path[1])).QueryResult() } + // Cache wrap the commit-multistore for safety. ctx := sdk.NewContext(app.cms.CacheMultiStore(), app.checkState.ctx.BlockHeader(), true, app.Logger). WithMinimumFees(app.minimumFees) // Passes the rest of the path as an argument to the querier. @@ -538,13 +543,13 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error { return nil } -// retrieve the context for the ante handler and store the tx bytes; store -// the vote infos if the tx runs within the deliverTx() state. -func (app *BaseApp) getContextForAnte(mode RunTxMode, txBytes []byte) (ctx sdk.Context) { - // Get the context - ctx = app.getState(mode).ctx.WithTxBytes(txBytes) - if mode == RunTxModeDeliver { - ctx = ctx.WithVoteInfos(app.voteInfos) +// retrieve the context for the tx w/ txBytes and other memoized values. +func (app *BaseApp) getContextForTx(mode RunTxMode, txBytes []byte) (ctx sdk.Context) { + ctx = app.getState(mode).ctx. + WithTxBytes(txBytes). + WithVoteInfos(app.voteInfos) + if mode == RunTxModeSimulate { + ctx, _ = ctx.CacheContext() } return } @@ -619,20 +624,13 @@ func (app *BaseApp) getState(mode RunTxMode) *state { return app.deliverState } -func (app *BaseApp) initializeContext(ctx sdk.Context, mode RunTxMode) sdk.Context { - if mode == RunTxModeSimulate { - ctx = ctx.WithMultiStore(app.getState(RunTxModeSimulate).CacheMultiStore()) - } - return ctx -} - -// cacheTxContext returns a new context based off of the provided context with a -// cache wrapped multi-store and the store itself to allow the caller to write -// changes from the cached multi-store. -func (app *BaseApp) cacheTxContext( - ctx sdk.Context, txBytes []byte, mode RunTxMode, -) (sdk.Context, sdk.CacheMultiStore) { - msCache := app.getState(mode).CacheMultiStore() +// cacheTxContext returns a new context based off of the provided context with +// a cache wrapped multi-store. +func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) ( + sdk.Context, sdk.CacheMultiStore) { + ms := ctx.MultiStore() + // TODO: https://github.com/cosmos/cosmos-sdk/issues/2824 + msCache := ms.CacheMultiStore() if msCache.TracingEnabled() { msCache = msCache.WithTracingContext( sdk.TraceContext( @@ -654,8 +652,8 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk // meter so we initialize upfront. var gasWanted uint64 var msCache sdk.CacheMultiStore - ctx := app.getContextForAnte(mode, txBytes) - ctx = app.initializeContext(ctx, mode) + ctx := app.getContextForTx(mode, txBytes) + ms := ctx.MultiStore() ctxWithNoCache := ctx defer func() { @@ -711,32 +709,37 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk // NOTE: Alternatively, we could require that anteHandler ensures that // writes do not happen if aborted/failed. This may have some // performance benefits, but it'll be more difficult to get right. - anteCtx, msCache = app.cacheTxContext(ctx, txBytes, mode) + anteCtx, msCache = app.cacheTxContext(ctx, txBytes) newCtx, result, abort := anteHandler(anteCtx, tx, (mode == RunTxModeSimulate)) if abort { return result } if !newCtx.IsZero() { - ctx = newCtx - ctxWithNoCache = newCtx + // At this point, newCtx.MultiStore() is cache wrapped, + // or something else replaced by anteHandler. + // We want the original ms, not one which was cache-wrapped + // for the ante handler. + ctx = newCtx.WithMultiStore(ms) } msCache.Write() gasWanted = result.GasWanted } - if mode == RunTxModeSimulate { - result = app.runMsgs(ctx, msgs, mode) - result.GasWanted = gasWanted + if mode == RunTxModeCheck { return } // Create a new context based off of the existing context with a cache wrapped // multi-store in case message processing fails. - runMsgCtx, msCache := app.cacheTxContext(ctx, txBytes, mode) + runMsgCtx, msCache := app.cacheTxContext(ctx, txBytes) result = app.runMsgs(runMsgCtx, msgs, mode) result.GasWanted = gasWanted + if mode == RunTxModeSimulate { + return + } + // only update state if all messages pass if result.IsOK() { msCache.Write() diff --git a/types/context.go b/types/context.go index 7f7cd7700..a34000f4f 100644 --- a/types/context.go +++ b/types/context.go @@ -73,12 +73,12 @@ func (c Context) Value(key interface{}) interface{} { // KVStore fetches a KVStore from the MultiStore. func (c Context) KVStore(key StoreKey) KVStore { - return c.multiStore().GetKVStore(key).Gas(c.GasMeter(), cachedKVGasConfig) + return c.MultiStore().GetKVStore(key).Gas(c.GasMeter(), cachedKVGasConfig) } // TransientStore fetches a TransientStore from the MultiStore. func (c Context) TransientStore(key StoreKey) KVStore { - return c.multiStore().GetKVStore(key).Gas(c.GasMeter(), cachedTransientGasConfig) + return c.MultiStore().GetKVStore(key).Gas(c.GasMeter(), cachedTransientGasConfig) } //---------------------------------------- @@ -146,7 +146,7 @@ const ( // NOTE: Do not expose MultiStore. // MultiStore exposes all the keys. // Instead, pass the context and the store key. -func (c Context) multiStore() MultiStore { +func (c Context) MultiStore() MultiStore { return c.Value(contextKeyMultiStore).(MultiStore) } @@ -230,7 +230,7 @@ func (c Context) WithMinimumFees(minFees Coins) Context { // Cache the multistore and return a new cached context. The cached context is // written to the context when writeCache is called. func (c Context) CacheContext() (cc Context, writeCache func()) { - cms := c.multiStore().CacheMultiStore() + cms := c.MultiStore().CacheMultiStore() cc = c.WithMultiStore(cms) return cc, cms.Write } From 5efa55a0ae24d3afd5c77fe3d421bb49d86a7f2e Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Tue, 11 Dec 2018 18:22:25 +0800 Subject: [PATCH 4/5] Merge with https://github.com/cosmos/cosmos-sdk/pull/2949 --- app/baseapp.go | 7 ++++++- modules/stake/handler.go | 9 +++++++++ modules/stake/handler_test.go | 18 ++++++++++++++++++ modules/stake/keeper/test_common.go | 18 +++++++++--------- modules/stake/stake.go | 19 ++++++++++--------- modules/stake/types/errors.go | 6 ++++++ types/context.go | 11 ++++------- 7 files changed, 62 insertions(+), 26 deletions(-) diff --git a/app/baseapp.go b/app/baseapp.go index 0ef3728bc..ed37ec500 100644 --- a/app/baseapp.go +++ b/app/baseapp.go @@ -64,6 +64,10 @@ type BaseApp struct { deliverState *state // for DeliverTx voteInfos []abci.VoteInfo // absent validators from begin block + // consensus params + // TODO move this in the future to baseapp param store on main store. + consensusParams *abci.ConsensusParams + // minimum fees for spam prevention minimumFees sdk.Coins @@ -547,7 +551,8 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error { func (app *BaseApp) getContextForTx(mode RunTxMode, txBytes []byte) (ctx sdk.Context) { ctx = app.getState(mode).ctx. WithTxBytes(txBytes). - WithVoteInfos(app.voteInfos) + WithVoteInfos(app.voteInfos). + WithConsensusParams(app.consensusParams) if mode == RunTxModeSimulate { ctx, _ = ctx.CacheContext() } diff --git a/modules/stake/handler.go b/modules/stake/handler.go index cb7a52333..045394c54 100644 --- a/modules/stake/handler.go +++ b/modules/stake/handler.go @@ -8,6 +8,8 @@ import ( "github.com/irisnet/irishub/modules/stake/tags" "github.com/irisnet/irishub/modules/stake/types" abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/common" + tmtypes "github.com/tendermint/tendermint/types" ) func NewHandler(k keeper.Keeper) sdk.Handler { @@ -103,6 +105,13 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k return ErrBadDenom(k.Codespace()).Result() } + if ctx.ConsensusParams() != nil { + tmPubKey := tmtypes.TM2PB.PubKey(msg.PubKey) + if !common.StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) { + return ErrValidatorPubKeyTypeUnsupported(k.Codespace(), tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes).Result() + } + } + validator := NewValidator(msg.ValidatorAddr, msg.PubKey, msg.Description) commission := NewCommissionWithTime( msg.Commission.Rate, msg.Commission.MaxRate, diff --git a/modules/stake/handler_test.go b/modules/stake/handler_test.go index 1d8545d2a..a1a12b594 100644 --- a/modules/stake/handler_test.go +++ b/modules/stake/handler_test.go @@ -10,6 +10,9 @@ import ( sdk "github.com/irisnet/irishub/types" keep "github.com/irisnet/irishub/modules/stake/keeper" "github.com/irisnet/irishub/modules/stake/types" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/crypto/secp256k1" + tmtypes "github.com/tendermint/tendermint/types" ) //______________________________________________________________________ @@ -157,6 +160,21 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) { assert.Equal(t, Description{}, validator.Description) } +func TestInvalidPubKeyTypeMsgCreateValidator(t *testing.T) { + ctx, _, keeper := keep.CreateTestInput(t, false, sdk.NewIntWithDecimal(1000,18)) + addr := sdk.ValAddress(keep.Addrs[0]) + invalidPk := secp256k1.GenPrivKey().PubKey() + // invalid pukKey type should not be allowed + msgCreateValidator := NewTestMsgCreateValidator(addr, invalidPk, sdk.NewIntWithDecimal(10,18)) + got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) + require.False(t, got.IsOK(), "%v", got) + ctx = ctx.WithConsensusParams(&abci.ConsensusParams{ + Validator: &abci.ValidatorParams{PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeSecp256k1}}, + }) + got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper) + require.True(t, got.IsOK(), "%v", got) +} + func TestDuplicatesMsgCreateValidatorOnBehalfOf(t *testing.T) { ctx, _, keeper := keep.CreateTestInput(t, false, sdk.NewIntWithDecimal(1000, 18)) diff --git a/modules/stake/keeper/test_common.go b/modules/stake/keeper/test_common.go index c4d49f273..03c468c10 100644 --- a/modules/stake/keeper/test_common.go +++ b/modules/stake/keeper/test_common.go @@ -7,21 +7,20 @@ import ( "strconv" "testing" + "github.com/irisnet/irishub/codec" + "github.com/irisnet/irishub/modules/auth" + "github.com/irisnet/irishub/modules/bank" + "github.com/irisnet/irishub/modules/params" + "github.com/irisnet/irishub/modules/stake/types" + "github.com/irisnet/irishub/store" + sdk "github.com/irisnet/irishub/types" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" - - "github.com/irisnet/irishub/codec" - "github.com/irisnet/irishub/store" - sdk "github.com/irisnet/irishub/types" - "github.com/irisnet/irishub/modules/auth" - "github.com/irisnet/irishub/modules/bank" - "github.com/irisnet/irishub/modules/params" - "github.com/irisnet/irishub/modules/stake/types" + tmtypes "github.com/tendermint/tendermint/types" ) // dummy addresses used for testing @@ -94,6 +93,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initCoins sdk.Int) (sdk.Conte require.Nil(t, err) ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger()) + ctx = ctx.WithConsensusParams(&abci.ConsensusParams{Validator: &abci.ValidatorParams{PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeEd25519}}}) cdc := MakeTestCodec() accountKeeper := auth.NewAccountKeeper( cdc, // amino codec diff --git a/modules/stake/stake.go b/modules/stake/stake.go index 5b4829ddb..e974d22f0 100644 --- a/modules/stake/stake.go +++ b/modules/stake/stake.go @@ -118,15 +118,16 @@ const ( ) var ( - ErrNilValidatorAddr = types.ErrNilValidatorAddr - ErrNoValidatorFound = types.ErrNoValidatorFound - ErrValidatorOwnerExists = types.ErrValidatorOwnerExists - ErrValidatorPubKeyExists = types.ErrValidatorPubKeyExists - ErrValidatorJailed = types.ErrValidatorJailed - ErrBadRemoveValidator = types.ErrBadRemoveValidator - ErrDescriptionLength = types.ErrDescriptionLength - ErrCommissionNegative = types.ErrCommissionNegative - ErrCommissionHuge = types.ErrCommissionHuge + ErrNilValidatorAddr = types.ErrNilValidatorAddr + ErrNoValidatorFound = types.ErrNoValidatorFound + ErrValidatorOwnerExists = types.ErrValidatorOwnerExists + ErrValidatorPubKeyExists = types.ErrValidatorPubKeyExists + ErrValidatorPubKeyTypeUnsupported = types.ErrValidatorPubKeyTypeNotSupported + ErrValidatorJailed = types.ErrValidatorJailed + ErrBadRemoveValidator = types.ErrBadRemoveValidator + ErrDescriptionLength = types.ErrDescriptionLength + ErrCommissionNegative = types.ErrCommissionNegative + ErrCommissionHuge = types.ErrCommissionHuge ErrNilDelegatorAddr = types.ErrNilDelegatorAddr ErrBadDenom = types.ErrBadDenom diff --git a/modules/stake/types/errors.go b/modules/stake/types/errors.go index a14f8476d..662c9a01b 100644 --- a/modules/stake/types/errors.go +++ b/modules/stake/types/errors.go @@ -6,6 +6,7 @@ import ( "time" sdk "github.com/irisnet/irishub/types" + "strings" ) type CodeType = sdk.CodeType @@ -44,6 +45,11 @@ func ErrValidatorPubKeyExists(codespace sdk.CodespaceType) sdk.Error { return sdk.NewError(codespace, CodeInvalidValidator, "validator already exist for this pubkey, must use new validator pubkey") } +func ErrValidatorPubKeyTypeNotSupported(codespace sdk.CodespaceType, keyType string, supportedTypes []string) sdk.Error { + msg := fmt.Sprintf("validator pubkey type %s is not supported, must use %s", keyType, strings.Join(supportedTypes, ",")) + return sdk.NewError(codespace, CodeInvalidValidator, msg) +} + func ErrValidatorJailed(codespace sdk.CodespaceType) sdk.Error { return sdk.NewError(codespace, CodeInvalidValidator, "validator for this address is currently jailed") } diff --git a/types/context.go b/types/context.go index a34000f4f..469db6e6d 100644 --- a/types/context.go +++ b/types/context.go @@ -48,6 +48,7 @@ func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, logger log.Lo c = c.WithVoteInfos(nil) c = c.WithGasMeter(NewInfiniteGasMeter()) c = c.WithMinimumFees(Coins{}) + c = c.WithConsensusParams(nil) return c } @@ -154,8 +155,8 @@ func (c Context) BlockHeader() abci.Header { return c.Value(contextKeyBlockHeade func (c Context) BlockHeight() int64 { return c.Value(contextKeyBlockHeight).(int64) } -func (c Context) ConsensusParams() abci.ConsensusParams { - return c.Value(contextKeyConsensusParams).(abci.ConsensusParams) +func (c Context) ConsensusParams() *abci.ConsensusParams { + return c.Value(contextKeyConsensusParams).(*abci.ConsensusParams) } func (c Context) ChainID() string { return c.Value(contextKeyChainID).(string) } @@ -200,11 +201,7 @@ func (c Context) WithBlockHeight(height int64) Context { } func (c Context) WithConsensusParams(params *abci.ConsensusParams) Context { - if params == nil { - return c - } - return c.withValue(contextKeyConsensusParams, params). - WithGasMeter(NewGasMeter(uint64(params.BlockSize.MaxGas))) + return c.withValue(contextKeyConsensusParams, params) } func (c Context) WithChainID(chainID string) Context { return c.withValue(contextKeyChainID, chainID) } From 51f1d52a329d0cf92e9ab2cace830f648268216f Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Tue, 11 Dec 2018 20:13:43 +0800 Subject: [PATCH 5/5] remove ctxWithNoCache --- app/baseapp.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/baseapp.go b/app/baseapp.go index ed37ec500..34afbbd05 100644 --- a/app/baseapp.go +++ b/app/baseapp.go @@ -659,7 +659,6 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk var msCache sdk.CacheMultiStore ctx := app.getContextForTx(mode, txBytes) ms := ctx.MultiStore() - ctxWithNoCache := ctx defer func() { if r := recover(); r != nil { @@ -679,7 +678,7 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk feeRefundHandler := app.Engine.GetCurrent().GetFeeRefundHandler() // Refund unspent fee if mode != RunTxModeCheck && feeRefundHandler != nil { - _, err := feeRefundHandler(ctxWithNoCache, tx, result) + _, err := feeRefundHandler(ctx, tx, result) if err != nil { result = sdk.ErrInternal(err.Error()).Result() result.GasWanted = gasWanted