Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author a sibling block in case best block's slot is same as current slot #2726

Merged
merged 14 commits into from
Sep 9, 2022
Merged
15 changes: 15 additions & 0 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ func (b *Service) handleSlot(epoch, slotNum uint64,
return err
}

slotNumOfTheBestBlock, err := b.blockState.GetSlotForBlock(parentHeader.Hash())
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("could not get slot for block %s: %w", parentHeader.Hash(), err)
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
}

if slotNumOfTheBestBlock == slotNum {
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
// pick parent of best block instead to handle slot
newParentHeader, err := b.blockState.GetHeader(parentHeader.ParentHash)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("could not get header for hash %s: %w", parentHeader.ParentHash, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

parentHeader = newParentHeader
}
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

if parentHeader == nil {
return errNilParentHeader
}
Expand Down