Merge pull request #82 from ava-labs/bootstrap-heap

move cache check and use heap in bootstrapping
This commit is contained in:
Stephen Buttolph 2020-06-17 22:09:27 -04:00 committed by GitHub
commit f616952736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 10 deletions

View File

@ -127,15 +127,12 @@ func (b *bootstrapper) fetch(vtxID ids.ID) error {
// Process vertices
func (b *bootstrapper) process(vtx avalanche.Vertex) error {
toProcess := []avalanche.Vertex{vtx}
for len(toProcess) > 0 {
newLen := len(toProcess) - 1
vtx := toProcess[newLen]
toProcess = toProcess[:newLen]
if _, ok := b.processedCache.Get(vtx.ID()); ok { // already processed this
continue
}
toProcess := newMaxVertexHeap()
if _, ok := b.processedCache.Get(vtx.ID()); !ok { // only process if we haven't already
toProcess.Push(vtx)
}
for toProcess.Len() > 0 {
vtx := toProcess.Pop()
switch vtx.Status() {
case choices.Unknown:
if err := b.fetch(vtx.ID()); err != nil {
@ -171,7 +168,9 @@ func (b *bootstrapper) process(vtx avalanche.Vertex) error {
}
}
for _, parent := range vtx.Parents() {
toProcess = append(toProcess, parent)
if _, ok := b.processedCache.Get(parent.ID()); !ok { // already processed this
toProcess.Push(parent)
}
}
b.processedCache.Put(vtx.ID(), nil)
}