Tests that the trie scheduler can correctly reconstruct the state even if only partial results are returned, and the others sent only later.
(t *testing.T)
| 167 | // Tests that the trie scheduler can correctly reconstruct the state even if only |
| 168 | // partial results are returned, and the others sent only later. |
| 169 | func TestIterativeDelayedStateSync(t *testing.T) { |
| 170 | // Create a random state to copy |
| 171 | srcDb, srcRoot, srcAccounts := makeTestState() |
| 172 | |
| 173 | // Create a destination state and sync with the scheduler |
| 174 | dstDb := database.NewMemDatabase() |
| 175 | sched := NewStateSync(srcRoot, dstDb) |
| 176 | |
| 177 | queue := append([]common.Hash{}, sched.Missing(0)...) |
| 178 | for len(queue) > 0 { |
| 179 | // Sync only half of the scheduled nodes |
| 180 | results := make([]trie.SyncResult, len(queue)/2+1) |
| 181 | for i, hash := range queue[:len(results)] { |
| 182 | data, err := srcDb.TrieDB().Node(hash) |
| 183 | if err != nil { |
| 184 | t.Fatalf("failed to retrieve node data for %x", hash) |
| 185 | } |
| 186 | results[i] = trie.SyncResult{Hash: hash, Data: data} |
| 187 | } |
| 188 | if _, index, err := sched.Process(results); err != nil { |
| 189 | t.Fatalf("failed to process result #%d: %v", index, err) |
| 190 | } |
| 191 | if index, err := sched.Commit(dstDb); err != nil { |
| 192 | t.Fatalf("failed to commit data #%d: %v", index, err) |
| 193 | } |
| 194 | queue = append(queue[len(results):], sched.Missing(0)...) |
| 195 | } |
| 196 | // Cross check that the two states are in sync |
| 197 | checkStateAccounts(t, dstDb, srcRoot, srcAccounts) |
| 198 | } |
| 199 | |
| 200 | // Tests that given a root hash, a trie can sync iteratively on a single thread, |
| 201 | // requesting retrieval tasks and returning all of them in one go, however in a |
nothing calls this directly
no test coverage detected