From 83e2ca054f9ea401e0cb0e9a4378bed2b72ba9b0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 18 Nov 2022 16:34:24 +0300 Subject: [PATCH] core: simplify header hash list restoration logic We don't care about header, we only need hashes here. --- pkg/core/blockchain.go | 10 ++++------ pkg/core/util.go | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index d7b06cf6f..da41dfbf5 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -442,20 +442,18 @@ func (bc *Blockchain) init() error { targetHash = genesisBlock.Hash() bc.headerHashes = append(bc.headerHashes, targetHash) } - headers := make([]*block.Header, 0) + headers := make([]util.Uint256, 0, headerBatchCount) for hash != targetHash { header, err := bc.GetHeader(hash) if err != nil { return fmt.Errorf("could not get header %s: %w", hash, err) } - headers = append(headers, header) + headers = append(headers, header.Hash()) hash = header.PrevHash } - headerSliceReverse(headers) - for _, h := range headers { - bc.headerHashes = append(bc.headerHashes, h.Hash()) - } + hashSliceReverse(headers) + bc.headerHashes = append(bc.headerHashes, headers...) } // Check whether StateChangeState stage is in the storage and continue interrupted state jump / state reset if so. diff --git a/pkg/core/util.go b/pkg/core/util.go index 8ba894c52..2694e8885 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -64,8 +64,8 @@ func getNextConsensusAddress(validators []*keys.PublicKey) (val util.Uint160, er return hash.Hash160(raw), nil } -// headerSliceReverse reverses the given slice of *Header. -func headerSliceReverse(dest []*block.Header) { +// hashSliceReverse reverses the given slice of util.Uint256. +func hashSliceReverse(dest []util.Uint256) { for i, j := 0, len(dest)-1; i < j; i, j = i+1, j-1 { dest[i], dest[j] = dest[j], dest[i] }