From c9f5e4db76fa7a99c3102e107eff3be5b5066477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 23 Sep 2016 08:16:52 +0300 Subject: [PATCH] core, internal: fix up the state caching --- core/chain_makers_test.go | 2 +- core/state/state_object.go | 4 +--- core/state/statedb.go | 4 +++- internal/ethapi/api.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index f52b09ad90..5fc255c716 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -79,7 +79,7 @@ func ExampleGenerateChain() { evmux := &event.TypeMux{} blockchain, _ := NewBlockChain(db, MakeChainConfig(), FakePow{}, evmux) if i, err := blockchain.InsertChain(chain); err != nil { - fmt.Printf("insert error (block %d): %v\n", i, err) + fmt.Printf("insert error (block %d): %v\n", chain[i].NumberU64(), err) return } diff --git a/core/state/state_object.go b/core/state/state_object.go index c4b5b16928..5f30177cde 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -193,8 +193,6 @@ func (self *StateObject) CommitTrie(db trie.Database, dbw trie.DatabaseWriter) e fmt.Println("dbErr:", self.dbErr) return self.dbErr } - self.dbErr = nil - root, err := self.trie.CommitTo(dbw) if err == nil { self.data.Root = root @@ -253,7 +251,7 @@ func (c *StateObject) Address() common.Address { return c.address } -// LoadCode returns the contract code associated with this object, if any. +// Code returns the contract code associated with this object, if any. func (self *StateObject) Code(db trie.Database) []byte { if self.code != nil { return self.code diff --git a/core/state/statedb.go b/core/state/statedb.go index 9b3cf0eb00..270cd44bd4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -265,7 +265,9 @@ func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObje // Use cached account data from the canon state if possible. if data, ok := self.all[addr]; ok { - return NewObject(addr, data) + obj := NewObject(addr, data) + self.SetStateObject(obj) + return obj } // Load the object from the database. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0b1384f585..6480085ddc 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1280,8 +1280,8 @@ func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) { } // SetHead rewinds the head of the blockchain to a previous block. -func (api *PrivateDebugAPI) SetHead(number uint64) { - api.b.SetHead(number) +func (api *PrivateDebugAPI) SetHead(number rpc.HexNumber) { + api.b.SetHead(uint64(number.Int64())) } // PublicNetAPI offers network related RPC methods