diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 9f9665e618..176c742b9a 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1324,7 +1324,7 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade err = p.slash(spoiledVal, state, header, cx, txs, receipts, systemTxs, usedGas, false) if err != nil { // it is possible that slash validator failed because of the slash channel is disabled. - log.Error("slash validator failed", "block hash", header.Hash(), "address", spoiledVal) + log.Error("slash validator failed", "block hash", header.Hash(), "address", spoiledVal, "err", err) } } } diff --git a/core/state/database.go b/core/state/database.go index 0c637ebb8b..f5f960496f 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -198,13 +198,15 @@ func (db *CachingDB) Reader(stateRoot common.Hash) (Reader, error) { readers = append(readers, sr) // snap reader is optional } } - // Set up the trie reader, which is expected to always be available - // as the gatekeeper unless the state is corrupted. - tr, err := newTrieReader(stateRoot, db.triedb, db.pointCache) - if err != nil { - return nil, err + if !db.NoTries() { + // Set up the trie reader, which is expected to always be available + // as the gatekeeper unless the state is corrupted. + tr, err := newTrieReader(stateRoot, db.triedb, db.pointCache) + if err != nil { + return nil, err + } + readers = append(readers, tr) } - readers = append(readers, tr) return newMultiReader(readers...) } diff --git a/core/state/state_object.go b/core/state/state_object.go index ce8397152f..39898d5f99 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -482,8 +482,12 @@ func (s *stateObject) commit() (*accountUpdate, *trienode.NodeSet, error) { s.origin = s.data.Copy() return op, nil, nil } - root, nodes := s.trie.Commit(false) - s.data.Root = root + var nodes *trienode.NodeSet + if !s.db.db.NoTries() { + var root common.Hash + root, nodes = s.trie.Commit(false) + s.data.Root = root + } s.origin = s.data.Copy() return op, nodes, nil } diff --git a/core/state/statedb.go b/core/state/statedb.go index ebe16900c4..463d750c33 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1025,31 +1025,30 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { usedAddrs [][]byte deletedAddrs []common.Address ) - if !s.noTrie { - for addr, op := range s.mutations { - if op.applied { - continue - } - op.applied = true - - if op.isDelete() { - deletedAddrs = append(deletedAddrs, addr) - } else { - s.updateStateObject(s.stateObjects[addr]) - s.AccountUpdated += 1 - } - usedAddrs = append(usedAddrs, common.CopyBytes(addr[:])) // Copy needed for closure - } - for _, deletedAddr := range deletedAddrs { - s.deleteStateObject(deletedAddr) - s.AccountDeleted += 1 + for addr, op := range s.mutations { + if op.applied { + continue } - s.AccountUpdates += time.Since(start) + op.applied = true - if s.prefetcher != nil { - s.prefetcher.used(common.Hash{}, s.originalRoot, usedAddrs) + if op.isDelete() { + deletedAddrs = append(deletedAddrs, addr) + } else { + s.updateStateObject(s.stateObjects[addr]) + s.AccountUpdated += 1 } + usedAddrs = append(usedAddrs, common.CopyBytes(addr[:])) // Copy needed for closure + } + for _, deletedAddr := range deletedAddrs { + s.deleteStateObject(deletedAddr) + s.AccountDeleted += 1 + } + s.AccountUpdates += time.Since(start) + + if s.prefetcher != nil && len(usedAddrs) > 0 { + s.prefetcher.used(common.Hash{}, s.originalRoot, usedAddrs) } + // Track the amount of time wasted on hashing the account trie defer func(start time.Time) { s.AccountHashes += time.Since(start) }(time.Now()) @@ -1335,7 +1334,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { // code didn't anticipate for. workers.Go(func() error { if s.noTrie { - root = types.EmptyRootHash + root = s.expectedRoot return nil } // Write the account trie changes, measuring the amount of wasted time @@ -1360,9 +1359,6 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { // 2 threads in total. But that kind of depends on the account commit being // more expensive than it should be, so let's fix that and revisit this todo. for addr, op := range s.mutations { - if s.noTrie { - continue - } if op.isDelete() { continue } diff --git a/core/state/trie_prefetcher.go b/core/state/trie_prefetcher.go index 6b9e0515bc..0d63cb0bc1 100644 --- a/core/state/trie_prefetcher.go +++ b/core/state/trie_prefetcher.go @@ -520,6 +520,7 @@ func (sf *subfetcher) loop() { for { select { case <-sf.wake: + //TODO(zzzckck): why OpenTrie twice? // Subfetcher was woken up, retrieve any tasks to avoid spinning the lock if sf.trie == nil { if sf.owner == (common.Hash{}) {