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
19 changes: 19 additions & 0 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,25 @@ func (b *Service) handleSlot(epoch, slotNum uint64,
return err
}

bestBlockSlotNum, err := b.blockState.GetSlotForBlock(parentHeader.Hash())
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 bestBlockSlotNum > slotNum {
return errLaggingSlot
}
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

if bestBlockSlotNum == slotNum {
// 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
1 change: 1 addition & 0 deletions lib/babe/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (
errInvalidSlotTechnique = errors.New("invalid slot claiming technique")
errNoBABEAuthorityKeyProvided = errors.New("cannot create BABE service as authority; no keypair provided")
errLastDigestItemNotSeal = errors.New("last digest item is not seal")
errLaggingSlot = errors.New("cannot claim slot, current slot is smaller than slot of best block")

other Other
invalidCustom InvalidCustom
Expand Down