forked from cerc-io/laconicd-deprecated
build
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
rpctypes "github.com/cosmos/ethermint/ethereum/rpc/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
|
||||
"github.com/InjectiveLabs/sdk-go/ethereum/rpc"
|
||||
"github.com/InjectiveLabs/sdk-go/wrappers"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
)
|
||||
|
||||
@@ -30,8 +23,6 @@ func GetQueryCmd() *cobra.Command {
|
||||
cmd.AddCommand(
|
||||
GetStorageCmd(),
|
||||
GetCodeCmd(),
|
||||
GetErc20Balance(),
|
||||
GetAccount(),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
@@ -112,88 +103,3 @@ func GetCodeCmd() *cobra.Command {
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetErc20Balance queries the erc20 balance of an address
|
||||
func GetErc20Balance() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "erc20balance [contract] [address]",
|
||||
Short: "Gets erc20 balance of an account",
|
||||
Long: "Gets erc20 balance of an account.",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
contract := args[0]
|
||||
address := args[1]
|
||||
|
||||
erc20ABI, err := abi.JSON(strings.NewReader(wrappers.ERC20ABI))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input, err := erc20ABI.Pack("balanceOf", common.HexToAddress(address))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := &types.QueryStaticCallRequest{
|
||||
Address: contract,
|
||||
Input: input,
|
||||
}
|
||||
|
||||
res, err := queryClient.StaticCall(rpc.ContextWithHeight(clientCtx.Height), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ret := big.NewInt(0)
|
||||
err = erc20ABI.UnpackIntoInterface(&ret, "balanceOf", res.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintString(ret.String())
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetAccount queries the account by address
|
||||
func GetAccount() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "account [address]",
|
||||
Short: "Get an account by address",
|
||||
Long: "Get an account by address",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
address := args[0]
|
||||
|
||||
req := &types.QueryAccountRequest{
|
||||
Address: address,
|
||||
}
|
||||
|
||||
res, err := queryClient.Account(rpc.ContextWithHeight(clientCtx.Height), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package keeper
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/cosmos/ethermint/metrics"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -37,10 +35,6 @@ func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
||||
// the store. The EVM end block logic doesn't update the validator set, thus it returns
|
||||
// an empty slice.
|
||||
func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
// Gas costs are handled within msg handler so costs should be ignored
|
||||
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/cosmos/ethermint/metrics"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -21,17 +20,11 @@ var _ types.QueryServer = Keeper{}
|
||||
|
||||
// Account implements the Query/Account gRPC method
|
||||
func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*types.QueryAccountResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsZeroAddress(req.Address) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrZeroAddress.Error(),
|
||||
@@ -42,7 +35,6 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ
|
||||
so := k.GetOrNewStateObject(ctx, ethcmn.HexToAddress(req.Address))
|
||||
balance, err := ethermint.MarshalBigInt(so.Balance())
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -54,17 +46,12 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ
|
||||
}
|
||||
|
||||
func (k Keeper) CosmosAccount(c context.Context, req *types.QueryCosmosAccountRequest) (*types.QueryCosmosAccountResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsZeroAddress(req.Address) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrZeroAddress.Error(),
|
||||
@@ -92,17 +79,11 @@ func (k Keeper) CosmosAccount(c context.Context, req *types.QueryCosmosAccountRe
|
||||
|
||||
// Balance implements the Query/Balance gRPC method
|
||||
func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsZeroAddress(req.Address) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrZeroAddress.Error(),
|
||||
@@ -114,7 +95,6 @@ func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*typ
|
||||
balanceInt := k.GetBalance(ctx, ethcmn.HexToAddress(req.Address))
|
||||
balance, err := ethermint.MarshalBigInt(balanceInt)
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.Internal,
|
||||
"failed to marshal big.Int to string",
|
||||
@@ -128,17 +108,12 @@ func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*typ
|
||||
|
||||
// Storage implements the Query/Storage gRPC method
|
||||
func (k Keeper) Storage(c context.Context, req *types.QueryStorageRequest) (*types.QueryStorageResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsZeroAddress(req.Address) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrZeroAddress.Error(),
|
||||
@@ -159,17 +134,11 @@ func (k Keeper) Storage(c context.Context, req *types.QueryStorageRequest) (*typ
|
||||
|
||||
// Code implements the Query/Code gRPC method
|
||||
func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.QueryCodeResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsZeroAddress(req.Address) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrZeroAddress.Error(),
|
||||
@@ -188,17 +157,11 @@ func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.Que
|
||||
|
||||
// TxLogs implements the Query/TxLogs gRPC method
|
||||
func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types.QueryTxLogsResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsEmptyHash(req.Hash) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrEmptyHash.Error(),
|
||||
@@ -210,7 +173,6 @@ func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types
|
||||
hash := ethcmn.HexToHash(req.Hash)
|
||||
logs, err := k.GetLogs(ctx, hash)
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.Internal,
|
||||
err.Error(),
|
||||
@@ -224,17 +186,12 @@ func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types
|
||||
|
||||
// TxReceipt implements the Query/TxReceipt gRPC method
|
||||
func (k Keeper) TxReceipt(c context.Context, req *types.QueryTxReceiptRequest) (*types.QueryTxReceiptResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsEmptyHash(req.Hash) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrEmptyHash.Error(),
|
||||
@@ -246,7 +203,6 @@ func (k Keeper) TxReceipt(c context.Context, req *types.QueryTxReceiptRequest) (
|
||||
hash := ethcmn.HexToHash(req.Hash)
|
||||
receipt, found := k.GetTxReceiptFromHash(ctx, hash)
|
||||
if !found {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.NotFound, types.ErrTxReceiptNotFound.Error(),
|
||||
)
|
||||
@@ -259,12 +215,7 @@ func (k Keeper) TxReceipt(c context.Context, req *types.QueryTxReceiptRequest) (
|
||||
|
||||
// TxReceiptsByBlockHeight implements the Query/TxReceiptsByBlockHeight gRPC method
|
||||
func (k Keeper) TxReceiptsByBlockHeight(c context.Context, req *types.QueryTxReceiptsByBlockHeightRequest) (*types.QueryTxReceiptsByBlockHeightResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
@@ -278,17 +229,12 @@ func (k Keeper) TxReceiptsByBlockHeight(c context.Context, req *types.QueryTxRec
|
||||
|
||||
// TxReceiptsByBlockHash implements the Query/TxReceiptsByBlockHash gRPC method
|
||||
func (k Keeper) TxReceiptsByBlockHash(c context.Context, req *types.QueryTxReceiptsByBlockHashRequest) (*types.QueryTxReceiptsByBlockHashResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsEmptyHash(req.Hash) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrEmptyHash.Error(),
|
||||
@@ -307,17 +253,12 @@ func (k Keeper) TxReceiptsByBlockHash(c context.Context, req *types.QueryTxRecei
|
||||
|
||||
// BlockLogs implements the Query/BlockLogs gRPC method
|
||||
func (k Keeper) BlockLogs(c context.Context, req *types.QueryBlockLogsRequest) (*types.QueryBlockLogsResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if types.IsEmptyHash(req.Hash) {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
types.ErrEmptyHash.Error(),
|
||||
@@ -335,12 +276,8 @@ func (k Keeper) BlockLogs(c context.Context, req *types.QueryBlockLogsRequest) (
|
||||
|
||||
// BlockBloom implements the Query/BlockBloom gRPC method
|
||||
func (k Keeper) BlockBloom(c context.Context, req *types.QueryBlockBloomRequest) (*types.QueryBlockBloomResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
@@ -353,7 +290,6 @@ func (k Keeper) BlockBloom(c context.Context, req *types.QueryBlockBloomRequest)
|
||||
|
||||
bloom, found := k.GetBlockBloom(ctx, height)
|
||||
if !found {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(
|
||||
codes.NotFound, types.ErrBloomNotFound.Error(),
|
||||
)
|
||||
@@ -366,12 +302,8 @@ func (k Keeper) BlockBloom(c context.Context, req *types.QueryBlockBloomRequest)
|
||||
|
||||
// Params implements the Query/Params gRPC method
|
||||
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
if req == nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"github.com/cosmos/ethermint/metrics"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
)
|
||||
|
||||
@@ -41,8 +40,6 @@ type Keeper struct {
|
||||
// LogsCache keeps mapping of contract address -> eth logs emitted
|
||||
// during EVM execution in the current block.
|
||||
LogsCache map[common.Address][]*ethtypes.Log
|
||||
|
||||
svcTags metrics.Tags
|
||||
}
|
||||
|
||||
// NewKeeper generates new evm module keeper
|
||||
@@ -57,10 +54,6 @@ func NewKeeper(
|
||||
|
||||
// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
|
||||
return &Keeper{
|
||||
svcTags: metrics.Tags{
|
||||
"svc": "evm_k",
|
||||
},
|
||||
|
||||
cdc: cdc,
|
||||
accountKeeper: ak,
|
||||
bankKeeper: bankKeeper,
|
||||
@@ -84,10 +77,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||
|
||||
// GetBlockBloom gets bloombits from block height
|
||||
func (k Keeper) GetBlockBloom(ctx sdk.Context, height int64) (ethtypes.Bloom, bool) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
key := types.BloomKey(height)
|
||||
@@ -102,10 +91,6 @@ func (k Keeper) GetBlockBloom(ctx sdk.Context, height int64) (ethtypes.Bloom, bo
|
||||
|
||||
// SetBlockBloom sets the mapping from block height to bloom bits
|
||||
func (k Keeper) SetBlockBloom(ctx sdk.Context, height int64, bloom ethtypes.Bloom) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
key := types.BloomKey(height)
|
||||
@@ -114,10 +99,6 @@ func (k Keeper) SetBlockBloom(ctx sdk.Context, height int64, bloom ethtypes.Bloo
|
||||
|
||||
// GetBlockHash gets block height from block consensus hash
|
||||
func (k Keeper) GetBlockHashFromHeight(ctx sdk.Context, height int64) ([]byte, bool) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.KeyBlockHeightHash(uint64(height)))
|
||||
if len(bz) == 0 {
|
||||
@@ -129,10 +110,6 @@ func (k Keeper) GetBlockHashFromHeight(ctx sdk.Context, height int64) ([]byte, b
|
||||
|
||||
// SetBlockHash sets the mapping from block consensus hash to block height
|
||||
func (k Keeper) SetBlockHash(ctx sdk.Context, hash []byte, height int64) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := sdk.Uint64ToBigEndian(uint64(height))
|
||||
store.Set(types.KeyBlockHash(common.BytesToHash(hash)), bz)
|
||||
@@ -140,10 +117,6 @@ func (k Keeper) SetBlockHash(ctx sdk.Context, hash []byte, height int64) {
|
||||
|
||||
// GetBlockHash gets block height from block consensus hash
|
||||
func (k Keeper) GetBlockHeightByHash(ctx sdk.Context, hash common.Hash) (int64, bool) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.KeyBlockHash(hash))
|
||||
if len(bz) == 0 {
|
||||
@@ -156,20 +129,12 @@ func (k Keeper) GetBlockHeightByHash(ctx sdk.Context, hash common.Hash) (int64,
|
||||
|
||||
// SetBlockHash sets the mapping from block consensus hash to block height
|
||||
func (k Keeper) SetBlockHeightToHash(ctx sdk.Context, hash []byte, height int64) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
store.Set(types.KeyBlockHeightHash(uint64(height)), hash)
|
||||
}
|
||||
|
||||
// SetTxReceiptToHash sets the mapping from tx hash to tx receipt
|
||||
func (k Keeper) SetTxReceiptToHash(ctx sdk.Context, hash common.Hash, receipt *types.TxReceipt) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
||||
|
||||
data := k.cdc.MustMarshalBinaryBare(receipt)
|
||||
@@ -190,10 +155,6 @@ func (k Keeper) SetHeightHash(ctx sdk.Context, height uint64, hash common.Hash)
|
||||
|
||||
// GetTxReceiptFromHash gets tx receipt by tx hash.
|
||||
func (k Keeper) GetTxReceiptFromHash(ctx sdk.Context, hash common.Hash) (*types.TxReceipt, bool) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
data := store.Get(types.KeyHashTxReceipt(hash))
|
||||
if data == nil || len(data) == 0 {
|
||||
@@ -208,10 +169,6 @@ func (k Keeper) GetTxReceiptFromHash(ctx sdk.Context, hash common.Hash) (*types.
|
||||
|
||||
// AddTxHashToBlock stores tx hash in the list of tx for the block.
|
||||
func (k Keeper) AddTxHashToBlock(ctx sdk.Context, blockHeight int64, txHash common.Hash) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
key := types.KeyBlockHeightTxs(uint64(blockHeight))
|
||||
|
||||
list := types.BytesList{}
|
||||
@@ -230,10 +187,6 @@ func (k Keeper) AddTxHashToBlock(ctx sdk.Context, blockHeight int64, txHash comm
|
||||
|
||||
// GetTxsFromBlock returns list of tx hash in the block by height.
|
||||
func (k Keeper) GetTxsFromBlock(ctx sdk.Context, blockHeight int64) []common.Hash {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
key := types.KeyBlockHeightTxs(uint64(blockHeight))
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
@@ -255,10 +208,6 @@ func (k Keeper) GetTxsFromBlock(ctx sdk.Context, blockHeight int64) []common.Has
|
||||
|
||||
// GetTxReceiptsByBlockHeight gets tx receipts by block height.
|
||||
func (k Keeper) GetTxReceiptsByBlockHeight(ctx sdk.Context, blockHeight int64) []*types.TxReceipt {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
txs := k.GetTxsFromBlock(ctx, blockHeight)
|
||||
if len(txs) == 0 {
|
||||
return nil
|
||||
@@ -285,10 +234,6 @@ func (k Keeper) GetTxReceiptsByBlockHeight(ctx sdk.Context, blockHeight int64) [
|
||||
|
||||
// GetTxReceiptsByBlockHash gets tx receipts by block hash.
|
||||
func (k Keeper) GetTxReceiptsByBlockHash(ctx sdk.Context, hash common.Hash) []*types.TxReceipt {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
blockHeight, ok := k.GetBlockHeightByHash(ctx, hash)
|
||||
if !ok {
|
||||
return nil
|
||||
@@ -299,10 +244,6 @@ func (k Keeper) GetTxReceiptsByBlockHash(ctx sdk.Context, hash common.Hash) []*t
|
||||
|
||||
// GetAllTxLogs return all the transaction logs from the store.
|
||||
func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixLogs)
|
||||
defer iterator.Close()
|
||||
@@ -320,10 +261,6 @@ func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs {
|
||||
|
||||
// GetAccountStorage return state storage associated with an account
|
||||
func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (types.Storage, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
storage := types.Storage{}
|
||||
|
||||
err := k.ForEachStorage(ctx, address, func(key, value common.Hash) bool {
|
||||
@@ -339,10 +276,6 @@ func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (type
|
||||
|
||||
// GetChainConfig gets block height from block consensus hash
|
||||
func (k Keeper) GetChainConfig(ctx sdk.Context) (types.ChainConfig, bool) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.KeyPrefixChainConfig)
|
||||
if len(bz) == 0 {
|
||||
@@ -356,10 +289,6 @@ func (k Keeper) GetChainConfig(ctx sdk.Context) (types.ChainConfig, bool) {
|
||||
|
||||
// SetChainConfig sets the mapping from block consensus hash to block height
|
||||
func (k Keeper) SetChainConfig(ctx sdk.Context, config types.ChainConfig) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := k.cdc.MustMarshalBinaryBare(&config)
|
||||
store.Set(types.KeyPrefixChainConfig, bz)
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/ethermint/metrics"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -20,16 +19,11 @@ import (
|
||||
var _ types.MsgServer = &Keeper{}
|
||||
|
||||
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
// parse the chainID from a string to a base-10 integer
|
||||
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -44,7 +38,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
"homestead_err": homesteadErr.Error(),
|
||||
}).Warningln("failed to verify signatures with EIP155 and Homestead signers")
|
||||
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, errors.New("no valid signatures")
|
||||
}
|
||||
}
|
||||
@@ -84,7 +77,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
|
||||
config, found := k.GetChainConfig(ctx)
|
||||
if !found {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, types.ErrChainConfigNotFound
|
||||
}
|
||||
|
||||
@@ -93,7 +85,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
if err.Error() == "execution reverted" && executionResult != nil {
|
||||
// keep the execution result for revert reason
|
||||
executionResult.Response.Reverted = true
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
|
||||
if !st.Simulate {
|
||||
blockHash, _ := k.GetBlockHashFromHeight(ctx, ctx.BlockHeight())
|
||||
@@ -117,7 +108,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
return executionResult.Response, nil
|
||||
}
|
||||
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -180,7 +170,6 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
)
|
||||
}
|
||||
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return executionResult.Response, nil
|
||||
}
|
||||
|
||||
@@ -232,15 +221,10 @@ func (k *Keeper) InternalEthereumTx(
|
||||
sender common.Address,
|
||||
tx *types.TxData,
|
||||
) (*types.MsgEthereumTxResponse, error) {
|
||||
metrics.ReportFuncCall(k.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(k.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// parse the chainID from a string to a base-10 integer
|
||||
chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID())
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -281,7 +265,6 @@ func (k *Keeper) InternalEthereumTx(
|
||||
|
||||
config, found := k.GetChainConfig(ctx)
|
||||
if !found {
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, types.ErrChainConfigNotFound
|
||||
}
|
||||
|
||||
@@ -290,7 +273,6 @@ func (k *Keeper) InternalEthereumTx(
|
||||
if err.Error() == "execution reverted" && executionResult != nil {
|
||||
// keep the execution result for revert reason
|
||||
executionResult.Response.Reverted = true
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
|
||||
if !st.Simulate {
|
||||
blockHash, _ := k.GetBlockHashFromHeight(ctx, ctx.BlockHeight())
|
||||
@@ -314,7 +296,6 @@ func (k *Keeper) InternalEthereumTx(
|
||||
return executionResult.Response, err
|
||||
}
|
||||
|
||||
metrics.ReportFuncError(k.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
+10
-30
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
@@ -43,7 +42,6 @@ func (suite *GenesisTestSuite) TestValidateGenesisAccount() {
|
||||
"valid genesis account",
|
||||
GenesisAccount{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
NewState(suite.hash, suite.hash),
|
||||
@@ -55,23 +53,6 @@ func (suite *GenesisTestSuite) TestValidateGenesisAccount() {
|
||||
"empty account address bytes",
|
||||
GenesisAccount{
|
||||
Address: ethcmn.Address{}.String(),
|
||||
Balance: sdk.OneInt(),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"empty account balance",
|
||||
GenesisAccount{
|
||||
Address: suite.address,
|
||||
Balance: sdk.Int{},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"negative account balance",
|
||||
GenesisAccount{
|
||||
Address: suite.address,
|
||||
Balance: sdk.NewInt(-1),
|
||||
},
|
||||
false,
|
||||
},
|
||||
@@ -79,7 +60,6 @@ func (suite *GenesisTestSuite) TestValidateGenesisAccount() {
|
||||
"empty code bytes",
|
||||
GenesisAccount{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: "",
|
||||
},
|
||||
false,
|
||||
@@ -115,8 +95,8 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
|
||||
Accounts: []GenesisAccount{
|
||||
{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
{Key: suite.hash.String()},
|
||||
},
|
||||
@@ -167,16 +147,16 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
|
||||
Accounts: []GenesisAccount{
|
||||
{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
NewState(suite.hash, suite.hash),
|
||||
},
|
||||
},
|
||||
{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
NewState(suite.hash, suite.hash),
|
||||
},
|
||||
@@ -191,8 +171,8 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
|
||||
Accounts: []GenesisAccount{
|
||||
{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
{Key: suite.hash.String()},
|
||||
},
|
||||
@@ -241,8 +221,8 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
|
||||
Accounts: []GenesisAccount{
|
||||
{
|
||||
Address: suite.address,
|
||||
Balance: sdk.OneInt(),
|
||||
Code: suite.code,
|
||||
|
||||
Code: suite.code,
|
||||
Storage: Storage{
|
||||
{Key: suite.hash.String()},
|
||||
},
|
||||
|
||||
@@ -3,7 +3,6 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/xlab/suplog"
|
||||
@@ -16,7 +15,6 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/ethermint/metrics"
|
||||
)
|
||||
|
||||
// StateTransition defines data to transitionDB in evm
|
||||
@@ -35,17 +33,6 @@ type StateTransition struct {
|
||||
Sender common.Address
|
||||
Simulate bool // i.e CheckTx execution
|
||||
Debug bool // enable EVM debugging
|
||||
|
||||
once sync.Once
|
||||
svcTags metrics.Tags
|
||||
}
|
||||
|
||||
func (st *StateTransition) initOnce() {
|
||||
st.once.Do(func() {
|
||||
st.svcTags = metrics.Tags{
|
||||
"svc": "evm_state",
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GasInfo returns the gas limit, gas consumed and gas refunded from the EVM transition
|
||||
@@ -96,14 +83,12 @@ func (st *StateTransition) newEVM(
|
||||
config ChainConfig,
|
||||
extraEIPs []int64,
|
||||
) *vm.EVM {
|
||||
st.initOnce()
|
||||
|
||||
// Create context for evm
|
||||
blockCtx := vm.BlockContext{
|
||||
CanTransfer: core.CanTransfer,
|
||||
Transfer: core.Transfer,
|
||||
GetHash: GetHashFn(ctx, csdb),
|
||||
Coinbase: common.Address{}, // there's no benefitiary since we're not mining
|
||||
Coinbase: common.Address{}, // there's no beneficiary since we're not mining
|
||||
BlockNumber: big.NewInt(ctx.BlockHeight()),
|
||||
Time: big.NewInt(ctx.BlockHeader().Time.Unix()),
|
||||
Difficulty: big.NewInt(0), // unused. Only required in PoW context
|
||||
@@ -139,17 +124,10 @@ func (st *StateTransition) newEVM(
|
||||
// returning the evm execution result.
|
||||
// NOTE: State transition checks are run during AnteHandler execution.
|
||||
func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (resp *ExecutionResult, err error) {
|
||||
st.initOnce()
|
||||
|
||||
metrics.ReportFuncCall(st.svcTags)
|
||||
doneFn := metrics.ReportFuncTiming(st.svcTags)
|
||||
defer doneFn()
|
||||
|
||||
contractCreation := st.Recipient == nil
|
||||
|
||||
cost, err := core.IntrinsicGas(st.Payload, contractCreation, true, false)
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(st.svcTags)
|
||||
err = sdkerrors.Wrap(err, "invalid intrinsic gas for transaction")
|
||||
return nil, err
|
||||
}
|
||||
@@ -185,7 +163,6 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
gasPrice := ctx.MinGasPrices().AmountOf(params.EvmDenom)
|
||||
//gasPrice := sdk.ZeroDec()
|
||||
if gasPrice.IsNil() {
|
||||
metrics.ReportFuncError(st.svcTags)
|
||||
return nil, errors.New("min gas price cannot be nil")
|
||||
}
|
||||
|
||||
@@ -263,8 +240,6 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
|
||||
if err != nil {
|
||||
// Consume gas before returning
|
||||
metrics.EVMRevertedTx(st.svcTags)
|
||||
metrics.EVMGasConsumed(resp.GasInfo.GasConsumed)
|
||||
ctx.GasMeter().ConsumeGas(resp.GasInfo.GasConsumed, "evm execution consumption")
|
||||
return resp, err
|
||||
}
|
||||
@@ -283,7 +258,6 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
if st.TxHash != nil && !st.Simulate {
|
||||
logs, err = csdb.GetLogs(*st.TxHash)
|
||||
if err != nil {
|
||||
metrics.ReportFuncError(st.svcTags)
|
||||
err = errors.Wrap(err, "failed to get logs")
|
||||
return nil, err
|
||||
}
|
||||
@@ -296,7 +270,6 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
// Finalise state if not a simulated transaction
|
||||
// TODO: change to depend on config
|
||||
if err := csdb.Finalise(true); err != nil {
|
||||
metrics.ReportFuncError(st.svcTags)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -317,7 +290,7 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
|
||||
// Consume gas from evm execution
|
||||
// Out of gas check does not need to be done here since it is done within the EVM execution
|
||||
metrics.EVMGasConsumed(resp.GasInfo.GasConsumed)
|
||||
|
||||
// TODO: @albert, @maxim, decide if can take this out, since InternalEthereumTx may want to continue execution afterwards
|
||||
// which will use gas.
|
||||
_ = currentGasMeter
|
||||
@@ -331,8 +304,6 @@ func (st *StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (re
|
||||
// Opcodes that attempt to perform such modifications will result in exceptions
|
||||
// instead of performing the modifications.
|
||||
func (st *StateTransition) StaticCall(ctx sdk.Context, config ChainConfig) ([]byte, error) {
|
||||
st.initOnce()
|
||||
|
||||
// This gas limit the the transaction gas limit with intrinsic gas subtracted
|
||||
gasLimit := st.GasLimit - ctx.GasMeter().GasConsumed()
|
||||
csdb := st.Csdb.WithContext(ctx)
|
||||
|
||||
@@ -126,7 +126,7 @@ func (suite *StateDBTestSuite) TestTransitionDb() {
|
||||
"nil gas price",
|
||||
func() {
|
||||
invalidGas := sdk.DecCoins{
|
||||
{Denom: ethermint.InjectiveCoin},
|
||||
{Denom: ethermint.PhotonCoin},
|
||||
}
|
||||
suite.ctx = suite.ctx.WithMinGasPrices(invalidGas)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user