Skip to content

Commit

Permalink
Merge PR: Clear Logs of failed txs (#2963)
Browse files Browse the repository at this point in the history
* clear Logs of failed txs

* modify code

* improve code

* improve code

* sort imports

---------

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
LeoGuo621 and KamiD authored Mar 1, 2023
1 parent 6f892cd commit fc82565
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions app/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
"github.com/okex/exchain/libs/tendermint/global"

lru "github.com/hashicorp/golang-lru"

coretypes "github.com/okex/exchain/libs/tendermint/rpc/core/types"

"github.com/spf13/viper"

"golang.org/x/time/rate"

"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/x/evm/watcher"
"golang.org/x/time/rate"

rpctypes "github.com/okex/exchain/app/rpc/types"
evmtypes "github.com/okex/exchain/x/evm/types"
Expand All @@ -30,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/bloombits"
ethtypes "github.com/ethereum/go-ethereum/core/types"

tmtypes "github.com/okex/exchain/libs/tendermint/types"
dbm "github.com/okex/exchain/libs/tm-db"
)
Expand Down Expand Up @@ -281,12 +284,16 @@ func (b *EthermintBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.L
if err != nil {
return nil, err
}

execRes, err := evmtypes.DecodeResultData(txRes.TxResult.Data)
if err != nil {
return nil, err
}

// Sometimes failed txs leave Logs which need to be cleared
if !txRes.TxResult.IsOK() && execRes.Logs != nil {
return []*ethtypes.Log{}, nil
}

return execRes.Logs, nil
}

Expand Down
4 changes: 3 additions & 1 deletion app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,9 +1338,11 @@ func (api *PublicEthereumAPI) GetTransactionReceipt(hash common.Hash) (*watcher.
status = 0 // transaction failed
}

if len(data.Logs) == 0 {
if len(data.Logs) == 0 || status == 0 {
data.Logs = []*ethtypes.Log{}
data.Bloom = ethtypes.BytesToBloom(make([]byte, 256))
}

contractAddr := &data.ContractAddress
if data.ContractAddress == common.HexToAddress("0x00000000000000000000") {
contractAddr = nil
Expand Down
4 changes: 3 additions & 1 deletion app/rpc/namespaces/eth/api_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ func (api *PublicEthereumAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctyp
status = 0 // transaction failed
}

if len(data.Logs) == 0 {
if len(data.Logs) == 0 || status == 0 {
data.Logs = []*ethtypes.Log{}
data.Bloom = ethtypes.BytesToBloom(make([]byte, 256))
}

contractAddr := &data.ContractAddress
if data.ContractAddress == common.HexToAddress("0x00000000000000000000") {
contractAddr = nil
Expand Down
8 changes: 4 additions & 4 deletions x/evm/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"bytes"
"encoding/hex"
"fmt"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"math/big"
"math/bits"
"strings"
"sync"

"github.com/tendermint/go-amino"

ethcmn "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/okex/exchain/app/crypto/ethsecp256k1"
"github.com/pkg/errors"
"github.com/tendermint/go-amino"
"golang.org/x/crypto/sha3"

"github.com/okex/exchain/app/crypto/ethsecp256k1"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
)

type KV struct {
Expand Down

0 comments on commit fc82565

Please sign in to comment.