mirror of https://github.com/poanetwork/gecko.git
Merge pull request #82 from ava-labs/bootstrap-heap
move cache check and use heap in bootstrapping
This commit is contained in:
commit
f616952736
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue