From c5673077480ec439fce2c014ac56f450c4a08f5c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 Nov 2019 18:00:14 +0300 Subject: [PATCH] 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. --- pkg/core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 00e44b62e..8b2ecfa75 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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() {