From b5199625cd2962dcbb55a8634b7e2534b635dcf5 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 Nov 2019 17:58:19 +0300 Subject: [PATCH] core: init genesis block header if there are no other headers in DB Fixes crash when restarted after the DB initialization and no blocks written into the DB. --- pkg/core/blockchain.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 8f31adfb9..00e44b62e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -135,6 +135,9 @@ func (bc *Blockchain) init() error { if err != nil { return err } + if bc.storedHeaderCount == 0 && currHeaderHeight == 0 { + bc.headerList.Add(currHeaderHash) + } // There is a high chance that the Node is stopped before the next // batch of 2000 headers was stored. Via the currentHeaders stored we can sync