Skip to content

Commit

Permalink
upgraded go-ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
lmittmann committed Jul 29, 2023
1 parent e7a1e37 commit fffb636
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
golang.org/x/time v0.3.0
)

replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.12.1-0.20230711134323-4b06e4f25e9a
replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.12.1-0.20230728070838-8f2ae29b8f77

require (
github.com/DataDog/zstd v1.5.2 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/ethereum/c-kzg-4844 v0.3.0 h1:3Y3hD6l5i0dEYsBL50C+Om644kve3pNqoAcvE26o9zI=
github.com/ethereum/c-kzg-4844 v0.3.0/go.mod h1:WI2Nd82DMZAAZI1wV2neKGost9EKjvbpQR9OqE5Qqa8=
github.com/ethereum/go-ethereum v1.12.1-0.20230711134323-4b06e4f25e9a h1:I0vtPDbUGsyLlWj4ItkiJGfFFHzdJp6HCDg0QJ9qbVU=
github.com/ethereum/go-ethereum v1.12.1-0.20230711134323-4b06e4f25e9a/go.mod h1:aYRabMoCARQdLowZJ3zLe5k2+QcvBerNEX+vr3zb+k8=
github.com/ethereum/go-ethereum v1.12.1-0.20230728070838-8f2ae29b8f77 h1:b3uiqqHx+e6Mnfb4cJMsAzS7FmJWpxs+PixCg//t2CY=
github.com/ethereum/go-ethereum v1.12.1-0.20230728070838-8f2ae29b8f77/go.mod h1:zKetLweqBR8ZS+1O9iJWI8DvmmD2NzD19apjEWDCsnw=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
Expand Down Expand Up @@ -152,6 +152,7 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
Expand Down Expand Up @@ -307,7 +308,7 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q=
github.com/urfave/cli/v2 v2.24.1 h1:/QYYr7g0EhwXEML8jO+8OYt5trPnLHS0p3mrgExJ5NU=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
Expand Down
74 changes: 37 additions & 37 deletions w3vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,42 @@ type vmOptions struct {
}

func New(opts ...Option) *VM {
c := &VM{opts: new(vmOptions)}
v := &VM{opts: new(vmOptions)}
for _, opt := range opts {
opt(c)
opt(v)
}

c.fetcher = c.opts.fetcher
v.fetcher = v.opts.fetcher

// set chain config
c.chainConfig = c.opts.chainConfig
if c.chainConfig == nil {
if c.fetcher != nil {
c.chainConfig = params.MainnetChainConfig
v.chainConfig = v.opts.chainConfig
if v.chainConfig == nil {
if v.fetcher != nil {
v.chainConfig = params.MainnetChainConfig
} else {
c.chainConfig = allEthashProtocolChanges
v.chainConfig = allEthashProtocolChanges
}
}

c.blockCtx = c.opts.blockCtx
if c.blockCtx == nil {
if c.opts.header != nil {
c.blockCtx = newBlockContext(c.opts.header, c.fetcherHashFunc(c.fetcher))
v.blockCtx = v.opts.blockCtx
if v.blockCtx == nil {
if v.opts.header != nil {
v.blockCtx = newBlockContext(v.opts.header, v.fetcherHashFunc(v.fetcher))
} else {
c.blockCtx = defaultBlockContext()
v.blockCtx = defaultBlockContext()
}
}

// set DB
c.db = state.NewDB(c.fetcher)
if c.opts.preState != nil {
c.db.SetState(c.opts.preState)
v.db = state.NewDB(v.fetcher)
if v.opts.preState != nil {
v.db.SetState(v.opts.preState)
}
return c
return v
}

func (vm *VM) Apply(msg *w3types.Message, tracers ...vm.EVMLogger) (*Receipt, error) {
return vm.apply(msg, false, newMultiEVMLogger(tracers))
func (v *VM) Apply(msg *w3types.Message, tracers ...vm.EVMLogger) (*Receipt, error) {
return v.apply(msg, false, newMultiEVMLogger(tracers))
}

func (v *VM) apply(msg *w3types.Message, isCall bool, tracer vm.EVMLogger) (*Receipt, error) {
Expand Down Expand Up @@ -125,18 +125,18 @@ func (v *VM) apply(msg *w3types.Message, isCall bool, tracer vm.EVMLogger) (*Rec
if isCall {
stateDB.RevertToSnapshot(0)
} else {
stateDB.Commit(false)
stateDB.Commit(0, false)
}
return receipt, receipt.Err
}

func (vm *VM) Call(msg *w3types.Message, tracers ...vm.EVMLogger) (*Receipt, error) {
return vm.apply(msg, true, newMultiEVMLogger(tracers))
func (v *VM) Call(msg *w3types.Message, tracers ...vm.EVMLogger) (*Receipt, error) {
return v.apply(msg, true, newMultiEVMLogger(tracers))
}

func (vm *VM) CallFunc(contract common.Address, f w3types.Func, args ...any) Returner {
func (v *VM) CallFunc(contract common.Address, f w3types.Func, args ...any) Returner {
return &returner{
vm: vm,
vm: v,
msg: &w3types.Message{
To: &contract,
Func: f,
Expand All @@ -163,49 +163,49 @@ func (r *returner) Returns(returns ...any) error {
}

// Nonce returns the nonce of Address addr.
func (vm *VM) Nonce(addr common.Address) uint64 {
acc, err := vm.db.GetAccount(addr)
func (v *VM) Nonce(addr common.Address) uint64 {
acc, err := v.db.GetAccount(addr)
if err != nil {
return 0
}
return acc.Nonce
}

// Balance returns the balance of Address addr.
func (vm *VM) Balance(addr common.Address) *big.Int {
acc, err := vm.db.GetAccount(addr)
func (v *VM) Balance(addr common.Address) *big.Int {
acc, err := v.db.GetAccount(addr)
if err != nil {
return new(big.Int)
}
return acc.Balance
}

// Code returns the code of Address addr.
func (vm *VM) Code(addr common.Address) []byte {
code, err := vm.db.ContractCode(addr, hash0)
func (v *VM) Code(addr common.Address) []byte {
code, err := v.db.ContractCode(addr, hash0)
if err != nil {
return nil
}
return code
}

// StorageAt returns the state of Address addr at the give storage Hash slot.
func (vm *VM) StorageAt(addr common.Address, slot common.Hash) common.Hash {
storageVal, err := vm.db.GetStorage(addr, slot[:])
func (v *VM) StorageAt(addr common.Address, slot common.Hash) common.Hash {
storageVal, err := v.db.GetStorage(addr, slot[:])
if err != nil {
return hash0
}
return common.BytesToHash(storageVal)
}

func (c *VM) buildMessage(msg *w3types.Message, skipAccChecks bool) (*core.Message, *vm.TxContext, error) {
func (v *VM) buildMessage(msg *w3types.Message, skipAccChecks bool) (*core.Message, *vm.TxContext, error) {
nonce := msg.Nonce
if nonce == 0 && !skipAccChecks && msg.From != addr0 {
nonce = c.Nonce(msg.From)
nonce = v.Nonce(msg.From)
}

gasLimit := msg.Gas
if maxGasLimit := c.blockCtx.GasLimit; gasLimit == 0 {
if maxGasLimit := v.blockCtx.GasLimit; gasLimit == 0 {
gasLimit = maxGasLimit
} else if gasLimit > maxGasLimit {
gasLimit = maxGasLimit
Expand All @@ -225,7 +225,7 @@ func (c *VM) buildMessage(msg *w3types.Message, skipAccChecks bool) (*core.Messa
gasPrice := nilToZero(msg.GasPrice)
gasFeeCap := nilToZero(msg.GasFeeCap)
gasTipCap := nilToZero(msg.GasTipCap)
if baseFee := c.blockCtx.BaseFee; baseFee != nil && baseFee.Sign() > 0 {
if baseFee := v.blockCtx.BaseFee; baseFee != nil && baseFee.Sign() > 0 {
gasPrice = math.BigMin(gasFeeCap, new(big.Int).Add(baseFee, gasTipCap))
}

Expand All @@ -249,7 +249,7 @@ func (c *VM) buildMessage(msg *w3types.Message, skipAccChecks bool) (*core.Messa
nil
}

func (vm *VM) fetcherHashFunc(fetcher state.Fetcher) vm.GetHashFunc {
func (v *VM) fetcherHashFunc(fetcher state.Fetcher) vm.GetHashFunc {
return func(n uint64) common.Hash {
blockNumber := new(big.Int).SetUint64(n)
hash, _ := fetcher.HeaderHash(blockNumber)
Expand Down

0 comments on commit fffb636

Please sign in to comment.