From a976721a97c9ddbbeb688080fab3ba8a7631237c Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 30 Mar 2015 03:21:25 -0700 Subject: [PATCH] state: fix GetStorage on blockcache with unknown account --- state/block_cache.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/state/block_cache.go b/state/block_cache.go index 9af3b4ed..c900accc 100644 --- a/state/block_cache.go +++ b/state/block_cache.go @@ -95,9 +95,11 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) { if removed { panic("GetStorage() on removed account") } - if storage == nil { + if acc != nil && storage == nil { storage = makeStorage(cache.db, acc.StorageRoot) cache.accounts[string(addr.Prefix(20))] = accountInfo{acc, storage, false, dirty} + } else if acc == nil { + return Zero256 } // Load and set cache @@ -145,6 +147,9 @@ func (cache *BlockCache) Sync() { addr, key := Tuple256Split(storageKey) if addr != curAddr || curAcc == nil { acc, storage, removed, _ := cache.accounts[string(addr.Prefix(20))].unpack() + if storage == nil { + storage = makeStorage(cache.db, acc.StorageRoot) + } curAddr = addr curAcc = acc curAccRemoved = removed @@ -161,6 +166,7 @@ func (cache *BlockCache) Sync() { curStorage.Remove(key.Bytes()) } else { curStorage.Set(key.Bytes(), value.Bytes()) + cache.accounts[string(addr.Prefix(20))] = accountInfo{curAcc, curStorage, false, true} } }