diff --git a/app/rpc/backend/backend.go b/app/rpc/backend/backend.go index 0715164902..bc3560ee89 100644 --- a/app/rpc/backend/backend.go +++ b/app/rpc/backend/backend.go @@ -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" @@ -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" ) @@ -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 } diff --git a/app/rpc/namespaces/eth/api.go b/app/rpc/namespaces/eth/api.go index 5f25d91d38..4d56d7d390 100644 --- a/app/rpc/namespaces/eth/api.go +++ b/app/rpc/namespaces/eth/api.go @@ -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 diff --git a/app/rpc/namespaces/eth/api_multi.go b/app/rpc/namespaces/eth/api_multi.go index 316fa09e0b..36f5039178 100644 --- a/app/rpc/namespaces/eth/api_multi.go +++ b/app/rpc/namespaces/eth/api_multi.go @@ -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 diff --git a/x/evm/types/utils.go b/x/evm/types/utils.go index 89620c453a..628a4bdbda 100644 --- a/x/evm/types/utils.go +++ b/x/evm/types/utils.go @@ -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 {