Commit 5d6866aa authored by vicotor's avatar vicotor

update code

parent b141dadd
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
package evm package evm
import ( import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"code.wuban.net.cn/cmpchain/ethtracer/evm/vm" "code.wuban.net.cn/cmpchain/ethtracer/evm/vm"
"code.wuban.net.cn/cmpchain/ethtracer/params" "code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/tracing" "code.wuban.net.cn/cmpchain/ethtracer/tracing"
"code.wuban.net.cn/cmpchain/ethtracer/types"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types" metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"math/big" "math/big"
...@@ -32,17 +32,17 @@ type ChainContext interface { ...@@ -32,17 +32,17 @@ type ChainContext interface {
// Engine retrieves the chain's consensus engine. // Engine retrieves the chain's consensus engine.
//Engine() consensus.Engine //Engine() consensus.Engine
Author(header *types.Header) (metatypes.Address, error) Author(header *evmtypes.Header) (metatypes.Address, error)
// GetHeader returns the header corresponding to the hash/number argument pair. // GetHeader returns the header corresponding to the hash/number argument pair.
GetHeader(metatypes.Hash, uint64) *types.Header GetHeader(metatypes.Hash, uint64) *evmtypes.Header
// Config returns the chain's configuration. // Config returns the chain's configuration.
Config() *params.ChainConfig Config() *params.ChainConfig
} }
// NewEVMBlockContext creates a new context for use in the EVM. // NewEVMBlockContext creates a new context for use in the EVM.
func NewEVMBlockContext(header *types.Header, chain ChainContext, author *metatypes.Address) vm.BlockContext { func NewEVMBlockContext(header *evmtypes.Header, chain ChainContext, author *metatypes.Address) vm.BlockContext {
var ( var (
beneficiary metatypes.Address beneficiary metatypes.Address
baseFee *big.Int baseFee *big.Int
...@@ -70,8 +70,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *metaty ...@@ -70,8 +70,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *metaty
Transfer: Transfer, Transfer: Transfer,
GetHash: GetHashFn(header, chain), GetHash: GetHashFn(header, chain),
Coinbase: beneficiary, Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.BlockNumber.GetInt()), BlockNumber: new(big.Int).Set(header.Number),
Time: header.Timestamp, Time: header.Time,
Difficulty: big.NewInt(0), Difficulty: big.NewInt(0),
BaseFee: baseFee, BaseFee: baseFee,
BlobBaseFee: blobBaseFee, BlobBaseFee: blobBaseFee,
...@@ -94,36 +94,36 @@ func NewEVMTxContext(msg *Message) vm.TxContext { ...@@ -94,36 +94,36 @@ func NewEVMTxContext(msg *Message) vm.TxContext {
} }
// GetHashFn returns a GetHashFunc which retrieves header hashes by number // GetHashFn returns a GetHashFunc which retrieves header hashes by number
func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) metatypes.Hash { func GetHashFn(ref *evmtypes.Header, chain ChainContext) func(n uint64) metatypes.Hash {
// Cache will initially contain [refHash.parent], // Cache will initially contain [refHash.parent],
// Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...] // Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...]
var cache []metatypes.Hash var cache []metatypes.Hash
return func(n uint64) metatypes.Hash { return func(n uint64) metatypes.Hash {
if ref.Number().Uint64() <= n { if ref.Number.Uint64() <= n {
// This situation can happen if we're doing tracing and using // This situation can happen if we're doing tracing and using
// block overrides. // block overrides.
return metatypes.Hash{} return metatypes.Hash{}
} }
// If there's no hash cache yet, make one // If there's no hash cache yet, make one
if len(cache) == 0 { if len(cache) == 0 {
cache = append(cache, ref.Parent()) cache = append(cache, ref.ParentHash)
} }
if idx := ref.Number().Uint64() - n - 1; idx < uint64(len(cache)) { if idx := ref.Number.Uint64() - n - 1; idx < uint64(len(cache)) {
return cache[idx] return cache[idx]
} }
// No luck in the cache, but we can start iterating from the last element we already know // No luck in the cache, but we can start iterating from the last element we already know
lastKnownHash := cache[len(cache)-1] lastKnownHash := cache[len(cache)-1]
lastKnownNumber := ref.Number().Uint64() - uint64(len(cache)) lastKnownNumber := ref.Number.Uint64() - uint64(len(cache))
for { for {
header := chain.GetHeader(lastKnownHash, lastKnownNumber) header := chain.GetHeader(lastKnownHash, lastKnownNumber)
if header == nil { if header == nil {
break break
} }
cache = append(cache, header.Parent()) cache = append(cache, header.ParentHash)
lastKnownHash = header.Parent() lastKnownHash = header.ParentHash
lastKnownNumber = header.Number().Uint64() - 1 lastKnownNumber = header.Number.Uint64() - 1
if n == lastKnownNumber { if n == lastKnownNumber {
return lastKnownHash return lastKnownHash
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment