eth/protocols/eth: do check earlier

This commit is contained in:
Martin Holst Swende 2024-08-20 10:34:31 +02:00
parent 08bb58b482
commit 0ee306b19a
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -42,6 +42,9 @@ func handleGetBlockHeaders(backend Backend, msg Decoder, peer *Peer) error {
// ServiceGetBlockHeadersQuery assembles the response to a header query. It is // ServiceGetBlockHeadersQuery assembles the response to a header query. It is
// exposed to allow external packages to test protocol behavior. // exposed to allow external packages to test protocol behavior.
func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersRequest, peer *Peer) []rlp.RawValue { func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersRequest, peer *Peer) []rlp.RawValue {
if query.Amount == 0 {
return nil
}
if query.Skip == 0 { if query.Skip == 0 {
// The fast path: when the request is for a contiguous segment of headers. // The fast path: when the request is for a contiguous segment of headers.
return serviceContiguousBlockHeaderQuery(chain, query) return serviceContiguousBlockHeaderQuery(chain, query)
@ -144,9 +147,6 @@ func serviceContiguousBlockHeaderQuery(chain *core.BlockChain, query *GetBlockHe
if count > maxHeadersServe { if count > maxHeadersServe {
count = maxHeadersServe count = maxHeadersServe
} }
if count == 0 {
return nil
}
if query.Origin.Hash == (common.Hash{}) { if query.Origin.Hash == (common.Hash{}) {
// Number mode, just return the canon chain segment. The backend // Number mode, just return the canon chain segment. The backend
// delivers in [N, N-1, N-2..] descending order, so we need to // delivers in [N, N-1, N-2..] descending order, so we need to