les: fix nextRequest best variables selection

This commit is contained in:
Wenshao Zhong 2018-11-15 19:17:03 +08:00
parent 14346e4ef9
commit 667f5eca14

View file

@ -410,6 +410,7 @@ func (f *lightFetcher) nextRequest() (*distReq, uint64) {
bestHash common.Hash bestHash common.Hash
bestAmount uint64 bestAmount uint64
) )
bestAmount--
bestTd := f.maxConfirmedTd bestTd := f.maxConfirmedTd
bestSyncing := false bestSyncing := false
@ -417,7 +418,7 @@ func (f *lightFetcher) nextRequest() (*distReq, uint64) {
for hash, n := range fp.nodeByHash { for hash, n := range fp.nodeByHash {
if !f.checkKnownNode(p, n) && !n.requested && (bestTd == nil || n.td.Cmp(bestTd) >= 0) { if !f.checkKnownNode(p, n) && !n.requested && (bestTd == nil || n.td.Cmp(bestTd) >= 0) {
amount := f.requestAmount(p, n) amount := f.requestAmount(p, n)
if bestTd == nil || n.td.Cmp(bestTd) > 0 || amount < bestAmount { if amount < bestAmount {
bestHash = hash bestHash = hash
bestAmount = amount bestAmount = amount
bestTd = n.td bestTd = n.td