Skip to content

Commit 804f45b

Browse files
Move selectStartGear lock from Handler into Engines (#2182)
1 parent 7ed450b commit 804f45b

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

snow/engine/avalanche/bootstrap/bootstrapper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ type bootstrapper struct {
8989
processedCache *cache.LRU[ids.ID, struct{}]
9090
}
9191

92-
func (b *bootstrapper) Clear() error {
92+
func (b *bootstrapper) Clear(context.Context) error {
93+
b.Ctx.Lock.Lock()
94+
defer b.Ctx.Lock.Unlock()
95+
9396
if err := b.VtxBlocked.Clear(); err != nil {
9497
return err
9598
}

snow/engine/common/bootstrapable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ type Bootstrapable interface {
2121
ForceAccepted(ctx context.Context, acceptedContainerIDs []ids.ID) error
2222

2323
// Clear removes all containers to be processed upon bootstrapping
24-
Clear() error
24+
Clear(ctx context.Context) error
2525
}

snow/engine/common/test_bootstrapable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type BootstrapableTest struct {
2626

2727
CantForceAccepted, CantClear bool
2828

29-
ClearF func() error
29+
ClearF func(ctx context.Context) error
3030
ForceAcceptedF func(ctx context.Context, acceptedContainerIDs []ids.ID) error
3131
}
3232

@@ -35,9 +35,9 @@ func (b *BootstrapableTest) Default(cant bool) {
3535
b.CantForceAccepted = cant
3636
}
3737

38-
func (b *BootstrapableTest) Clear() error {
38+
func (b *BootstrapableTest) Clear(ctx context.Context) error {
3939
if b.ClearF != nil {
40-
return b.ClearF()
40+
return b.ClearF(ctx)
4141
}
4242
if b.CantClear && b.T != nil {
4343
require.FailNow(b.T, errClear.Error())

snow/engine/common/traced_bootstrapable_engine.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func (e *tracedBootstrapableEngine) ForceAccepted(ctx context.Context, acceptedC
3838
return e.bootstrapableEngine.ForceAccepted(ctx, acceptedContainerIDs)
3939
}
4040

41-
func (e *tracedBootstrapableEngine) Clear() error {
42-
return e.bootstrapableEngine.Clear()
41+
func (e *tracedBootstrapableEngine) Clear(ctx context.Context) error {
42+
ctx, span := e.tracer.Start(ctx, "tracedBootstrapableEngine.Clear")
43+
defer span.End()
44+
45+
return e.bootstrapableEngine.Clear(ctx)
4346
}

snow/engine/snowman/bootstrap/bootstrapper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ func (b *bootstrapper) markUnavailable(nodeID ids.NodeID) {
412412
}
413413
}
414414

415-
func (b *bootstrapper) Clear() error {
415+
func (b *bootstrapper) Clear(context.Context) error {
416+
b.Ctx.Lock.Lock()
417+
defer b.Ctx.Lock.Unlock()
418+
416419
if err := b.Config.Blocked.Clear(); err != nil {
417420
return err
418421
}

snow/engine/snowman/syncer/state_syncer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,5 +625,8 @@ func (ss *stateSyncer) IsEnabled(ctx context.Context) (bool, error) {
625625
return false, nil
626626
}
627627

628+
ss.Ctx.Lock.Lock()
629+
defer ss.Ctx.Lock.Unlock()
630+
628631
return ss.stateSyncVM.StateSyncEnabled(ctx)
629632
}

snow/networking/handler/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,10 @@ func (h *handler) selectStartingGear(ctx context.Context) (common.Engine, error)
216216
}
217217

218218
// drop bootstrap state from previous runs before starting state sync
219-
return engines.StateSyncer, engines.Bootstrapper.Clear()
219+
return engines.StateSyncer, engines.Bootstrapper.Clear(ctx)
220220
}
221221

222222
func (h *handler) Start(ctx context.Context, recoverPanic bool) {
223-
h.ctx.Lock.Lock()
224223
gear, err := h.selectStartingGear(ctx)
225224
if err != nil {
226225
h.ctx.Lock.Unlock()
@@ -232,6 +231,7 @@ func (h *handler) Start(ctx context.Context, recoverPanic bool) {
232231
return
233232
}
234233

234+
h.ctx.Lock.Lock()
235235
err = gear.Start(ctx, 0)
236236
h.ctx.Lock.Unlock()
237237
if err != nil {

0 commit comments

Comments
 (0)