Skip to content

Commit 51df1c1

Browse files
zsfelfoldikaralabe
authored andcommitted
les: add announcement safety check to light fetcher (#17034)
1 parent f524ec4 commit 51df1c1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

les/fetcher.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,16 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
267267
}
268268
n = n.parent
269269
}
270+
// n is now the reorg common ancestor, add a new branch of nodes
271+
if n != nil && (head.Number >= n.number+maxNodeCount || head.Number <= n.number) {
272+
// if announced head block height is lower or same as n or too far from it to add
273+
// intermediate nodes then discard previous announcement info and trigger a resync
274+
n = nil
275+
fp.nodeCnt = 0
276+
fp.nodeByHash = make(map[common.Hash]*fetcherTreeNode)
277+
}
270278
if n != nil {
271-
// n is now the reorg common ancestor, add a new branch of nodes
272-
// check if the node count is too high to add new nodes
279+
// check if the node count is too high to add new nodes, discard oldest ones if necessary
273280
locked := false
274281
for uint64(fp.nodeCnt)+head.Number-n.number > maxNodeCount && fp.root != nil {
275282
if !locked {

0 commit comments

Comments
 (0)