From 4ee7eea7c446569158c1c2bd38403478a86686f6 Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 11 Dec 2020 03:00:29 +0800 Subject: [PATCH] stargate: fix ethereum transaction (#604) * bump cosmos-sdk dependency * fix tx encoding * fix eth tx * update cosmos-sdk to latest version * use cryptotypes.PrivKey --- app/ante/ante.go | 5 +- app/ante/ante_test.go | 12 ++-- app/ante/utils_test.go | 9 +-- app/encoding.go | 57 ++++++++++++++- app/ethermint.go | 14 +++- app/ethermint_test.go | 3 +- app/test_helpers.go | 1 + client/testnet.go | 6 +- cmd/ethermintd/genaccounts.go | 4 +- cmd/ethermintd/root.go | 8 ++- codec/codec.go | 3 +- crypto/codec/amino.go | 7 +- crypto/codec/codec.go | 8 --- crypto/ethsecp256k1/ethsecp256k1.go | 6 +- crypto/ethsecp256k1/ethsecp256k1_test.go | 9 +-- crypto/hd/algorithm.go | 5 +- go.mod | 15 ++-- go.sum | 37 ++++++---- rpc/apis.go | 3 +- rpc/backend/backend.go | 3 +- rpc/config.go | 6 +- rpc/namespaces/eth/api.go | 1 + rpc/namespaces/eth/filters/api.go | 6 -- rpc/namespaces/eth/filters/subscription.go | 1 + server/start.go | 58 ++++++++------- server/util.go | 1 + types/config.go | 1 + types/config_test.go | 3 +- x/evm/keeper/grpc_query_test.go | 3 +- x/evm/keeper/keeper.go | 2 +- x/evm/keeper/msg_server.go | 1 + x/evm/types/msg.go | 82 +++++++++++++++++++--- x/evm/types/utils_test.go | 3 +- 33 files changed, 265 insertions(+), 118 deletions(-) diff --git a/app/ante/ante.go b/app/ante/ante.go index 98dff78d2..564ff235f 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -57,8 +57,9 @@ func NewAnteHandler( authante.NewRejectExtensionOptionsDecorator(), NewEthMempoolFeeDecorator(evmKeeper), authante.NewValidateBasicDecorator(), - authante.TxTimeoutHeightDecorator{}, - authante.NewValidateMemoDecorator(ak), + // TODO: add timeout for MsgEthereumTx + // authante.TxTimeoutHeightDecorator{}, + // authante.NewValidateMemoDecorator(ak), NewEthSigVerificationDecorator(), NewAccountVerificationDecorator(ak, bankKeeper, evmKeeper), NewNonceVerificationDecorator(ak), diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 0ff5196c8..c3369f8bf 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -9,9 +9,9 @@ import ( ethcmn "github.com/ethereum/go-ethereum/common" - tmcrypto "github.com/tendermint/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ethermint/app" @@ -83,7 +83,7 @@ func (suite *AnteTestSuite) TestValidTx() { msg1 := newTestMsg(addr1, addr2) msgs := []sdk.Msg{msg1} - privKeys := []tmcrypto.PrivKey{priv1, priv2} + privKeys := []cryptotypes.PrivKey{priv1, priv2} accNums := []uint64{acc1.GetAccountNumber(), acc2.GetAccountNumber()} accSeqs := []uint64{acc1.GetSequence(), acc2.GetSequence()} @@ -115,7 +115,7 @@ func (suite *AnteTestSuite) TestSDKInvalidSigs() { // require validation failure with no signers msgs := []sdk.Msg{msg1} - privKeys := []tmcrypto.PrivKey{} + privKeys := []cryptotypes.PrivKey{} accNums := []uint64{acc1.GetAccountNumber(), acc2.GetAccountNumber()} accSeqs := []uint64{acc1.GetSequence(), acc2.GetSequence()} @@ -125,7 +125,7 @@ func (suite *AnteTestSuite) TestSDKInvalidSigs() { // require validation failure with invalid number of signers msgs = []sdk.Msg{msg1} - privKeys = []tmcrypto.PrivKey{priv1} + privKeys = []cryptotypes.PrivKey{priv1} accNums = []uint64{acc1.GetAccountNumber(), acc2.GetAccountNumber()} accSeqs = []uint64{acc1.GetSequence(), acc2.GetSequence()} @@ -136,7 +136,7 @@ func (suite *AnteTestSuite) TestSDKInvalidSigs() { msg2 := newTestMsg(addr1, addr3) msgs = []sdk.Msg{msg1, msg2} - privKeys = []tmcrypto.PrivKey{priv1, priv2, priv3} + privKeys = []cryptotypes.PrivKey{priv1, priv2, priv3} accNums = []uint64{acc1.GetAccountNumber(), acc2.GetAccountNumber(), 0} accSeqs = []uint64{acc1.GetSequence(), acc2.GetSequence(), 0} @@ -157,7 +157,7 @@ func (suite *AnteTestSuite) TestSDKInvalidAcc() { fee := newTestStdFee() msg1 := newTestMsg(addr1) msgs := []sdk.Msg{msg1} - privKeys := []tmcrypto.PrivKey{priv1} + privKeys := []cryptotypes.PrivKey{priv1} // require validation failure with invalid account number accNums := []uint64{1} diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index 85fd83825..456191d26 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -18,9 +18,10 @@ import ( ethermint "github.com/cosmos/ethermint/types" evmtypes "github.com/cosmos/ethermint/x/evm/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + ethcrypto "github.com/ethereum/go-ethereum/crypto" - tmcrypto "github.com/tendermint/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) @@ -66,7 +67,7 @@ func newTestStdFee() legacytx.StdFee { } // GenerateAddress generates an Ethereum address. -func newTestAddrKey() (sdk.AccAddress, tmcrypto.PrivKey) { +func newTestAddrKey() (sdk.AccAddress, cryptotypes.PrivKey) { privkey, _ := ethsecp256k1.GenerateKey() addr := ethcrypto.PubkeyToAddress(privkey.ToECDSA().PublicKey) @@ -74,7 +75,7 @@ func newTestAddrKey() (sdk.AccAddress, tmcrypto.PrivKey) { } func newTestSDKTx( - ctx sdk.Context, msgs []sdk.Msg, privs []tmcrypto.PrivKey, + ctx sdk.Context, msgs []sdk.Msg, privs []cryptotypes.PrivKey, accNums []uint64, seqs []uint64, fee legacytx.StdFee, ) sdk.Tx { @@ -96,7 +97,7 @@ func newTestSDKTx( return legacytx.NewStdTx(msgs, fee, sigs, "") } -func newTestEthTx(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, priv tmcrypto.PrivKey) (sdk.Tx, error) { +func newTestEthTx(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey) (sdk.Tx, error) { chainIDEpoch, err := ethermint.ParseChainID(ctx.ChainID()) if err != nil { return nil, err diff --git a/app/encoding.go b/app/encoding.go index 3340e8fc7..b20b1d5e4 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,17 +1,72 @@ package app import ( + "github.com/cosmos/cosmos-sdk/client" + amino "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/cosmos/ethermint/codec" + evmtypes "github.com/cosmos/ethermint/x/evm/types" ) // MakeEncodingConfig creates an EncodingConfig for testing func MakeEncodingConfig() params.EncodingConfig { - encodingConfig := params.MakeTestEncodingConfig() + cdc := amino.NewLegacyAmino() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := amino.NewProtoCodec(interfaceRegistry) + + encodingConfig := params.EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxConfig: NewTxConfig(marshaler), + Amino: cdc, + } + codec.RegisterLegacyAminoCodec(encodingConfig.Amino) ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) codec.RegisterInterfaces(encodingConfig.InterfaceRegistry) ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } + +type txConfig struct { + cdc amino.ProtoCodecMarshaler + client.TxConfig +} + +// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The +// first enabled sign mode will become the default sign mode. +func NewTxConfig(marshaler amino.ProtoCodecMarshaler) client.TxConfig { + return &txConfig{ + marshaler, + tx.NewTxConfig(marshaler, tx.DefaultSignModes), + } +} + +// TxEncoder overwites sdk.TxEncoder to support MsgEthereumTx +func (g txConfig) TxEncoder() sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + ethtx, ok := tx.(*evmtypes.MsgEthereumTx) + if ok { + return g.cdc.MarshalBinaryBare(ethtx) + } + return g.TxConfig.TxEncoder()(tx) + } +} + +// TxDecoder overwites sdk.TxDecoder to support MsgEthereumTx +func (g txConfig) TxDecoder() sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + var ethtx evmtypes.MsgEthereumTx + + err := g.cdc.UnmarshalBinaryBare(txBytes, ðtx) + if err == nil { + return ðtx, nil + } + + return g.TxConfig.TxDecoder()(txBytes) + } +} diff --git a/app/ethermint.go b/app/ethermint.go index 07ad5663d..d44be4002 100644 --- a/app/ethermint.go +++ b/app/ethermint.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -86,6 +87,7 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" "github.com/cosmos/ethermint/app/ante" + ethermintrpc "github.com/cosmos/ethermint/rpc" "github.com/cosmos/ethermint/server" "github.com/cosmos/ethermint/server/api" "github.com/cosmos/ethermint/server/config" @@ -314,7 +316,7 @@ func NewEthermintApp( // Create IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper, + appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper, ) // register the proposal types @@ -601,10 +603,10 @@ func (app *EthermintApp) RegisterAPIRoutes(apiSvr *sdkapi.Server, apiConfig sdkc authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) - ModuleBasics.RegisterGRPCGatewayRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter) + ModuleBasics.RegisterGRPCGatewayRoutes(apiSvr.ClientCtx, apiSvr.GRPCGatewayRouter) // Register Ethereum namespaces - // ethermintrpc.RegisterRoutes(clientCtx, apiSvr.Router) + ethermintrpc.RegisterEthereum(clientCtx, apiSvr.Router) // register swagger API from root so that other applications can override easily if apiConfig.Swagger { @@ -617,6 +619,11 @@ func (app *EthermintApp) RegisterTxService(clientCtx client.Context) { authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } +// RegisterTendermintService implements the Application.RegisterTendermintService method. +func (app *EthermintApp) RegisterTendermintService(clientCtx client.Context) { + tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) +} + // RegisterEthereumServers registers all application ethereum routes with the provided // API server. func (app *EthermintApp) RegisterEthereumServers(apiSvr *api.Server, apiConfig config.EthereumConfig) { @@ -661,6 +668,7 @@ func initParamsKeeper( paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) // ethermint subspaces paramsKeeper.Subspace(evmtypes.ModuleName) diff --git a/app/ethermint_test.go b/app/ethermint_test.go index 0126d133f..a31d5c3ef 100644 --- a/app/ethermint_test.go +++ b/app/ethermint_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" - "github.com/cosmos/cosmos-sdk/simapp" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/simapp" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" diff --git a/app/test_helpers.go b/app/test_helpers.go index bb49150e8..23a5bf33a 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -5,6 +5,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/simapp" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" diff --git a/client/testnet.go b/client/testnet.go index 2a068475f..ea0ce98ff 100644 --- a/client/testnet.go +++ b/client/testnet.go @@ -14,7 +14,6 @@ import ( "github.com/spf13/cobra" tmconfig "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/crypto" tmos "github.com/tendermint/tendermint/libs/os" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/types" @@ -24,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" @@ -145,7 +145,7 @@ func InitTestnet( } nodeIDs := make([]string, numValidators) - valPubKeys := make([]crypto.PubKey, numValidators) + valPubKeys := make([]cryptotypes.PubKey, numValidators) appConfig := srvconfig.DefaultConfig() appConfig.MinGasPrices = minGasPrices @@ -392,7 +392,7 @@ func initGenFiles( func collectGenFiles( clientCtx client.Context, nodeConfig *tmconfig.Config, chainID string, - nodeIDs []string, valPubKeys []crypto.PubKey, numValidators int, + nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int, outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, ) error { diff --git a/cmd/ethermintd/genaccounts.go b/cmd/ethermintd/genaccounts.go index cb3fe7b32..24871390f 100644 --- a/cmd/ethermintd/genaccounts.go +++ b/cmd/ethermintd/genaccounts.go @@ -79,7 +79,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa addr = info.GetAddress() } - coins, err := sdk.ParseCoins(args[1]) + coins, err := sdk.ParseCoinsNormalized(args[1]) if err != nil { return fmt.Errorf("failed to parse coins: %w", err) } @@ -88,7 +88,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd) vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt) - vestingAmt, err := sdk.ParseCoins(vestingAmtStr) + vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr) if err != nil { return fmt.Errorf("failed to parse vesting amount: %w", err) } diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index 3fa6826bf..8283b7293 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -6,6 +6,8 @@ import ( "os" "path/filepath" + "github.com/rs/zerolog" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/snapshots" @@ -13,6 +15,7 @@ import ( "github.com/spf13/cast" "github.com/spf13/cobra" + tmcfg "github.com/tendermint/tendermint/config" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -82,9 +85,10 @@ func Execute(rootCmd *cobra.Command) error { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) - ctx = context.WithValue(ctx, sdkserver.ServerContextKey, sdkserver.NewDefaultContext()) + ctx = context.WithValue(ctx, sdkserver.ServerContextKey, srvCtx) - rootCmd.PersistentFlags().String("log_level", srvCtx.Config.LogLevel, "The logging level in the format of :,...") + rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)") + rootCmd.PersistentFlags().String(flags.FlagLogFormat, tmcfg.LogFormatJSON, "The logging format (json|plain)") executor := tmcli.PrepareBaseCmd(rootCmd, "", app.DefaultNodeHome) return executor.ExecuteContext(ctx) diff --git a/codec/codec.go b/codec/codec.go index f27702604..647822428 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" + sdk "github.com/cosmos/cosmos-sdk/types" cryptocodec "github.com/cosmos/ethermint/crypto/codec" ethermint "github.com/cosmos/ethermint/types" @@ -11,7 +12,7 @@ import ( // RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - std.RegisterLegacyAminoCodec(cdc) + sdk.RegisterLegacyAminoCodec(cdc) cryptocodec.RegisterCrypto(cdc) } diff --git a/crypto/codec/amino.go b/crypto/codec/amino.go index 7b769d8c2..f7c647ed3 100644 --- a/crypto/codec/amino.go +++ b/crypto/codec/amino.go @@ -2,6 +2,8 @@ package codec import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/ethermint/crypto/ethsecp256k1" @@ -17,12 +19,13 @@ func init() { // RegisterCrypto registers all crypto dependency types with the provided Amino // codec. func RegisterCrypto(cdc *codec.LegacyAmino) { + keyring.RegisterLegacyAminoCodec(cdc) + cryptocodec.RegisterCrypto(cdc) cdc.RegisterConcrete(ðsecp256k1.PubKey{}, ethsecp256k1.PubKeyName, nil) cdc.RegisterConcrete(ðsecp256k1.PrivKey{}, ethsecp256k1.PrivKeyName, nil) - keyring.RegisterLegacyAminoCodec(cdc) // update SDK's key codec to include the ethsecp256k1 keys. - keyring.CryptoCdc = cdc + legacy.Cdc = cdc } diff --git a/crypto/codec/codec.go b/crypto/codec/codec.go index 3544adf5e..c644ec7c3 100644 --- a/crypto/codec/codec.go +++ b/crypto/codec/codec.go @@ -1,8 +1,6 @@ package codec import ( - tmcrypto "github.com/tendermint/tendermint/crypto" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -14,12 +12,6 @@ import ( // RegisterInterfaces registers the sdk.Tx interface. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterInterface("tendermint.crypto.PubKey", (*tmcrypto.PubKey)(nil)) - registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &ed25519.PubKey{}) - registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &secp256k1.PubKey{}) - registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &multisig.LegacyAminoPubKey{}) - registry.RegisterImplementations((*tmcrypto.PubKey)(nil), ðsecp256k1.PubKey{}) - registry.RegisterInterface("cosmos.crypto.PubKey", (*cryptotypes.PubKey)(nil)) registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &ed25519.PubKey{}) registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{}) diff --git a/crypto/ethsecp256k1/ethsecp256k1.go b/crypto/ethsecp256k1/ethsecp256k1.go index 824c793ca..77aba05b6 100644 --- a/crypto/ethsecp256k1/ethsecp256k1.go +++ b/crypto/ethsecp256k1/ethsecp256k1.go @@ -60,7 +60,7 @@ func (privKey *PrivKey) Bytes() []byte { } // PubKey returns the ECDSA private key's public key. -func (privKey PrivKey) PubKey() tmcrypto.PubKey { +func (privKey PrivKey) PubKey() cryptotypes.PubKey { ecdsaPrivKey := privKey.ToECDSA() return &PubKey{ Key: ethcrypto.CompressPubkey(&ecdsaPrivKey.PublicKey), @@ -68,7 +68,7 @@ func (privKey PrivKey) PubKey() tmcrypto.PubKey { } // Equals returns true if two ECDSA private keys are equal and false otherwise. -func (privKey *PrivKey) Equals(other tmcrypto.PrivKey) bool { +func (privKey *PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool { return privKey.Type() == other.Type() && subtle.ConstantTimeCompare(privKey.Bytes(), other.Bytes()) == 1 } @@ -156,7 +156,7 @@ func (pubKey *PubKey) Type() string { } // Equals returns true if the pubkey type is the same and their bytes are deeply equal. -func (pubKey *PubKey) Equals(other tmcrypto.PubKey) bool { +func (pubKey *PubKey) Equals(other cryptotypes.PubKey) bool { return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes()) } diff --git a/crypto/ethsecp256k1/ethsecp256k1_test.go b/crypto/ethsecp256k1/ethsecp256k1_test.go index dc9805075..d6d688c71 100644 --- a/crypto/ethsecp256k1/ethsecp256k1_test.go +++ b/crypto/ethsecp256k1/ethsecp256k1_test.go @@ -4,13 +4,14 @@ import ( "encoding/base64" "testing" - "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" + ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/secp256k1" - tmcrypto "github.com/tendermint/tendermint/crypto" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) func TestPrivKey(t *testing.T) { @@ -18,7 +19,7 @@ func TestPrivKey(t *testing.T) { privKey, err := GenerateKey() require.NoError(t, err) require.True(t, privKey.Equals(privKey)) - require.Implements(t, (*tmcrypto.PrivKey)(nil), privKey) + require.Implements(t, (*cryptotypes.PrivKey)(nil), privKey) // validate inequality privKey2, err := GenerateKey() @@ -49,7 +50,7 @@ func TestPrivKey_PubKey(t *testing.T) { pubKey := &PubKey{ Key: privKey.PubKey().Bytes(), } - require.Implements(t, (*tmcrypto.PubKey)(nil), pubKey) + require.Implements(t, (*cryptotypes.PubKey)(nil), pubKey) // validate inequality privKey2, err := GenerateKey() diff --git a/crypto/hd/algorithm.go b/crypto/hd/algorithm.go index 3d3602213..56c4b259b 100644 --- a/crypto/hd/algorithm.go +++ b/crypto/hd/algorithm.go @@ -8,10 +8,9 @@ import ( ethaccounts "github.com/ethereum/go-ethereum/accounts" ethcrypto "github.com/ethereum/go-ethereum/crypto" - "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/ethermint/crypto/ethsecp256k1" ) @@ -96,7 +95,7 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn { // Generate generates a secp256k1 private key from the given bytes. func (s ethSecp256k1Algo) Generate() hd.GenerateFn { - return func(bz []byte) crypto.PrivKey { + return func(bz []byte) cryptotypes.PrivKey { var bzArr = make([]byte, ethsecp256k1.PrivKeySize) copy(bzArr, bz) diff --git a/go.mod b/go.mod index 352e0aeb2..5dde56301 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/btcsuite/btcd v0.21.0-beta github.com/btcsuite/btcutil v1.0.2 github.com/cespare/cp v1.1.1 // indirect - github.com/cosmos/cosmos-sdk v0.40.0-rc3 + github.com/cosmos/cosmos-sdk v0.40.0-rc3.0.20201207213327-da6b7f775596 github.com/deckarep/golang-set v1.7.1 // indirect github.com/ethereum/go-ethereum v1.9.24 github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect @@ -16,23 +16,24 @@ require ( github.com/golang/protobuf v1.4.3 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 - github.com/grpc-ecosystem/grpc-gateway v1.15.2 + github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/mattn/go-colorable v0.1.8 // indirect github.com/miguelmota/go-ethereum-hdwallet v0.0.0-20200123000308-a60dcd172b4c github.com/pkg/errors v0.9.1 github.com/prometheus/tsdb v0.10.0 // indirect github.com/regen-network/cosmos-proto v0.3.0 + github.com/rs/zerolog v1.20.0 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 github.com/stretchr/testify v1.6.1 - github.com/tendermint/tendermint v0.34.0-rc6 - github.com/tendermint/tm-db v0.6.2 + github.com/tendermint/tendermint v0.34.0 + github.com/tendermint/tm-db v0.6.3 github.com/tyler-smith/go-bip39 v1.0.2 - golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee - google.golang.org/genproto v0.0.0-20201015140912-32ed001d685c - google.golang.org/grpc v1.33.0 + golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 + google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 + google.golang.org/grpc v1.33.2 gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 61e3fe73a..9bf2a1014 100644 --- a/go.sum +++ b/go.sum @@ -141,13 +141,13 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.40.0-rc3 h1:sS9BZ82dOxXiZPZdfrzSniEAzLLN0oTP5lFVyjnq2x4= -github.com/cosmos/cosmos-sdk v0.40.0-rc3/go.mod h1:eKgbkQO4FEvC+a1+eyRuL7UgluGK1ad4PufPTpQc6ZA= +github.com/cosmos/cosmos-sdk v0.40.0-rc3.0.20201207213327-da6b7f775596 h1:I/JcfBLLmsiFk4Nyf19/GLnzqdsIr0ZHToeFGDTc+ss= +github.com/cosmos/cosmos-sdk v0.40.0-rc3.0.20201207213327-da6b7f775596/go.mod h1:1NNWkanC/d68dpNYjjJ5Qve4aMEBzVg736cn3oUMPeo= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= -github.com/cosmos/iavl v0.15.0-rc4 h1:P1wmET7BueqCzfxsn+BzVkDWDLY9ij2JNwkbIdM7RG8= -github.com/cosmos/iavl v0.15.0-rc4/go.mod h1:5CsecJdh44Uj4vZ6WSPeWq84hNW5BwRI36ZsAbfJvRw= +github.com/cosmos/iavl v0.15.0-rc5 h1:AMKgaAjXwGANWv56NL4q4hV+a0puSkLYD6cCQAv3i44= +github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -322,14 +322,15 @@ github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= -github.com/grpc-ecosystem/grpc-gateway v1.15.2 h1:HC+hWRWf+v5zTMPyoaYTKIJih+4sd4XRWmj0qlG87Co= -github.com/grpc-ecosystem/grpc-gateway v1.15.2/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -586,6 +587,8 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= +github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM= +github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -620,6 +623,9 @@ github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9Ac github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs= +github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -705,8 +711,12 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= github.com/tendermint/tendermint v0.34.0-rc6 h1:SVuKGvvE22KxfuK8QUHctUrmOWJsncZSYXIYtcnoKN0= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= +github.com/tendermint/tendermint v0.34.0 h1:eXCfMgoqVSzrjzOj6clI9GAejcHH0LvOlRjpCmMJksU= +github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= +github.com/tendermint/tm-db v0.6.3 h1:ZkhQcKnB8/2jr5EaZwGndN4owkPsGezW2fSisS9zGbg= +github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc= github.com/tjfoc/gmsm v1.3.0/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -769,8 +779,8 @@ golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -911,6 +921,7 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190912185636-87d9f09c5d89/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -956,9 +967,8 @@ google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201014134559-03b6142f0dc9/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201015140912-32ed001d685c h1:FM0/YezufKHjM3Y9gndHmhytJuCHW0bExs92Pu3LTQ0= -google.golang.org/genproto v0.0.0-20201015140912-32ed001d685c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -978,8 +988,9 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.0 h1:IBKSUNL2uBS2DkJBncPP+TwT0sp9tgA8A75NjHt6umg= -google.golang.org/grpc v1.33.0/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/rpc/apis.go b/rpc/apis.go index 9903b3129..fc326efd6 100644 --- a/rpc/apis.go +++ b/rpc/apis.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/ethermint/crypto/ethsecp256k1" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/ethermint/rpc/backend" "github.com/cosmos/ethermint/rpc/namespaces/eth" "github.com/cosmos/ethermint/rpc/namespaces/eth/filters" @@ -13,6 +12,8 @@ import ( "github.com/cosmos/ethermint/rpc/namespaces/personal" "github.com/cosmos/ethermint/rpc/namespaces/web3" rpctypes "github.com/cosmos/ethermint/rpc/types" + + "github.com/cosmos/cosmos-sdk/client" ) // RPC namespaces and API version diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index b4baf6101..aa7c248a0 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -6,10 +6,11 @@ import ( "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/client" rpctypes "github.com/cosmos/ethermint/rpc/types" evmtypes "github.com/cosmos/ethermint/x/evm/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" diff --git a/rpc/config.go b/rpc/config.go index 616ccb2d8..155c43d46 100644 --- a/rpc/config.go +++ b/rpc/config.go @@ -1,17 +1,19 @@ package rpc import ( - "github.com/cosmos/cosmos-sdk/client" "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/ethermint/rpc/websockets" "github.com/cosmos/ethermint/server/config" + "github.com/ethereum/go-ethereum/rpc" ) // RegisterEthereum creates a new ethereum JSON-RPC server and recreates a CLI command to start Cosmos REST server with web3 RPC API and // Cosmos rest-server endpoints -func RegisterEthereum(clientCtx client.Context, r *mux.Router, _ config.EthereumConfig) { +func RegisterEthereum(clientCtx client.Context, r *mux.Router) { server := rpc.NewServer() r.HandleFunc("/", server.ServeHTTP).Methods("POST", "OPTIONS") diff --git a/rpc/namespaces/eth/api.go b/rpc/namespaces/eth/api.go index 7849508e9..ad1c718ff 100644 --- a/rpc/namespaces/eth/api.go +++ b/rpc/namespaces/eth/api.go @@ -66,6 +66,7 @@ func NewAPI( api := &PublicEthereumAPI{ ctx: context.Background(), clientCtx: clientCtx, + queryClient: rpctypes.NewQueryClient(clientCtx), chainIDEpoch: epoch, logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "json-rpc", "namespace", "eth"), backend: backend, diff --git a/rpc/namespaces/eth/filters/api.go b/rpc/namespaces/eth/filters/api.go index fcb7e0572..0843bee81 100644 --- a/rpc/namespaces/eth/filters/api.go +++ b/rpc/namespaces/eth/filters/api.go @@ -59,12 +59,6 @@ type PublicFilterAPI struct { // NewAPI returns a new PublicFilterAPI instance. func NewAPI(clientCtx client.Context, backend Backend) *PublicFilterAPI { - // start the client to subscribe to Tendermint events - err := clientCtx.Client.Start() - if err != nil { - panic(err) - } - api := &PublicFilterAPI{ clientCtx: clientCtx, backend: backend, diff --git a/rpc/namespaces/eth/filters/subscription.go b/rpc/namespaces/eth/filters/subscription.go index ee09f6ebe..34d31e21e 100644 --- a/rpc/namespaces/eth/filters/subscription.go +++ b/rpc/namespaces/eth/filters/subscription.go @@ -8,6 +8,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/rpc" + coretypes "github.com/tendermint/tendermint/rpc/core/types" ) diff --git a/server/start.go b/server/start.go index ef6d1b7b6..6c5d6f619 100644 --- a/server/start.go +++ b/server/start.go @@ -165,6 +165,25 @@ func startStandAlone(ctx *sdkserver.Context, appCreator AppCreator) error { func startInProcess(ctx *sdkserver.Context, clientCtx client.Context, appCreator AppCreator) error { cfg := ctx.Config home := cfg.RootDir + var cpuProfileCleanup func() + + if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" { + f, err := os.Create(cpuProfile) + if err != nil { + return err + } + + ctx.Logger.Info("starting CPU profiler", "profile", cpuProfile) + if err := pprof.StartCPUProfile(f); err != nil { + return err + } + + cpuProfileCleanup = func() { + ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) + pprof.StopCPUProfile() + f.Close() + } + } traceWriterFile := ctx.Viper.GetString(flagTraceStore) db, err := openDB(home) @@ -198,10 +217,15 @@ func startInProcess(ctx *sdkserver.Context, clientCtx client.Context, appCreator if err != nil { return err } + ctx.Logger.Debug("Initialization: tmNode created") if err := tmNode.Start(); err != nil { return err } + ctx.Logger.Debug("Initialization: tmNode started") + + // Add the tx service to the gRPC router. + app.RegisterTxService(clientCtx) var apiSrv *api.Server @@ -219,8 +243,6 @@ func startInProcess(ctx *sdkserver.Context, clientCtx client.Context, appCreator apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server")) app.RegisterAPIRoutes(apiSrv.Server, config.API) - // TODO: register Ethereum routes - app.RegisterEthereumServers(apiSrv, config.Ethereum) errCh := make(chan error) go func() { @@ -244,31 +266,7 @@ func startInProcess(ctx *sdkserver.Context, clientCtx client.Context, appCreator } } - if config.Ethereum.EnableWebsocket { - - } - - var cpuProfileCleanup func() - - if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" { - f, err := os.Create(cpuProfile) - if err != nil { - return err - } - - ctx.Logger.Info("starting CPU profiler", "profile", cpuProfile) - if err := pprof.StartCPUProfile(f); err != nil { - return err - } - - cpuProfileCleanup = func() { - ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) - pprof.StopCPUProfile() - f.Close() - } - } - - sdkserver.TrapSignal(func() { + defer func() { if tmNode.IsRunning() { _ = tmNode.Stop() } @@ -286,8 +284,8 @@ func startInProcess(ctx *sdkserver.Context, clientCtx client.Context, appCreator } ctx.Logger.Info("exiting...") - }) + }() - // run forever (the node will not be returned) - select {} + // Wait for SIGINT or SIGTERM signal + return sdkserver.WaitForQuitSignals() } diff --git a/server/util.go b/server/util.go index f6b4d434a..80c4c1899 100644 --- a/server/util.go +++ b/server/util.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + tmcfg "github.com/tendermint/tendermint/config" dbm "github.com/tendermint/tm-db" diff --git a/types/config.go b/types/config.go index 4b07b873a..cc11cf17d 100644 --- a/types/config.go +++ b/types/config.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + ethaccounts "github.com/ethereum/go-ethereum/accounts" ) diff --git a/types/config_test.go b/types/config_test.go index 685eb5114..c3fc1f002 100644 --- a/types/config_test.go +++ b/types/config_test.go @@ -48,8 +48,7 @@ func TestSetCoinType(t *testing.T) { func TestHDPath(t *testing.T) { params := *hd.NewFundraiserParams(0, Bip44CoinType, 0) - // need to prepend "m/" because the below method provided by the sdk does not add the proper prepending - hdPath := "m/" + params.String() + hdPath := params.String() require.Equal(t, "m/44'/60'/0'/0/0", hdPath) require.Equal(t, hdPath, BIP44HDPath) } diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 25c17758c..c16a271dc 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -11,9 +11,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ethermint "github.com/cosmos/ethermint/types" "github.com/cosmos/ethermint/x/evm/types" + + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ) func (suite *KeeperTestSuite) TestQueryAccount() { diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 2e386d362..3e0e7b1b9 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -27,7 +27,7 @@ type Keeper struct { // - storing Account's Code // - storing transaction Logs // - storing block height -> bloom filter map. Needed for the Web3 API. - // - storing block hash -> block height map. Needed for the Web3 API. TODO: remove + // - storing block hash -> block height map. Needed for the Web3 API. storeKey sdk.StoreKey // Ethermint concrete implementation on the EVM StateDB interface CommitStateDB *types.CommitStateDB diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 0c28e5fa2..dfa467729 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( "math/big" "github.com/armon/go-metrics" + tmtypes "github.com/tendermint/tendermint/types" ethcmn "github.com/ethereum/go-ethereum/common" diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index 12870a757..ca2162f2c 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -170,7 +170,43 @@ func (msg MsgEthereumTx) RLPSignBytes(chainID *big.Int) ethcmn.Hash { // EncodeRLP implements the rlp.Encoder interface. func (msg *MsgEthereumTx) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, &msg.Data) + var recipient *ethcmn.Address + if msg.Data.Recipient != nil { + to := ethcmn.HexToAddress(msg.Data.Recipient.Address) + recipient = &to + } + var hash ethcmn.Hash + if len(msg.Data.Hash) > 0 { + hash = ethcmn.HexToHash(msg.Data.Hash) + } + data := struct { + AccountNonce uint64 + Price *big.Int `json:"gasPrice"` + GasLimit uint64 `json:"gas"` + Recipient *ethcmn.Address `json:"to" rlp:"nil"` // nil means contract creation + Amount *big.Int `json:"value"` + Payload []byte `json:"input"` + + // signature values + V *big.Int `json:"v"` + R *big.Int `json:"r"` + S *big.Int `json:"s"` + + // hash is only used when marshaling to JSON + Hash *ethcmn.Hash `json:"hash" rlp:"-"` + }{ + AccountNonce: msg.Data.AccountNonce, + Price: new(big.Int).SetBytes(msg.Data.Price), + GasLimit: msg.Data.GasLimit, + Recipient: recipient, + Amount: new(big.Int).SetBytes(msg.Data.Amount), + Payload: msg.Data.Payload, + V: new(big.Int).SetBytes(msg.Data.V), + R: new(big.Int).SetBytes(msg.Data.R), + S: new(big.Int).SetBytes(msg.Data.S), + Hash: &hash, + } + return rlp.Encode(w, data) } // DecodeRLP implements the rlp.Decoder interface. @@ -181,10 +217,45 @@ func (msg *MsgEthereumTx) DecodeRLP(s *rlp.Stream) error { return err } - if err := s.Decode(&msg.Data); err != nil { + var data struct { + AccountNonce uint64 + Price *big.Int `json:"gasPrice"` + GasLimit uint64 `json:"gas"` + Recipient *ethcmn.Address `json:"to" rlp:"nil"` // nil means contract creation + Amount *big.Int `json:"value"` + Payload []byte `json:"input"` + + // signature values + V *big.Int `json:"v"` + R *big.Int `json:"r"` + S *big.Int `json:"s"` + + // hash is only used when marshaling to JSON + Hash *ethcmn.Hash `json:"hash" rlp:"-"` + } + + if err := s.Decode(&data); err != nil { return err } + var hash string + if data.Hash != nil { + hash = data.Hash.String() + } + + msg.Data = &TxData{ + AccountNonce: data.AccountNonce, + Price: data.Price.Bytes(), + GasLimit: data.GasLimit, + Recipient: &Recipient{Address: data.Recipient.String()}, + Amount: data.Amount.Bytes(), + Payload: data.Payload, + V: data.V.Bytes(), + R: data.R.Bytes(), + S: data.S.Bytes(), + Hash: hash, + } + msg.Size_ = float64(ethcmn.StorageSize(rlp.ListSize(size))) return nil } @@ -304,12 +375,7 @@ func (msg *MsgEthereumTx) GetFrom() sdk.AccAddress { return nil } - address, err := sdk.AccAddressFromBech32(msg.From.Address) - if err != nil { - return nil - } - - return address + return sdk.AccAddress(ethcmn.HexToAddress(msg.From.Address).Bytes()) } // deriveChainID derives the chain id from the given v parameter diff --git a/x/evm/types/utils_test.go b/x/evm/types/utils_test.go index 3c22348a5..e582f86db 100644 --- a/x/evm/types/utils_test.go +++ b/x/evm/types/utils_test.go @@ -3,9 +3,10 @@ package types import ( "testing" + "github.com/stretchr/testify/require" + ethcmn "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" ) func TestEvmDataEncoding(t *testing.T) {