diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-03-26 17:28:46 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-03-26 17:28:46 +0800 |
commit | 1fae50a199903d28dac76e78ef065ba0ad96cf17 (patch) | |
tree | 06836e94cc3ef0153de197cfcbc6832c5f466628 /core/evm.go | |
parent | 933972d139b0fe291cb01c7ad2c0f9d3109a68dd (diff) | |
download | go-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.go | 19 |
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{} } } |