Skip to content

Commit 752c75f

Browse files
committed
core/vm: resolve circular dependency to debug vm storage
1 parent 1b8566a commit 752c75f

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

‎core/vm/contract.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ContractRef interface {
2727
ReturnGas(*big.Int, *big.Int)
2828
Address() common.Address
2929
SetCode([]byte)
30+
EachStorage(cb func(key, value []byte))
3031
}
3132

3233
// Contract represents an ethereum contract in the state database. It contains
@@ -124,3 +125,9 @@ func (self *Contract) SetCallCode(addr *common.Address, code []byte) {
124125
self.Code = code
125126
self.CodeAddr = addr
126127
}
128+
129+
// EachStorage iterates the contract's storage and calls a method for every key
130+
// value pair.
131+
func (self *Contract) EachStorage(cb func(key, value []byte)) {
132+
self.caller.EachStorage(cb)
133+
}

‎core/vm/environment.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ type Account interface {
121121
Address() common.Address
122122
ReturnGas(*big.Int, *big.Int)
123123
SetCode([]byte)
124+
EachStorage(cb func(key, value []byte))
124125
}

‎core/vm/jit_test.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ type vmBench struct {
125125

126126
type account struct{}
127127

128-
func (account) SubBalance(amount *big.Int) {}
129-
func (account) AddBalance(amount *big.Int) {}
130-
func (account) SetBalance(*big.Int) {}
131-
func (account) SetNonce(uint64) {}
132-
func (account) Balance() *big.Int { return nil }
133-
func (account) Address() common.Address { return common.Address{} }
134-
func (account) ReturnGas(*big.Int, *big.Int) {}
135-
func (account) SetCode([]byte) {}
128+
func (account) SubBalance(amount *big.Int) {}
129+
func (account) AddBalance(amount *big.Int) {}
130+
func (account) SetBalance(*big.Int) {}
131+
func (account) SetNonce(uint64) {}
132+
func (account) Balance() *big.Int { return nil }
133+
func (account) Address() common.Address { return common.Address{} }
134+
func (account) ReturnGas(*big.Int, *big.Int) {}
135+
func (account) SetCode([]byte) {}
136+
func (account) EachStorage(cb func(key, value []byte)) {}
136137

137138
func runVmBench(test vmBench, b *testing.B) {
138139
var sender account

‎core/vm/vm.go‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,9 @@ func (self *Vm) log(pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, st
376376
stck[i] = new(big.Int).Set(item)
377377
}
378378
storage := make(map[common.Hash][]byte)
379-
/*
380-
object := contract.self.(*state.StateObject)
381-
object.EachStorage(func(k, v []byte) {
382-
storage[common.BytesToHash(k)] = v
383-
})
384-
*/
379+
contract.self.EachStorage(func(k, v []byte) {
380+
storage[common.BytesToHash(k)] = v
381+
})
385382
self.env.AddStructLog(StructLog{pc, op, new(big.Int).Set(gas), cost, mem, stck, storage, err})
386383
}
387384
}

0 commit comments

Comments
 (0)