Skip to content

Commit

Permalink
fix dependency cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Apr 20, 2024
1 parent 9b4aa4c commit c8d879b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 11 additions & 5 deletions nodebuilder/header/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,32 @@ func newP2PExchange[H libhead.Header[H]](
// newSyncer constructs new Syncer for headers.
func newSyncer[H libhead.Header[H]](
ex libhead.Exchange[H],
fservice libfraud.Service[H],
store libhead.Store[H],
sub libhead.Subscriber[H],
cfg Config,
) (*sync.Syncer[H], *modfraud.ServiceBreaker[*sync.Syncer[H], H], error) {
) (*sync.Syncer[H], error) {
opts := []sync.Option{sync.WithParams(cfg.Syncer), sync.WithBlockTime(modp2p.BlockTime)}
if MetricsEnabled {
opts = append(opts, sync.WithMetrics())
}

syncer, err := sync.NewSyncer[H](ex, store, sub, opts...)
if err != nil {
return nil, nil, err
return nil, err
}

return syncer, &modfraud.ServiceBreaker[*sync.Syncer[H], H]{
return syncer, nil
}

func newFraudedSyncer[H libhead.Header[H]](
fservice libfraud.Service[H],
syncer *sync.Syncer[H],
) *modfraud.ServiceBreaker[*sync.Syncer[H], H] {
return &modfraud.ServiceBreaker[*sync.Syncer[H], H]{
Service: syncer,
FraudType: byzantine.BadEncoding,
FraudServ: fservice,
}, nil
}
}

// newInitStore constructs an initialized store
Expand Down
4 changes: 3 additions & 1 deletion nodebuilder/header/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func ConstructModule[H libhead.Header[H]](tp node.Type, cfg *Config) fx.Option {
fx.Provide(func(subscriber *p2p.Subscriber[H]) libhead.Subscriber[H] {
return subscriber
}),
fx.Provide(newSyncer[H]),
fx.Provide(fx.Annotate(
newSyncer[H],
newFraudedSyncer[H],
fx.OnStart(func(
ctx context.Context,
breaker *modfraud.ServiceBreaker[*sync.Syncer[H], H],
Expand All @@ -49,6 +50,7 @@ func ConstructModule[H libhead.Header[H]](tp node.Type, cfg *Config) fx.Option {
return breaker.Stop(ctx)
}),
)),
fx.Invoke(func(*modfraud.ServiceBreaker[*sync.Syncer[H], H]) {}), // ensure ServiceBreaker is constructed
fx.Provide(fx.Annotate(
func(ps *pubsub.PubSub, network modp2p.Network) (*p2p.Subscriber[H], error) {
opts := []p2p.SubscriberOption{p2p.WithSubscriberNetworkID(network.String())}
Expand Down

0 comments on commit c8d879b

Please sign in to comment.