Skip to content

Commit

Permalink
Merge PR: fix feesplit cache contaminate when parallel-tx rerun (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylsGit authored Nov 4, 2022
1 parent 40e8b32 commit 2be7717
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions app/app_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ type feeSplitInfo struct {
}

func updateFeeSplitHandler(txFeesplit *sync.Map) sdk.UpdateFeeSplitHandler {
return func(txHash common.Hash, withdrawer sdk.AccAddress, fee sdk.Coins) {
// For rerun tx of parallel, feeSplitInfo is rewritten
txFeesplit.Store(txHash.String(), feeSplitInfo{withdrawer.String(), fee})
return func(txHash common.Hash, withdrawer sdk.AccAddress, fee sdk.Coins, isDelete bool) {
if isDelete {
// For rerun tx of parallel, feeSplitInfo is deleted when EnableFeeSplit is false
txFeesplit.Delete(txHash.String())
} else {
// For rerun tx of parallel, feeSplitInfo is rewritten when EnableFeeSplit is true
txFeesplit.Store(txHash.String(), feeSplitInfo{withdrawer.String(), fee})
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/types/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type EvmSysContractAddressHandler func(ctx Context, addr AccAddress) bool
type UpdateFeeCollectorAccHandler func(ctx Context, balance Coins, txFeesplit *sync.Map) error

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)
type UpdateFeeSplitHandler func(txHash common.Hash, addr AccAddress, fee Coins, isDelete bool)
type GetTxFeeAndFromHandler func(ctx Context, tx Tx) (Coins, bool, string, string, error)
type GetTxFeeHandler func(tx Tx) Coins

Expand Down
4 changes: 3 additions & 1 deletion x/feesplit/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (k Keeper) PostTxProcessing(
// check if the fees are globally enabled
params := k.GetParamsWithCache(ctx)
if !params.EnableFeeSplit {
// delete feesplit info
k.updateFeeSplitHandler(receipt.TxHash, nil, nil, true)
return nil
}

Expand Down Expand Up @@ -95,7 +97,7 @@ func (k Keeper) PostTxProcessing(
fees := sdk.Coins{{Denom: sdk.DefaultBondDenom, Amount: developerFee}}

// distribute the fees to the contract deployer / withdraw address
k.updateFeeSplitHandler(receipt.TxHash, withdrawer, fees)
k.updateFeeSplitHandler(receipt.TxHash, withdrawer, fees, false)

// add innertx
k.addFeesplitInnerTx(receipt.TxHash.Hex(), withdrawer.String(), fees.String())
Expand Down

0 comments on commit 2be7717

Please sign in to comment.