MCPcopy Create free account
hub / github.com/CPChain/chain / testIterativeStateSync

Function testIterativeStateSync

core/state/sync_test.go:137–165  ·  view source on GitHub ↗
(t *testing.T, batch int)

Source from the content-addressed store, hash-verified

135func TestIterativeStateSyncBatched(t *testing.T) { testIterativeStateSync(t, 100) }
136
137func testIterativeStateSync(t *testing.T, batch int) {
138 // Create a random state to copy
139 srcDb, srcRoot, srcAccounts := makeTestState()
140
141 // Create a destination state and sync with the scheduler
142 dstDb := database.NewMemDatabase()
143 sched := NewStateSync(srcRoot, dstDb)
144
145 queue := append([]common.Hash{}, sched.Missing(batch)...)
146 for len(queue) > 0 {
147 results := make([]trie.SyncResult, len(queue))
148 for i, hash := range queue {
149 data, err := srcDb.TrieDB().Node(hash)
150 if err != nil {
151 t.Fatalf("failed to retrieve node data for %x", hash)
152 }
153 results[i] = trie.SyncResult{Hash: hash, Data: data}
154 }
155 if _, index, err := sched.Process(results); err != nil {
156 t.Fatalf("failed to process result #%d: %v", index, err)
157 }
158 if index, err := sched.Commit(dstDb); err != nil {
159 t.Fatalf("failed to commit data #%d: %v", index, err)
160 }
161 queue = append(queue[:0], sched.Missing(batch)...)
162 }
163 // Cross check that the two states are in sync
164 checkStateAccounts(t, dstDb, srcRoot, srcAccounts)
165}
166
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.

Callers 2

Calls 6

makeTestStateFunction · 0.85
NewStateSyncFunction · 0.85
checkStateAccountsFunction · 0.85
TrieDBMethod · 0.65
ProcessMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected