Skip to content

Commit

Permalink
[Functions] Fix missing items in subscriptions checker (#10696)
Browse files Browse the repository at this point in the history
1. Add a nil-check when constructing the plugin
2. Include subscriptions in Start/Close methods of both handlers
  • Loading branch information
bolekk authored Sep 19, 2023
1 parent eba9a27 commit 844516f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
13 changes: 10 additions & 3 deletions core/services/functions/connector_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"

"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/api"
Expand Down Expand Up @@ -92,13 +94,18 @@ func (h *functionsConnectorHandler) HandleGatewayMessage(ctx context.Context, ga

func (h *functionsConnectorHandler) Start(ctx context.Context) error {
return h.StartOnce("FunctionsConnectorHandler", func() error {
return h.allowlist.Start(ctx)
if err := h.allowlist.Start(ctx); err != nil {
return err
}
return h.subscriptions.Start(ctx)
})
}

func (h *functionsConnectorHandler) Close() error {
return h.StopOnce("FunctionsConnectorHandler", func() error {
return h.allowlist.Close()
return h.StopOnce("FunctionsConnectorHandler", func() (err error) {
err = multierr.Combine(err, h.allowlist.Close())
err = multierr.Combine(err, h.subscriptions.Close())
return
})
}

Expand Down
2 changes: 2 additions & 0 deletions core/services/functions/connector_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestFunctionsConnectorHandler(t *testing.T) {
require.NoError(t, err)
allowlist.On("Start", mock.Anything).Return(nil)
allowlist.On("Close", mock.Anything).Return(nil)
subscriptions.On("Start", mock.Anything).Return(nil)
subscriptions.On("Close", mock.Anything).Return(nil)
handler, err := functions.NewFunctionsConnectorHandler(addr.Hex(), privateKey, storage, allowlist, rateLimiter, subscriptions, *assets.NewLinkFromJuels(0), logger)
require.NoError(t, err)

Expand Down
17 changes: 14 additions & 3 deletions core/services/gateway/handlers/functions/handler.functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
Expand Down Expand Up @@ -290,7 +291,14 @@ func (h *functionsHandler) Start(ctx context.Context) error {
return h.StartOnce("FunctionsHandler", func() error {
h.lggr.Info("starting FunctionsHandler")
if h.allowlist != nil {
return h.allowlist.Start(ctx)
if err := h.allowlist.Start(ctx); err != nil {
return err
}
}
if h.subscriptions != nil {
if err := h.subscriptions.Start(ctx); err != nil {
return err
}
}
return nil
})
Expand All @@ -300,8 +308,11 @@ func (h *functionsHandler) Close() error {
return h.StopOnce("FunctionsHandler", func() (err error) {
close(h.chStop)
if h.allowlist != nil {
return h.allowlist.Close()
err = multierr.Combine(err, h.allowlist.Close())
}
return nil
if h.subscriptions != nil {
err = multierr.Combine(err, h.subscriptions.Close())
}
return
})
}
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/functions/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func NewFunctionsServices(functionsOracleArgs, thresholdOracleArgs, s4OracleArgs
}
allServices = append(allServices, job.NewServiceAdapter(functionsReportingPluginOracle))

if pluginConfig.GatewayConnectorConfig != nil && s4Storage != nil && pluginConfig.OnchainAllowlist != nil && pluginConfig.RateLimiter != nil {
if pluginConfig.GatewayConnectorConfig != nil && s4Storage != nil && pluginConfig.OnchainAllowlist != nil && pluginConfig.RateLimiter != nil && pluginConfig.OnchainSubscriptions != nil {
allowlist, err2 := gwFunctions.NewOnchainAllowlist(conf.Chain.Client(), *pluginConfig.OnchainAllowlist, conf.Logger)
if err2 != nil {
return nil, errors.Wrap(err, "failed to create OnchainAllowlist")
Expand Down

0 comments on commit 844516f

Please sign in to comment.