Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 4, 2024
1 parent 8d6162f commit 11262aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 3 additions & 10 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package keeper

import (
"encoding/binary"
"math/big"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -311,27 +310,21 @@ func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, er
// SetHeaderHash stores the hash of the current block header in the store.
func (k Keeper) SetHeaderHash(ctx sdk.Context) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash)
key := make([]byte, 8)
height, err := ethermint.SafeUint64(ctx.BlockHeight())
if err != nil {
panic(err)
}
binary.BigEndian.PutUint64(key, height)
store.Set(key, ctx.HeaderHash())
store.Set(types.GetHeaderHashKey(height), ctx.HeaderHash())
}

// GetHeaderHash retrieves the hash of a block header from the store by height.
func (k Keeper) GetHeaderHash(ctx sdk.Context, height uint64) []byte {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash)
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, height)
return store.Get(key)
return store.Get(types.GetHeaderHashKey(height))
}

// DeleteHeaderHash removes the hash of a block header from the store by height
func (k Keeper) DeleteHeaderHash(ctx sdk.Context, height uint64) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash)
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, height)
store.Delete(key)
store.Delete(types.GetHeaderHashKey(height))
}
6 changes: 6 additions & 0 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc {
if ctx.BlockHeight() < h {
return common.Hash{}
}
if ctx.BlockHeight() == h {
headerHash := ctx.HeaderHash()
if len(headerHash) != 0 {
return common.BytesToHash(headerHash)
}
}
return common.BytesToHash(k.GetHeaderHash(ctx, height))
}
}
Expand Down
6 changes: 6 additions & 0 deletions x/evm/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ func ObjectBloomKey(txIndex, msgIndex int) []byte {
binary.BigEndian.PutUint64(key[9:], value)
return key[:]
}

func GetHeaderHashKey(height uint64) []byte {
key := make([]byte, len(KeyPrefixHeaderHash)+8)
binary.BigEndian.PutUint64(key, height)
return key
}

0 comments on commit 11262aa

Please sign in to comment.