Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

stateDB txlog store enhancement #461

Merged
merged 18 commits into from
Aug 31, 2021
Merged
Prev Previous commit
Next Next commit
simplify SetLog(s)
  • Loading branch information
JayT106 committed Aug 30, 2021
commit 389beda9f80b4fa793792936c01cb699bd20c727
14 changes: 11 additions & 3 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,26 @@ func (k Keeper) GetTxLogs(txHash common.Hash) []*ethtypes.Log {
// SetLogs sets the logs for a transaction in the KVStore.
func (k Keeper) SetLogs(txHash common.Hash, logs []*ethtypes.Log) {
JayT106 marked this conversation as resolved.
Show resolved Hide resolved
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.KeyPrefixLogs)

for _, log := range logs {
var key = txHash.Bytes()
key = append(key, sdk.Uint64ToBigEndian(uint64(log.Index))...)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
k.SetLog(store, key, log)
txIndexLog := types.NewLogFromEth(log)
bz := k.cdc.MustMarshal(txIndexLog)
store.Set(key, bz)
}
}

// SetLog sets the log for a transaction in the KVStore.
func (k Keeper) SetLog(s prefix.Store, key []byte, log *ethtypes.Log) {
func (k Keeper) SetLog(log *ethtypes.Log) {
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.KeyPrefixLogs)

var key = log.TxHash.Bytes()
key = append(key, sdk.Uint64ToBigEndian(uint64(log.Index))...)

txIndexLog := types.NewLogFromEth(log)
bz := k.cdc.MustMarshal(txIndexLog)
s.Set(key, bz)
store.Set(key, bz)
}

// DeleteLogs removes the logs from the KVStore. It is used during journal.Revert.
Expand Down
8 changes: 1 addition & 7 deletions x/evm/keeper/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,7 @@ func (k *Keeper) AddLog(log *ethtypes.Log) {

log.Index = uint(k.GetLogSizeTransient())
k.IncreaseLogSizeTransient()

s := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.KeyPrefixLogs)

var key = log.TxHash.Bytes()
key = append(key, sdk.Uint64ToBigEndian(uint64(log.Index))...)

k.SetLog(s, key, log)
k.SetLog(log)

k.Logger(k.Ctx()).Debug(
"log added",
Expand Down