From 176cedc909181896feefa2032f5d021feb1c7740 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Tue, 6 Jun 2023 17:06:12 +0800 Subject: [PATCH 1/6] fix feecollector --- app/ante/account.go | 47 +++---------------- app/app.go | 1 + app/app_parallel.go | 19 ++++++-- app/refund/refund.go | 10 ++-- libs/cosmos-sdk/baseapp/abci.go | 17 +------ libs/cosmos-sdk/baseapp/baseapp.go | 2 +- .../baseapp/baseapp_mode_deliver.go | 4 +- libs/cosmos-sdk/baseapp/baseapp_parallel.go | 30 ++++++++++-- libs/cosmos-sdk/baseapp/baseapp_runtx.go | 13 +---- libs/cosmos-sdk/baseapp/options.go | 7 +++ libs/cosmos-sdk/types/handler.go | 2 + libs/ibc-go/testing/simapp/app.go | 15 +++++- 12 files changed, 81 insertions(+), 86 deletions(-) diff --git a/app/ante/account.go b/app/ante/account.go index 8fe95a2cb..c8b1b1306 100644 --- a/app/ante/account.go +++ b/app/ante/account.go @@ -152,7 +152,7 @@ func nonceVerification(ctx sdk.Context, acc exported.Account, msgEthTx *evmtypes return ctx, nil } -func ethGasConsume(ek EVMKeeper, ak accountKeeperInterface, sk types.SupplyKeeper, ctx *sdk.Context, acc exported.Account, accGetGas sdk.Gas, msgEthTx *evmtypes.MsgEthereumTx, simulate bool) error { +func ethGasConsume(ek EVMKeeper, sk types.SupplyKeeper, ctx *sdk.Context, acc exported.Account, accGetGas sdk.Gas, msgEthTx *evmtypes.MsgEthereumTx, simulate bool) error { gasLimit := msgEthTx.GetGas() if shouldIntrinsicGas(ek, ctx, msgEthTx) { @@ -181,7 +181,11 @@ func ethGasConsume(ek EVMKeeper, ak accountKeeperInterface, sk types.SupplyKeepe ctx.UpdateFromAccountCache(acc, accGetGas) - err := deductFees(ek, ak, sk, *ctx, acc, feeAmt) + err := auth.DeductFees(sk, *ctx, acc, feeAmt) + if !ctx.IsCheckTx() { + toAcc := sk.GetModuleAddress(types.FeeCollectorName) + ek.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, acc.GetAddress(), toAcc, innertx.CosmosCallType, innertx.SendCallName, feeAmt, err) + } if err != nil { return err } @@ -208,43 +212,6 @@ func IsE2CTx(ek EVMKeeper, ctx *sdk.Context, msgEthTx *evmtypes.MsgEthereumTx) b return false } -func deductFees(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.SupplyKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) error { - blockTime := ctx.BlockTime() - coins := acc.GetCoins() - - if !fees.IsValid() { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) - } - - // verify the account has enough funds to pay for fees - balance, hasNeg := coins.SafeSub(fees) - if hasNeg { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, - "insufficient funds to pay for fees; %s < %s", coins, fees) - } - - // Validate the account has enough "spendable" coins as this will cover cases - // such as vesting accounts. - spendableCoins := acc.SpendableCoins(blockTime) - if _, hasNeg := spendableCoins.SafeSub(fees); hasNeg { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, - "insufficient funds to pay for fees; %s < %s", spendableCoins, fees) - } - - // set coins and record innertx - err := acc.SetCoins(balance) - if !ctx.IsCheckTx() { - toAcc := sk.GetModuleAddress(types.FeeCollectorName) - ik.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, acc.GetAddress(), toAcc, innertx.CosmosCallType, innertx.SendCallName, fees, err) - } - if err != nil { - return err - } - ak.SetAccount(ctx, acc) - - return nil -} - func incrementSeq(ctx sdk.Context, msgEthTx *evmtypes.MsgEthereumTx, accAddress sdk.AccAddress, ak auth.AccountKeeper, acc exported.Account) { if ctx.IsCheckTx() && !ctx.IsReCheckTx() && !baseapp.IsMempoolEnableRecheck() && !ctx.IsTraceTx() { return @@ -335,7 +302,7 @@ func (avd AccountAnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate ctx.EnableAccountCache() // account would be updated - err = ethGasConsume(avd.evmKeeper, avd.ak, avd.sk, &ctx, acc, getAccGasUsed, msgEthTx, simulate) + err = ethGasConsume(avd.evmKeeper, avd.sk, &ctx, acc, getAccGasUsed, msgEthTx, simulate) acc = nil acc, _ = ctx.GetFromAccountCacheData().(exported.Account) ctx.DisableAccountCache() diff --git a/app/app.go b/app/app.go index adbd60053..490f79e68 100644 --- a/app/app.go +++ b/app/app.go @@ -698,6 +698,7 @@ func NewOKBChainApp( app.SetUpdateWasmTxCount(fixCosmosTxCountInWasmForParallelTx(app.WasmHandler.TXCounterStoreKey)) app.SetUpdateFeeCollectorAccHandler(updateFeeCollectorHandler(app.BankKeeper, app.SupplyKeeper)) + app.SetGetFeeCollectorInfo(getFeeCollectorInfo(app.BankKeeper, app.SupplyKeeper)) app.SetParallelTxLogHandlers(fixLogForParallelTxHandler(app.EvmKeeper)) app.SetPreDeliverTxHandler(preDeliverTxHandler(app.AccountKeeper)) app.SetPartialConcurrentHandlers(getTxFeeAndFromHandler(app.EvmKeeper)) diff --git a/app/app_parallel.go b/app/app_parallel.go index 86f2476c6..4eb84f83b 100644 --- a/app/app_parallel.go +++ b/app/app_parallel.go @@ -18,12 +18,23 @@ import ( wasmkeeper "github.com/okx/okbchain/x/wasm/keeper" ) +func getFeeCollectorInfo(bk bank.Keeper, sk supply.Keeper) sdk.GetFeeCollectorInfo { + return func(ctx sdk.Context, onlyGetFeeCollectorStoreKey bool) (sdk.Coins, []byte) { + if onlyGetFeeCollectorStoreKey { + return sdk.Coins{}, auth.AddressStoreKey(sk.GetModuleAddress(auth.FeeCollectorName)) + } + return bk.GetCoins(ctx, sk.GetModuleAddress(auth.FeeCollectorName)), nil + } +} + // feeCollectorHandler set or get the value of feeCollectorAcc func updateFeeCollectorHandler(bk bank.Keeper, sk supply.Keeper) sdk.UpdateFeeCollectorAccHandler { return func(ctx sdk.Context, balance sdk.Coins, txFeesplit []*sdk.FeeSplitInfo) error { - err := bk.SetCoins(ctx, sk.GetModuleAccount(ctx, auth.FeeCollectorName).GetAddress(), balance) - if err != nil { - return err + if !balance.Empty() { + err := bk.SetCoins(ctx, sk.GetModuleAccount(ctx, auth.FeeCollectorName).GetAddress(), balance) + if err != nil { + return err + } } // split fee @@ -32,7 +43,7 @@ func updateFeeCollectorHandler(bk bank.Keeper, sk supply.Keeper) sdk.UpdateFeeCo feesplits, sortAddrs := groupByAddrAndSortFeeSplits(txFeesplit) for _, addr := range sortAddrs { acc := sdk.MustAccAddressFromBech32(addr) - err = sk.SendCoinsFromModuleToAccount(ctx, auth.FeeCollectorName, acc, feesplits[addr]) + err := sk.SendCoinsFromModuleToAccount(ctx, auth.FeeCollectorName, acc, feesplits[addr]) if err != nil { return err } diff --git a/app/refund/refund.go b/app/refund/refund.go index 9ba8a1914..fc7b307d2 100644 --- a/app/refund/refund.go +++ b/app/refund/refund.go @@ -4,14 +4,14 @@ import ( "math/big" "sync" - "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/ante" - "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/keeper" - sdk "github.com/okx/okbchain/libs/cosmos-sdk/types" sdkerrors "github.com/okx/okbchain/libs/cosmos-sdk/types/errors" "github.com/okx/okbchain/libs/cosmos-sdk/types/innertx" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth" + "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/ante" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/exported" + "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/keeper" + "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/refund" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/types" tmtypes "github.com/okx/okbchain/libs/tendermint/types" ) @@ -89,10 +89,9 @@ func gasRefund(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.Sup gas := feeTx.GetGas() fees := feeTx.GetFee() gasFees := calculateRefundFees(gasUsed, gas, fees) - newCoins := feePayerAcc.GetCoins().Add(gasFees...) // set coins and record innertx - err = feePayerAcc.SetCoins(newCoins) + err = refund.RefundFees(sk, ctx, feePayerAcc.GetAddress(), gasFees) if !ctx.IsCheckTx() { fromAddr := sk.GetModuleAddress(types.FeeCollectorName) ik.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, fromAddr, feePayerAcc.GetAddress(), innertx.CosmosCallType, innertx.SendCallName, gasFees, err) @@ -100,7 +99,6 @@ func gasRefund(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.Sup if err != nil { return nil, err } - ak.SetAccount(ctx, feePayerAcc) return gasFees, nil } diff --git a/libs/cosmos-sdk/baseapp/abci.go b/libs/cosmos-sdk/baseapp/abci.go index 1d83cd59d..35cfc5ae3 100644 --- a/libs/cosmos-sdk/baseapp/abci.go +++ b/libs/cosmos-sdk/baseapp/abci.go @@ -168,28 +168,15 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg app.anteTracer = trace.NewTracer(trace.AnteChainDetail) - app.feeCollector = sdk.Coins{} - app.feeChanged = false + app.feeCollector = nil // clean FeeSplitCollector app.FeeSplitCollector = make([]*sdk.FeeSplitInfo, 0) return res } -func (app *BaseApp) UpdateFeeCollector(fee sdk.Coins, add bool) { - if fee.IsZero() { - return - } - app.feeChanged = true - if add { - app.feeCollector = app.feeCollector.Add(fee...) - } else { - app.feeCollector = app.feeCollector.Sub(fee) - } -} - func (app *BaseApp) updateFeeCollectorAccount(isEndBlock bool) { - if app.updateFeeCollectorAccHandler == nil || !app.feeChanged { + if app.updateFeeCollectorAccHandler == nil { return } diff --git a/libs/cosmos-sdk/baseapp/baseapp.go b/libs/cosmos-sdk/baseapp/baseapp.go index 70b8a261d..c82829842 100644 --- a/libs/cosmos-sdk/baseapp/baseapp.go +++ b/libs/cosmos-sdk/baseapp/baseapp.go @@ -150,6 +150,7 @@ type BaseApp struct { // nolint: maligned fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed. updateFeeCollectorAccHandler sdk.UpdateFeeCollectorAccHandler + getFeeCollectorInfoHandler sdk.GetFeeCollectorInfo logFix sdk.LogFix updateCosmosTxCount sdk.UpdateCosmosTxCount @@ -202,7 +203,6 @@ type BaseApp struct { // nolint: maligned parallelTxManage *parallelTxManager feeCollector sdk.Coins - feeChanged bool // used to judge whether should update the fee-collector account FeeSplitCollector []*sdk.FeeSplitInfo checkTxNum int64 diff --git a/libs/cosmos-sdk/baseapp/baseapp_mode_deliver.go b/libs/cosmos-sdk/baseapp/baseapp_mode_deliver.go index 301962548..fb437e9aa 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_mode_deliver.go +++ b/libs/cosmos-sdk/baseapp/baseapp_mode_deliver.go @@ -53,8 +53,8 @@ func (m *modeHandlerDeliver) handleDeferRefund(info *runTxInfo) { if m.app.GasRefundHandler == nil { return } - refund := handleGasRefund(info, m.app.cacheTxContext, m.app.GasRefundHandler) - m.app.UpdateFeeCollector(refund, false) + handleGasRefund(info, m.app.cacheTxContext, m.app.GasRefundHandler) + if info.ctx.GetFeeSplitInfo().HasFee { m.app.FeeSplitCollector = append(m.app.FeeSplitCollector, info.ctx.GetFeeSplitInfo()) } diff --git a/libs/cosmos-sdk/baseapp/baseapp_parallel.go b/libs/cosmos-sdk/baseapp/baseapp_parallel.go index 68b0f6ff1..2f73bb9c8 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_parallel.go +++ b/libs/cosmos-sdk/baseapp/baseapp_parallel.go @@ -19,6 +19,8 @@ var ( maxTxResultInChan = 200000 maxGoroutineNumberInParaTx = runtime.NumCPU() multiCacheListClearInterval = int64(100) + + feeAccountKeyInStore = make([]byte, 0) ) type extraDataForTx struct { @@ -189,6 +191,10 @@ func (app *BaseApp) ParallelTxs(txs [][]byte, onlyCalSender bool) []*abci.Respon return make([]*abci.ResponseDeliverTx, 0) } + if len(feeAccountKeyInStore) == 0 { + _, feeAccountKeyInStore = app.getFeeCollectorInfoHandler(app.deliverState.ctx, true) + } + pm := app.parallelTxManage pm.init(txs, app.deliverState.ctx.BlockHeight(), app.deliverState.ms) @@ -263,6 +269,21 @@ func (app *BaseApp) runTxs() []*abci.ResponseDeliverTx { pm.blockGasMeterMu.Unlock() pm.SetCurrentIndex(pm.upComingTxIndex, res) + + if !res.msIsNil { + // update fee collector balance + if pm.extraTxsInfo[pm.upComingTxIndex].isEvm { + // evm:fee-refund + pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[pm.upComingTxIndex].fee.Sub(pm.finalResult[pm.upComingTxIndex].paraMsg.RefundFee)...) + } else { + // non-evm:reload fee collector balance + ctx, _ := app.cacheTxContext(app.getContextForTx(runTxModeDeliver, []byte{}), []byte{}) + ctx.SetMultiStore(app.parallelTxManage.cms) + pm.currTxFee, _ = app.getFeeCollectorInfoHandler(ctx, false) + } + + } + currentGas += uint64(res.resp.GasUsed) if isReRun { @@ -300,9 +321,10 @@ func (app *BaseApp) runTxs() []*abci.ResponseDeliverTx { pm.alreadyEnd = true pm.stop <- struct{}{} - // fix logs - app.feeChanged = true + // update fee collector balance app.feeCollector = app.parallelTxManage.currTxFee + + // fix logs receiptsLogs := app.endParallelTxs(pm.txSize) ctx, _ := app.cacheTxContext(app.getContextForTx(runTxModeDeliver, []byte{}), []byte{}) ctx.SetMultiStore(app.parallelTxManage.cms) @@ -696,7 +718,6 @@ func (pm *parallelTxManager) addBlockCacheToChainCache() { } var ( - feeAccountKey, _ = hex.DecodeString("01f1829676db577682e944fc3493d451b67ff3e29f") wasmTxCountKey, _ = hex.DecodeString("08") ) @@ -705,7 +726,7 @@ func (pm *parallelTxManager) isConflict(e *executeResult) bool { return true //TODO fix later } for storeKey, rw := range e.rwSet { - delete(rw.Read, string(feeAccountKey)) + delete(rw.Read, string(feeAccountKeyInStore)) delete(rw.Read, string(wasmTxCountKey)) for key, value := range rw.Read { @@ -820,5 +841,4 @@ func (pm *parallelTxManager) SetCurrentIndex(txIndex int, res *executeResult) { pm.conflictCheck[storeKey].Write[key] = value } } - pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[txIndex].fee.Sub(pm.finalResult[txIndex].paraMsg.RefundFee)...) } diff --git a/libs/cosmos-sdk/baseapp/baseapp_runtx.go b/libs/cosmos-sdk/baseapp/baseapp_runtx.go index 55243ea7a..3c4011161 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_runtx.go +++ b/libs/cosmos-sdk/baseapp/baseapp_runtx.go @@ -86,12 +86,6 @@ func (app *BaseApp) runtxWithInfo(info *runTxInfo, mode runTxMode, txBytes []byt handler := info.handler app.pin(trace.ValTxMsgs, true, mode) - if tx.GetType() != sdk.EvmTxType && mode == runTxModeDeliver { - // should update the balance of FeeCollector's account when run non-evm tx - // which uses non-infiniteGasMeter during AnteHandleChain - app.updateFeeCollectorAccount(false) - } - //init info context err = handler.handleStartHeight(info, height) if err != nil { @@ -177,12 +171,7 @@ func (app *BaseApp) runtxWithInfo(info *runTxInfo, mode runTxMode, txBytes []byt } } app.pin(trace.RunAnte, false, mode) - - if app.getTxFeeHandler != nil && mode == runTxModeDeliver { - fee := app.getTxFeeHandler(tx) - app.UpdateFeeCollector(fee, true) - } - + isAnteSucceed = true app.pin(trace.RunMsg, true, mode) err = handler.handleRunMsg(info) diff --git a/libs/cosmos-sdk/baseapp/options.go b/libs/cosmos-sdk/baseapp/options.go index 312a4a8c6..80ace8ae3 100644 --- a/libs/cosmos-sdk/baseapp/options.go +++ b/libs/cosmos-sdk/baseapp/options.go @@ -170,6 +170,13 @@ func (app *BaseApp) SetUpdateFeeCollectorAccHandler(handler sdk.UpdateFeeCollect app.updateFeeCollectorAccHandler = handler } +func (app *BaseApp) SetGetFeeCollectorInfo(handle sdk.GetFeeCollectorInfo) { + if app.sealed { + panic("SetGetFeeCollectorBalance() on sealed BaseApp") + } + app.getFeeCollectorInfoHandler = handle +} + func (app *BaseApp) SetParallelTxLogHandlers(fixLog sdk.LogFix) { if app.sealed { panic("SetPallTxLogHandler() on sealed BaseApp") diff --git a/libs/cosmos-sdk/types/handler.go b/libs/cosmos-sdk/types/handler.go index 0b2512ee8..cd45aa1dc 100644 --- a/libs/cosmos-sdk/types/handler.go +++ b/libs/cosmos-sdk/types/handler.go @@ -27,6 +27,8 @@ type UpdateFeeCollectorAccHandler func(ctx Context, balance Coins, txFeesplit [] type UpdateCosmosTxCount func(ctx Context, txCount int) +type GetFeeCollectorInfo func(ctx Context, onlyGetFeeCollectorStoreKey bool) (Coins, []byte) + type LogFix func(tx []Tx, logIndex []int, hasEnterEvmTx []bool, errs []error, resp []abci.ResponseDeliverTx) (logs [][]byte) type UpdateFeeSplitHandler func(txHash common.Hash, addr AccAddress, fee Coins, isDelete bool) type GetTxFeeAndFromHandler func(ctx Context, tx Tx) (Coins, bool, bool, string, string, error, bool) diff --git a/libs/ibc-go/testing/simapp/app.go b/libs/ibc-go/testing/simapp/app.go index 8e0e5ca75..154ffe1eb 100644 --- a/libs/ibc-go/testing/simapp/app.go +++ b/libs/ibc-go/testing/simapp/app.go @@ -696,6 +696,7 @@ func NewSimApp( app.SetAccNonceHandler(NewAccHandler(app.AccountKeeper)) app.SetUpdateWasmTxCount(fixCosmosTxCountInWasmForParallelTx(app.WasmHandler.TXCounterStoreKey)) app.SetUpdateFeeCollectorAccHandler(updateFeeCollectorHandler(app.BankKeeper, app.SupplyKeeper.Keeper)) + app.SetGetFeeCollectorInfo(getFeeCollectorInfo(app.BankKeeper, app.SupplyKeeper.Keeper)) app.SetParallelTxLogHandlers(fixLogForParallelTxHandler(app.EvmKeeper)) app.SetPartialConcurrentHandlers(getTxFeeAndFromHandler(app.EvmKeeper)) app.SetGetTxFeeHandler(getTxFeeHandler()) @@ -723,7 +724,19 @@ func NewSimApp( func updateFeeCollectorHandler(bk bank.Keeper, sk supply.Keeper) sdk.UpdateFeeCollectorAccHandler { return func(ctx sdk.Context, balance sdk.Coins, txFeesplit []*sdk.FeeSplitInfo) error { - return bk.SetCoins(ctx, sk.GetModuleAccount(ctx, auth.FeeCollectorName).GetAddress(), balance) + if !balance.Empty() { + return bk.SetCoins(ctx, sk.GetModuleAccount(ctx, auth.FeeCollectorName).GetAddress(), balance) + } + return nil + } +} + +func getFeeCollectorInfo(bk bank.Keeper, sk supply.Keeper) sdk.GetFeeCollectorInfo { + return func(ctx sdk.Context, onlyGetFeeCollectorStoreKey bool) (sdk.Coins, []byte) { + if onlyGetFeeCollectorStoreKey { + return sdk.Coins{}, auth.AddressStoreKey(sk.GetModuleAddress(auth.FeeCollectorName)) + } + return bk.GetCoins(ctx, sk.GetModuleAddress(auth.FeeCollectorName)), nil } } From d65a224c11d8ac8ef8622c31f66fc0318b37046b Mon Sep 17 00:00:00 2001 From: ylsGit Date: Mon, 12 Jun 2023 20:44:30 +0800 Subject: [PATCH 2/6] fix repetitive innertx --- app/ante/account.go | 5 ----- app/refund/refund.go | 4 ---- 2 files changed, 9 deletions(-) diff --git a/app/ante/account.go b/app/ante/account.go index c8b1b1306..a99eb877f 100644 --- a/app/ante/account.go +++ b/app/ante/account.go @@ -12,7 +12,6 @@ import ( "github.com/okx/okbchain/libs/cosmos-sdk/baseapp" sdk "github.com/okx/okbchain/libs/cosmos-sdk/types" sdkerrors "github.com/okx/okbchain/libs/cosmos-sdk/types/errors" - "github.com/okx/okbchain/libs/cosmos-sdk/types/innertx" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/exported" "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/types" @@ -182,10 +181,6 @@ func ethGasConsume(ek EVMKeeper, sk types.SupplyKeeper, ctx *sdk.Context, acc ex ctx.UpdateFromAccountCache(acc, accGetGas) err := auth.DeductFees(sk, *ctx, acc, feeAmt) - if !ctx.IsCheckTx() { - toAcc := sk.GetModuleAddress(types.FeeCollectorName) - ek.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, acc.GetAddress(), toAcc, innertx.CosmosCallType, innertx.SendCallName, feeAmt, err) - } if err != nil { return err } diff --git a/app/refund/refund.go b/app/refund/refund.go index fc7b307d2..c2f53d238 100644 --- a/app/refund/refund.go +++ b/app/refund/refund.go @@ -92,10 +92,6 @@ func gasRefund(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.Sup // set coins and record innertx err = refund.RefundFees(sk, ctx, feePayerAcc.GetAddress(), gasFees) - if !ctx.IsCheckTx() { - fromAddr := sk.GetModuleAddress(types.FeeCollectorName) - ik.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, fromAddr, feePayerAcc.GetAddress(), innertx.CosmosCallType, innertx.SendCallName, gasFees, err) - } if err != nil { return nil, err } From 613245098f07df9c7e544ae668466595f792bce4 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Thu, 15 Jun 2023 21:59:14 +0800 Subject: [PATCH 3/6] updatre --- libs/cosmos-sdk/baseapp/abci.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/libs/cosmos-sdk/baseapp/abci.go b/libs/cosmos-sdk/baseapp/abci.go index b30cb47ef..b30766c1b 100644 --- a/libs/cosmos-sdk/baseapp/abci.go +++ b/libs/cosmos-sdk/baseapp/abci.go @@ -187,18 +187,6 @@ func (app *BaseApp) UpdateGlobalGasConfig(ctx sdk.Context) { stypes.UpdateGlobalGasConfig(app.getGasConfigHandler(ctx)) } -func (app *BaseApp) UpdateFeeCollector(fee sdk.Coins, add bool) { - if fee.IsZero() { - return - } - app.feeChanged = true - if add { - app.feeCollector = app.feeCollector.Add(fee...) - } else { - app.feeCollector = app.feeCollector.Sub(fee) - } -} - func (app *BaseApp) updateFeeCollectorAccount(isEndBlock bool) { if app.updateFeeCollectorAccHandler == nil { return From f648eaa449af93f2b1201f39ac33ab4658a501b4 Mon Sep 17 00:00:00 2001 From: chunfengSun <516108736@qq.com> Date: Thu, 29 Jun 2023 11:01:38 +0800 Subject: [PATCH 4/6] Update baseapp_parallel.go --- libs/cosmos-sdk/baseapp/baseapp_parallel.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libs/cosmos-sdk/baseapp/baseapp_parallel.go b/libs/cosmos-sdk/baseapp/baseapp_parallel.go index ebca8ec51..8abd67bf8 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_parallel.go +++ b/libs/cosmos-sdk/baseapp/baseapp_parallel.go @@ -271,17 +271,7 @@ func (app *BaseApp) runTxs() []*abci.ResponseDeliverTx { pm.SetCurrentIndex(pm.upComingTxIndex, res) if !res.msIsNil { - // update fee collector balance - if pm.extraTxsInfo[pm.upComingTxIndex].isEvm { - // evm:fee-refund - pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[pm.upComingTxIndex].fee.Sub(pm.finalResult[pm.upComingTxIndex].paraMsg.RefundFee)...) - } else { - // non-evm:reload fee collector balance - ctx, _ := app.cacheTxContext(app.getContextForTx(runTxModeDeliver, []byte{}), []byte{}) - ctx.SetMultiStore(app.parallelTxManage.cms) - pm.currTxFee, _ = app.getFeeCollectorInfoHandler(ctx, false) - } - + pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[pm.upComingTxIndex].fee.Sub(pm.finalResult[pm.upComingTxIndex].paraMsg.RefundFee)...) } currentGas += uint64(res.resp.GasUsed) From 9e940f6b359f0a16b7ece0ce1104f0bd50ca5b59 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Fri, 14 Jul 2023 18:03:07 +0800 Subject: [PATCH 5/6] fix merge error --- libs/cosmos-sdk/baseapp/baseapp_parallel.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/cosmos-sdk/baseapp/baseapp_parallel.go b/libs/cosmos-sdk/baseapp/baseapp_parallel.go index 60ccf9193..6a0ebc6e3 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_parallel.go +++ b/libs/cosmos-sdk/baseapp/baseapp_parallel.go @@ -265,14 +265,11 @@ func (app *BaseApp) runTxs() []*abci.ResponseDeliverTx { app.deliverState.ctx.BlockGasMeter().ConsumeGas(sdk.Gas(res.resp.GasUsed), "unexpected error") pm.blockGasMeterMu.Unlock() - pm.SetCurrentIndex(pm.upComingTxIndex, res) - if !res.msIsNil { pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[pm.upComingTxIndex].fee.Sub(pm.finalResult[pm.upComingTxIndex].paraMsg.RefundFee)...) } pm.SetCurrentIndexTxRes(pm.upComingTxIndex, res) - currentGas += uint64(res.resp.GasUsed) if isReRun { From dd926909f8bca9be70c29519aa30bca2dfe8eeda Mon Sep 17 00:00:00 2001 From: LeoGuo621 <335209779@qq.com> Date: Fri, 14 Jul 2023 18:24:08 +0800 Subject: [PATCH 6/6] Update baseapp_parallel.go fix conflict --- libs/cosmos-sdk/baseapp/baseapp_parallel.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/cosmos-sdk/baseapp/baseapp_parallel.go b/libs/cosmos-sdk/baseapp/baseapp_parallel.go index 6a0ebc6e3..9f14c056c 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_parallel.go +++ b/libs/cosmos-sdk/baseapp/baseapp_parallel.go @@ -265,11 +265,12 @@ func (app *BaseApp) runTxs() []*abci.ResponseDeliverTx { app.deliverState.ctx.BlockGasMeter().ConsumeGas(sdk.Gas(res.resp.GasUsed), "unexpected error") pm.blockGasMeterMu.Unlock() + pm.SetCurrentIndexTxRes(pm.upComingTxIndex, res) + if !res.msIsNil { pm.currTxFee = pm.currTxFee.Add(pm.extraTxsInfo[pm.upComingTxIndex].fee.Sub(pm.finalResult[pm.upComingTxIndex].paraMsg.RefundFee)...) } - pm.SetCurrentIndexTxRes(pm.upComingTxIndex, res) currentGas += uint64(res.resp.GasUsed) if isReRun {