Tests that the trie scheduler can correctly reconstruct the state even if only partial results are returned (Even those randomly), others sent only later.
(t *testing.T)
| 244 | // Tests that the trie scheduler can correctly reconstruct the state even if only |
| 245 | // partial results are returned (Even those randomly), others sent only later. |
| 246 | func TestIterativeRandomDelayedStateSync(t *testing.T) { |
| 247 | // Create a random state to copy |
| 248 | srcDb, srcRoot, srcAccounts := makeTestState() |
| 249 | |
| 250 | // Create a destination state and sync with the scheduler |
| 251 | dstDb := database.NewMemDatabase() |
| 252 | sched := NewStateSync(srcRoot, dstDb) |
| 253 | |
| 254 | queue := make(map[common.Hash]struct{}) |
| 255 | for _, hash := range sched.Missing(0) { |
| 256 | queue[hash] = struct{}{} |
| 257 | } |
| 258 | for len(queue) > 0 { |
| 259 | // Sync only half of the scheduled nodes, even those in random order |
| 260 | results := make([]trie.SyncResult, 0, len(queue)/2+1) |
| 261 | for hash := range queue { |
| 262 | delete(queue, hash) |
| 263 | |
| 264 | data, err := srcDb.TrieDB().Node(hash) |
| 265 | if err != nil { |
| 266 | t.Fatalf("failed to retrieve node data for %x", hash) |
| 267 | } |
| 268 | results = append(results, trie.SyncResult{Hash: hash, Data: data}) |
| 269 | |
| 270 | if len(results) >= cap(results) { |
| 271 | break |
| 272 | } |
| 273 | } |
| 274 | // Feed the retrieved results back and queue new tasks |
| 275 | if _, index, err := sched.Process(results); err != nil { |
| 276 | t.Fatalf("failed to process result #%d: %v", index, err) |
| 277 | } |
| 278 | if index, err := sched.Commit(dstDb); err != nil { |
| 279 | t.Fatalf("failed to commit data #%d: %v", index, err) |
| 280 | } |
| 281 | for _, hash := range sched.Missing(0) { |
| 282 | queue[hash] = struct{}{} |
| 283 | } |
| 284 | } |
| 285 | // Cross check that the two states are in sync |
| 286 | checkStateAccounts(t, dstDb, srcRoot, srcAccounts) |
| 287 | } |
| 288 | |
| 289 | // Tests that at any point in time during a sync, only complete sub-tries are in |
| 290 | // the database. |
nothing calls this directly
no test coverage detected