Skip to content

Commit

Permalink
les: add announcement safety check to light fetcher (ethereum#17034)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi authored and firmianavan committed Aug 28, 2018
1 parent 49bc5e8 commit 9b55335
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions les/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,16 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
}
n = n.parent
}
// n is now the reorg common ancestor, add a new branch of 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 {
// 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
// check if the node count is too high to add new nodes, discard oldest ones if necessary
locked := false
for uint64(fp.nodeCnt)+head.Number-n.number > maxNodeCount && fp.root != nil {
if !locked {
Expand Down

0 comments on commit 9b55335

Please sign in to comment.