@@ -738,8 +738,8 @@ func (s *Syncer) loadSyncStatus() {
738
738
s .accountBytes += common .StorageSize (len (key ) + len (value ))
739
739
},
740
740
}
741
- task .genTrie = trie .NewStackTrie (func (owner common. Hash , path []byte , hash common.Hash , val []byte ) {
742
- rawdb .WriteTrieNode (task .genBatch , owner , path , hash , val , s .scheme )
741
+ task .genTrie = trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
742
+ rawdb .WriteTrieNode (task .genBatch , common. Hash {} , path , hash , val , s .scheme )
743
743
})
744
744
for accountHash , subtasks := range task .SubTasks {
745
745
for _ , subtask := range subtasks {
@@ -751,9 +751,10 @@ func (s *Syncer) loadSyncStatus() {
751
751
s .storageBytes += common .StorageSize (len (key ) + len (value ))
752
752
},
753
753
}
754
- subtask .genTrie = trie .NewStackTrieWithOwner (func (owner common.Hash , path []byte , hash common.Hash , val []byte ) {
754
+ owner := accountHash // local assignment for stacktrie writer closure
755
+ subtask .genTrie = trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
755
756
rawdb .WriteTrieNode (subtask .genBatch , owner , path , hash , val , s .scheme )
756
- }, accountHash )
757
+ })
757
758
}
758
759
}
759
760
}
@@ -810,8 +811,8 @@ func (s *Syncer) loadSyncStatus() {
810
811
Last : last ,
811
812
SubTasks : make (map [common.Hash ][]* storageTask ),
812
813
genBatch : batch ,
813
- genTrie : trie .NewStackTrie (func (owner common. Hash , path []byte , hash common.Hash , val []byte ) {
814
- rawdb .WriteTrieNode (batch , owner , path , hash , val , s .scheme )
814
+ genTrie : trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
815
+ rawdb .WriteTrieNode (batch , common. Hash {} , path , hash , val , s .scheme )
815
816
}),
816
817
})
817
818
log .Debug ("Created account sync task" , "from" , next , "last" , last )
@@ -2004,14 +2005,15 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
2004
2005
s .storageBytes += common .StorageSize (len (key ) + len (value ))
2005
2006
},
2006
2007
}
2008
+ owner := account // local assignment for stacktrie writer closure
2007
2009
tasks = append (tasks , & storageTask {
2008
2010
Next : common.Hash {},
2009
2011
Last : r .End (),
2010
2012
root : acc .Root ,
2011
2013
genBatch : batch ,
2012
- genTrie : trie .NewStackTrieWithOwner (func (owner common. Hash , path []byte , hash common.Hash , val []byte ) {
2014
+ genTrie : trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
2013
2015
rawdb .WriteTrieNode (batch , owner , path , hash , val , s .scheme )
2014
- }, account ),
2016
+ }),
2015
2017
})
2016
2018
for r .Next () {
2017
2019
batch := ethdb.HookedBatch {
@@ -2025,9 +2027,9 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
2025
2027
Last : r .End (),
2026
2028
root : acc .Root ,
2027
2029
genBatch : batch ,
2028
- genTrie : trie .NewStackTrieWithOwner (func (owner common. Hash , path []byte , hash common.Hash , val []byte ) {
2030
+ genTrie : trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
2029
2031
rawdb .WriteTrieNode (batch , owner , path , hash , val , s .scheme )
2030
- }, account ),
2032
+ }),
2031
2033
})
2032
2034
}
2033
2035
for _ , task := range tasks {
@@ -2072,9 +2074,10 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
2072
2074
slots += len (res .hashes [i ])
2073
2075
2074
2076
if i < len (res .hashes )- 1 || res .subTask == nil {
2075
- tr := trie .NewStackTrieWithOwner (func (owner common.Hash , path []byte , hash common.Hash , val []byte ) {
2076
- rawdb .WriteTrieNode (batch , owner , path , hash , val , s .scheme )
2077
- }, account )
2077
+ // no need to make local reassignment of account: this closure does not outlive the loop
2078
+ tr := trie .NewStackTrie (func (path []byte , hash common.Hash , val []byte ) {
2079
+ rawdb .WriteTrieNode (batch , account , path , hash , val , s .scheme )
2080
+ })
2078
2081
for j := 0 ; j < len (res .hashes [i ]); j ++ {
2079
2082
tr .Update (res.hashes [i ][j ][:], res.slots [i ][j ])
2080
2083
}
0 commit comments