From d27810b6b56209426b657b84e33677606edd7441 Mon Sep 17 00:00:00 2001 From: KamiD <44460798+KamiD@users.noreply.github.com> Date: Wed, 30 Dec 2020 23:39:21 +0800 Subject: [PATCH] evm: reset cache after csdb is committed (#676) * reset after commit, fix wrong apphash when restart a node with snapshot * remove ClearStateObjects * add comment, edit the CHANGELOG.md --- CHANGELOG.md | 1 + x/evm/keeper/abci.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 653ef25e..a1f146e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent * (evm) [\#661](https://github.com/cosmos/ethermint/pull/661) Set nonce to the EVM account on genesis initialization. * (rpc) [\#648](https://github.com/cosmos/ethermint/issues/648) Fix block cumulative gas used value. * (evm) [\#621](https://github.com/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`. diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 8c8495a8..6a8baf52 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -44,14 +44,17 @@ func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.Valid // Update account balances before committing other parts of state k.UpdateAccounts(ctx) + root, err := k.Commit(ctx, true) // Commit state objects to KV store - if _, err := k.Commit(ctx, true); err != nil { + if err != nil { k.Logger(ctx).Error("failed to commit state objects", "error", err, "height", ctx.BlockHeight()) panic(err) } - // Clear accounts cache after account data has been committed - k.ClearStateObjects(ctx) + // reset all cache after account data has been committed, that make sure node state consistent + if err = k.Reset(ctx, root); err != nil { + panic(err) + } // set the block bloom filter bytes to store bloom := ethtypes.BytesToBloom(k.Bloom.Bytes())