8000 Allow running registration service only by poszu · Pull Request #417 · spacemeshos/poet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow running registration service only #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions registration/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (

"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/poet/logging"
"github.com/spacemeshos/poet/registration"
"github.com/spacemeshos/poet/registration/mocks"
"github.com/spacemeshos/poet/server"
"github.com/spacemeshos/poet/shared"
"github.com/spacemeshos/poet/transport"
)

func TestSubmitIdempotence(t *testing.T) {
Expand Down Expand Up @@ -137,6 +140,34 @@ func TestOpeningRounds(t *testing.T) {
})
}

func TestWorkingWithoutWorkerService(t *testing.T) {
t.Parallel()

reg, err := registration.New(
context.Background(),
time.Now(),
t.TempDir(),
transport.NewInMemory(),
&server.RoundConfig{EpochDuration: time.Millisecond * 10},
)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, reg.Close()) })

var eg errgroup.Group
ctx, cancel := context.WithCancel(logging.NewContext(context.Background(), zaptest.NewLogger(t)))
defer cancel()
eg.Go(func() error { return reg.Run(ctx) })

// Verify that registration keeps opening rounds even without the worker service.
// Only check if the round number is incremented to not rely on the exact timing.
for i := 0; i < 3; i++ {
round := reg.OpenRound()
require.Eventually(t, func() bool { return reg.OpenRound() > round }, time.Second, time.Millisecond*10)
}
cancel()
require.NoError(t, 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
8 changes: 7 additions & 1 deletion registration/round.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,13 @@ func (r *round) getMembers() (members [][]byte) {
return members
}

// Close the round.
// Flushes pending submits and closes the DB.
// It's safe to call Close multiple times.
func (r *round) Close() error {
r.flushPendingSubmits()
return r.db.Close()
if err := r.db.Close(); err != nil && !errors.Is(err, leveldb.ErrClosed) {
return err
}
return nil
}
3 changes: 3 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Config struct {
Round *RoundConfig `group:"Round"`
Registration registration.Config `group:"Registration"`
Service service.Config `group:"Service"`

DisableWorker bool `long:"disable-worker" description:"Whether to disable worker service for PoSW"`
}

type Genesis time.Time
Expand Down Expand Up @@ -92,6 +94,7 @@ func DefaultConfig() *Config {
Round: DefaultRoundConfig(),
Registration: registration.DefaultConfig(),
Service: service.DefaultConfig(),
DisableWorker: false,
}
}

Expand Down
12 changes: 9 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,19 @@ func (s *Server) Start(ctx context.Context) error {
),
)

logger.Info("starting registration service")
serverGroup.Go(func() error {
return s.reg.Run(ctx)
})

serverGroup.Go(func() error {
return s.svc.Run(ctx)
})
if !s.cfg.DisableWorker {
logger.Info("starting PoSW worker service")
serverGroup.Go(func() error {
return s.svc.Run(ctx)
})
} else {
logger.Info("PoSW worker service is disabled")
}

rpcServer := rpc.NewServer(s.svc, s.reg, s.cfg.Round.PhaseShift, s.cfg.Round.CycleGap)
grpcServer := grpc.NewServer(
Expand Down
3 changes: 3 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestInfoEndpoint(t *testing.T) {
ctx = logging.NewContext(ctx, zaptest.NewLogger(t))

cfg := server.DefaultConfig()
cfg.DisableWorker = true
cfg.PoetDir = t.TempDir()
cfg.RawRPCListener = randomHost
cfg.RawRESTListener = randomHost
Expand Down Expand Up @@ -98,6 +99,7 @@ func TestSubmitSignatureVerification(t *testing.T) {
ctx = logging.NewContext(ctx, zaptest.NewLogger(t))

cfg := server.DefaultConfig()
cfg.DisableWorker = true
cfg.PoetDir = t.TempDir()
cfg.RawRPCListener = randomHost
cfg.RawRESTListener = randomHost
Expand Down Expand Up @@ -148,6 +150,7 @@ func TestSubmitPowVerification(t *testing.T) {
ctx = logging.NewContext(ctx, zaptest.NewLogger(t))

cfg := server.DefaultConfig()
cfg.DisableWorker = true
cfg.PoetDir = t.TempDir()
cfg.RawRPCListener = randomHost
cfg.RawRESTListener = randomHost
Expand Down
4 changes: 4 additions & 0 deletions transport/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transport
import (
"context"

"github.com/spacemeshos/poet/logging"
"github.com/spacemeshos/poet/registration"
"github.com/spacemeshos/poet/service"
"github.com/spacemeshos/poet/shared"
Expand Down Expand Up @@ -38,6 +39,9 @@ func (m *inMemory) ExecuteRound(ctx context.Context, epoch uint, membershipRoot
return nil
case <-ctx.Done():
return ctx.Err()
default:
logging.FromContext(ctx).Info("nobody listens to closed rounds - dropping")
return nil
}
}

Expand Down
0