core: fix potential issue with header list init

If we're to receive some 500 headers (less than `headerBatchCount`) and quit
before receiving more of them we end up with clean `bc.headerList` that will
be inited going backwards to the `targetHash`, but code path doesn't add add
the `targetHash` itself which it should do in this particular case, otherwise
we end with no genesis block hash in the list.
This commit is contained in:
Roman Khimov 2019-11-06 18:00:14 +03:00
parent b5199625cd
commit c567307748

View file

@ -153,6 +153,7 @@ func (bc *Blockchain) init() error {
return err
}
targetHash = genesisBlock.Hash()
bc.headerList.Add(targetHash)
}
headers := make([]*Header, 0)
@ -164,7 +165,6 @@ func (bc *Blockchain) init() error {
headers = append(headers, header)
hash = header.PrevHash
}
headerSliceReverse(headers)
for _, h := range headers {
if !h.Verify() {