From 08bb58b482cb44c7fb933c41c3b9f98af6422f80 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 15 Aug 2024 15:00:22 +0200 Subject: [PATCH 1/2] eth/protocols/eth: handle Count Zero --- eth/protocols/eth/handlers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index bdc630a9f467..c79d8f7c04db 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -144,6 +144,9 @@ func serviceContiguousBlockHeaderQuery(chain *core.BlockChain, query *GetBlockHe if count > maxHeadersServe { count = maxHeadersServe } + if count == 0 { + return nil + } if query.Origin.Hash == (common.Hash{}) { // Number mode, just return the canon chain segment. The backend // delivers in [N, N-1, N-2..] descending order, so we need to From 0ee306b19aafee69144e071e132e74d998a57ad2 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 20 Aug 2024 10:34:31 +0200 Subject: [PATCH 2/2] eth/protocols/eth: do check earlier --- eth/protocols/eth/handlers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index c79d8f7c04db..b3886270f3dd 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -42,6 +42,9 @@ func handleGetBlockHeaders(backend Backend, msg Decoder, peer *Peer) error { // ServiceGetBlockHeadersQuery assembles the response to a header query. It is // exposed to allow external packages to test protocol behavior. func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersRequest, peer *Peer) []rlp.RawValue { + if query.Amount == 0 { + return nil + } if query.Skip == 0 { // The fast path: when the request is for a contiguous segment of headers. return serviceContiguousBlockHeaderQuery(chain, query) @@ -144,9 +147,6 @@ func serviceContiguousBlockHeaderQuery(chain *core.BlockChain, query *GetBlockHe if count > maxHeadersServe { count = maxHeadersServe } - if count == 0 { - return nil - } if query.Origin.Hash == (common.Hash{}) { // Number mode, just return the canon chain segment. The backend // delivers in [N, N-1, N-2..] descending order, so we need to