Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use evm index and tendermint as source of truth when trace status discrepency. #28

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import (
"encoding/json"
"fmt"
"math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -125,7 +126,52 @@
return nil, err
}

return decodedResult, nil
jsonResult, ok := decodedResult.(map[string]interface{})

if !ok {
// gracefully fallback to default behavior
return decodedResult, nil
}

// handle edge cases in differences between traced tx status
// and actual tx status when it was executed as part of a block
// this can happen when
// - tracing a tx succeeds even though when the tx was executed
// the block gas meter became exhausted
if jsonResult["failed"] != transaction.Failed {
// override trace transaction status with actual tx status
jsonResult["failed"] = transaction.Failed
_, exists := jsonResult["error"]

if !exists {
// use tendermint as source of truth for error message
// and gas usage
query := fmt.Sprintf("%s.%s='%s'", evmtypes.TypeMsgEthereumTx, evmtypes.AttributeKeyEthereumTxHash, hash.Hex())
resTxs, err := b.clientCtx.Client.TxSearch(b.ctx, query, false, nil, nil, "")

Check failure on line 151 in rpc/backend/tracing.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
if err != nil {
panic(err)
}

if resTxs.TotalCount != 1 {
// gracefully fallback to default behavior
return decodedResult, nil
}

txMe := resTxs.Txs[0]

// using the actual gas used amount for when the tx was executed
jsonResult["gas_used"] = txMe.TxResult.GasUsed

// TODO: supporting configuring max error string length
// some indexing services (e.g. blockscout) have a character limit
// for the field that stores this data
maxErrorStringLength := math.Min(200, float64(len(txMe.TxResult.Log)-1))
jsonResult["error"] = txMe.TxResult.Log[0:int64(maxErrorStringLength)]

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
}
}

return jsonResult, nil
}

// TraceBlock configures a new tracer according to the provided configuration, and
Expand Down
Loading