From 0805bf80e57aaa6a4b96aa8b3e142a8c0183ccb1 Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Thu, 27 May 2021 05:26:01 -0400 Subject: [PATCH] evm: fix `EndBlock` panic (#51) --- app/app.go | 8 ++++---- client/testnet.go | 36 +----------------------------------- tests/rpc/rpc_test.go | 4 ++-- x/evm/keeper/abci.go | 1 + 4 files changed, 8 insertions(+), 41 deletions(-) diff --git a/app/app.go b/app/app.go index c2e2126e..213554a6 100644 --- a/app/app.go +++ b/app/app.go @@ -230,7 +230,7 @@ func NewEthermintApp( cdc := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - // NOTE we use custom Injective transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx + // NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx bApp := baseapp.NewBaseApp( appName, logger, @@ -383,7 +383,7 @@ func NewEthermintApp( ibc.NewAppModule(app.IBCKeeper), params.NewAppModule(app.ParamsKeeper), transferModule, - // Injective app modules + // Ethermint app modules evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.BankKeeper), ) @@ -413,7 +413,7 @@ func NewEthermintApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName, - // Injective modules + // Ethermint modules evmtypes.ModuleName, // NOTE: crisis module must go at the end to check for invariants on each module @@ -457,7 +457,7 @@ func NewEthermintApp( app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) - // use Injective's custom AnteHandler + // use Ethermint's custom AnteHandler app.SetAnteHandler( ante.NewAnteHandler( app.AccountKeeper, app.BankKeeper, app.EvmKeeper, diff --git a/client/testnet.go b/client/testnet.go index 1fcbef01..bdc51d7b 100644 --- a/client/testnet.go +++ b/client/testnet.go @@ -4,16 +4,13 @@ package client import ( "bufio" - "bytes" "encoding/json" "errors" "fmt" - "io/ioutil" "log" "net" "os" "path/filepath" - "strings" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -47,8 +44,6 @@ import ( evmtypes "github.com/cosmos/ethermint/x/evm/types" "github.com/cosmos/ethermint/cmd/ethermintd/config" - "github.com/cosmos/ethermint/crypto/ethsecp256k1" - "github.com/ethereum/go-ethereum/common" ) var ( @@ -136,7 +131,7 @@ func InitTestnet( ) error { if chainID == "" { - chainID = fmt.Sprintf("injective-%d", tmrand.Int63n(9999999999999)+1) + chainID = fmt.Sprintf("ethermint-%d", tmrand.Int63n(9999999999999)+1) } if !chaintypes.IsValidChainID(chainID) { @@ -297,9 +292,6 @@ func InitTestnet( } config.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appConfig) - - ethPrivKey, err := keyring.NewUnsafe(kb).UnsafeExportPrivKeyHex(nodeDirName) - initPeggo(outputDir, nodeDirName, []byte(strings.ToUpper(ethPrivKey))) } if err := initGenFiles(clientCtx, mbm, chainID, coinDenom, genAccounts, genBalances, genFiles, numValidators); err != nil { @@ -318,32 +310,6 @@ func InitTestnet( return nil } -func initPeggo(outputDir string, nodeDirName string, privKey []byte) { - peggoDir := filepath.Join(outputDir, nodeDirName, "peggo") - if envdata, _ := ioutil.ReadFile("./templates/peggo_config.template"); len(envdata) > 0 { - s := bufio.NewScanner(bytes.NewReader(envdata)) - for s.Scan() { - parts := strings.Split(s.Text(), "=") - if len(parts) != 2 { - continue - } else { - content := []byte(s.Text()) - if parts[0] == "PEGGY_COSMOS_PRIVKEY" { - content = append([]byte(parts[0]+"="), privKey...) - } else if parts[0] == "PEGGY_ETH_PRIVATE_KEY" { - newPrivkey, _ := ethsecp256k1.GenerateKey() - privKeyStr := common.Bytes2Hex(newPrivkey.GetKey()) - privKeyBytes := []byte(strings.ToUpper(privKeyStr)) - content = append([]byte(parts[0]+"="), privKeyBytes...) - } - if err := appendToFile(fmt.Sprintf("config.env"), peggoDir, content); err != nil { - fmt.Println("Error writing peggo config", "error", err) - } - } - } - } -} - func initGenFiles( clientCtx client.Context, mbm module.BasicManager, diff --git a/tests/rpc/rpc_test.go b/tests/rpc/rpc_test.go index 1a69406a..c038f6c7 100644 --- a/tests/rpc/rpc_test.go +++ b/tests/rpc/rpc_test.go @@ -1,7 +1,7 @@ // This is a test utility for Ethermint's Web3 JSON-RPC services. // -// To run these tests please first ensure you have the injectived running -// and have started the RPC service with `injectived rest-server`. +// To run these tests please first ensure you have the ethermintd running +// and have started the RPC service with `ethermintd rest-server`. // // You can configure the desired HOST and MODE as well package rpc diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 2443fb5b..8325cca6 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -45,6 +45,7 @@ func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.Valid // Gas costs are handled within msg handler so costs should be ignored ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) k.CommitStateDB.WithContext(ctx) + k.WithContext(ctx) // Update account balances before committing other parts of state k.CommitStateDB.UpdateAccounts()