Skip to content

Commit

Permalink
Remove remaning method to update poet servers (#5211)
Browse files Browse the repository at this point in the history
Clean up leftovers missed in #5209.
  • Loading branch information
poszu committed Nov 1, 2023
1 parent 47b74be commit 6957575
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 75 deletions.
94 changes: 23 additions & 71 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package activation

import (
"context"
"encoding/hex"
"errors"
"fmt"
"io/fs"
Expand Down Expand Up @@ -68,8 +67,7 @@ type Config struct {
// it is responsible for initializing post, receiving poet proof and orchestrating nipst. after which it will
// calculate total weight and providing relevant view as proof.
type Builder struct {
pendingPoetClients atomic.Pointer[[]poetClient]
started atomic.Bool
started atomic.Bool

eg errgroup.Group

Expand All @@ -91,15 +89,14 @@ type Builder struct {
smeshingMutex sync.Mutex

// pendingATX is created with current commitment and nipost from current challenge.
pendingATX *types.ActivationTx
layerClock layerClock
syncer syncer
log log.Logger
parentCtx context.Context
stop context.CancelFunc
poetCfg PoetConfig
poetRetryInterval time.Duration
poetClientInitializer PoETClientInitializer
pendingATX *types.ActivationTx
layerClock layerClock
syncer syncer
log log.Logger
parentCtx context.Context
stop context.CancelFunc
poetCfg PoetConfig
poetRetryInterval time.Duration
}

// BuilderOption ...
Expand All @@ -113,16 +110,6 @@ func WithPoetRetryInterval(interval time.Duration) BuilderOption {
}
}

// PoETClientInitializer interfaces for creating PoetProvingServiceClient.
type PoETClientInitializer func(string, PoetConfig) (poetClient, error)

// WithPoETClientInitializer modifies initialization logic for PoET client. Used during client update.
func WithPoETClientInitializer(initializer PoETClientInitializer) BuilderOption {
return func(b *Builder) {
b.poetClientInitializer = initializer
}
}

// WithContext modifies parent context for background job.
func WithContext(ctx context.Context) BuilderOption {
return func(b *Builder) {
Expand Down Expand Up @@ -158,21 +145,20 @@ func NewBuilder(
opts ...BuilderOption,
) *Builder {
b := &Builder{
parentCtx: context.Background(),
signer: signer,
nodeID: nodeID,
coinbaseAccount: conf.CoinbaseAccount,
goldenATXID: conf.GoldenATXID,
regossipInterval: conf.RegossipInterval,
cdb: cdb,
publisher: publisher,
postService: postService,
nipostBuilder: nipostBuilder,
layerClock: layerClock,
syncer: syncer,
log: log,
poetRetryInterval: defaultPoetRetryInterval,
poetClientInitializer: defaultPoetClientFunc,
parentCtx: context.Background(),
signer: signer,
nodeID: nodeID,
coinbaseAccount: conf.CoinbaseAccount,
goldenATXID: conf.GoldenATXID,
regossipInterval: conf.RegossipInterval,
cdb: cdb,
publisher: publisher,
postService: postService,
nipostBuilder: nipostBuilder,
layerClock: layerClock,
syncer: syncer,
log: log,
poetRetryInterval: defaultPoetRetryInterval,
}
for _, opt := range opts {
opt(b)
Expand Down Expand Up @@ -471,40 +457,6 @@ func (b *Builder) buildNIPostChallenge(ctx context.Context) (*types.NIPostChalle
return challenge, nil
}

// UpdatePoETServers updates poet client. Context is used to verify that the target is responsive.
func (b *Builder) UpdatePoETServers(ctx context.Context, endpoints []string) error {
b.log.WithContext(ctx).With().Debug("request to update poet services",
log.Array("endpoints", log.ArrayMarshalerFunc(func(encoder log.ArrayEncoder) error {
for _, endpoint := range endpoints {
encoder.AppendString(endpoint)
}
return nil
})))

clients := make([]poetClient, 0, len(endpoints))
for _, endpoint := range endpoints {
client, err := b.poetClientInitializer(endpoint, b.poetCfg)
if err != nil {
return &PoetSvcUnstableError{source: fmt.Errorf("initial poet client '%s': %w", endpoint, err)}
}
// TODO(dshulyak) not enough information to verify that PoetServiceID matches with an expected one.
// Maybe it should be provided during update.
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
sid, err := client.PoetServiceID(ctx)
if err != nil {
return &PoetSvcUnstableError{source: fmt.Errorf("failed to query poet '%s' for ID: %w", endpoint, err)}
}
b.log.WithContext(ctx).
With().
Debug("preparing to update poet service", log.String("poet_id", hex.EncodeToString(sid.ServiceID)))
clients = append(clients, client)
}

b.pendingPoetClients.Store(&clients)
return nil
}

// SetCoinbase sets the address rewardAddress to be the coinbase account written into the activation transaction
// the rewards for blocks made by this miner will go to this address.
func (b *Builder) SetCoinbase(rewardAddress types.Address) {
Expand Down
4 changes: 0 additions & 4 deletions activation/poet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ type HTTPPoetClient struct {
logger *zap.Logger
}

func defaultPoetClientFunc(address string, cfg PoetConfig) (poetClient, error) {
return NewHTTPPoetClient(address, cfg)
}

func checkRetry(ctx context.Context, resp *http.Response, err error) (bool, error) {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return true, nil
Expand Down

0 comments on commit 6957575

Please sign in to comment.