les: add announcement safety check to light fetcher (#17034)

pull/17161/head
Felföldi Zsolt 6 years ago committed by Péter Szilágyi
parent f524ec4326
commit 51df1c1f20
  1. 11
      les/fetcher.go

@ -267,9 +267,16 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
} }
n = n.parent n = n.parent
} }
if n != nil {
// n is now the reorg common ancestor, add a new branch of nodes // n is now the reorg common ancestor, add a new branch of nodes
// check if the node count is too high to add new nodes if n != nil && (head.Number >= n.number+maxNodeCount || head.Number <= n.number) {
// if announced head block height is lower or same as n or too far from it to add
// intermediate nodes then discard previous announcement info and trigger a resync
n = nil
fp.nodeCnt = 0
fp.nodeByHash = make(map[common.Hash]*fetcherTreeNode)
}
if n != nil {
// check if the node count is too high to add new nodes, discard oldest ones if necessary
locked := false locked := false
for uint64(fp.nodeCnt)+head.Number-n.number > maxNodeCount && fp.root != nil { for uint64(fp.nodeCnt)+head.Number-n.number > maxNodeCount && fp.root != nil {
if !locked { if !locked {

Loading…
Cancel
Save