Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove epoch number?

@qdm12 qdm12 Apr 20, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's added in the initiateEpoch method (well in HasEpochData further down the call stack), so to avoid repeating the epoch number a bunch of times in the error.

Anyway, the function handling the argument should be the only one adding context to the error with it, not its callers.

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)
Comment thread
kishansagathiya marked this conversation as resolved.
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)
Comment thread
kishansagathiya marked this conversation as resolved.
return nil, 0, fmt.Errorf("cannot check epoch state: %w", err)
}

if !has {
Expand Down