Skip to content

Commit

Permalink
Remove keys from the worker svc
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Sep 7, 2023
1 parent 5a527d6 commit 5f5e624
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
1 change: 0 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func New(ctx context.Context, cfg config.Config) (*Server, error) {
transport,
service.WithConfig(cfg.Service),
service.WithRoundConfig(cfg.Round),
service.WithPrivateKey(privateKey),
)
if err != nil {
return nil, fmt.Errorf("failed to create Service: %v", err)
Expand Down
31 changes: 8 additions & 23 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
"context"
"crypto/ed25519"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -32,8 +31,6 @@ type Service struct {
roundCfg round_config.Config
datadir string
minMemoryLayer uint

privKey ed25519.PrivateKey
}

type ClosedRound struct {
Expand All @@ -47,19 +44,12 @@ type RegistrationService interface {
}

type newServiceOption struct {
privateKey ed25519.PrivateKey
cfg Config
roundCfg round_config.Config
cfg Config
roundCfg round_config.Config
}

type newServiceOptionFunc func(*newServiceOption)

func WithPrivateKey(privateKey ed25519.PrivateKey) newServiceOptionFunc {
return func(o *newServiceOption) {
o.privateKey = privateKey
}
}

func WithConfig(cfg Config) newServiceOptionFunc {
return func(o *newServiceOption) {
o.cfg = cfg
Expand Down Expand Up @@ -88,14 +78,6 @@ func NewService(
for _, opt := range opts {
opt(options)
}
if options.privateKey == nil {
logging.FromContext(ctx).Info("generating new private key")
_, privateKey, err := ed25519.GenerateKey(nil)
if err != nil {
return nil, fmt.Errorf("generating key: %w", err)
}
options.privateKey = privateKey
}

estimatedLeaves := uint64(options.roundCfg.RoundDuration().Seconds()) * uint64(options.cfg.EstimatedLeavesPerSecond)
minMemoryLayer := uint(0)
Expand All @@ -116,12 +98,15 @@ func NewService(
roundCfg: options.roundCfg,
minMemoryLayer: minMemoryLayer,
datadir: datadir,
privKey: options.privateKey,
registration: registration,
}

logging.FromContext(ctx).
Info("created poet worker service", zap.Binary("pubkey", s.privKey.Public().(ed25519.PublicKey)), zap.Time("genesis", s.genesis), zap.Uint("min memory layer", s.minMemoryLayer), zap.Object("round config", s.roundCfg))
logging.FromContext(ctx).Info(
"created poet worker service",
zap.Time("genesis", s.genesis),
zap.Uint("min memory layer", s.minMemoryLayer),
zap.Object("round config", s.roundCfg),
)

return s, nil
}
Expand Down

0 comments on commit 5f5e624

Please sign in to comment.