From c16c2bf1020b487ed270cf4a4602ee260c4fc14c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 Nov 2019 17:56:06 +0300 Subject: [PATCH] core: store current header reference on clean init Missing it the following line could fail on subsequent restarts: currHeaderHeight, currHeaderHash, err := storage.CurrentHeaderHeight(bc.store) if the node was stopped before any headers had been received. --- pkg/core/blockchain.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index ac8ca3365..8f31adfb9 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -101,6 +101,10 @@ func (bc *Blockchain) init() error { return err } bc.headerList = NewHeaderHashList(genesisBlock.Hash()) + err = bc.store.Put(storage.SYSCurrentHeader.Bytes(), hashAndIndexToBytes(genesisBlock.Hash(), genesisBlock.Index)) + if err != nil { + return err + } return bc.storeBlock(genesisBlock) } if ver != version {