Skip to content

Commit 619b37c

Browse files
committed
core, tests: get_hash fix
Make sure that we're fetching the hash from the current chain and not the canonical chain. Conflicts: core/vm/environment.go
1 parent 465e810 commit 619b37c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

core/vm/environment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type Environment interface {
3131

3232
Origin() common.Address
3333
BlockNumber() *big.Int
34-
GetHash(n uint64) common.Hash
34+
// The n'th hash ago from this block number
35+
GetHash(uint64) common.Hash
36+
// The handler's address
3537
Coinbase() common.Address
3638
Time() *big.Int
3739
Difficulty() *big.Int

core/vm_env.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ func (self *VMEnv) SetDepth(i int) { self.depth = i }
5959
func (self *VMEnv) VmType() vm.Type { return self.typ }
6060
func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t }
6161
func (self *VMEnv) GetHash(n uint64) common.Hash {
62-
if block := self.chain.GetBlockByNumber(n); block != nil {
63-
return block.Hash()
62+
for block := self.chain.GetBlock(self.header.ParentHash); block != nil; block = self.chain.GetBlock(block.ParentHash()) {
63+
if block.NumberU64() == n {
64+
return block.Hash()
65+
}
6466
}
6567

6668
return common.Hash{}

tests/util.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ type Env struct {
131131
initial bool
132132
Gas *big.Int
133133

134-
origin common.Address
135-
//parent common.Hash
134+
origin common.Address
135+
parent common.Hash
136136
coinbase common.Address
137137

138138
number *big.Int
@@ -163,7 +163,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
163163
env := NewEnv(state)
164164

165165
env.origin = common.HexToAddress(exeValues["caller"])
166-
//env.parent = common.Hex2Bytes(envValues["previousHash"])
166+
env.parent = common.HexToHash(envValues["previousHash"])
167167
env.coinbase = common.HexToAddress(envValues["currentCoinbase"])
168168
env.number = common.Big(envValues["currentNumber"])
169169
env.time = common.Big(envValues["currentTimestamp"])
@@ -174,10 +174,8 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
174174
return env
175175
}
176176

177-
func (self *Env) Origin() common.Address { return self.origin }
178-
func (self *Env) BlockNumber() *big.Int { return self.number }
179-
180-
//func (self *Env) PrevHash() []byte { return self.parent }
177+
func (self *Env) Origin() common.Address { return self.origin }
178+
func (self *Env) BlockNumber() *big.Int { return self.number }
181179
func (self *Env) Coinbase() common.Address { return self.coinbase }
182180
func (self *Env) Time() *big.Int { return self.time }
183181
func (self *Env) Difficulty() *big.Int { return self.difficulty }

0 commit comments

Comments
 (0)