@@ -105,7 +105,7 @@ func TestEmptySync(t *testing.T) {
105105func TestIterativeSyncIndividual (t * testing.T ) { testIterativeSync (t , 1 ) }
106106func TestIterativeSyncBatched (t * testing.T ) { testIterativeSync (t , 100 ) }
107107
108- func testIterativeSync (t * testing.T , batch int ) {
108+ func testIterativeSync (t * testing.T , count int ) {
109109 // Create a random trie to copy
110110 srcDb , srcTrie , srcData := makeTestTrie ()
111111
@@ -114,7 +114,7 @@ func testIterativeSync(t *testing.T, batch int) {
114114 triedb := NewDatabase (diskdb )
115115 sched := NewSync (srcTrie .Hash (), diskdb , nil , NewSyncBloom (1 , diskdb ))
116116
117- queue := append ([]common.Hash {}, sched .Missing (batch )... )
117+ queue := append ([]common.Hash {}, sched .Missing (count )... )
118118 for len (queue ) > 0 {
119119 results := make ([]SyncResult , len (queue ))
120120 for i , hash := range queue {
@@ -127,10 +127,12 @@ func testIterativeSync(t *testing.T, batch int) {
127127 if _ , index , err := sched .Process (results ); err != nil {
128128 t .Fatalf ("failed to process result #%d: %v" , index , err )
129129 }
130- if index , err := sched .Commit (diskdb ); err != nil {
131- t .Fatalf ("failed to commit data #%d: %v" , index , err )
130+ batch := diskdb .NewBatch ()
131+ if err := sched .Commit (batch ); err != nil {
132+ t .Fatalf ("failed to commit data: %v" , err )
132133 }
133- queue = append (queue [:0 ], sched .Missing (batch )... )
134+ batch .Write ()
135+ queue = append (queue [:0 ], sched .Missing (count )... )
134136 }
135137 // Cross check that the two tries are in sync
136138 checkTrieContents (t , triedb , srcTrie .Hash ().Bytes (), srcData )
@@ -161,9 +163,11 @@ func TestIterativeDelayedSync(t *testing.T) {
161163 if _ , index , err := sched .Process (results ); err != nil {
162164 t .Fatalf ("failed to process result #%d: %v" , index , err )
163165 }
164- if index , err := sched .Commit (diskdb ); err != nil {
165- t .Fatalf ("failed to commit data #%d: %v" , index , err )
166+ batch := diskdb .NewBatch ()
167+ if err := sched .Commit (batch ); err != nil {
168+ t .Fatalf ("failed to commit data: %v" , err )
166169 }
170+ batch .Write ()
167171 queue = append (queue [len (results ):], sched .Missing (10000 )... )
168172 }
169173 // Cross check that the two tries are in sync
@@ -176,7 +180,7 @@ func TestIterativeDelayedSync(t *testing.T) {
176180func TestIterativeRandomSyncIndividual (t * testing.T ) { testIterativeRandomSync (t , 1 ) }
177181func TestIterativeRandomSyncBatched (t * testing.T ) { testIterativeRandomSync (t , 100 ) }
178182
179- func testIterativeRandomSync (t * testing.T , batch int ) {
183+ func testIterativeRandomSync (t * testing.T , count int ) {
180184 // Create a random trie to copy
181185 srcDb , srcTrie , srcData := makeTestTrie ()
182186
@@ -186,7 +190,7 @@ func testIterativeRandomSync(t *testing.T, batch int) {
186190 sched := NewSync (srcTrie .Hash (), diskdb , nil , NewSyncBloom (1 , diskdb ))
187191
188192 queue := make (map [common.Hash ]struct {})
189- for _ , hash := range sched .Missing (batch ) {
193+ for _ , hash := range sched .Missing (count ) {
190194 queue [hash ] = struct {}{}
191195 }
192196 for len (queue ) > 0 {
@@ -203,11 +207,13 @@ func testIterativeRandomSync(t *testing.T, batch int) {
203207 if _ , index , err := sched .Process (results ); err != nil {
204208 t .Fatalf ("failed to process result #%d: %v" , index , err )
205209 }
206- if index , err := sched .Commit (diskdb ); err != nil {
207- t .Fatalf ("failed to commit data #%d: %v" , index , err )
210+ batch := diskdb .NewBatch ()
211+ if err := sched .Commit (batch ); err != nil {
212+ t .Fatalf ("failed to commit data: %v" , err )
208213 }
214+ batch .Write ()
209215 queue = make (map [common.Hash ]struct {})
210- for _ , hash := range sched .Missing (batch ) {
216+ for _ , hash := range sched .Missing (count ) {
211217 queue [hash ] = struct {}{}
212218 }
213219 }
@@ -248,9 +254,11 @@ func TestIterativeRandomDelayedSync(t *testing.T) {
248254 if _ , index , err := sched .Process (results ); err != nil {
249255 t .Fatalf ("failed to process result #%d: %v" , index , err )
250256 }
251- if index , err := sched .Commit (diskdb ); err != nil {
252- t .Fatalf ("failed to commit data #%d: %v" , index , err )
257+ batch := diskdb .NewBatch ()
258+ if err := sched .Commit (batch ); err != nil {
259+ t .Fatalf ("failed to commit data: %v" , err )
253260 }
261+ batch .Write ()
254262 for _ , result := range results {
255263 delete (queue , result .Hash )
256264 }
@@ -293,9 +301,11 @@ func TestDuplicateAvoidanceSync(t *testing.T) {
293301 if _ , index , err := sched .Process (results ); err != nil {
294302 t .Fatalf ("failed to process result #%d: %v" , index , err )
295303 }
296- if index , err := sched .Commit (diskdb ); err != nil {
297- t .Fatalf ("failed to commit data #%d: %v" , index , err )
304+ batch := diskdb .NewBatch ()
305+ if err := sched .Commit (batch ); err != nil {
306+ t .Fatalf ("failed to commit data: %v" , err )
298307 }
308+ batch .Write ()
299309 queue = append (queue [:0 ], sched .Missing (0 )... )
300310 }
301311 // Cross check that the two tries are in sync
@@ -329,9 +339,11 @@ func TestIncompleteSync(t *testing.T) {
329339 if _ , index , err := sched .Process (results ); err != nil {
330340 t .Fatalf ("failed to process result #%d: %v" , index , err )
331341 }
332- if index , err := sched .Commit (diskdb ); err != nil {
333- t .Fatalf ("failed to commit data #%d: %v" , index , err )
342+ batch := diskdb .NewBatch ()
343+ if err := sched .Commit (batch ); err != nil {
344+ t .Fatalf ("failed to commit data: %v" , err )
334345 }
346+ batch .Write ()
335347 for _ , result := range results {
336348 added = append (added , result .Hash )
337349 }
0 commit comments