core: fix runtime error index out of range [0] with length 0, close #1765 (#1766)

This commit is contained in:
Daniel Liu 2025-11-14 22:35:37 +08:00 committed by GitHub
parent 812abd4b83
commit 7d4578496c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2164,6 +2164,10 @@ func (bc *BlockChain) getResultBlock(block *types.Block, verifiedM2 bool) (*Resu
winner = append(winner, parent)
parent = bc.GetBlock(parent.ParentHash(), parent.NumberU64()-1)
}
// fix issue #1765, return at once if winner is empty
if len(winner) == 0 {
return nil, errors.New("winner is empty")
}
for j := 0; j < len(winner)/2; j++ {
winner[j], winner[len(winner)-1-j] = winner[len(winner)-1-j], winner[j]
}