Skip to content

Commit

Permalink
fixed null pointer panic when iterating over a block without loaded h…
Browse files Browse the repository at this point in the history
…eader
  • Loading branch information
pk910 committed Aug 23, 2023
1 parent e4db1ed commit 1a920d1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion indexer/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,14 @@ func (cache *indexerCache) getFirstCanonicalBlock(epoch uint64, head []byte) *Ca
canonicalBlock := cache.getLastCanonicalBlock(epoch, head)
for canonicalBlock != nil {
canonicalBlock.mutex.RLock()
parentRoot := []byte(canonicalBlock.header.Message.ParentRoot)
var parentRoot []byte = nil
if canonicalBlock.header != nil {
parentRoot = []byte(canonicalBlock.header.Message.ParentRoot)
}
canonicalBlock.mutex.RUnlock()
if parentRoot == nil {
return canonicalBlock
}
parentCanonicalBlock := cache.getCachedBlock(parentRoot)
if parentCanonicalBlock == nil || utils.EpochOfSlot(parentCanonicalBlock.Slot) != epoch {
return canonicalBlock
Expand Down

0 comments on commit 1a920d1

Please sign in to comment.