Skip to content

Commit

Permalink
fix(f3): fix hot loop in F3 participation
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Oct 10, 2024
1 parent a116278 commit 4a25048
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Update `EthGetBlockByNumber` to return a pointer to ethtypes.EthBlock or nil for null rounds. ([filecoin-project/lotus#12529](https://github.com/filecoin-project/lotus/pull/12529))
- Reduce size of embedded genesis CAR files by removing WASM actor blocks and compressing with zstd. This reduces the `lotus` binary size by approximately 10 MiB. ([filecoin-project/lotus#12439](https://github.com/filecoin-project/lotus/pull/12439))
- Add ChainSafe operated Calibration archival node to the bootstrap list ([filecoin-project/lotus#12517](https://github.com/filecoin-project/lotus/pull/12517))
- Fix hotloop in F3 pariticpation API ([filecoin-project/lotus#12575](https://github.com/filecoin-project/lotus/pull/12575))

## Bug Fixes

Expand Down
29 changes: 21 additions & 8 deletions node/modules/storageminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,28 @@ func newF3Participator(node v1api.FullNode, participant dtypes.MinerAddress, bac

func (p *f3Participator) participate(ctx context.Context) error {
for ctx.Err() == nil {
if ticket, err := p.tryGetF3ParticipationTicket(ctx); err != nil {
return err
} else if lease, participating, err := p.tryF3Participate(ctx, ticket); err != nil {
start := time.Now()
ticket, err := p.tryGetF3ParticipationTicket(ctx)
if err != nil {
return err
} else if !participating {
continue
} else if err := p.awaitLeaseExpiry(ctx, lease); err != nil {
}
lease, participating, err := p.tryF3Participate(ctx, ticket)
if err != nil {
return err
}
if participating {
if err := p.awaitLeaseExpiry(ctx, lease); err != nil {
return err
}
}
const minPeriod = 500 * time.Millisecond
if sinceLastLoop := time.Since(start); sinceLastLoop < minPeriod {
select {
case <-time.After(minPeriod - sinceLastLoop):
case <-ctx.Done():
return ctx.Err()
}
}
log.Info("Restarting F3 participation")
}
return ctx.Err()
Expand Down Expand Up @@ -485,8 +498,8 @@ func (p *f3Participator) awaitLeaseExpiry(ctx context.Context, lease api.F3Parti
}
log.Errorw("Failed to check F3 progress while awaiting lease expiry. Retrying after backoff.", "attempts", p.backoff.Attempt(), "backoff", p.backoff.Duration(), "err", err)
p.backOff(ctx)
case progress.ID+2 >= lease.ValidityTerm:
log.Infof("F3 progressed (%d) to within two instances of lease expiry (%d). Restarting participation.", progress.ID, lease.ValidityTerm)
case progress.ID+2 >= lease.FromInstance+lease.ValidityTerm:
log.Infof("F3 progressed (%d) to within two instances of lease expiry (%d+%d). Restarting participation.", progress.ID, lease.FromInstance, lease.ValidityTerm)
return nil
default:
remainingInstanceLease := lease.ValidityTerm - progress.ID
Expand Down

0 comments on commit 4a25048

Please sign in to comment.