panic wrapper functions

This commit is contained in:
Ethan Buchman
2015-07-21 10:46:05 -04:00
parent 5983088a32
commit 8e50bf15de
45 changed files with 229 additions and 275 deletions
+7 -19
View File
@@ -64,21 +64,17 @@ func (cache *BlockCache) GetAccount(addr []byte) *acm.Account {
func (cache *BlockCache) UpdateAccount(acc *acm.Account) {
addr := acc.Address
_, storage, removed, _ := cache.accounts[string(addr)].unpack()
// SANITY CHECK
if removed {
panic("UpdateAccount on a removed account")
PanicSanity("UpdateAccount on a removed account")
}
// SANITY CHECK END
cache.accounts[string(addr)] = accountInfo{acc, storage, false, true}
}
func (cache *BlockCache) RemoveAccount(addr []byte) {
// SANITY CHECK
_, _, removed, _ := cache.accounts[string(addr)].unpack()
if removed {
panic("RemoveAccount on a removed account")
PanicSanity("RemoveAccount on a removed account")
}
// SANITY CHECK END
cache.accounts[string(addr)] = accountInfo{nil, nil, true, false}
}
@@ -95,11 +91,9 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) {
// Get or load storage
acc, storage, removed, dirty := cache.accounts[string(addr.Postfix(20))].unpack()
// SANITY CHECK
if removed {
panic("GetStorage() on removed account")
PanicSanity("GetStorage() on removed account")
}
// SANITY CHECK END
if acc != nil && storage == nil {
storage = makeStorage(cache.db, acc.StorageRoot)
cache.accounts[string(addr.Postfix(20))] = accountInfo{acc, storage, false, dirty}
@@ -119,12 +113,10 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) {
// NOTE: Set value to zero to removed from the trie.
func (cache *BlockCache) SetStorage(addr Word256, key Word256, value Word256) {
// SANITY CHECK
_, _, removed, _ := cache.accounts[string(addr.Postfix(20))].unpack()
if removed {
panic("SetStorage() on a removed account")
PanicSanity("SetStorage() on a removed account")
}
// SANITY CHECK END
cache.storages[Tuple256{addr, key}] = storageInfo{value, true}
}
@@ -151,12 +143,10 @@ func (cache *BlockCache) UpdateNameRegEntry(entry *types.NameRegEntry) {
}
func (cache *BlockCache) RemoveNameRegEntry(name string) {
// SANITY CHECK
_, removed, _ := cache.names[name].unpack()
if removed {
panic("RemoveNameRegEntry on a removed entry")
PanicSanity("RemoveNameRegEntry on a removed entry")
}
// SANITY CHECK END
cache.names[name] = nameInfo{nil, true, false}
}
@@ -222,8 +212,7 @@ func (cache *BlockCache) Sync() {
if removed {
removed := cache.backend.RemoveAccount(acc.Address)
if !removed {
// SOMETHING HORRIBLE HAS GONE WRONG
panic(Fmt("Could not remove account to be removed: %X", acc.Address))
PanicCrisis(Fmt("Could not remove account to be removed: %X", acc.Address))
}
} else {
if acc == nil {
@@ -256,8 +245,7 @@ func (cache *BlockCache) Sync() {
if removed {
removed := cache.backend.RemoveNameRegEntry(nameStr)
if !removed {
// SOMETHING HORRIBLE HAS GONE WRONG
panic(Fmt("Could not remove namereg entry to be removed: %s", nameStr))
PanicCrisis(Fmt("Could not remove namereg entry to be removed: %s", nameStr))
}
} else {
if entry == nil {