evm: update block bloom (#193)

Closes #139
This commit is contained in:
yihuang 2021-06-30 15:37:03 +08:00 committed by GitHub
parent 3b3daa4b48
commit 036ffb7a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 19 deletions

View File

@ -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{}

View File

@ -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

View File

@ -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
}

View File

@ -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)