Skip to content

Commit

Permalink
activation: stopping smeshing while initializing tries to generate pr…
Browse files Browse the repository at this point in the history
…oof (#4706)

## Motivation
When a smesher pauses initialization the code will try to generate a proof and fail with error "post setup incomplete"

## Changes
When initialization is paused do not try to generate a proof.

## Test Plan
Test was added that fails without the change and passes with the change.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)
  • Loading branch information
fasmat committed Jul 14, 2023
1 parent 7cc743a commit 85b3ad2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,18 @@ func (b *Builder) StartSmeshing(coinbase types.Address, opts PostSetupOpts) erro

select {
case <-ctx.Done():
return ctx.Err()
return nil
case <-b.syncer.RegisterForATXSynced():
// ensure we are ATX synced before starting the PoST Session
}

// If start session returns any error other than context.Canceled
// (which is how we signal it to stop) then we panic.
if err := b.postSetupProvider.StartSession(ctx); err != nil && !errors.Is(err, context.Canceled) {
err := b.postSetupProvider.StartSession(ctx)
switch {
case errors.Is(err, context.Canceled):
return nil
case err != nil:
b.log.Panic("initialization failed: %v", err)
}

Expand Down
16 changes: 16 additions & 0 deletions activation/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ func TestBuilder_RestartSmeshing(t *testing.T) {
})
}

func TestBuilder_StoppingSmeshingBefore_Initialized(t *testing.T) {
tab := newTestBuilder(t)
tab.mpost.EXPECT().PrepareInitializer(gomock.Any(), gomock.Any()).AnyTimes()
tab.mpost.EXPECT().StartSession(gomock.Any()).DoAndReturn(func(ctx context.Context) error {
// wait for stop to be called
<-ctx.Done()
return ctx.Err()
}).AnyTimes()

require.NoError(t, tab.StartSmeshing(types.Address{}, PostSetupOpts{}))
require.NoError(t, tab.StopSmeshing(false))

// no calls to GenerateProof after stopping
require.NoError(t, tab.eg.Wait()) // returns without error (StartSmeshing can be called again)
}

func TestBuilder_StartSmeshing_PanicsOnErrInStartSession(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down

0 comments on commit 85b3ad2

Please sign in to comment.