Skip to content

Commit 08b78bc

Browse files
authored
fix early start of F3 in case of delayed bootstrap tipset (#1035)
If bootstrap tipset is delayed, we don't want to start immediately instead we want to ensure that this tipset first exists Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 1e1c233 commit 08b78bc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

bootstrap_delay_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestComputeBootstrapDelay(t *testing.T) {
6464
name: "out of sync - way after bootstrap",
6565
time: genesis.Add(time.Duration(bootstrapEpoch+100)*period + 1*time.Second),
6666
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch - 100), period: period},
67-
want: 0 * time.Second,
67+
want: 1 * time.Nanosecond, // we don't start immediately as the tipset we need is not available yet
6868
},
6969
{
7070
name: "out of sync - way before bootstrap",

f3.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func (m *F3) GetPowerTableByInstance(ctx context.Context, instance uint64) (gpbf
136136

137137
// computeBootstrapDelay returns the time at which the F3 instance specified by
138138
// the passed manifest should be started.
139+
// It will return 0 if the manifest bootstrap epoch is greater than the current epoch.
140+
// It will also return 1ns if the manifest bootstrap epoch is equal to the current epoch but by
141+
// the time calculation, we should have already received the bootstrap tipset.
139142
func computeBootstrapDelay(ts ec.TipSet, clock clock.Clock, mfst manifest.Manifest) time.Duration {
140143
currentEpoch := ts.Epoch()
141144
if currentEpoch >= mfst.BootstrapEpoch {
@@ -144,7 +147,9 @@ func computeBootstrapDelay(ts ec.TipSet, clock clock.Clock, mfst manifest.Manife
144147
epochDelay := mfst.BootstrapEpoch - currentEpoch
145148
start := ts.Timestamp().Add(time.Duration(epochDelay) * mfst.EC.Period)
146149
delay := clock.Until(start)
147-
delay = max(delay, 0)
150+
// ensure that we don't start immediately
151+
// to trigger waiting for the bootstrap tipset to exist
152+
delay = max(delay, 1*time.Nanosecond)
148153
return delay
149154
}
150155

@@ -185,6 +190,8 @@ func (m *F3) Start(startCtx context.Context) (_err error) {
185190
delay := computeBootstrapDelay(ts, m.clock, m.mfst)
186191
if delay > 0 {
187192
log.Infow("waiting for bootstrap epoch", "duration", delay.String())
193+
// reduce hot-looping by waiting for at least 20ms
194+
delay = max(delay, 20*time.Millisecond)
188195
startTimer.Reset(delay)
189196
} else {
190197
err = m.startInternal(m.runningCtx)

0 commit comments

Comments
 (0)