aboutsummaryrefslogtreecommitdiffstats
path: root/core/evm.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-03-26 17:28:46 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-03-26 17:28:46 +0800
commit1fae50a199903d28dac76e78ef065ba0ad96cf17 (patch)
tree06836e94cc3ef0153de197cfcbc6832c5f466628 /core/evm.go
parent933972d139b0fe291cb01c7ad2c0f9d3109a68dd (diff)
downloadgo-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.gz
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.bz2
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.lz
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.xz
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.zst
go-tangerine-1fae50a199903d28dac76e78ef065ba0ad96cf17.zip
core: minor evm polishes and optimizations
Diffstat (limited to 'core/evm.go')
-rw-r--r--core/evm.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/core/evm.go b/core/evm.go
index 55db53927..596ea95fb 100644
--- a/core/evm.go
+++ b/core/evm.go
@@ -60,13 +60,26 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author
// GetHashFn returns a GetHashFunc which retrieves header hashes by number
func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash {
+ var cache map[uint64]common.Hash
+
return func(n uint64) common.Hash {
+ // If there's no hash cache yet, make one
+ if cache == nil {
+ cache = map[uint64]common.Hash{
+ ref.Number.Uint64() - 1: ref.ParentHash,
+ }
+ }
+ // Try to fulfill the request from the cache
+ if hash, ok := cache[n]; ok {
+ return hash
+ }
+ // Not cached, iterate the blocks and cache the hashes
for header := chain.GetHeader(ref.ParentHash, ref.Number.Uint64()-1); header != nil; header = chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) {
- if header.Number.Uint64() == n {
- return header.Hash()
+ cache[header.Number.Uint64()-1] = header.ParentHash
+ if n == header.Number.Uint64()-1 {
+ return header.ParentHash
}
}
-
return common.Hash{}
}
}