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).
This commit is contained in:
Roman Khimov 2020-09-16 16:33:42 +03:00
parent 7cbb660082
commit 33ea179f6e

View file

@ -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())