diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-11-01 19:31:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 19:31:12 +0800 |
commit | f4d878f3d83187d27411c0ea5ebd55a82b27e35e (patch) | |
tree | 0a684c4ebb5ce6846862df6c10d0209991122751 /trie | |
parent | 61acd18e7967d67fd6db24be360586cf017d577b (diff) | |
parent | e1b4acfb6e6a0f930afeb79749ac56c381609258 (diff) | |
download | go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar.gz go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar.bz2 go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar.lz go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar.xz go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.tar.zst go-tangerine-f4d878f3d83187d27411c0ea5ebd55a82b27e35e.zip |
Merge pull request #3216 from karalabe/fastsync-bigdb-tuning
core/state, eth/downloader, trie: reset fast-failure on progress
Diffstat (limited to 'trie')
-rw-r--r-- | trie/sync.go | 18 | ||||
-rw-r--r-- | trie/sync_test.go | 12 |
2 files changed, 18 insertions, 12 deletions
diff --git a/trie/sync.go b/trie/sync.go index 58b8a1fb6..2158ab750 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -142,34 +142,40 @@ func (s *TrieSync) Missing(max int) []common.Hash { return requests } -// Process injects a batch of retrieved trie nodes data. -func (s *TrieSync) Process(results []SyncResult) (int, error) { +// Process injects a batch of retrieved trie nodes data, returning if something +// was committed to the database and also the index of an entry if processing of +// it failed. +func (s *TrieSync) Process(results []SyncResult) (bool, int, error) { + committed := false + for i, item := range results { // If the item was not requested, bail out request := s.requests[item.Hash] if request == nil { - return i, ErrNotRequested + return committed, i, ErrNotRequested } // If the item is a raw entry request, commit directly if request.raw { request.data = item.Data s.commit(request, nil) + committed = true continue } // Decode the node data content and update the request node, err := decodeNode(item.Hash[:], item.Data, 0) if err != nil { - return i, err + return committed, i, err } request.data = item.Data // Create and schedule a request for all the children nodes requests, err := s.children(request, node) if err != nil { - return i, err + return committed, i, err } if len(requests) == 0 && request.deps == 0 { s.commit(request, nil) + committed = true continue } request.deps += len(requests) @@ -177,7 +183,7 @@ func (s *TrieSync) Process(results []SyncResult) (int, error) { s.schedule(child) } } - return 0, nil + return committed, 0, nil } // Pending returns the number of state entries currently pending for download. diff --git a/trie/sync_test.go b/trie/sync_test.go index a763dc564..5292fe5cb 100644 --- a/trie/sync_test.go +++ b/trie/sync_test.go @@ -122,7 +122,7 @@ func testIterativeTrieSync(t *testing.T, batch int) { } results[i] = SyncResult{hash, data} } - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } queue = append(queue[:0], sched.Missing(batch)...) @@ -152,7 +152,7 @@ func TestIterativeDelayedTrieSync(t *testing.T) { } results[i] = SyncResult{hash, data} } - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } queue = append(queue[len(results):], sched.Missing(10000)...) @@ -190,7 +190,7 @@ func testIterativeRandomTrieSync(t *testing.T, batch int) { results = append(results, SyncResult{hash, data}) } // Feed the retrieved results back and queue new tasks - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } queue = make(map[common.Hash]struct{}) @@ -231,7 +231,7 @@ func TestIterativeRandomDelayedTrieSync(t *testing.T) { } } // Feed the retrieved results back and queue new tasks - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } for _, result := range results { @@ -272,7 +272,7 @@ func TestDuplicateAvoidanceTrieSync(t *testing.T) { results[i] = SyncResult{hash, data} } - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } queue = append(queue[:0], sched.Missing(0)...) @@ -304,7 +304,7 @@ func TestIncompleteTrieSync(t *testing.T) { results[i] = SyncResult{hash, data} } // Process each of the trie nodes - if index, err := sched.Process(results); err != nil { + if _, index, err := sched.Process(results); err != nil { t.Fatalf("failed to process result #%d: %v", index, err) } for _, result := range results { |