Skip to content

Commit

Permalink
mv "SetHeightHash" fron endBlock to beginBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
summerpro committed Dec 10, 2020
1 parent 50352df commit c6b3172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package keeper

import (
"github.com/ethereum/go-ethereum/common"
"math/big"

abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"

ethtypes "github.com/ethereum/go-ethereum/core/types"

"github.com/okex/okexchain/x/evm/types"
)

// BeginBlock sets the block hash -> block height map for the previous block height
Expand All @@ -22,7 +21,12 @@ func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
// Gas costs are handled within msg handler so costs should be ignored
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())

k.SetBlockHash(ctx, req.Header.LastBlockId.GetHash(), req.Header.GetHeight()-1)
// Set the hash -> height and height -> hash mapping.
hash := req.Header.LastBlockId.GetHash()
height := req.Header.GetHeight() - 1

k.SetHeightHash(ctx, uint64(height), common.BytesToHash(hash))
k.SetBlockHash(ctx, hash, height)

// reset counters that are used on CommitStateDB.Prepare
k.Bloom = big.NewInt(0)
Expand All @@ -37,13 +41,6 @@ func (k Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.Valid
// Gas costs are handled within msg handler so costs should be ignored
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())

// Set the hash for the current height.
// NOTE: we set the hash here instead of on BeginBlock in order to set the final block prior to
// an upgrade. If we set it on BeginBlock the last block from prior to the upgrade wouldn't be
// included on the store.
hash := types.HashFromContext(ctx)
k.SetHeightHash(ctx, uint64(ctx.BlockHeight()), hash)

// Update account balances before committing other parts of state
k.UpdateAccounts(ctx)

Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type revision struct {

// CommitStateDB implements the Geth state.StateDB interface. Instead of using
// a trie and database for querying and persistence, the Keeper uses KVStores
// and an account mapper is used to facilitate state transitions.
// and an AccountKeeper to facilitate state transitions.
//
// TODO: This implementation is subject to change in regards to its statefull
// manner. In otherwords, how this relates to the keeper in this module.
Expand Down

0 comments on commit c6b3172

Please sign in to comment.