aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/statedb.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-07-06 07:19:48 +0800
committerFelix Lange <fjl@twurst.com>2015-09-23 04:53:49 +0800
commit565d9f2306d19f63be6a6e1b8fc480af8dca9617 (patch)
tree5474c7c534aaeff2b82c84346e53d899f7551555 /core/state/statedb.go
parent6b91a4abe529ea4f01771209e080b118ab847fe9 (diff)
downloaddexon-565d9f2306d19f63be6a6e1b8fc480af8dca9617.tar.gz
dexon-565d9f2306d19f63be6a6e1b8fc480af8dca9617.tar.zst
dexon-565d9f2306d19f63be6a6e1b8fc480af8dca9617.zip
core, trie: new trie
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r--core/state/statedb.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 24f97e32a..c2bc99564 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -49,12 +49,20 @@ type StateDB struct {
// Create a new state from a given trie
func New(root common.Hash, db ethdb.Database) *StateDB {
- trie := trie.NewSecure(root[:], db)
- return &StateDB{root: root, db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: new(big.Int), logs: make(map[common.Hash]Logs)}
-}
-
-func (self *StateDB) PrintRoot() {
- self.trie.Trie.PrintRoot()
+ tr, err := trie.NewSecure(root, db)
+ if err != nil {
+ // TODO: bubble this up
+ tr, _ = trie.NewSecure(common.Hash{}, db)
+ glog.Errorf("can't create state trie with root %x: %v", root[:], err)
+ }
+ return &StateDB{
+ root: root,
+ db: db,
+ trie: tr,
+ stateObjects: make(map[string]*StateObject),
+ refund: new(big.Int),
+ logs: make(map[common.Hash]Logs),
+ }
}
func (self *StateDB) StartRecord(thash, bhash common.Hash, ti int) {
@@ -304,7 +312,7 @@ func (self *StateDB) Set(state *StateDB) {
}
func (s *StateDB) Root() common.Hash {
- return common.BytesToHash(s.trie.Root())
+ return s.trie.Hash()
}
// Syncs the trie and all siblings
@@ -348,7 +356,7 @@ func (self *StateDB) SyncIntermediate() {
// SyncObjects syncs the changed objects to the trie
func (self *StateDB) SyncObjects() {
- self.trie = trie.NewSecure(self.root[:], self.db)
+ self.trie, _ = trie.NewSecure(self.root, self.db)
self.refund = new(big.Int)