Skip to content

Commit

Permalink
fully wait for finality before bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jul 7, 2024
1 parent 9bb913d commit f010345
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,18 @@ func (m *F3) computeBootstrapDelay(manifest *manifest.Manifest) (time.Duration,
return 0, err

Check warning on line 141 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L140-L141

Added lines #L140 - L141 were not covered by tests
}

// We bootstrap now if we're at the correct time, whether or
// not we've hit the correct epoch. The important thing is
// that:
//
// 1. All nodes will use BootstrapEpoch - Finality to pick the base.
// 2. All nodes will bootstrap at the same time.
currentEpoch := ts.Epoch()
if currentEpoch >= manifest.BootstrapEpoch {
return 0, nil
}
epochDelay := manifest.BootstrapEpoch - currentEpoch
start := ts.Timestamp().Add(time.Duration(epochDelay) * manifest.ECPeriod)
return max(time.Until(start), 0), nil
delay := time.Until(start)
// Add additional delay to skip over null epochs. That way we wait the full 900 epochs.
if delay <= 0 {
delay = manifest.ECPeriod + delay%manifest.ECPeriod

Check warning on line 153 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L153

Added line #L153 was not covered by tests
}
return delay, nil
}

// Run start the module. It will exit when context is cancelled.
Expand Down Expand Up @@ -195,29 +194,28 @@ func (m *F3) Start(startCtx context.Context) (_err error) {
}

defer manifestChangeTimer.Stop()

for m.runningCtx.Err() == nil {
select {
case update := <-m.manifestProvider.ManifestUpdates():
if pendingManifest != nil && !manifestChangeTimer.Stop() {
<-manifestChangeTimer.C

Check warning on line 201 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L201

Added line #L201 was not covered by tests
}

pendingManifest = update
if delay, err := m.computeBootstrapDelay(update); err != nil {
return err
} else if delay > 0 {
manifestChangeTimer.Reset(delay)
continue
}
case <-manifestChangeTimer.C:
case <-m.runningCtx.Done():
return nil
}
if err := m.reconfigure(m.runningCtx, pendingManifest); err != nil {
return xerrors.Errorf("failed to reconfigure F3: %w", err)

if delay, err := m.computeBootstrapDelay(pendingManifest); err != nil {
return err

Check warning on line 210 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L210

Added line #L210 was not covered by tests
} else if delay > 0 {
manifestChangeTimer.Reset(delay)
} else {
if err := m.reconfigure(m.runningCtx, pendingManifest); err != nil {
return xerrors.Errorf("failed to reconfigure F3: %w", err)

Check warning on line 215 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L215

Added line #L215 was not covered by tests
}
pendingManifest = nil
}
pendingManifest = nil
}
return nil

Check warning on line 220 in f3.go

View check run for this annotation

Codecov / codecov/patch

f3.go#L220

Added line #L220 was not covered by tests
})
Expand Down

0 comments on commit f010345

Please sign in to comment.