Skip to content

Commit

Permalink
fix: check error is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Oct 15, 2024
1 parent a7ea144 commit ee7f51c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ scratchpad
.vscode
*.out
dockerfile
sophon-miner.log
20 changes: 10 additions & 10 deletions f3participant/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewParticipant(ctx context.Context,
errgrp, runningCtx := errgroup.WithContext(runningCtx)
return &Participant{
node: node,
participant: address.Address(participant),
participant: participant,
backoff: backoff,
maxCheckProgressAttempts: maxCheckProgress,
leaseTerm: leaseTerm,
Expand Down Expand Up @@ -132,7 +132,7 @@ func (p *Participant) tryGetF3ParticipationTicket(ctx context.Context) (types.F3
switch ticket, err := p.node.F3GetOrRenewParticipationTicket(ctx, p.participant, p.previousTicket, p.leaseTerm); {
case ctx.Err() != nil:
return types.F3ParticipationTicket{}, ctx.Err()
case strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
log.Errorw("Cannot participate in F3 as it is disabled.", "err", err)
return types.F3ParticipationTicket{}, xerrors.Errorf("acquiring F3 participation ticket: %w", err)
case err != nil:
Expand All @@ -154,25 +154,25 @@ func (p *Participant) tryF3Participate(ctx context.Context, ticket types.F3Parti
switch lease, err := p.node.F3Participate(ctx, ticket); {
case ctx.Err() != nil:
return types.F3ParticipationLease{}, false, ctx.Err()
case strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
log.Errorw("Cannot participate in F3 as it is disabled.", "err", err)
return types.F3ParticipationLease{}, false, xerrors.Errorf("attempting F3 participation with ticket: %w", err)
case strings.Contains(err.Error(), types.ErrF3ParticipationTicketExpired.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3ParticipationTicketExpired.Error()):
log.Warnw("F3 participation ticket expired while attempting to participate. Acquiring a new ticket.", "attempts", p.backoff.Attempt(), "err", err)
return types.F3ParticipationLease{}, false, nil
case strings.Contains(err.Error(), types.ErrF3ParticipationTicketStartBeforeExisting.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3ParticipationTicketStartBeforeExisting.Error()):
log.Warnw("F3 participation ticket starts before the existing lease. Acquiring a new ticket.", "attempts", p.backoff.Attempt(), "err", err)
return types.F3ParticipationLease{}, false, nil
case strings.Contains(err.Error(), types.ErrF3ParticipationTicketInvalid.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3ParticipationTicketInvalid.Error()):
log.Errorw("F3 participation ticket is not valid. Acquiring a new ticket after backoff.", "backoff", p.backoff.Duration(), "attempts", p.backoff.Attempt(), "err", err)
p.backOff(ctx)
return types.F3ParticipationLease{}, false, nil
case strings.Contains(err.Error(), types.ErrF3ParticipationIssuerMismatch.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3ParticipationIssuerMismatch.Error()):
log.Warnw("Node is not the issuer of F3 participation ticket. Miner maybe load-balancing or node has changed. Retrying F3 participation after backoff.", "backoff", p.backoff.Duration(), "err", err)
p.backOff(ctx)
log.Debugw("Reattempting F3 participation with the same ticket.", "attempts", p.backoff.Attempt())
continue
case strings.Contains(err.Error(), types.ErrF3NotReady.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3NotReady.Error()):
log.Warnw("F3 is not ready. Retrying F3 participation after backoff.", "backoff", p.backoff.Duration(), "err", err)
p.backOff(ctx)
continue
Expand All @@ -199,7 +199,7 @@ func (p *Participant) awaitLeaseExpiry(ctx context.Context, lease types.F3Partic
for ctx.Err() == nil {
manifest, err := p.node.F3GetManifest(ctx)
switch {
case strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
log.Errorw("Cannot await F3 participation lease expiry as F3 is disabled.", "err", err)
return xerrors.Errorf("awaiting F3 participation lease expiry: %w", err)
case err != nil:
Expand All @@ -217,7 +217,7 @@ func (p *Participant) awaitLeaseExpiry(ctx context.Context, lease types.F3Partic
return nil
}
switch progress, err := p.node.F3GetProgress(ctx); {
case strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
case err != nil && strings.Contains(err.Error(), types.ErrF3Disabled.Error()):
log.Errorw("Cannot await F3 participation lease expiry as F3 is disabled.", "err", err)
return xerrors.Errorf("awaiting F3 participation lease expiry: %w", err)
case err != nil:
Expand Down
6 changes: 0 additions & 6 deletions node/modules/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ func NewMultiParticipant(lc fx.Lifecycle,
return nil, err
}

running, err := node.F3IsRunning(mCtx)
if err != nil || !running {
log.Warnf("f3 is not running: %v", err)
return nil, nil
}

mp, err := f3participant.NewMultiParticipant(mCtx, node, minerManager)
if err != nil {
return nil, err
Expand Down

0 comments on commit ee7f51c

Please sign in to comment.