Commit 5d6866aa authored by vicotor's avatar vicotor

update code

parent b141dadd
......@@ -17,10 +17,10 @@
package evm
import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"code.wuban.net.cn/cmpchain/ethtracer/evm/vm"
"code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/tracing"
"code.wuban.net.cn/cmpchain/ethtracer/types"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/holiman/uint256"
"math/big"
......@@ -32,17 +32,17 @@ type ChainContext interface {
// Engine retrieves the chain's 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(metatypes.Hash, uint64) *types.Header
GetHeader(metatypes.Hash, uint64) *evmtypes.Header
// Config returns the chain's configuration.
Config() *params.ChainConfig
}
// 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 (
beneficiary metatypes.Address
baseFee *big.Int
......@@ -70,8 +70,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *metaty
Transfer: Transfer,
GetHash: GetHashFn(header, chain),
Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.BlockNumber.GetInt()),
Time: header.Timestamp,
BlockNumber: new(big.Int).Set(header.Number),
Time: header.Time,
Difficulty: big.NewInt(0),
BaseFee: baseFee,
BlobBaseFee: blobBaseFee,
......@@ -94,36 +94,36 @@ func NewEVMTxContext(msg *Message) vm.TxContext {
}
// 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],
// Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...]
var cache []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
// block overrides.
return metatypes.Hash{}
}
// If there's no hash cache yet, make one
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]
}
// No luck in the cache, but we can start iterating from the last element we already know
lastKnownHash := cache[len(cache)-1]
lastKnownNumber := ref.Number().Uint64() - uint64(len(cache))
lastKnownNumber := ref.Number.Uint64() - uint64(len(cache))
for {
header := chain.GetHeader(lastKnownHash, lastKnownNumber)
if header == nil {
break
}
cache = append(cache, header.Parent())
lastKnownHash = header.Parent()
lastKnownNumber = header.Number().Uint64() - 1
cache = append(cache, header.ParentHash)
lastKnownHash = header.ParentHash
lastKnownNumber = header.Number.Uint64() - 1
if n == lastKnownNumber {
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