Skip to content

Commit

Permalink
Merge PR:smb fix (#1971)
Browse files Browse the repository at this point in the history
* add log

* change log

* remove for test

* optimize GetTxFeeAndFromHandler

* remove log

* encapsulate getTxFeeHandler for serial usage

* optimize GetTxFeeHandler

* optimize getTxFeeHandler
  • Loading branch information
MinZhu09 authored May 2, 2022
1 parent 1344c62 commit 5076a1f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 42 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func NewOKExChainApp(
app.SetParallelTxHandlers(updateFeeCollectorHandler(app.BankKeeper, app.SupplyKeeper), fixLogForParallelTxHandler(app.EvmKeeper))
app.SetPreDeliverTxHandler(preDeliverTxHandler(app.AccountKeeper))
app.SetPartialConcurrentHandlers(getTxFeeAndFromHandler(app.AccountKeeper))
app.SetGetTxFeeHandler(getTxFeeHandler())

if loadLatest {
err := app.LoadLatestVersion(app.keys[bam.MainStoreKey])
Expand Down
42 changes: 42 additions & 0 deletions app/app_parallel.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package app

import (
"encoding/hex"
"strings"

ethermint "github.com/okex/exchain/app/types"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/x/auth"
authante "github.com/okex/exchain/libs/cosmos-sdk/x/auth/ante"
"github.com/okex/exchain/libs/cosmos-sdk/x/bank"
"github.com/okex/exchain/libs/cosmos-sdk/x/supply"
"github.com/okex/exchain/x/evm"
Expand Down Expand Up @@ -61,3 +65,41 @@ func evmTxVerifySigHandler(chainID string, blockHeight int64, evmTx *evmtypes.Ms
}
return nil
}

func getTxFeeHandler() sdk.GetTxFeeHandler {
return func(tx sdk.Tx) (fee sdk.Coins) {
if feeTx, ok := tx.(authante.FeeTx); ok {
fee = feeTx.GetFee()
}

return
}
}

// getTxFeeAndFromHandler get tx fee and from
func getTxFeeAndFromHandler(ak auth.AccountKeeper) sdk.GetTxFeeAndFromHandler {
return func(ctx sdk.Context, tx sdk.Tx) (fee sdk.Coins, isEvm bool, from string, to string, err error) {
if evmTx, ok := tx.(*evmtypes.MsgEthereumTx); ok {
isEvm = true
err = evmTx.VerifySig(evmTx.ChainID(), ctx.BlockHeight())
if err != nil {
return
}
fee = evmTx.GetFee()
from = evmTx.BaseTx.From
if len(from) > 2 {
from = strings.ToLower(from[2:])
}
if evmTx.To() != nil {
to = strings.ToLower(evmTx.To().String()[2:])
}
} else if feeTx, ok := tx.(authante.FeeTx); ok {
fee = feeTx.GetFee()
feePayer := feeTx.FeePayer(ctx)
feePayerAcc := ak.GetAccount(ctx, feePayer)
from = hex.EncodeToString(feePayerAcc.GetAddress())
}

return
}
}
38 changes: 0 additions & 38 deletions app/app_partial_concurrent.go

This file was deleted.

5 changes: 3 additions & 2 deletions libs/cosmos-sdk/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type BaseApp struct { // nolint: maligned
logFix sdk.LogFix

getTxFeeAndFromHandler sdk.GetTxFeeAndFromHandler
getTxFeeHandler sdk.GetTxFeeHandler

// volatile states:
//
Expand Down Expand Up @@ -194,8 +195,8 @@ type BaseApp struct { // nolint: maligned

parallelTxManage *parallelTxManager
deliverTxsMgr *DTTManager
feeForCollector sdk.Coins
feeChanged bool // used to judge whether should update the fee-collector account
feeForCollector sdk.Coins
feeChanged bool // used to judge whether should update the fee-collector account

chainCache *sdk.Cache
blockCache *sdk.Cache
Expand Down
4 changes: 2 additions & 2 deletions libs/cosmos-sdk/baseapp/baseapp_runtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (app *BaseApp) runtxWithInfo(info *runTxInfo, mode runTxMode, txBytes []byt
}
app.pin(RunAnte, false, mode)

if app.getTxFeeAndFromHandler != nil && mode == runTxModeDeliver {
fee, _, _, _, _ := app.getTxFeeAndFromHandler(info.ctx, tx)
if app.getTxFeeHandler != nil && mode == runTxModeDeliver {
fee := app.getTxFeeHandler(tx)
app.UpdateFeeForCollector(fee, true)
}

Expand Down
7 changes: 7 additions & 0 deletions libs/cosmos-sdk/baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,10 @@ func (app *BaseApp) SetPartialConcurrentHandlers(etf sdk.GetTxFeeAndFromHandler)
}
app.getTxFeeAndFromHandler = etf
}

func (app *BaseApp) SetGetTxFeeHandler(handler sdk.GetTxFeeHandler){
if app.sealed {
panic("SetGetTxFeeHandler() on sealed BaseApp")
}
app.getTxFeeHandler = handler
}
1 change: 1 addition & 0 deletions libs/cosmos-sdk/types/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type UpdateFeeCollectorAccHandler func(ctx Context, balance Coins) error
type LogFix func(logIndex []int, errs []error) (logs [][]byte)

type GetTxFeeAndFromHandler func(ctx Context, tx Tx) (Coins, bool, string, string, error)
type GetTxFeeHandler func(tx Tx) Coins

// AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing.
type AnteDecorator interface {
Expand Down

0 comments on commit 5076a1f

Please sign in to comment.