Skip to content

Commit

Permalink
fix(lib/babe): epoch context error wrapping (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 authored Apr 22, 2022
1 parent 89c32ae commit c053dea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dot/state/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ func (s *EpochState) HasEpochData(epoch uint64) (bool, error) {
return has, nil
}

if !errors.Is(chaindb.ErrKeyNotFound, err) {
// we can have `has == false` and `err == nil`
// so ensure the error is not nil in the condition below.
if err != nil && !errors.Is(chaindb.ErrKeyNotFound, err) {
return false, fmt.Errorf("cannot check database for epoch key %d: %w", epoch, err)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (b *Service) initiate() {
func (b *Service) initiateAndGetEpochHandler(epoch uint64) (*epochHandler, error) {
epochData, err := b.initiateEpoch(epoch)
if err != nil {
return nil, fmt.Errorf("failed to initiate epoch %d: %w", epoch, err)
return nil, fmt.Errorf("failed to initiate epoch: %w", err)
}

logger.Debugf("initiated epoch with threshold %s, randomness 0x%x and authorities %v",
Expand Down Expand Up @@ -430,7 +430,7 @@ func (b *Service) runEngine() error {
if errors.Is(err, errServicePaused) || errors.Is(err, context.Canceled) {
return nil
} else if err != nil {
return err
return fmt.Errorf("cannot handle epoch: %w", err)
}

epoch = next
Expand All @@ -442,7 +442,7 @@ func (b *Service) handleEpoch(epoch uint64) (next uint64, err error) {
defer cancel()
b.epochHandler, err = b.initiateAndGetEpochHandler(epoch)
if err != nil {
return 0, fmt.Errorf("cannot initiate and get epoch handler for epoch %d: %w", epoch, err)
return 0, fmt.Errorf("cannot initiate and get epoch handler: %w", err)
}

// get start slot for current epoch
Expand Down
2 changes: 1 addition & 1 deletion lib/babe/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (b *Service) getEpochDataAndStartSlot(epoch uint64) (*epochData, uint64, er

has, err := b.epochState.HasEpochData(epoch)
if err != nil {
return nil, 0, fmt.Errorf("cannot check for epoch data for epoch %d: %w", epoch, err)
return nil, 0, fmt.Errorf("cannot check epoch state: %w", err)
}

if !has {
Expand Down

0 comments on commit c053dea

Please sign in to comment.