Skip to content

Commit

Permalink
Merge pull request #313 from spacemeshos/remove-reset-config-flag
Browse files Browse the repository at this point in the history
Remove --norecovery and --reset flags
  • Loading branch information
poszu authored Jun 27, 2023
2 parents 58a3564 + 21c20dd commit af1a560
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 86 deletions.
27 changes: 5 additions & 22 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Config struct {
EpochDuration time.Duration `long:"epoch-duration" description:"Epoch duration"`
PhaseShift time.Duration `long:"phase-shift"`
CycleGap time.Duration `long:"cycle-gap"`
NoRecovery bool `long:"norecovery" description:"whether to disable a potential recovery procedure"`
Reset bool `long:"reset" description:"whether to reset the service state by deleting the datadir"`

InitialPowChallenge string `long:"pow-challenge" description:"The initial PoW challenge for the first round"`
PowDifficulty uint `long:"pow-difficulty" description:"PoW difficulty (in the number of leading zero bits)"`
Expand Down Expand Up @@ -144,18 +142,6 @@ func NewService(ctx context.Context, cfg *Config, datadir string, opts ...Option
zap.Duration("phase shift", cfg.PhaseShift),
)

if cfg.Reset {
entries, err := os.ReadDir(datadir)
if err != nil {
return nil, err
}
for _, entry := range entries {
if err := os.RemoveAll(filepath.Join(datadir, entry.Name())); err != nil {
return nil, err
}
}
}

state, err := loadServiceState(datadir)
if err != nil {
if !errors.Is(err, ErrFileIsMissing) {
Expand Down Expand Up @@ -346,14 +332,11 @@ func (s *Service) scheduleRound(ctx context.Context, round *round) <-chan time.T
// It stops when the `ctx` is canceled.
func (s *Service) Run(ctx context.Context) error {
var toResume *round
if s.cfg.NoRecovery {
logging.FromContext(ctx).Info("Recovery is disabled")
} else {
var err error
s.openRound, toResume, err = s.recover(ctx)
if err != nil {
return fmt.Errorf("failed to recover: %v", err)
}

var err error
s.openRound, toResume, err = s.recover(ctx)
if err != nil {
return fmt.Errorf("failed to recover: %v", err)
}

return s.loop(ctx, toResume)
Expand Down
64 changes: 0 additions & 64 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,70 +510,6 @@ func TestService_Recovery_MissingOpenRound(t *testing.T) {
req.NoError(eg.Wait())
}

// Test if `reset` flag works.
// Scenario:
// - run Service and wait for round 0 to start executing,
// - shutdown the Service
// - restart Service with reset flag == true
// - expect the persisted state to be discarded:
// - round 0 should not exist
// - round 1 should be open
func TestService_Recovery_Reset(t *testing.T) {
t.Parallel()
req := require.New(t)
cfg := &service.Config{
Genesis: service.Genesis(time.Now().Add(time.Second)),
EpochDuration: time.Hour,
Reset: true,
}
tempdir := t.TempDir()

// Create a new service instance.
s, err := service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var eg errgroup.Group
eg.Go(func() error { return s.Run(ctx) })
req.NoError(s.Start(context.Background()))

// Wait for round 0 to start executing.
req.Eventually(func() bool {
info, err := s.Info(context.Background())
req.NoError(err)
return info.ExecutingRoundId != nil && *info.ExecutingRoundId == "0"
}, cfg.EpochDuration*2, time.Millisecond*100)

cancel()
req.NoError(eg.Wait())

time.Sleep(time.Second)

// Create a new service instance.
s, err = service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

ctx, cancel = context.WithCancel(context.Background())
defer cancel()
eg = errgroup.Group{}
eg.Go(func() error {
err := s.Run(ctx)
assert.NoError(t, err)
cancel()
return err
})

// Service instance should not recover the round 0 in-execution.
info, err := s.Info(ctx)
req.NoError(err)
req.Equal("1", info.OpenRoundID)
req.Empty(info.ExecutingRoundId)

cancel()
req.NoError(eg.Wait())
}

// Test if Proof of Work challenge is rotated every round.
// The challenge should be changed to the root of PoET proof Merkle tree
// of the previous round.
Expand Down

0 comments on commit af1a560

Please sign in to comment.