Skip to content

Commit

Permalink
Merge pull request #35 from Kava-Labs/dl/apply-patches
Browse files Browse the repository at this point in the history
Apply recent patches
  • Loading branch information
DracoLi authored Feb 6, 2024
2 parents 69d03e8 + 0ef3822 commit e46067e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ replace (
// use cosmos keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Use cosmos-sdk fork with staking transfer events, and custom tally handler support
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.47.2-0.20240101221523-62b74a63ed1b
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.47.7-kava.1
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0=
github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
github.com/kava-labs/cosmos-sdk v0.47.2-0.20240101221523-62b74a63ed1b h1:dEGcAv0vfjrsZ4Y4JVNPATTo66cJAclAKJavHkP20lM=
github.com/kava-labs/cosmos-sdk v0.47.2-0.20240101221523-62b74a63ed1b/go.mod h1:7ODtonLpPpUXz1euAxNbpZEZTSnq61dibiA3X/5/oYU=
github.com/kava-labs/cosmos-sdk v0.47.7-kava.1 h1:35qRvLNoOSOmmDSQt2rm0q7YB+DamcJHjYzjuKvsYs8=
github.com/kava-labs/cosmos-sdk v0.47.7-kava.1/go.mod h1:7ODtonLpPpUXz1euAxNbpZEZTSnq61dibiA3X/5/oYU=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
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 @@ package backend
import (
"encoding/json"
"fmt"
"math"

tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -125,7 +126,52 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
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, "")

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)]
}
}

return jsonResult, nil
}

// TraceBlock configures a new tracer according to the provided configuration, and
Expand Down
6 changes: 0 additions & 6 deletions server/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ const (
GRPCWebAddress = "grpc-web.address"
)

// Cosmos API flags
const (
RPCEnable = "api.enable"
EnabledUnsafeCors = "api.enabled-unsafe-cors"
)

// JSON-RPC flags
const (
JSONRPCEnable = "json-rpc.enable"
Expand Down
14 changes: 11 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,21 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint64(server.FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks")
cmd.Flags().String(srvflags.AppDBBackend, "", "The type of database for application and snapshots databases")

cmd.Flags().Bool(server.FlagAPIEnable, false, "Define if the API server should be enabled")
cmd.Flags().Bool(server.FlagAPISwagger, false, "Define if swagger documentation should automatically be registered (Note: the API must also be enabled)")
cmd.Flags().String(server.FlagAPIAddress, serverconfig.DefaultAPIAddress, "the API server address to listen on")
cmd.Flags().Uint(server.FlagAPIMaxOpenConnections, 1000, "Define the number of maximum open connections")
cmd.Flags().Uint(server.FlagRPCReadTimeout, 10, "Define the Tendermint RPC read timeout (in seconds)")
cmd.Flags().Uint(server.FlagRPCWriteTimeout, 0, "Define the Tendermint RPC write timeout (in seconds)")
cmd.Flags().Uint(server.FlagRPCMaxBodyBytes, 1000000, "Define the Tendermint maximum response body (in bytes)")
cmd.Flags().Bool(server.FlagAPIEnableUnsafeCORS, false, "Define if CORS should be enabled (unsafe - use it at your own risk)")

cmd.Flags().Bool(srvflags.GRPCOnly, false, "Start the node in gRPC query only mode without Tendermint process")
cmd.Flags().Bool(srvflags.GRPCEnable, true, "Define if the gRPC server should be enabled")
cmd.Flags().String(srvflags.GRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on")
cmd.Flags().Bool(srvflags.GRPCWebEnable, true, "Define if the gRPC-Web server should be enabled. (Note: gRPC must also be enabled.)")
cmd.Flags().String(srvflags.GRPCWebAddress, serverconfig.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on")

cmd.Flags().Bool(srvflags.RPCEnable, false, "Defines if Cosmos-sdk REST server should be enabled")
cmd.Flags().Bool(srvflags.EnabledUnsafeCors, false, "Defines if CORS should be enabled (unsafe - use it at your own risk)")

cmd.Flags().Bool(srvflags.JSONRPCEnable, true, "Define if the JSON-RPC server should be enabled")
cmd.Flags().StringSlice(srvflags.JSONRPCAPI, config.GetDefaultAPINamespaces(), "Defines a list of JSON-RPC namespaces that should be enabled")
cmd.Flags().String(srvflags.JSONRPCAddress, config.DefaultJSONRPCAddress, "the JSON-RPC server address to listen on")
Expand All @@ -220,6 +226,8 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint64(server.FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval")
cmd.Flags().Uint32(server.FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep")

cmd.Flags().Bool(server.FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree")

// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
return cmd
Expand Down

0 comments on commit e46067e

Please sign in to comment.