Skip to content

Commit b95846d

Browse files
committed
rebase fix
1 parent 98b08c3 commit b95846d

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

light/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"math/big"
2121

2222
"github.com/ethereum/go-ethereum/common"
23+
"github.com/ethereum/go-ethereum/crypto"
2324
"github.com/ethereum/go-ethereum/logger"
2425
"github.com/ethereum/go-ethereum/logger/glog"
2526
"golang.org/x/net/context"
@@ -156,7 +157,7 @@ func (self *LightState) SetNonce(ctx context.Context, addr common.Address, nonce
156157
func (self *LightState) SetCode(ctx context.Context, addr common.Address, code []byte) error {
157158
stateObject, err := self.GetOrNewStateObject(ctx, addr)
158159
if err == nil && stateObject != nil {
159-
stateObject.SetCode(code)
160+
stateObject.SetCode(crypto.Keccak256Hash(code), code)
160161
}
161162
return err
162163
}

light/state_object.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ func (self *StateObject) Code() []byte {
217217
}
218218

219219
// SetCode sets the contract code
220-
func (self *StateObject) SetCode(code []byte) {
220+
func (self *StateObject) SetCode(hash common.Hash, code []byte) {
221221
self.code = code
222-
self.codeHash = crypto.Keccak256(code)
222+
self.codeHash = hash[:]
223223
self.dirty = true
224224
}
225225

light/vm_env.go

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ethereum/go-ethereum/core"
2424
"github.com/ethereum/go-ethereum/core/types"
2525
"github.com/ethereum/go-ethereum/core/vm"
26+
"github.com/ethereum/go-ethereum/crypto"
2627
"golang.org/x/net/context"
2728
)
2829

@@ -40,10 +41,7 @@ type VMEnv struct {
4041
msg core.Message
4142
depth int
4243
chain *LightChain
43-
typ vm.Type
44-
// structured logging
45-
logs []vm.StructLog
46-
err error
44+
err error
4745
}
4846

4947
// NewEnv creates a new execution environment based on an ODR capable light state
@@ -53,7 +51,6 @@ func NewEnv(ctx context.Context, state *LightState, chainConfig *core.ChainConfi
5351
chain: chain,
5452
header: header,
5553
msg: msg,
56-
typ: vm.StdVmTy,
5754
}
5855
env.state = &VMState{ctx: ctx, state: state, env: env}
5956

@@ -69,12 +66,9 @@ func (self *VMEnv) Coinbase() common.Address { return self.header.Coinbase }
6966
func (self *VMEnv) Time() *big.Int { return self.header.Time }
7067
func (self *VMEnv) Difficulty() *big.Int { return self.header.Difficulty }
7168
func (self *VMEnv) GasLimit() *big.Int { return self.header.GasLimit }
72-
func (self *VMEnv) Value() *big.Int { return self.msg.Value() }
7369
func (self *VMEnv) Db() vm.Database { return self.state }
7470
func (self *VMEnv) Depth() int { return self.depth }
7571
func (self *VMEnv) SetDepth(i int) { self.depth = i }
76-
func (self *VMEnv) VmType() vm.Type { return self.typ }
77-
func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t }
7872
func (self *VMEnv) GetHash(n uint64) common.Hash {
7973
for header := self.chain.GetHeader(self.header.ParentHash, self.header.Number.Uint64()-1); header != nil; header = self.chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) {
8074
if header.GetNumberU64() == n {
@@ -92,12 +86,12 @@ func (self *VMEnv) CanTransfer(from common.Address, balance *big.Int) bool {
9286
return self.state.GetBalance(from).Cmp(balance) >= 0
9387
}
9488

95-
func (self *VMEnv) MakeSnapshot() vm.Database {
96-
return &VMState{ctx: self.ctx, state: self.state.state.Copy(), env: self}
89+
func (self *VMEnv) SnapshotDatabase() int {
90+
return self.state.SnapshotDatabase()
9791
}
9892

99-
func (self *VMEnv) SetSnapshot(copy vm.Database) {
100-
self.state.state.Set(copy.(*VMState).state)
93+
func (self *VMEnv) RevertToSnapshot(idx int) {
94+
self.state.RevertToSnapshot(idx)
10195
}
10296

10397
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) {
@@ -111,16 +105,12 @@ func (self *VMEnv) CallCode(me vm.ContractRef, addr common.Address, data []byte,
111105
return core.CallCode(self, me, addr, data, gas, price, value)
112106
}
113107

114-
func (self *VMEnv) Create(me vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) {
115-
return core.Create(self, me, data, gas, price, value)
108+
func (self *VMEnv) DelegateCall(me vm.ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error) {
109+
return core.DelegateCall(self, me, addr, data, gas, price)
116110
}
117111

118-
func (self *VMEnv) StructLogs() []vm.StructLog {
119-
return self.logs
120-
}
121-
122-
func (self *VMEnv) AddStructLog(log vm.StructLog) {
123-
self.logs = append(self.logs, log)
112+
func (self *VMEnv) Create(me vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) {
113+
return core.Create(self, me, data, gas, price, value)
124114
}
125115

126116
// Error returns the error (if any) that happened during execution.
@@ -132,9 +122,10 @@ func (self *VMEnv) Error() error {
132122
// passes it to any state operation that requires it.
133123
type VMState struct {
134124
vm.Database
135-
ctx context.Context
136-
state *LightState
137-
env *VMEnv
125+
ctx context.Context
126+
state *LightState
127+
snapshots []*LightState
128+
env *VMEnv
138129
}
139130

140131
// errHandler handles and stores any state error that happens during execution.
@@ -144,6 +135,16 @@ func (s *VMState) errHandler(err error) {
144135
}
145136
}
146137

138+
func (self *VMState) SnapshotDatabase() int {
139+
self.snapshots = append(self.snapshots, self.state.Copy())
140+
return len(self.snapshots) - 1
141+
}
142+
143+
func (self *VMState) RevertToSnapshot(idx int) {
144+
self.state.Set(self.snapshots[idx])
145+
self.snapshots = self.snapshots[:idx]
146+
}
147+
147148
// GetAccount returns the account object of the given account or nil if the
148149
// account does not exist
149150
func (s *VMState) GetAccount(addr common.Address) vm.Account {
@@ -203,6 +204,18 @@ func (s *VMState) GetCode(addr common.Address) []byte {
203204
return res
204205
}
205206

207+
func (s *VMState) GetCodeHash(addr common.Address) common.Hash {
208+
res, err := s.state.GetCode(s.ctx, addr)
209+
s.errHandler(err)
210+
return crypto.Keccak256Hash(res)
211+
}
212+
213+
func (s *VMState) GetCodeSize(addr common.Address) int {
214+
res, err := s.state.GetCode(s.ctx, addr)
215+
s.errHandler(err)
216+
return len(res)
217+
}
218+
206219
// SetCode sets the contract code at the specified account
207220
func (s *VMState) SetCode(addr common.Address, code []byte) {
208221
err := s.state.SetCode(s.ctx, addr, code)
@@ -234,7 +247,7 @@ func (s *VMState) SetState(addr common.Address, key common.Hash, value common.Ha
234247
}
235248

236249
// Delete marks an account to be removed and clears its balance
237-
func (s *VMState) Delete(addr common.Address) bool {
250+
func (s *VMState) Suicide(addr common.Address) bool {
238251
res, err := s.state.Delete(s.ctx, addr)
239252
s.errHandler(err)
240253
return res
@@ -249,7 +262,7 @@ func (s *VMState) Exist(addr common.Address) bool {
249262

250263
// IsDeleted returns true if the given account has been marked for deletion
251264
// or false if the account does not exist
252-
func (s *VMState) IsDeleted(addr common.Address) bool {
265+
func (s *VMState) HasSuicided(addr common.Address) bool {
253266
res, err := s.state.IsDeleted(s.ctx, addr)
254267
s.errHandler(err)
255268
return res

0 commit comments

Comments
 (0)