Skip to content

Commit

Permalink
pkg/loop: clean up background contexts (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 10, 2024
1 parent 2fd6491 commit d1831b6
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/loop/ccip_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewCommitService(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec.Cm
}

func (m *CommitFactoryService) NewReportingPlugin(ctx context.Context, config ocrtypes.ReportingPluginConfig) (ocrtypes.ReportingPlugin, ocrtypes.ReportingPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocrtypes.ReportingPluginInfo{}, err
}
return m.Service.NewReportingPlugin(ctx, config)
Expand Down
2 changes: 1 addition & 1 deletion pkg/loop/ccip_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewExecutionService(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec
}

func (m *ExecutionFactoryService) NewReportingPlugin(ctx context.Context, config ocrtypes.ReportingPluginConfig) (ocrtypes.ReportingPlugin, ocrtypes.ReportingPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocrtypes.ReportingPluginInfo{}, err
}
return m.Service.NewReportingPlugin(ctx, config)
Expand Down
5 changes: 0 additions & 5 deletions pkg/loop/internal/goplugin/plugin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,6 @@ func (s *PluginService[P, S]) WaitCtx(ctx context.Context) error {
}
}

// Wait is the context-ignorant version of WaitCtx above.
func (s *PluginService[P, S]) Wait() error {
return s.WaitCtx(context.Background())
}

// XXXTestHook returns a TestPluginService.
// It must only be called once, and before Start.
func (s *PluginService[P, S]) XXXTestHook() TestPluginService[P, S] {
Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/internal/relayerset/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (r *relayerClient) Name() string {
return name
}

func (r *relayerClient) LatestHead(_ context.Context) (types.Head, error) {
latestHead, err := r.relayerSetClient.RelayerLatestHead(context.Background(), r.relayerID)
func (r *relayerClient) LatestHead(ctx context.Context) (types.Head, error) {
latestHead, err := r.relayerSetClient.RelayerLatestHead(ctx, r.relayerID)
if err != nil {
r.log.Error("error getting latestHead", "error", err)
return types.Head{}, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/loop/median_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewMedianService(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec.Cm
}

func (m *MedianService) NewReportingPlugin(ctx context.Context, config ocrtypes.ReportingPluginConfig) (ocrtypes.ReportingPlugin, ocrtypes.ReportingPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocrtypes.ReportingPluginInfo{}, err
}
return m.Service.NewReportingPlugin(ctx, config)
Expand Down
8 changes: 4 additions & 4 deletions pkg/loop/mercury_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewMercuryV4Service(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec
}

func (m *MercuryV4Service) NewMercuryPlugin(ctx context.Context, config ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocr3types.MercuryPluginInfo{}, err
}
return m.Service.NewMercuryPlugin(ctx, config)
Expand Down Expand Up @@ -78,7 +78,7 @@ func NewMercuryV3Service(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec
}

func (m *MercuryV3Service) NewMercuryPlugin(ctx context.Context, config ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocr3types.MercuryPluginInfo{}, err
}
return m.Service.NewMercuryPlugin(ctx, config)
Expand Down Expand Up @@ -110,7 +110,7 @@ func NewMercuryV1Service(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec
}

func (m *MercuryV1Service) NewMercuryPlugin(ctx context.Context, config ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocr3types.MercuryPluginInfo{}, err
}
return m.Service.NewMercuryPlugin(ctx, config)
Expand Down Expand Up @@ -144,7 +144,7 @@ func NewMercuryV2Service(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec
}

func (m *MercuryV2Service) NewMercuryPlugin(ctx context.Context, config ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) {
if err := m.Wait(); err != nil {
if err := m.WaitCtx(ctx); err != nil {
return nil, ocr3types.MercuryPluginInfo{}, err
}
return m.Service.NewMercuryPlugin(ctx, config)
Expand Down
4 changes: 2 additions & 2 deletions pkg/loop/reportingplugins/loopp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewLOOPPService(
}

func (g *LOOPPService) NewReportingPlugin(ctx context.Context, config ocrtypes.ReportingPluginConfig) (ocrtypes.ReportingPlugin, ocrtypes.ReportingPluginInfo, error) {
if err := g.Wait(); err != nil {
if err := g.WaitCtx(ctx); err != nil {
return nil, ocrtypes.ReportingPluginInfo{}, err
}
return g.Service.NewReportingPlugin(ctx, config)
Expand All @@ -87,7 +87,7 @@ func NewLOOPPServiceValidation(
}

func (g *LOOPPServiceValidation) ValidateConfig(ctx context.Context, config map[string]interface{}) error {
if err := g.Wait(); err != nil {
if err := g.WaitCtx(ctx); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/loop/reportingplugins/ocr3/loopp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewLOOPPService(
}

func (g *LOOPPService) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[[]byte], ocr3types.ReportingPluginInfo, error) {
if err := g.Wait(); err != nil {
if err := g.WaitCtx(ctx); err != nil {
return nil, ocr3types.ReportingPluginInfo{}, err
}
return g.Service.NewReportingPlugin(ctx, config)
Expand Down

0 comments on commit d1831b6

Please sign in to comment.