core: don't panic on init when there are less than 2000 hashes
If you're to sync less than 2000 headers no batched header key-value is gonna be written into the DB and init() would panic because bc.headerList.Len() would return 0. Use genesis block as a target in this case.
This commit is contained in:
parent
dafd385f57
commit
b533dfceba
1 changed files with 10 additions and 1 deletions
|
@ -137,7 +137,16 @@ func (bc *Blockchain) init() error {
|
||||||
// that with stored blocks.
|
// that with stored blocks.
|
||||||
if currHeaderHeight > bc.storedHeaderCount {
|
if currHeaderHeight > bc.storedHeaderCount {
|
||||||
hash := currHeaderHash
|
hash := currHeaderHash
|
||||||
targetHash := bc.headerList.Get(bc.headerList.Len() - 1)
|
var targetHash util.Uint256
|
||||||
|
if bc.headerList.Len() > 0 {
|
||||||
|
targetHash = bc.headerList.Get(bc.headerList.Len() - 1)
|
||||||
|
} else {
|
||||||
|
genesisBlock, err := createGenesisBlock(bc.config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
targetHash = genesisBlock.Hash()
|
||||||
|
}
|
||||||
headers := make([]*Header, 0)
|
headers := make([]*Header, 0)
|
||||||
|
|
||||||
for hash != targetHash {
|
for hash != targetHash {
|
||||||
|
|
Loading…
Reference in a new issue