diff options
author | Felix Lange <fjl@twurst.com> | 2016-09-23 03:04:58 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-09-26 16:09:52 +0800 |
commit | a59a93f476434f2805c8fd3e10bf1b2f579b078f (patch) | |
tree | 17d1f3abefabfd7f8cb9149994a4788d2c0f08bc /core/state/managed_state.go | |
parent | e859f3696783ec75d9bb39c0c66eda3a88cea8c6 (diff) | |
download | go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.gz go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.bz2 go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.lz go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.xz go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.tar.zst go-tangerine-a59a93f476434f2805c8fd3e10bf1b2f579b078f.zip |
core/state: track all accounts in canon state
This change introduces a global, per-state cache that keeps account data
in the canon state. Thanks to @karalabe for lots of fixes.
Diffstat (limited to 'core/state/managed_state.go')
-rw-r--r-- | core/state/managed_state.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/core/state/managed_state.go b/core/state/managed_state.go index f8e2f2b87..ad73dc0dc 100644 --- a/core/state/managed_state.go +++ b/core/state/managed_state.go @@ -33,14 +33,14 @@ type ManagedState struct { mu sync.RWMutex - accounts map[string]*account + accounts map[common.Address]*account } // ManagedState returns a new managed state with the statedb as it's backing layer func ManageState(statedb *StateDB) *ManagedState { return &ManagedState{ StateDB: statedb.Copy(), - accounts: make(map[string]*account), + accounts: make(map[common.Address]*account), } } @@ -103,7 +103,7 @@ func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) { so := ms.GetOrNewStateObject(addr) so.SetNonce(nonce) - ms.accounts[addr.Str()] = newAccount(so) + ms.accounts[addr] = newAccount(so) } // HasAccount returns whether the given address is managed or not @@ -114,29 +114,28 @@ func (ms *ManagedState) HasAccount(addr common.Address) bool { } func (ms *ManagedState) hasAccount(addr common.Address) bool { - _, ok := ms.accounts[addr.Str()] + _, ok := ms.accounts[addr] return ok } // populate the managed state func (ms *ManagedState) getAccount(addr common.Address) *account { - straddr := addr.Str() - if account, ok := ms.accounts[straddr]; !ok { + if account, ok := ms.accounts[addr]; !ok { so := ms.GetOrNewStateObject(addr) - ms.accounts[straddr] = newAccount(so) + ms.accounts[addr] = newAccount(so) } else { // Always make sure the state account nonce isn't actually higher // than the tracked one. so := ms.StateDB.GetStateObject(addr) - if so != nil && uint64(len(account.nonces))+account.nstart < so.nonce { - ms.accounts[straddr] = newAccount(so) + if so != nil && uint64(len(account.nonces))+account.nstart < so.Nonce() { + ms.accounts[addr] = newAccount(so) } } - return ms.accounts[straddr] + return ms.accounts[addr] } func newAccount(so *StateObject) *account { - return &account{so, so.nonce, nil} + return &account{so, so.Nonce(), nil} } |