core: simplify header hash list restoration logic
We don't care about header, we only need hashes here.
This commit is contained in:
parent
ff284d5d5c
commit
83e2ca054f
2 changed files with 6 additions and 8 deletions
|
@ -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.
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue