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 e699ca4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) error {
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call

Check warning on line 35 in x/evm/keeper/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/abci.go#L35

Added line #L35 was not covered by tests
}
for i := ctx.BlockHeight() - headerHashNum; i >= 0; i-- {
if i := ctx.BlockHeight() - headerHashNum; i > 0 {
h, err := ethermint.SafeUint64(i)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call

Check warning on line 40 in x/evm/keeper/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/abci.go#L40

Added line #L40 was not covered by tests
Expand Down
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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

Check warning on line 315 in x/evm/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/keeper.go#L315

Added line #L315 was not covered by tests
}
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))

Check warning on line 323 in x/evm/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/keeper.go#L321-L323

Added lines #L321 - L323 were not covered by tests
}

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

Check warning on line 112 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L112

Added line #L112 was not covered by tests
}
}
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

Check warning on line 119 in x/evm/types/key.go

View check run for this annotation

Codecov / codecov/patch

x/evm/types/key.go#L116-L119

Added lines #L116 - L119 were not covered by tests
}

0 comments on commit e699ca4

Please sign in to comment.