From 33ea179f6e5eeb2d95bd12157acaada576bfd5ca Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 16 Sep 2020 16:33:42 +0300 Subject: [PATCH] core: remove forward index check from addHeaders() It can't ever happen. We're guaranteed to have a consistent chain of headers (we're verifying them above, if we're not verifying --- it's not our fault) that starts at HeaderHeight that was actual when we were asking for it previously. HeaderHeight can only move forward, so if that happened that would be filtered out by the condition below and the first one can't happen. Though to be absolutely sure change the second check to only pass "+1" headers (which is what we want). --- pkg/core/blockchain.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index b5302bac1..65055893d 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -483,10 +483,7 @@ func (bc *Blockchain) addHeaders(verify bool, headers ...*block.Header) (err err oldlen := len(bc.headerHashes) var lastHeader *block.Header for _, h := range headers { - if int(h.Index-1) >= len(bc.headerHashes) { - return fmt.Errorf("height of received header %d is higher than the current header %d", h.Index, len(bc.headerHashes)) - } - if int(h.Index) < len(bc.headerHashes) { + if int(h.Index) != len(bc.headerHashes) { continue } bc.headerHashes = append(bc.headerHashes, h.Hash())