mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 23:13:45 +00:00
feat: make BLOCKHASH return only last blockhash (#196)
* make BLOCKHASH return only last blockhash * fix * small fix
This commit is contained in:
parent
98eb664f23
commit
7c3657b61b
2 changed files with 5 additions and 5 deletions
|
|
@ -440,10 +440,10 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
|
||||||
}
|
}
|
||||||
var upper, lower uint64
|
var upper, lower uint64
|
||||||
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
||||||
if upper < 257 {
|
if upper < 2 {
|
||||||
lower = 0
|
lower = 0
|
||||||
} else {
|
} else {
|
||||||
lower = upper - 256
|
lower = upper - 1
|
||||||
}
|
}
|
||||||
if num64 >= lower && num64 < upper {
|
if num64 >= lower && num64 < upper {
|
||||||
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
|
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
|
||||||
|
|
|
||||||
|
|
@ -337,10 +337,10 @@ func TestBlockhash(t *testing.T) {
|
||||||
if first.Uint64() != 999 {
|
if first.Uint64() != 999 {
|
||||||
t.Fatalf("second block should be 999, got %d (%x)", first, ret[32:64])
|
t.Fatalf("second block should be 999, got %d (%x)", first, ret[32:64])
|
||||||
}
|
}
|
||||||
if last.Uint64() != 744 {
|
if last.Uint64() != 0 {
|
||||||
t.Fatalf("last block should be 744, got %d (%x)", last, ret[64:96])
|
t.Fatalf("last block should be 0, got %d (%x)", last, ret[64:96])
|
||||||
}
|
}
|
||||||
if exp, got := 255, chain.counter; exp != got {
|
if exp, got := 0, chain.counter; exp != got {
|
||||||
t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got)
|
t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue