eth/protocols/snap: ascending capacity sort, reverse on callsites

msgrater
Péter Szilágyi 4 years ago
parent 2e2c72891a
commit 7b5a6f357d
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
  1. 17
      eth/protocols/snap/sync.go

@ -874,7 +874,7 @@ func (s *Syncer) assignAccountTasks(success chan *accountResponse, fail chan *ac
if len(idlers.ids) == 0 { if len(idlers.ids) == 0 {
return return
} }
sort.Sort(idlers) sort.Reverse(idlers)
// Iterate over all the tasks and try to find a pending one // Iterate over all the tasks and try to find a pending one
for _, task := range s.tasks { for _, task := range s.tasks {
@ -971,7 +971,7 @@ func (s *Syncer) assignBytecodeTasks(success chan *bytecodeResponse, fail chan *
if len(idlers.ids) == 0 { if len(idlers.ids) == 0 {
return return
} }
sort.Sort(idlers) sort.Reverse(idlers)
// Iterate over all the tasks and try to find a pending one // Iterate over all the tasks and try to find a pending one
for _, task := range s.tasks { for _, task := range s.tasks {
@ -1074,7 +1074,7 @@ func (s *Syncer) assignStorageTasks(success chan *storageResponse, fail chan *st
if len(idlers.ids) == 0 { if len(idlers.ids) == 0 {
return return
} }
sort.Sort(idlers) sort.Reverse(idlers)
// Iterate over all the tasks and try to find a pending one // Iterate over all the tasks and try to find a pending one
for _, task := range s.tasks { for _, task := range s.tasks {
@ -1230,7 +1230,7 @@ func (s *Syncer) assignTrienodeHealTasks(success chan *trienodeHealResponse, fai
if len(idlers.ids) == 0 { if len(idlers.ids) == 0 {
return return
} }
sort.Sort(idlers) sort.Reverse(idlers)
// Iterate over pending tasks and try to find a peer to retrieve with // Iterate over pending tasks and try to find a peer to retrieve with
for len(s.healer.trieTasks) > 0 || s.healer.scheduler.Pending() > 0 { for len(s.healer.trieTasks) > 0 || s.healer.scheduler.Pending() > 0 {
@ -1354,7 +1354,7 @@ func (s *Syncer) assignBytecodeHealTasks(success chan *bytecodeHealResponse, fai
if len(idlers.ids) == 0 { if len(idlers.ids) == 0 {
return return
} }
sort.Sort(idlers) sort.Reverse(idlers)
// Iterate over pending tasks and try to find a peer to retrieve with // Iterate over pending tasks and try to find a peer to retrieve with
for len(s.healer.codeTasks) > 0 || s.healer.scheduler.Pending() > 0 { for len(s.healer.codeTasks) > 0 || s.healer.scheduler.Pending() > 0 {
@ -2847,8 +2847,9 @@ func estimateRemainingSlots(hashes int, last common.Hash) (uint64, error) {
return space.Uint64() - uint64(hashes), nil return space.Uint64() - uint64(hashes), nil
} }
// capacitySort implements the Sort interface, allowing sorting py peer message // capacitySort implements the Sort interface, allowing sorting by peer message
// throughput (highest first). // throughput. Note, callers should use sort.Reverse to get the desired effect
// of highest capacity being at the front.
type capacitySort struct { type capacitySort struct {
ids []string ids []string
caps []float64 caps []float64
@ -2859,7 +2860,7 @@ func (s *capacitySort) Len() int {
} }
func (s *capacitySort) Less(i, j int) bool { func (s *capacitySort) Less(i, j int) bool {
return s.caps[i] > s.caps[j] return s.caps[i] < s.caps[j]
} }
func (s *capacitySort) Swap(i, j int) { func (s *capacitySort) Swap(i, j int) {

Loading…
Cancel
Save