core: simplify header hash list restoration logic

We don't care about header, we only need hashes here.
This commit is contained in:
Roman Khimov 2022-11-18 16:34:24 +03:00
parent ff284d5d5c
commit 83e2ca054f
2 changed files with 6 additions and 8 deletions

View file

@ -442,20 +442,18 @@ func (bc *Blockchain) init() error {
targetHash = genesisBlock.Hash() targetHash = genesisBlock.Hash()
bc.headerHashes = append(bc.headerHashes, targetHash) bc.headerHashes = append(bc.headerHashes, targetHash)
} }
headers := make([]*block.Header, 0) headers := make([]util.Uint256, 0, headerBatchCount)
for hash != targetHash { for hash != targetHash {
header, err := bc.GetHeader(hash) header, err := bc.GetHeader(hash)
if err != nil { if err != nil {
return fmt.Errorf("could not get header %s: %w", hash, err) return fmt.Errorf("could not get header %s: %w", hash, err)
} }
headers = append(headers, header) headers = append(headers, header.Hash())
hash = header.PrevHash hash = header.PrevHash
} }
headerSliceReverse(headers) hashSliceReverse(headers)
for _, h := range headers { bc.headerHashes = append(bc.headerHashes, headers...)
bc.headerHashes = append(bc.headerHashes, h.Hash())
}
} }
// Check whether StateChangeState stage is in the storage and continue interrupted state jump / state reset if so. // Check whether StateChangeState stage is in the storage and continue interrupted state jump / state reset if so.

View file

@ -64,8 +64,8 @@ func getNextConsensusAddress(validators []*keys.PublicKey) (val util.Uint160, er
return hash.Hash160(raw), nil return hash.Hash160(raw), nil
} }
// headerSliceReverse reverses the given slice of *Header. // hashSliceReverse reverses the given slice of util.Uint256.
func headerSliceReverse(dest []*block.Header) { func hashSliceReverse(dest []util.Uint256) {
for i, j := 0, len(dest)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(dest)-1; i < j; i, j = i+1, j-1 {
dest[i], dest[j] = dest[j], dest[i] dest[i], dest[j] = dest[j], dest[i]
} }