diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 58d89fe0..98c5b9d4 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -1,16 +1,14 @@ package keeper import ( - "math/big" "time" - ethtypes "github.com/ethereum/go-ethereum/core/types" - abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/tharsis/ethermint/x/evm/types" ) @@ -33,14 +31,7 @@ func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.Vali infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) k.WithContext(ctx) - // get the block bloom bytes from the transient store and set it to the persistent storage - bloomBig, found := k.GetBlockBloomTransient() - if !found { - bloomBig = big.NewInt(0) - } - - bloom := ethtypes.BytesToBloom(bloomBig.Bytes()) - k.SetBlockBloom(infCtx, req.Height, bloom) + k.SetBlockBloom(infCtx, req.Height, ethtypes.BytesToBloom(k.GetBlockBloomTransient().Bytes())) k.WithContext(ctx) return []abci.ValidatorUpdate{} diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 13ba4d8c..e6c72189 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -131,14 +131,14 @@ func (k Keeper) SetBlockBloom(ctx sdk.Context, height int64, bloom ethtypes.Bloo } // GetBlockBloomTransient returns bloom bytes for the current block height -func (k Keeper) GetBlockBloomTransient() (*big.Int, bool) { +func (k Keeper) GetBlockBloomTransient() *big.Int { store := k.ctx.TransientStore(k.transientKey) bz := store.Get(types.KeyPrefixTransientBloom) if len(bz) == 0 { - return nil, false + return big.NewInt(0) } - return new(big.Int).SetBytes(bz), true + return new(big.Int).SetBytes(bz) } // SetBlockBloomTransient sets the given bloom bytes to the transient store. This value is reset on diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index d6233cc4..de355ec6 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -144,11 +144,18 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT return nil, stacktrace.Propagate(err, "failed to apply ethereum core message") } - // set the ethereum-formatted hash to the tx result as the tendermint hash is different - // NOTE: see https://github.com/tendermint/tendermint/issues/6539 for reference. - txHash := tx.Hash() + // NOTE: we set up the transaction hash from tendermint as it is the format expected by the application: + // Remove once hashing is fixed on Tendermint. See https://github.com/tendermint/tendermint/issues/6539 + txHash := common.BytesToHash(tmtypes.Tx(k.ctx.TxBytes()).Hash()) res.Hash = txHash.Hex() - res.Logs = types.NewLogsFromEth(k.GetTxLogs(txHash)) + + logs := k.GetTxLogs(txHash) + res.Logs = types.NewLogsFromEth(logs) + + // update block bloom filter + bloom := k.GetBlockBloomTransient() + bloom.Or(bloom, big.NewInt(0).SetBytes(ethtypes.LogsBloom(logs))) + k.SetBlockBloomTransient(bloom) return res, nil } diff --git a/x/evm/keeper/statedb.go b/x/evm/keeper/statedb.go index ab18011c..63cf4706 100644 --- a/x/evm/keeper/statedb.go +++ b/x/evm/keeper/statedb.go @@ -607,7 +607,7 @@ func (k *Keeper) AddLog(log *ethtypes.Log) { log.BlockHash = common.BytesToHash(k.ctx.HeaderHash()) log.TxIndex = uint(k.GetTxIndexTransient()) - logs := k.GetTxLogs(log.TxHash) + logs := k.GetTxLogs(key) log.Index = uint(len(logs)) logs = append(logs, log)