Skip to content

Commit

Permalink
use snapshot to support revert
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 28, 2024
1 parent 5a41c08 commit 9464355
Show file tree
Hide file tree
Showing 11 changed files with 679 additions and 153 deletions.
14 changes: 7 additions & 7 deletions x/evm/keeper/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (k Keeper) CreateEVM(ctx context.Context, caller common.Address, tracer *tr
return ctx, nil, err
}

// prepare SDK context for EVM execution
ctx, err = prepareSDKContext(sdk.UnwrapSDKContext(ctx))
if err != nil {
return ctx, nil, err
}

evm := &vm.EVM{}
blockContext, err := k.buildBlockContext(ctx, evm, fee)
if err != nil {
Expand All @@ -181,19 +187,13 @@ func (k Keeper) CreateEVM(ctx context.Context, caller common.Address, tracer *tr
NumRetainBlockHashes: &params.NumRetainBlockHashes,
}

// prepare SDK context for EVM execution
ctx, err = prepareSDKContext(sdk.UnwrapSDKContext(ctx))
if err != nil {
return ctx, nil, err
}

*evm = *vm.NewEVMWithPrecompiles(
blockContext,
txContext,
stateDB,
types.DefaultChainConfig(ctx),
vmConfig,
k.precompiles.toMap(ctx),
k.precompiles.toMap(stateDB),
)

if tracer != nil {
Expand Down
6 changes: 2 additions & 4 deletions x/evm/keeper/precompiles.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"context"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"

Expand Down Expand Up @@ -55,10 +53,10 @@ func (k *Keeper) loadPrecompiles() error {
type precompiles []precompile

// toMap converts the precompiles to a map.
func (ps precompiles) toMap(ctx context.Context) map[common.Address]vm.PrecompiledContract {
func (ps precompiles) toMap(stateDB types.StateDB) map[common.Address]vm.PrecompiledContract {
m := make(map[common.Address]vm.PrecompiledContract)
for _, p := range ps {
m[p.addr] = p.contract.(types.WithContext).WithContext(ctx)
m[p.addr] = p.contract.(types.WithStateDB).WithStateDB(stateDB)
}

return m
Expand Down
Loading

0 comments on commit 9464355

Please sign in to comment.