Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Oct 20, 2023
1 parent 4abbccd commit fec3fb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
36 changes: 20 additions & 16 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ func newParams(
stateDB *StateDBAdapter,
getBlockHash GetBlockHash,
) (*Params, error) {
actionCtx := protocol.MustGetActionCtx(ctx)
blkCtx := protocol.MustGetBlockCtx(ctx)
featureCtx := protocol.MustGetFeatureCtx(ctx)
executorAddr := common.BytesToAddress(actionCtx.Caller.Bytes())
var contractAddrPointer *common.Address
var (
actionCtx = protocol.MustGetActionCtx(ctx)
blkCtx = protocol.MustGetBlockCtx(ctx)
featureCtx = protocol.MustGetFeatureCtx(ctx)
g = genesis.MustExtractGenesisContext(ctx)
contractAddrPointer *common.Address
)
if dest := execution.Contract(); dest != action.EmptyAddress {
contract, err := address.FromString(execution.Contract())
if err != nil {
Expand Down Expand Up @@ -162,11 +164,17 @@ func newParams(
Difficulty: new(big.Int).SetUint64(uint64(50)),
BaseFee: new(big.Int),
}
if g.IsRedsea(blkCtx.BlockHeight) {
// Merge enabled at Redsea height
tipHash := protocol.MustGetBlockchainCtx(ctx).Tip.Hash
h := common.BytesToHash(tipHash[:])
context.Random = &h
}

return &Params{
context,
vm.TxContext{
Origin: executorAddr,
Origin: common.BytesToAddress(actionCtx.Caller.Bytes()),
GasPrice: execution.GasPrice(),
},
execution.Nonce(),
Expand Down Expand Up @@ -209,10 +217,12 @@ func ExecuteContract(
) ([]byte, *action.Receipt, error) {
ctx, span := tracer.NewSpan(ctx, "evm.ExecuteContract")
defer span.End()
actionCtx := protocol.MustGetActionCtx(ctx)
blkCtx := protocol.MustGetBlockCtx(ctx)
g := genesis.MustExtractGenesisContext(ctx)
featureCtx := protocol.MustGetFeatureCtx(ctx)
var (
actionCtx = protocol.MustGetActionCtx(ctx)
blkCtx = protocol.MustGetBlockCtx(ctx)
g = genesis.MustExtractGenesisContext(ctx)
featureCtx = protocol.MustGetFeatureCtx(ctx)
)
stateDB, err := prepareStateDB(ctx, sm)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -418,12 +428,6 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte
config = vmCfg
}
chainConfig := getChainConfig(g, blockHeight, evmParams.evmNetworkID)
if g.IsRedsea(blockHeight) {
// Merge enabled at Redsea height
tipHash := protocol.MustGetBlockchainCtx(ctx).Tip.Hash
h := common.BytesToHash(tipHash[:])
evmParams.context.Random = &h
}
evm := vm.NewEVM(evmParams.context, evmParams.txCtx, stateDB, chainConfig, config)
if g.IsOkhotsk(blockHeight) {
accessList = evmParams.accessList
Expand Down
6 changes: 0 additions & 6 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -265,11 +264,6 @@ func TestConstantinople(t *testing.T) {

var evmConfig vm.Config
chainConfig := getChainConfig(g.Blockchain, e.height, ps.evmNetworkID)
if g.IsRedsea(e.height) {
// Merge enabled at Redsea height
h := common.BytesToHash(hash.ZeroHash256[:])
ps.context.Random = &h
}
evm := vm.NewEVM(ps.context, ps.txCtx, stateDB, chainConfig, evmConfig)
require.Equal(e.height, evm.Context.BlockNumber.Uint64())

Expand Down

0 comments on commit fec3fb6

Please sign in to comment.