@@ -112,6 +112,9 @@ func (d iterativeDump) OnRoot(root common.Hash) {
112112
113113// DumpToCollector iterates the state according to the given options and inserts
114114// the items into a collector for aggregation or serialization.
115+ //
116+ // The state iterator is still trie-based and can be converted to snapshot-based
117+ // once the state snapshot is fully integrated into database. TODO(rjl493456442).
115118func (s * StateDB ) DumpToCollector (c DumpCollector , conf * DumpConfig ) (nextKey []byte ) {
116119 // Sanitize the input to allow nil configs
117120 if conf == nil {
@@ -123,15 +126,20 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
123126 start = time .Now ()
124127 logged = time .Now ()
125128 )
126- log .Info ("Trie dumping started" , "root" , s .trie . Hash () )
127- c .OnRoot (s .trie . Hash () )
129+ log .Info ("Trie dumping started" , "root" , s .originalRoot )
130+ c .OnRoot (s .originalRoot )
128131
129- trieIt , err := s .trie .NodeIterator (conf .Start )
132+ tr , err := s .db .OpenTrie (s .originalRoot )
133+ if err != nil {
134+ return nil
135+ }
136+ trieIt , err := tr .NodeIterator (conf .Start )
130137 if err != nil {
131138 log .Error ("Trie dumping error" , "err" , err )
132139 return nil
133140 }
134141 it := trie .NewIterator (trieIt )
142+
135143 for it .Next () {
136144 var data types.StateAccount
137145 if err := rlp .DecodeBytes (it .Value , & data ); err != nil {
@@ -147,7 +155,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
147155 }
148156 address * common.Address
149157 addr common.Address
150- addrBytes = s . trie .GetKey (it .Key )
158+ addrBytes = tr .GetKey (it .Key )
151159 )
152160 if addrBytes == nil {
153161 missingPreimages ++
@@ -165,12 +173,13 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
165173 }
166174 if ! conf .SkipStorage {
167175 account .Storage = make (map [common.Hash ]string )
168- tr , err := obj .getTrie ()
176+
177+ storageTr , err := s .db .OpenStorageTrie (s .originalRoot , addr , obj .Root (), tr )
169178 if err != nil {
170179 log .Error ("Failed to load storage trie" , "err" , err )
171180 continue
172181 }
173- trieIt , err := tr .NodeIterator (nil )
182+ trieIt , err := storageTr .NodeIterator (nil )
174183 if err != nil {
175184 log .Error ("Failed to create trie iterator" , "err" , err )
176185 continue
@@ -182,7 +191,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
182191 log .Error ("Failed to decode the value returned by iterator" , "error" , err )
183192 continue
184193 }
185- key := s . trie .GetKey (storageIt .Key )
194+ key := storageTr .GetKey (storageIt .Key )
186195 if key == nil {
187196 continue
188197 }
0 commit comments