forked from cerc-io/laconicd-deprecated
x/evm: fix EndBlock consensus failure (#334)
* add test for sending tx w/ 21000 gas * improve rpc transfer test * use ctx in EndBlock * UpdateAccounts and ClearStateObjects with passed in context * log ethereum address on error Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
This commit is contained in:
co-authored by
Federico Kunze
Federico Kunze
parent
0921c863e7
commit
28e28f2a7b
+3
-3
@@ -31,16 +31,16 @@ func EndBlock(k Keeper, ctx sdk.Context, req abci.RequestEndBlock) []abci.Valida
|
||||
ctx = ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
|
||||
|
||||
// Update account balances before committing other parts of state
|
||||
k.CommitStateDB.UpdateAccounts()
|
||||
k.UpdateAccounts(ctx)
|
||||
|
||||
// Commit state objects to KV store
|
||||
_, err := k.CommitStateDB.WithContext(ctx).Commit(true)
|
||||
_, err := k.Commit(ctx, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Clear accounts cache after account data has been committed
|
||||
k.CommitStateDB.ClearStateObjects()
|
||||
k.ClearStateObjects(ctx)
|
||||
|
||||
bloom := ethtypes.BytesToBloom(k.Bloom.Bytes())
|
||||
k.SetBlockBloom(ctx, ctx.BlockHeight(), bloom)
|
||||
|
||||
+22
-3
@@ -1,6 +1,7 @@
|
||||
package evm_test
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -258,9 +260,6 @@ func (suite *EvmTestSuite) TestQueryTxLogs() {
|
||||
err = tx.Sign(big.NewInt(3), priv.ToECDSA())
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// result, err := evm.HandleEthTxMsg(suite.ctx, suite.app.EvmKeeper, tx)
|
||||
// suite.Require().NoError(err, "failed to handle eth tx msg")
|
||||
|
||||
result, err := suite.handler(suite.ctx, tx)
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(result)
|
||||
@@ -291,3 +290,23 @@ func (suite *EvmTestSuite) TestQueryTxLogs() {
|
||||
resultData.Logs[0].Data = []byte{}
|
||||
suite.Require().Equal(txLogs.Logs[0], resultData.Logs[0])
|
||||
}
|
||||
|
||||
func (suite *EvmTestSuite) TestSendTransaction() {
|
||||
gasLimit := uint64(21000)
|
||||
gasPrice := big.NewInt(1)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
suite.Require().NoError(err, "failed to create key")
|
||||
pub := priv.ToECDSA().Public().(*ecdsa.PublicKey)
|
||||
|
||||
suite.app.EvmKeeper.SetBalance(suite.ctx, ethcrypto.PubkeyToAddress(*pub), big.NewInt(100))
|
||||
|
||||
// send simple value transfer with gasLimit=21000
|
||||
tx := types.NewMsgEthereumTx(1, ðcmn.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil)
|
||||
err = tx.Sign(big.NewInt(3), priv.ToECDSA())
|
||||
suite.Require().NoError(err)
|
||||
|
||||
result, err := suite.handler(suite.ctx, tx)
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(result)
|
||||
}
|
||||
|
||||
@@ -228,6 +228,16 @@ func (k *Keeper) CreateAccount(ctx sdk.Context, addr ethcmn.Address) {
|
||||
k.CommitStateDB.WithContext(ctx).CreateAccount(addr)
|
||||
}
|
||||
|
||||
// UpdateAccounts calls CommitStateDB.UpdateAccounts using the passed in context
|
||||
func (k *Keeper) UpdateAccounts(ctx sdk.Context) {
|
||||
k.CommitStateDB.WithContext(ctx).UpdateAccounts()
|
||||
}
|
||||
|
||||
// ClearStateObjects calls CommitStateDB.ClearStateObjects using the passed in context
|
||||
func (k *Keeper) ClearStateObjects(ctx sdk.Context) {
|
||||
k.CommitStateDB.WithContext(ctx).ClearStateObjects()
|
||||
}
|
||||
|
||||
// Copy calls CommitStateDB.Copy using the passed in context
|
||||
func (k *Keeper) Copy(ctx sdk.Context) ethvm.StateDB {
|
||||
return k.CommitStateDB.WithContext(ctx).Copy()
|
||||
|
||||
Reference in New Issue
Block a user